The linear mixed model: modeling hierarchical and longitudinal data Analysis of Experimental Data AED The linear mixed model: modeling hierarchical and longitudinal data 1 of 44
Contents 1 Modeling Hierarchical Data 3 1.1 Overview.............................. 3 1.2 Example: the High School and Beyond data........... 4 1.3 Further issues............................ 38 2 Modeling Longitudinal Data 39 2.1 Example: Reaction times in a sleep deprivation study....... 40 AED The linear mixed model: modeling hierarchical and longitudinal data 2 of 44
1 Modeling Hierarchical Data 1.1 Overview especially in education (think students in schools ), applications of mixed models to hierarchical data have become very popular when researchers in the social sciences talk about multilevel analysis, they typically mean the application of mixed models to hierarchical data typical for this type of data is the sharp distinction between levels : the student level, and the school level, where one level (student) is nested in the other (school) data often contains both student characteristics and school charateristics; in a multilevel analysis, both types of variables can be included in one analysis simultaneously AED The linear mixed model: modeling hierarchical and longitudinal data 3 of 44
1.2 Example: the High School and Beyond data the following example is borrowed from Raudenbusch and Bryk (2001, chapter 4). the data are from the 1982 High School and Beyond survey, and pertain to 7185 U.S. high-school students from 160 schools (70 catholic, 90 public) these are the variables in the dataset: school an ordered factor designating the school that the student attends. minrty a factor with 2 levels (not used) sx a factor with levels Male and Female (not used) ses a numeric vector of socio-economic scores mach a numeric vector of Mathematics achievement scores meanses a numeric vector of mean ses for the school sector a factor with levels Public and Catholic cses a numeric vector of centered ses values where the centering is with respect to the meanses for the school AED The linear mixed model: modeling hierarchical and longitudinal data 4 of 44
the aim of the analysis is to determine how students math achievement scores are related to their family socioeconomic status but this relationship may very well vary among schools if there is indeed variation among schools, can we find any school characteristics that explain this variation? the two school characteristics that we will use are: sector: public school or Catholic school meanses: the average SES of students in the school AED The linear mixed model: modeling hierarchical and longitudinal data 5 of 44
Exploring the data > library(mlmrev) > summary(hsb82) school minrty sx ses mach 2305 : 67 No :5211 Male :3390 Min. :-3.7580000 Min. :-2.832 5619 : 66 Yes:1974 Female:3795 1st Qu.:-0.5380000 1st Qu.: 7.275 4292 : 65 Median : 0.0020000 Median :13.131 8857 : 64 Mean : 0.0001434 Mean :12.748 4042 : 64 3rd Qu.: 0.6020000 3rd Qu.:18.317 3610 : 64 Max. : 2.6920000 Max. :24.993 (Other):6795 meanses sector cses Min. :-1.1939459 Public :3642 Min. :-3.651e+00 1st Qu.:-0.3230000 Catholic:3543 1st Qu.:-4.479e-01 Median : 0.0320000 Median : 1.600e-02 Mean : 0.0001434 Mean :-9.144e-19 3rd Qu.: 0.3269123 3rd Qu.: 4.694e-01 Max. : 0.8249825 Max. : 2.856e+00 > head(hsb82) school minrty sx ses mach meanses sector cses 1 1224 No Female -1.528 5.876-0.434383 Public -1.09361702 2 1224 No Female -0.588 19.708-0.434383 Public -0.15361702 AED The linear mixed model: modeling hierarchical and longitudinal data 6 of 44
3 1224 No Male -0.528 20.349-0.434383 Public -0.09361702 4 1224 No Male -0.668 8.781-0.434383 Public -0.23361702 5 1224 No Male -0.158 17.898-0.434383 Public 0.27638298 6 1224 No Male 0.022 4.583-0.434383 Public 0.45638298 > tail(hsb82) school minrty sx ses mach meanses sector cses 7180 9586 Yes Female 1.612 20.967 0.6211525 Catholic 0.9908475 7181 9586 No Female 1.512 20.402 0.6211525 Catholic 0.8908475 7182 9586 No Female -0.038 14.794 0.6211525 Catholic -0.6591525 7183 9586 No Female 1.332 19.641 0.6211525 Catholic 0.7108475 7184 9586 No Female -0.008 16.241 0.6211525 Catholic -0.6291525 7185 9586 No Female 0.792 22.733 0.6211525 Catholic 0.1708475 AED The linear mixed model: modeling hierarchical and longitudinal data 7 of 44
Exploring the data: math achievement versus ses for several schools > set.seed(1234) > library(lattice) > cat <- sample(unique(hsb82$school[hsb82$sector == "Catholic"]), + 18) > Cat.18 <- Hsb82[is.element(Hsb82$school, cat), ] > plot1 <- xyplot(mach ses school, data = Cat.18, main = "Catholic", + xlab = "student SES", ylab = "Math Achievement", layout = c(6, + 3), panel = function(x, y) { + panel.xyplot(x, y) + panel.lmline(x, y) + }) > pub <- sample(unique(hsb82$school[hsb82$sector == "Public"]), + 18) > Pub.18 <- Hsb82[is.element(Hsb82$school, pub), ] > plot2 <- xyplot(mach ses school, data = Pub.18, main = "Public", + xlab = "student SES", ylab = "Math Achievement", layout = c(6, + 3), panel = function(x, y) { + panel.xyplot(x, y) + panel.lmline(x, y) + }) AED The linear mixed model: modeling hierarchical and longitudinal data 8 of 44
Catholic student SES Math Achievement 0 5 10 15 20 25 2 1 0 1 8800 8009 2 1 0 1 4511 9347 2 1 0 1 7342 4292 8857 5667 5720 9104 8150 0 5 10 15 20 25 9359 0 5 10 15 20 25 2208 2 1 0 1 1308 2755 2 1 0 1 2990 3020 2 1 0 1 6469 AED The linear mixed model: modeling hierarchical and longitudinal data 9 of 44
Public student SES Math Achievement 0 5 10 15 20 25 2 1 0 1 8367 1358 2 1 0 1 2818 5783 2 1 0 1 3013 4350 9397 6464 2651 2467 9158 0 5 10 15 20 25 4420 0 5 10 15 20 25 7734 2 1 0 1 9225 2768 2 1 0 1 3332 3351 2 1 0 1 7697 AED The linear mixed model: modeling hierarchical and longitudinal data 10 of 44
Fitting a simple regression model for each school separately > cat.list <- lmlist(mach ses school, subset = sector == "Catholic", + data = Hsb82) > head(coef(cat.list)) (Intercept) ses 7172 8.355037 0.9944805 4868 11.845609 1.2864712 2305 10.646595-0.7821112 8800 9.157380 2.5681254 5192 10.511666 1.6034950 4523 8.479699 2.3807892 > pub.list <- lmlist(mach ses school, subset = sector == "Public", + data = Hsb82) > head(coef(pub.list)) (Intercept) ses 8367 4.546383 0.2503748 8854 5.707002 1.9388446 4458 6.999212 1.1318372 5762 3.114085-1.0140992 6990 6.440875 0.9476903 5815 9.323601 3.0180018 AED The linear mixed model: modeling hierarchical and longitudinal data 11 of 44
Catholic 7172 4868 2305 8800 5192 4523 6816 2277 8009 4530 9021 4511 6578 9347 3705 3533 4253 7342 3499 7364 5650 2658 9508 4292 8857 1317 2629 4223 1462 4931 5667 5720 3498 3688 8165 9104 8150 4042 6074 1906 3992 4173 5761 7635 2458 3610 3838 9359 2208 1477 3039 1308 1433 1436 2526 2755 2990 3020 3427 5404 5619 6366 6469 7011 7332 7688 8193 8628 9198 9586 (Intercept) ses 5 10 15 20 5 0 5 AED The linear mixed model: modeling hierarchical and longitudinal data 12 of 44
Public 8367 8854 4458 5762 6990 5815 7341 1358 4383 3088 8775 7890 6144 6443 6808 2818 9340 5783 3013 7101 2639 3377 1296 4350 9397 2655 9292 8983 8188 4410 8707 1499 8477 1288 6291 1224 3967 6415 9550 6464 5937 7919 3716 1909 2651 2467 1374 6600 3881 2995 5838 9158 8946 7232 2917 6170 2030 8357 8531 4420 3999 4325 6484 6897 7734 8175 8874 9225 5640 6089 2768 5819 6397 1461 1637 1942 1946 2336 2626 2771 3152 3332 3351 3657 4642 7276 7345 7697 8202 8627 (Intercept) ses 0 5 10 15 20 5 0 5 10 AED The linear mixed model: modeling hierarchical and longitudinal data 13 of 44
Intercepts Slopes 5 10 15 20 2 0 2 4 6 Catholic Public Catholic Public AED The linear mixed model: modeling hierarchical and longitudinal data 14 of 44
Relationship intercepts and slopes and mean school SES 1.0 0.0 0.5 5 10 15 20 Mean SES School Intercept 1.0 0.0 0.5 2 0 2 4 6 Mean SES School Slope AED The linear mixed model: modeling hierarchical and longitudinal data 15 of 44
Model 1: a random-effects one-way ANOVA this is often called the empty model, since it containts no predictors, but simply reflects the nested structure no level-1 predictors, no level-2 predictors in the multilevel notation we specify a model for each level model for the first (student) level: y ij = α 0i + ɛ ij model for the second (school) level: α 0i = γ 00 + u 0i the combined model and the Laird-Ware form: y ij = γ 00 + u 0i + ɛ ij = β 0 + b 0i + ɛ ij AED The linear mixed model: modeling hierarchical and longitudinal data 16 of 44
this is an example of a random-effects one-way ANOVA model with one fixed effect (the intercept, β 0 ) representing the general population mean of math achievement, and two random effects: b 0i representing the deviation of math achievement in school i from the general mean ɛ ij representing the deviation of individual j s math achievement in school i from the school mean there are two variance components for this model: Var(b 0i ) = d 2 : the variance among school means Var(ɛ ij ) = σ 2 : the variance among individuals in the same school since b 0i and ɛ ij are assumed to be independent, the variation in math scores among individuals can be decomposed into these two variance components: Var(y ij ) = d 2 + σ 2 AED The linear mixed model: modeling hierarchical and longitudinal data 17 of 44
R code > fit.model1 <- lmer(mach 1 + (1 school), data = Hsb82) > summary(fit.model1) Linear mixed model fit by REML Formula: mach 1 + (1 school) Data: Hsb82 AIC BIC loglik deviance REMLdev 47123 47143-23558 47116 47117 Random effects: Groups Name Variance Std.Dev. school (Intercept) 8.614 2.9350 Residual 39.148 6.2569 Number of obs: 7185, groups: school, 160 Fixed effects: Estimate Std. Error t value (Intercept) 12.6370 0.2443 51.72 AED The linear mixed model: modeling hierarchical and longitudinal data 18 of 44
Intra-class correlation the intra-class correlation coefficient is the proportion of variation in individuals scores due to differences among schools: d 2 Var(y ij ) = d2 d 2 + σ 2 = ρ ρ may also be interpreted as the correlation between the math scores of two individuals from the same school: Cor(y ij, y ij ) = > s <- summary(fit.model1) > d2 <- as.numeric(s@remat[, 3])[1] > s2 <- as.numeric(s@remat[, 3])[2] > rho <- d2/(d2 + s2) > rho [1] 0.1803526 Cov(y ij, y ij ) Var(yij ) Var(y ij ) = d2 d 2 + σ 2 = ρ AED The linear mixed model: modeling hierarchical and longitudinal data 19 of 44
about 18 percent of the variation in students match-achievement scores is attributable to differences among schools this is often called the cluster effect AED The linear mixed model: modeling hierarchical and longitudinal data 20 of 44
Model 2: a random-effects one-way ANCOVA 1 level-1 predictor (SES, centered within school), no level-2 predictors random intercept, no random slopes model for the first (student) level: y ij = α 0i + α 1i cses ij + ɛ ij model for the second (school) level: α 0i = γ 00 + u 0i α 1i = γ 10 (the random intercept) (the constant slope) the combined model and the Laird-Ware form: y ij = (γ 00 + u 0i ) + γ 10 cses ij + ɛ ij = γ 00 + γ 10 cses ij + u 0i + ɛ ij = β 0 + β 1 x 1ij + b 0i + ɛ ij AED The linear mixed model: modeling hierarchical and longitudinal data 21 of 44
the fixed-effect coefficients β 0 and β 1 represent the average within-schools population intercept and slope respectively note: because SES is centered within schools, the intercept β 0 represents the average level of math achievement in the population the model has two variance-covariance components: Var(b 0i ) = d 2 : the variance among school intercepts Var(ɛ ij ) = σ 2 : the error variance around the within-school regressions AED The linear mixed model: modeling hierarchical and longitudinal data 22 of 44
R code > fit.model2 <- lmer(mach 1 + cses + (1 school), data = Hsb82) > summary(fit.model2) Linear mixed model fit by REML Formula: mach 1 + cses + (1 school) Data: Hsb82 AIC BIC loglik deviance REMLdev 46732 46760-23362 46720 46724 Random effects: Groups Name Variance Std.Dev. school (Intercept) 8.6723 2.9449 Residual 37.0104 6.0836 Number of obs: 7185, groups: school, 160 Fixed effects: Estimate Std. Error t value (Intercept) 12.6361 0.2445 51.69 cses 2.1912 0.1087 20.17 Correlation of Fixed Effects: (Intr) cses 0.000 AED The linear mixed model: modeling hierarchical and longitudinal data 23 of 44
Model 3: a random-coefficients regression model 1 level-1 predictor (SES, centered within school), no level-2 predictors random intercept and random slopes model for the first (student) level: y ij = α 0i + α 1i cses ij + ɛ ij model for the second (school) level: α 0i = γ 00 + u 0i α 1i = γ 10 + u 1i (the random intercept) (the random slope) the combined model and the Laird-Ware form: y ij = (γ 00 + u 0i ) + (γ 10 + u 1i ) cses ij + ɛ ij = γ 00 + γ 10 cses ij + u 0i + u 1i cses ij + ɛ ij = β 0 + β 1 x 1ij + b 0i + b 0i z 1ij + ɛ ij AED The linear mixed model: modeling hierarchical and longitudinal data 24 of 44
the fixed-effect coefficients β 0 and β 1 again represent the average withinschools population intercept and slope respectively the model has four variance-covariance components: Var(b 0i ) = d 2 0: the variance among school intercepts Var(b 1i ) = d 2 1: the variance among school slopes Cov(b 0i, b 1i ) = d 01 : the covariance between within-school intercepts and slopes Var(ɛ ij ) = σ 2 : the error variance around the within-school regressions AED The linear mixed model: modeling hierarchical and longitudinal data 25 of 44
R code > fit.model3 <- lmer(mach 1 + cses + (1 + cses school), data = Hsb82) > summary(fit.model3) Linear mixed model fit by REML Formula: mach 1 + cses + (1 + cses school) Data: Hsb82 AIC BIC loglik deviance REMLdev 46726 46768-23357 46711 46714 Random effects: Groups Name Variance Std.Dev. Corr school (Intercept) 8.68102 2.94636 cses 0.69399 0.83306 0.019 Residual 36.70019 6.05807 Number of obs: 7185, groups: school, 160 Fixed effects: Estimate Std. Error t value (Intercept) 12.6362 0.2445 51.69 cses 2.1932 0.1283 17.10 Correlation of Fixed Effects: (Intr) cses 0.009 AED The linear mixed model: modeling hierarchical and longitudinal data 26 of 44
Is the random slope necessary? R code > anova(fit.model2, fit.model3) Data: Hsb82 Models: fit.model2: mach 1 + cses + (1 school) fit.model3: mach 1 + cses + (1 + cses school) Df AIC BIC loglik Chisq Chi Df Pr(>Chisq) fit.model2 4 46728 46756-23360 fit.model3 6 46723 46764-23356 9.4299 2 0.00896 ** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05. 0.1 1 note: you can only compare two models using likelihood-ratio tests if the two models have the same fixed effects! AED The linear mixed model: modeling hierarchical and longitudinal data 27 of 44
Model 4: random intercept + level-2 predictor we drop the level-1 predictor (cses), but add a level-2 predictor (meanses) random intercept, no random slopes model for the first (student) level: model for the second (school) level: y ij = α 0i + ɛ ij α 0i = γ 00 + γ 01 meanses i + u 0i the combined model and the Laird-Ware form: y ij = γ 00 + γ 01 meanses i + u 0i + ɛ ij = β 0 + β 1 x 1ij + b 0i + ɛ ij note that in the Laird-Ware notation, we use a double index for the fixedeffects x ij, even if the variabele (meanses) does not change over students AED The linear mixed model: modeling hierarchical and longitudinal data 28 of 44
this model has two fixed effects (β 0 and β 1 ) and two random effects (b 0i and ɛ ij ) the interpretation of b 0i has changed: whereas in the previous model it had been the deviation of school i s mean from the grand mean, it now represents the residual (α 0i γ 00 γ 10 meanses j ); correspondingly, the variance component d 2 is now a conditional variance (conditional on the school mean SES) in Raudenbush and Bryk, this is called a Regression with means-as-outcomes model, because the school s mean (α 0i ) is predicted by the means SES of the school note in the following output that the residual variance between schools (2.64) is substantially smaller than the original (8.61) AED The linear mixed model: modeling hierarchical and longitudinal data 29 of 44
R code > fit <- lmer(mach 1 + meanses + (1 school), data = Hsb82) > summary(fit) Linear mixed model fit by REML Formula: mach 1 + meanses + (1 school) Data: Hsb82 AIC BIC loglik deviance REMLdev 46969 46997-23481 46959 46961 Random effects: Groups Name Variance Std.Dev. school (Intercept) 2.6389 1.6245 Residual 39.1571 6.2576 Number of obs: 7185, groups: school, 160 Fixed effects: Estimate Std. Error t value (Intercept) 12.6846 0.1493 84.98 meanses 5.8635 0.3614 16.22 Correlation of Fixed Effects: (Intr) meanses 0.010 AED The linear mixed model: modeling hierarchical and longitudinal data 30 of 44
Model 5: random intercept + level-1 predictor + level-2 predictor one level-1 predictor (cses), and a level-2 predictor (meanses) random intercept, nonrandomly varying slopes model for the first (student) level: y ij = α 0i + α 1i cses ij + ɛ ij model for the second (school) level: α 0i = γ 00 + γ 01 meanses i + u 0i α 1i = γ 10 + γ 11 meanses i the combined model and the Laird-Ware form: y ij = (γ 00 + γ 01 meanses i + u 0i ) + (γ 10 + γ 11 meanses i ) cses ij + ɛ ij = γ 00 + γ 01 meanses i + γ 10 cses ij + γ 11 meanses i cses ij + u 0i + ɛ ij = β 0 + β 1 x 1ij + β 2 x 2ij + β 3 (x 1ij x 2ij ) + b 0i + ɛ ij AED The linear mixed model: modeling hierarchical and longitudinal data 31 of 44
this model illustrates that in a mixed model, we combine predictors from both levels to construct an interaction term no random slopes are used in this model; the idea is that once we control for the level-2 predictor (meanses), little or no variance in the slopes remains to be explained; the slopes vary across schools, but as a strict function of meanses this results in a random-intercept only model AED The linear mixed model: modeling hierarchical and longitudinal data 32 of 44
R code > fit <- lmer(mach 1 + meanses * cses + (1 school), data = Hsb82) > summary(fit) Linear mixed model fit by REML Formula: mach 1 + meanses * cses + (1 school) Data: Hsb82 AIC BIC loglik deviance REMLdev 46580 46621-23284 46562 46568 Random effects: Groups Name Variance Std.Dev. school (Intercept) 2.6926 1.6409 Residual 37.0169 6.0842 Number of obs: 7185, groups: school, 160 Fixed effects: Estimate Std. Error t value (Intercept) 12.6833 0.1494 84.91 meanses 5.8662 0.3617 16.22 cses 2.2009 0.1090 20.20 meanses:cses 0.3248 0.2735 1.19 Correlation of Fixed Effects: (Intr) meanss cses meanses 0.010 cses 0.000 0.000 meanses:css 0.000 0.000 0.075 AED The linear mixed model: modeling hierarchical and longitudinal data 33 of 44
Model 6: intercepts-and-slopes-as-outcomes model we expand the model by including two level-2 predictors: meanses and sector; the slopes are again allowed to vary randomly model for the first (student) level: y ij = α 0i + α 1i cses ij + ɛ ij model for the second (school) level: α 0i = γ 00 + γ 01 meanses i + γ 02 sector i + u 0i α 1i = γ 10 + γ 11 meanses i + γ 12 sector i + u 1i AED The linear mixed model: modeling hierarchical and longitudinal data 34 of 44
the combined model and the Laird-Ware form: y ij = (γ 00 + γ 01 meanses i + γ 02 sector i + u 0i )+ (γ 10 + γ 11 meanses i + γ 12 sector i + u 1i ) cses ij + ɛ ij = γ 00 + γ 01 meanses i + γ 02 sector i + γ 10 cses ij + γ 11 meanses i cses ij + γ 12 sector i cses ij + u 0i + u 1i cses ij + ɛ ij = β 0 + β 1 x 1ij + β 2 x 2ij + β 3 x 3ij + β 4 (x 1ij x 3ij ) + β 5 (x 2ij x 3ij )+ b 0i + b 1i z 1ij + ɛ ij AED The linear mixed model: modeling hierarchical and longitudinal data 35 of 44
R code > fit.model6 <- lmer(mach 1 + meanses * cses + sector * cses + + (1 + cses school), data = Hsb82) > summary(fit.model6) Linear mixed model fit by REML Formula: mach 1 + meanses * cses + sector * cses + (1 + cses school) Data: Hsb82 AIC BIC loglik deviance REMLdev 46524 46592-23252 46496 46504 Random effects: Groups Name Variance Std.Dev. Corr school (Intercept) 2.37956 1.54258 cses 0.10123 0.31817 0.391 Residual 36.72115 6.05980 Number of obs: 7185, groups: school, 160 Fixed effects: Estimate Std. Error t value (Intercept) 12.1279 0.1993 60.86 meanses 5.3329 0.3692 14.45 cses 2.9450 0.1556 18.93 sectorcatholic 1.2266 0.3063 4.00 meanses:cses 1.0392 0.2989 3.48 cses:sectorcatholic -1.6427 0.2398-6.85 Correlation of Fixed Effects: AED The linear mixed model: modeling hierarchical and longitudinal data 36 of 44
(Intr) meanss cses sctrct mnss:c meanses 0.256 cses 0.075 0.019 sectorcthlc -0.699-0.356-0.052 meanses:css 0.019 0.074 0.293-0.026 css:sctrcth -0.052-0.027-0.696 0.077-0.351 Do we need the random slopes? > fit.model6bis <- lmer(mach 1 + meanses * cses + sector * cses + + (1 school), data = Hsb82) > anova(fit.model6bis, fit.model6) Data: Hsb82 Models: fit.model6bis: mach 1 + meanses * cses + sector * cses + (1 school) fit.model6: mach 1 + meanses * cses + sector * cses + (1 + cses school) Df AIC BIC loglik Chisq Chi Df Pr(>Chisq) fit.model6bis 8 46513 46568-23249 fit.model6 10 46516 46585-23248 0.9712 2 0.6153 no: apparently, the level-2 predictors do a sufficiently good job of accounting for differences in slopes that the variance component for slopes is no longer needed AED The linear mixed model: modeling hierarchical and longitudinal data 37 of 44
1.3 Further issues modern software (for example lmer in R) can also handle partially nested data structures (for example, some students belong to several schools) you should always center level-1 covariates the standard hierarchical model can be extended to include heterogeneous level-1 variance terms in this case: each individual/cluster has a different variance for example: math achievement is more variable among boys than girls heterogeneity of the level-1 variance may be modelled as a function of predictors at both levels in practice, the log of the variance is modelled (to ensure positivity) the presence of heterogeneity of variance at level-1 is often due to misspecification of the level-1 model AED The linear mixed model: modeling hierarchical and longitudinal data 38 of 44
2 Modeling Longitudinal Data longitudinal data is very similar to hierarchical data: you typically have two levels: the timepoints (level-1) and the individuals/units (level-2) the focus of the analysis is often to find an appropriate polynomial (linear, quadratic, cubic,... ) that describes the evolution or growth curve of the data over time the components of that polynomial (intercept, slope, quadratic component,... ) may be constant (fixed) or varying (random) across individuals/units a complication in longitudinal data is that it may not be longer reasonable to assume that the level-1 errors ɛ ij are independent, since observations taken close in time on the same individual/units may well be more similar than observations farther apart in time; this is called auto-correlation in the world of linear mixed models, there is a delicate trade-off between adding more random effects to the model (implying more complicated patterns in the covariance matrix) or using a more complicated form for Σ i AED The linear mixed model: modeling hierarchical and longitudinal data 39 of 44
2.1 Example: Reaction times in a sleep deprivation study Dependent variable: the average reaction time per day (Reaction) for subjects in a sleep deprivation study. On day 0 the subjects had their normal amount of sleep. Starting that night they were restricted to 3 hours of sleep per night. The observations represent the average reaction time on a series of tests given each day to each subject. Days Number of days of sleep deprivation Subject Subject number on which the observation was made dataset is available in the lme4 package AED The linear mixed model: modeling hierarchical and longitudinal data 40 of 44
Exploring the data: the spaghetti plot 450 Average reaction time (ms) 400 350 300 250 200 0 2 4 6 8 Days of sleep deprivation AED The linear mixed model: modeling hierarchical and longitudinal data 41 of 44
Exploring the data: linear regression for each subject Average reaction time (ms) 450 400 350 300 250 200 450 400 350 300 250 200 351 333 308 0 2 4 6 8 352 334 309 369 335 310 0 2 4 6 8 370 337 330 371 349 331 0 2 4 6 8 372 350 332 450 400 350 300 250 200 0 2 4 6 8 0 2 4 6 8 Days of sleep deprivation 0 2 4 6 8 AED The linear mixed model: modeling hierarchical and longitudinal data 42 of 44
A simple linear growth model > fit.linear <- lmer(reaction Days + (Days Subject), data = sleepstudy) > summary(fit.linear) Linear mixed model fit by REML Formula: Reaction Days + (Days Subject) Data: sleepstudy AIC BIC loglik deviance REMLdev 1756 1775-871.8 1752 1744 Random effects: Groups Name Variance Std.Dev. Corr Subject (Intercept) 612.092 24.7405 Days 35.072 5.9221 0.066 Residual 654.941 25.5918 Number of obs: 180, groups: Subject, 18 Fixed effects: Estimate Std. Error t value (Intercept) 251.405 6.825 36.84 Days 10.467 1.546 6.77 Correlation of Fixed Effects: (Intr) Days -0.138 > fit.quad <- lmer(reaction Days + I(Daysˆ2) + (Days Subject), AED The linear mixed model: modeling hierarchical and longitudinal data 43 of 44
+ data = sleepstudy) > summary(fit.quad) Linear mixed model fit by REML Formula: Reaction Days + I(Daysˆ2) + (Days Subject) Data: sleepstudy AIC BIC loglik deviance REMLdev 1757 1779-871.4 1750 1743 Random effects: Groups Name Variance Std.Dev. Corr Subject (Intercept) 613.108 24.7610 Days 35.108 5.9252 0.064 Residual 651.973 25.5338 Number of obs: 180, groups: Subject, 18 Fixed effects: Estimate Std. Error t value (Intercept) 255.4494 7.5135 34.00 Days 7.4341 2.8189 2.64 I(Daysˆ2) 0.3370 0.2619 1.29 Correlation of Fixed Effects: (Intr) Days Days -0.418 I(Daysˆ2) 0.418-0.836 AED The linear mixed model: modeling hierarchical and longitudinal data 44 of 44