################################################### ### chunk number 1: prelim ################################################### rm(list=ls()) try(detach(package:nlme)) try(detach(package:lme4)) setwd('W:/lehre/longitudinal_sommer08/uebung') options(width = 80, prompt = "R>") ################################################### ### chunk number 2: 1a eval=FALSE ################################################### ## plot(augPred(m)) ## plot(m, resid(.)~age|Subject,abline=0) ################################################### ### chunk number 3: 1asol ################################################### library(nlme) data(Orthodont) m <- lme(distance ~ I(age-11)*Sex , random= ~1|Subject, data=Orthodont) summary(m) print(plot(augPred(m))) ################################################### ### chunk number 4: 1asol2 ################################################### print(plot(m, resid(.)~age|Subject,abline=0)) ################################################### ### chunk number 5: 1bsol ################################################### m2 <- update(m,random=~I(age-11)|Subject) print(plot(comparePred(m,m2))) ################################################### ### chunk number 6: 1bsol2 ################################################### print(plot(m2, resid(.)~age|Subject,abline=0)) ################################################### ### chunk number 7: 1bsol3 ################################################### lmlist <- lmList(distance ~ I(age-11), data=Orthodont) print(plot(intervals(lmlist))) ################################################### ### chunk number 8: 1csol ################################################### m2.ml <- update(m2,method='ML') getVarCov(m2) getVarCov(m2.ml) ################################################### ### chunk number 9: 1csol2 ################################################### print(plot(compareFits(coef(m2)[,1:2],coef(m2.ml)[,1:2]))) ################################################### ### chunk number 10: 2a ################################################### m.mar <- gls(distance ~ I(age-11)*Sex, correlation = corSymm(form=~ 1| Subject), data=Orthodont) summary(m.mar) cov.m.mar <- getVarCov(m.mar) varb.m<-getVarCov(m)[1,1] cov2cor(cov.m.mar) varb.m/(varb.m+m$sigma^2) ################################################### ### chunk number 11: 2a2 ################################################### intervals(m.mar,which='var-cov') ################################################### ### chunk number 12: 2b ################################################### m.mar2 <- gls(distance ~ I(age-11)*Sex, correlation = corCompSymm(form=~ 1| Subject), data=Orthodont) summary(m.mar2) getVarCov(m.mar2) cov2cor(getVarCov(m.mar2))