data <- scan(what = list(group="",age=0,change=0), multi.line=F) aerobic 31 17.05 aerobic 23 4.96 aerobic 27 10.40 aerobic 28 11.05 aerobic 22 0.26 aerobic 24 2.51 running 23 -0.87 running 22 -10.74 running 22 -3.27 running 25 -1.97 running 27 7.50 running 20 -7.25 data table171 <- data.frame(data) rm(data) table171$group <- as.factor(table171$group) # look at the data plot(table171$age,table171$change,pch=as.numeric(table171$group), col=as.numeric(table171$group),ylab="Change",xlab="Age") legend("bottomright",levels(table171$group),pch=1:2,col=1:2) # standard ANCOVA assuming equal slopes tab171.lm1 <- lm(change ~ age +group , data=table171) anova(tab171.lm1) summary(tab171.lm1) # calculate adjustedMeans and standard errors from the effects package library(effects) adjustedMeans <- effect("group",tab171.lm1) adjustedMeans adjustedMeans$se # multiple comparisons using the multcomp package # (not needed here since there are two groups, but useful to know) library(multcomp) summary(glht(tab171.lm1,linfct=mcp(group="Tukey"))) # check assumptions windows() par(mfrow=c(2,2)) plot(tab171.lm1) par(mfrow=c(1,1)) # check equal slopes assumption tab171.lm2 <- lm(change ~ age +group +age:group , data=table171) anova(tab171.lm2) # quantities for calculating efficiency and standard errors Txx <- anova(lm(age ~ group , data=table171))$"Sum Sq"[1] Exx <- anova(lm(age ~ group , data=table171))$"Sum Sq"[2] MSE <- anova(lm(change ~ age +group , data=table171))$"Mean Sq"[3] MSEr <- anova(lm(change ~ group , data=table171))$"Mean Sq"[2] t <- 2 Efficiency <- MSEr/(MSE*(1 + Txx/((t-1)*Exx) ) )