hip<-read.table("hip.txt",col.names=c("y","age","sex","subj","time")) plot(hip$time,hip$y,type="n",xlab="time",ylab="haemataocrit") for (i in 1:30) lines(hip$time[hip$subj==i],hip$y[hip$subj==i]) library(nlme) AIC(lme(y~factor(time)+age+sex,random= ~1|subj,data=hip,method="ML")) AIC(lme(y~factor(time)+sex,random= ~1|subj,data=hip,method="ML")) AIC(lme(y~factor(time),random= ~1|subj,data=hip,method="ML")) AIC(lme(y~factor(time)+sex,random= ~1+factor(time)|subj,data=hip,method="ML")) AIC(lm(y~factor(time)+sex,data=hip)) hip.r<-lme(y~factor(time)+sex,random= ~1|subj,data=hip) summary(hip.r) hip.f<-lm(y~factor(subj)+factor(time)+sex,data=hip) hip.sex<-tapply(hip$sex,hip$subj,mean) plot(hip.f$coef[1]+c(0,hip.f$coef[2:30]),fixef(hip.r)[1]+fixef(hip.r)[4]*hip.sex+ranef(hip.r)[[1]],ylab="intercept (random effect)",xlab="intercept (fixed effect)",pch=ifelse(hip.sex==0,1,2)) abline(0,1)