# ANCOVA to check effect of covariate

I want to check whether a group of patients are significantly different from their control group. However, I also want to check if the p-value is still significant in case a covariate is taken into account. For that I created a simple data frame in R:

data <- data.frame(group = c(rep("CTRL", 10), rep("P", 10)),
response = c(10,11,14,16,17,17,19,20,21,22, 10,11,11,11,12,13,14,14,15,16),
age = c(40,41,45,43,50,51,55,57,60,62, 40,42,43,43,45,46,46,50,52,54))


First of all, I performed a normal ANOVA using the lm function. I tried 3 different ways to see if the results are the same. And they are:

anova(lm(data$response ~ data$group))

summary(lm(data$response ~ data$group))

summary(aov(data$response ~ data$group)


To check if the covariate age is correlated with the response variable I performed a correlation test:

cor.test(data$response, data$age)


Seeing a high and significant correlation I concluded that the significance between the control group and the patient group might be due to the effect of age.

I am now unsure how to perform the ANCOVA analysis to check if the effect between the two groups is really there or if it is just because of the covariate age.

To check this I did the following:

m1 <- lm(data$response ~ data$group + data$age) m2 <- lm(data$response ~ data\$group)

anova(m1, m2)


Comparing the two models resulted in a significant p-value. I would have thought of a p-value of much less significant then the one obtained with the normal anova. Is it actually right to compare the two models or can I achieve this by using only one model? I am really stuck here and hoping to find some helpful answers here.

Why not just:

#Is group important?
m1 <- with(data, lm(response~as.factor(group)))
summary(m1)
#Is age important and does it affect the effect of group?
m2 <- with(data, lm(response~as.factor(group)+age))
summary(m2)
#Does age affect the effect of group?
anova(m1,m2)


These are three different questions. In this case, all three are important, but to different degrees.

• The last anova(m1,m2) shows that age affects the effect of group but how can I extract a p-value which says that if all ages would be similar would there still be a difference between controls and patients? I am not sure if with the 3 p-values calculated above one can conclude that the controls are different to the patients ONLY because of the difference in their response? Nov 5, 2012 at 16:13
• Your model m2 assumes equal slopes for the response ~ age relationship across groups. I would suggest adding a third model which includes an interaction between the grouping factor and the covariate.
– chl
Nov 5, 2012 at 16:15
• @chl That's certainly a good idea, but not directly an answer to the original question. but m3 <- with(data, lm(response~as.factor(group)*age)) summary(m3) shows a small and insignificant interaction Nov 5, 2012 at 16:18
• I found no interaction (p=0.465), suggesting that the parallel group assumption holds, which can be checked visually (using lattice): xyplot(response ~ age, data=data, groups=group, type=c("p","r")).
– chl
Nov 5, 2012 at 16:21
• This last question makes no sense. Perhaps you mean "the response is different only because of group"? but that is answered, the answer is "no, age also matters". Model m2 controls for age. Nov 5, 2012 at 16:23