# Exercise 3.11 in Davis, 2002 # Continuation of Exercise 2.3 week <- c(0,2,4,6,8,10,12,14,16,18,19) m <- matrix(scan("c:\\data.ext\\davis\\kenward.dat"),ncol=13,byrow=T) group <- m[,1] calf <- m[,2] y <- m[,3:13] # code for graphics, using nlme and lattice libraries library(nlme) kenward <- balancedGrouped( y ~ week|calf, matrix(m[,3:13],nrow=60,ncol=11,dimnames=list(calf,week)), labels=list(y="Weight of calves in 19 weeks")) Group <- rep(group,rep(11,60)) # profile plot plot(kenward, outer=~as.factor(Group), aspect=1) # mean plot kenward.means <- aggregate(kenward$y,list(kenward$week,Group),mean,na.rm=TRUE) names(kenward.means)[1]<-"Week" kenward.means$Week <- as.numeric(levels(kenward.means$Week))[kenward.means$Week] names(kenward.means)[2]<-"Group" library(lattice) xyplot(x~Week|Group,kenward.means,ylab="Mean Weight of calves in 19 weeks") # (a) results <- matrix(0,nrow=11,ncol=5,byrow=TRUE) for (i in 1:11) { results[i,1] <- week[i] ttest <- t.test(y[,i]~group,var.equal=TRUE) results[i,2] <- ttest$estimate[1] results[i,3] <- ttest$estimate[2] results[i,4] <- ttest$statistic results[i,5] <- ttest$p.value } # (b) equality between groups summary(manova(y~group)) # (c) parallel profiles diff <- matrix(0,nrow=60,ncol=10) for (i in 1:10) diff[,i] <- y[,i]-y[,i+1] summary(manova(diff~group))