[R] ordinal predictor in anova
Vincent Staszewski
vincent.staszewski at ed.ac.uk
Wed Apr 13 12:36:49 CEST 2011
Hi,
I have a dataset with a continuous response variable and, among
other predictors, an ordinal variable.
Here is what it could look like
treatment <- factor(rep(c("AA", "AC", "AD","AE", "AB"), each = 10))
length <- c(75, 67, 70, 75, 65, 71, 67, 67, 76, 68,
57, 58, 60, 59, 62, 60, 60, 57, 59, 61,
58, 61, 56, 58, 57, 56, 61, 60, 57, 58,
58, 59, 58, 61, 57, 56, 58, 57, 57, 59,
62, 66, 65, 63, 64, 62, 65, 65, 62, 67)
This ordinal variable (treatment) contains 5 classes and can not be
recoded as a numerical variable (for example 1, 2,3,4 and 5) because I
have no information on the relative difference between classes (it
could as well be 1, 24, 25, 50,55). Coding it simply as a categorical
variable is also not ok because there is a hierarchy between the
groups. This is the definition of ordinal variable.
I have defined the ordinal variable (the order is from a priori prediction)
#NOW DEFINING THE ORDERED VARIABLE:
sugars$treatment_ordered<-ordered(sugars$treatment,c("AA", "AB","AC",
"AD","AE"))
The problem is that when I run the ANOVA or perform model
comparison, R is giving me the same results if I use either
"treatment" as a predictor in the model or "treatment_ordered".
anova(lm(length ~ treatment_ordered, sugars));anova(lm(length ~
treatment, sugars))
I've thought about using planned contrasts but I do not manage to
translate the prediction ("AA"<"AB"<"AC"< "AD"<"AE")
would it be
(AA<(AB,AC,AD,AE))&((AA,AB)<(AC,AD,AE))etc etc
(-1,0.25,0.25,0.25,0.25)&(-0.5,-0.5,0.33,0.33,0.33)&...
OR
(AA<AB)&(AB,AC)&...
(-1,1,0,0,0)&(0,-1,1,0,0)&...
and anyway you can only test one matrix at a time.
To make thinks a bit more complicated, I also have another factor,
categorical variable and I'd like to test the interaction with the
ordinal factor (of course sample sizes are higher in the "real"
dataset):
treatment <- factor(rep(c("AA", "AC", "AD","AE", "AB"), each = 10))
length <- c(75, 67, 70, 75, 65, 71, 67, 67, 76, 68,
57, 58, 60, 59, 62, 60, 60, 57, 59, 61,
58, 61, 56, 58, 57, 56, 61, 60, 57, 58,
58, 59, 58, 61, 57, 56, 58, 57, 57, 59,
62, 66, 65, 63, 64, 62, 65, 65, 62, 67)
treatment2 <- c("BA", "BA", "BB", "BB", "BC", "BC", "BD", "BD", "BE", "BE",
"BA", "BA", "BB", "BB", "BC", "BC", "BD", "BD", "BE", "BE",
"BA", "BA", "BB", "BB", "BC", "BC", "BD", "BD", "BE", "BE",
"BA", "BA", "BB", "BB", "BC", "BC", "BD", "BD", "BE", "BE",
"BA", "BA", "BB", "BB", "BC", "BC", "BD", "BD", "BE", "BE")
sugars <- data.frame(treatment, length,treatment2)
sugars$treatment_ordered<-ordered(sugars$treatment,c("AA", "AB","AC",
"AD","AE"))
anova(lm(length ~
treatment_ordered+treatment2+treatment_ordered:treatment2, sugars))
Any suggestions?
Thanks,
V.
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
----- End forwarded message -----
--
Vincent STASZEWSKI
Institute of Infection and Immunology Research
Ashworth Laboratories
Kings' Buildings
EH9 3JT
Edinburgh
Scotland, UK
Tel: 0044(0)131 650 8682
webpage: http://reece.bio.ed.ac.uk/vincent-staszewski.html
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
More information about the R-help
mailing list