PDA

View Full Version : ANCOVA mystery



violars
01-20-2009, 02:29 PM
Hello everybody,

I’m trying to do some ANCOVAs in R, and am wondering why the output I get from my models changes if I change the order of the variables. Here’s a couple of examples (I can't make the tables align properly...sorry!).


Response~Head+Replicate+Date+Age+Date:Age

Df Sum Sq Mean Sq F value Pr(>F)
Head 5 1257.6 251.5 10.2314 2.092e-08 ***
Replicate 5 832.9 166.6 6.7762 1.055e-05 ***
Date 3 203.3 67.8 2.7565 0.0446151 *
Age 1 340.2 340.2 13.8369 0.0002850 ***
Date:Age 3 539.5 179.8 7.3155 0.0001339 ***
Residuals 144 3540.0 24.6

Response~Replicate+Date+Head+Age+Date:Age

Df Sum Sq Mean Sq F value Pr(>F)
Replicate 5 752.6 150.5 6.1226 3.574e-05 ***
Date 3 203.3 67.8 2.7565 0.0446151 *
Head 5 1337.9 267.6 10.8849 6.752e-09 ***
Age 1 340.2 340.2 13.8369 0.0002850 ***
Date:Age 3 539.5 179.8 7.3155 0.0001339 ***
Residuals 144 3540.0 24.6


Age is a covariate, so I’ve put that last in the model. The other variables are just categorical factors with several different levels.


If anyone could shed any light, I’d be very grateful!!

Cheers :)

Mike White
01-21-2009, 03:35 AM
The examples for ancova in library HH show how the model changes with order of variables, e.g.

hotdog <- read.table(hh("datasets/hotdog.dat"), header=TRUE)
## This is the usual usage
## y ~ x + a or y ~ a + x ## constant slope, different intercepts
ancova(Sodium ~ Calories + Type, data=hotdog)
ancova(Sodium ~ Type + Calories, data=hotdog)

Order of the variables matters because the terms are added sequentially.
If you do a search of the R mailing list archives using
aov "order of the variables"
you will find similar queries about the effects of changing the order of the variables.

Masteras
01-21-2009, 04:16 PM
I know that is SPSS you can choose the sum of squares not to change and therefore destroying your mood. Try SPSS then, or SPlus

violars
01-27-2009, 10:48 AM
Great - thanks a lot for the advice. I'll look into it!