The Linear Mixed-Effects Model The R Statistical Computing Environment Basics and Beyond The Laird-Ware form of the linear mixed model: Mixed-Effects Models y ij = β 1 + β 2 x 2 ij + · · · + β p x pij + b 1 i z 1 ij + · · · + b qi z qij + ε ij N ( 0, ψ 2 ∼ k ) , Cov ( b ki , b k ′ i ) = ψ kk ′ b ki John Fox b ki , b k ′ i ′ are independent for i � = i ′ N ( 0, σ 2 λ ijj ) , Cov ( ε ij , ε ij ′ ) = σ 2 λ ijj ′ ∼ ε ij McMaster University ε ij , ε i ′ j ′ are independent for i � = i ′ ICPSR/Berkeley 2016 John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 1 / 13 John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 2 / 13 The Linear Mixed-Effects Model The Linear Mixed-Effects Model and: where: ψ 2 k are the variances and ψ kk ′ the covariances among the random y ij is the value of the response variable for the j th of n i observations in effects, assumed to be constant across groups. the i th of M groups or clusters. In some applications, the ψ ’s are parametrized in terms of a smaller β 1 , β 2 , . . . , β p are the fixed-effect coefficients, which are identical for number of fundamental parameters. all groups. ε ij is the error for observation j in group i . x 2 ij , . . . , x pij are the fixed-effect regressors for observation j in group i ; The errors for group i are assumed to be multivariately normally there is also implicitly a constant regressor, x 1 ij = 1. distributed, and independent of errors in other groups. b 1 i , . . . , b qi are the random-effect coefficients for group i , assumed to σ 2 λ ijj ′ are the covariances between errors in group i . be multivariately normally distributed, independent of the random effects of other groups. The random effects, therefore, vary by group. Generally, the λ ijj ′ are parametrized in terms of a few basic parameters, and their specific form depends upon context. The b ik are thought of as random variables, not as parameters, and are When observations are sampled independently within groups and are similar in this respect to the errors ε ij . assumed to have constant error variance (as is typical in hierarchical models), λ ijj = 1, λ ijj ′ = 0 (for j � = j ′ ), and thus the only free z 1 ij , . . . , z qij are the random-effect regressors. parameter to estimate is the common error variance, σ 2 . The z ’s are almost always a subset of the x ’s (and may include all of If the observations in a “group” represent longitudinal data on a single the x ’s). individual, then the structure of the λ ’s may be specified to capture When there is a random intercept term, z 1 ij = 1. serial (i.e., over-time) dependencies among the errors. John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 3 / 13 John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 4 / 13
Fitting Mixed Models in R A Mixed Model for the Exercise Data with the nlme and lme4 packages Longitudinal Model A level-1 model specifying a linear “growth curve” for log exercise for each subject: In the nlme package (Pinheiro, Bates, DebRoy, and Sarkar): log -exercise ij = α 0 i + α 1 i ( age ij − 8 ) + ε ij lme : linear mixed-effects models with nested random effects; can model serially correlated errors. nlme : nonlinear mixed-effects models. Our interest in detecting differences in exercise histories between subjects and controls suggests the level-2 model In the lme4 package (Bates, Maechler, Bolker, and Walker): lmer : linear mixed-effects models with nested or crossed random α 0 i = γ 00 + γ 01 group i + ω 0 i effects; no facility for serially correlated errors. α 1 i = γ 10 + γ 11 group i + ω 1 i glmer : generalized-linear mixed-effects models. where group is a dummy variable coded 1 for subjects and 0 for controls. John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 5 / 13 John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 6 / 13 A Mixed Model for the Exercise Data A Mixed Model for the Exercise Data Laird-Ware form of the Model Specifying the Model in lme Substituting the level-2 model into the level-1 model produces log -exercise ij = ( γ 00 + γ 01 group i + ω 0 i ) + ( γ 10 + γ 11 group i + ω 1 i )( age ij − 8 ) + ε ij = γ 00 + γ 01 group i + γ 10 ( age ij − 8 ) Using lme in the nlme package: + γ 11 group i × ( age ij − 8 ) lme(log.exercise ~ I(age - 8)*group, + ω 0 i + ω 1 i ( age ij − 8 ) + ε ij random = ~ I(age - 8) | subject, correlation = corCAR1(form = ~ age |subject) in Laird-Ware form, data=Blackmoor) Y ij = β 1 + β 2 x 2 ij + β 3 x 3 ij + β 4 x 4 ij + δ 1 i + δ 2 i z 2 ij + ε ij Continuous first-order autoregressive process for the errors: Cor ( ε it , ε i , t + s ) = ρ ( s ) = φ | s | where the time-interval between observations, s , need not be an integer. John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 7 / 13 John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 8 / 13
A Mixed Model for the HSB Data A Mixed Model for the HSB Data Hierarchical Model Laird-Ware Form of the Model Substituting the school-level equation into the individual-level A “level-1” model for math achievement: equation produces the combined or composite model: mathach ij = α 0 i + α 1 i cses ij + ε ij mathach ij = ( γ 00 + γ 01 ses i · + γ 02 sector i + u 0 i ) where cses ij = ses ij − ses i · γ 10 + γ 11 ses i · + γ 12 ses 2 � � + i · + γ 13 sector i + u 1 i cses ij Exploration of the data suggests the following “level-2” model: + ε ij = γ 00 + γ 01 ses i · + γ 02 sector i + u 0 i α 0 i = γ 00 + γ 01 ses i · + γ 02 sector i + γ 10 cses ij γ 10 + γ 11 ses i · + γ 12 ses 2 = i · + γ 13 sector i + u 1 i α 1 i + γ 11 ses i · × cses ij + γ 12 ses 2 i · × cses ij + γ 13 sector i × cses ij where sector is a dummy variable, coded 1 (say) for Catholic schools and 0 for public schools. + u 0 i + u 1 i cses ij + ε ij John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 9 / 13 John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 10 / 13 A Mixed Model for the HSB Data A Mixed Model for the HSB Data Laird-Ware Form of the Model Laird-Ware Form of the Model Note that all explanatory variables in the Laird-Ware form of the model carry subscripts i for schools and j individuals within schools, even when the explanatory variable in question is constant within schools. Except for notation, this is a mixed model in Laird-Ware form, as we can see by replacing γ ’s with β ’s and u ’s with b ’s: Thus, for example, x 2 ij = ses i · (and so all individuals in the same school share a common value of school-mean SES). = β 1 + β 2 x 2 ij + β 3 x 3 ij + β 4 x 4 ij y ij There is both a data-management issue here and a conceptual point: + β 5 x 5 ij + β 6 x 6 ij + β 7 x 7 ij With respect to data management, software that fits the Laird-Ware + b 1 i + b 2 i z 2 ij + ε ij form of the model (such as the lme or lmer functions in R) requires that level-2 explanatory variables (here sector and school-mean SES, which are characteristics of schools) appear in the level-1 (i.e., student) data set. The conceptual point is that the model can incorporate contextual effects — characteristics of the level-2 units can influence the level-1 response variable. John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 11 / 13 John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 12 / 13
A Mixed Model for the HSB Data Specifying the Model in lmer and lme Using lmer in the lme4 package: lmer(mathach ~ meanses + poly(meanses, 2, raw=TRUE):cses + sector*cses + (cses | school), data=Bryk) Using lme in the nlme package: lme(mathach ~ meanses + poly(meanses, 2, raw=TRUE):cses + sector*cses random = ~ cses | school, data=Bryk) John Fox (McMaster University) Mixed-Effects Models ICPSR/Berkeley 2016 13 / 13
Recommend
More recommend