*10. Multi-level Models, Repeated Measures and Time Series ## 10.1 Multi-Level Models, Including Repeated Measures Models ## 10.1.1 The Kiwifruit Shading Data, Again library(nlme) kiwishade\$plot<-factor(paste(kiwishade\$block, kiwishade\$shade, sep=".")) kiwishade.lme<-lme(yield~shade,random=~1|block/plot, data=kiwishade) summary(kiwishade.lme) anova(kiwishade.lme) intervals(kiwishade.lme) kiwishade.aov<-aov(yield~block+shade+Error(block:shade),data=kiwishade) summary(kiwishade.aov) ## 10.1.2 The Tinting of Car Windows itstar.lme<-lme(log(it)~tint*target*agegp*sex, random=~1|id, data=tinting,method="ML") it2.lme<-lme(log(it)~(tint+target+agegp+sex)^2, random=~1|id, data=tinting,method="ML") it1.lme<-lme(log(it)~(tint+target+agegp+sex), random=~1|id, data=tinting,method="ML") anova(itstar.lme,it2.lme,it1.lme) it2.reml<-update(it2.lme,method="REML") options(digits=3) summary(it2.reml)\$tTable ## 10.1.3 The Michelson Speed of Light Data library(MASS) # if needed michelson\$Run <- as.numeric(michelson\$Run) # Ensure Run is a variable mich.lme1 <- lme(fixed = Speed ~ Run, data = michelson, random = ~ Run| Expt, correlation = corAR1(form = ~ 1 | Expt), weights = varIdent(form = ~ 1 | Expt)) summary(mich.lme1) ## 10.2 Time Series Models ## 10.3 Exercises ## 10.4 References