[R] anova and contratst
Colm G.Connolly
Colm.Connolly at tcd.ie
Mon Oct 22 17:14:56 CEST 2007
Hi everybody,
I'm using the gmodels package to convert human readable contrasts
into the format required by R and would be grateful if someone could
confirm for me whether I've got the contrasts right in the sample
code below.
I'm working on the assumption that the contrasts are index according
to the way that levels reports them for a factor.
In my case levels(roi.errs$Group) reports ctrl, long, short in that
order so I'm assuming that to compare ctrl to short the correct
contrast is c(1, 0, -1). Am I correct?
I tried to perform 3 contrasts with my data and make.contrasts
complained about there being too many contrasts specified. Is this
because the number of contrasts can only be less than or equal to the
number of degrees of freedom that go into calculation of the mean
square for the Group term?
Is the only way to get the short vs long contrast to sacrifice one of
the other contrasts?
rm(list=ls());
library(gmodels);
Group = c("ctrl", "ctrl", "ctrl", "short", "short", "short", "long",
"long", "long")
Subject = c("66101_2", "66112_2", "66118_2", "66119", "66121",
"66123", "66026_3", "66030_2", "66044_3")
Mean_1 = c(-0.399281, 6.951385, 5.986774, 3.485916, 7.081511,
1.705302, 7.859186, 4.573201, 3.931118)
Mean_2 = c(0.350127, 5.863118, 3.826101, 0.999821, 9.099477,
2.376836, 5.384967, 5.950012, 7.688557)
roi.errs = data.frame(Group, Subject, Mean_1, Mean_2)
# planned contrasts
cmat = rbind(
"ctrl vs. short" = c(1, 0, -1),
"ctrl vs. long" = c(1, -1, 0));
groupContrasts=make.contrasts(cmat);
summarySplit=list(Group=list("ctrl vs. short" = 1, "ctrl vs. long"=2));
roi.err.aov<-aov(Mean_1 ~ Group, contrasts=list
("Group"=groupContrasts), data=roi.errs);
print(summary(roi.err.aov, split=summarySplit))
with(roi.errs, print(pairwise.t.test(Mean_1, Group)))
Thanks in advance,
--
Dr Colm G. Connolly
School of Psychology and Institute of Neuroscience
The Lloyd Building
University of Dublin
Trinity College, Dublin 2, Éire
Tel: +353-1-896-8475
Fax: +353-1-671-3183
More information about the R-help
mailing list