stefan.premke at email.de
2006-May-11 16:57 UTC
[R] model formulation for the following ANOVA
Hallo!
I have run a EEG experiment and got the following data
group: 1 2 1 2 1 2 1 2 ... as factor, 2 levels between subjects fixed effect
(patient vs control)
subj: 1 2 ... 14 1 2 ... 14 as factor 7 patients 7 control random effect
condition: 1 1 ... 2 2 ... 1 1 ... 2 2 as factor, 2 levels within subjects, ie
every subject worked on every cond fixed effect
roi: 1 ... 2 ... 3 ... 4 ... as factor, 4 levels within subjects, ie signal was
recored for every subject from all brain regions (of course) fixed effect
mean: as numeric the signal mean value in a given time window
I arranged that data in a data.frame called roiData
I want a linear model of groupmembership, condition and roi to predict the mean
signal value (as all the UV are kategorial and the AV is numeric this may be
called ANOVA). As a first step I want to model all possible effects and their
interactions (critisism that such a theory free hypothesis testing procedure is
hardly resonable aside)
I tried the following call (worked out with help of the following internet
resources
http://www.psych.northwestern.edu/Misc/s+.html example 5
?Notes on the use of R for psychology experiments and questionnaires? by
Jonathan Baron pp. 27ff)
summary(aov(mean~cond*roi*group+Error(subj/(cond*roi))+group,data=roiData))
if I got it right so far, then the Error(subj/...) expression take the repeated
measurement into accout and
the +group at the and tells R that group is a between factor not nested in subj
this was the R output
Error: subj
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 6 154.478 25.746
Error: subj:cond
Df Sum Sq Mean Sq F value Pr(>F)
cond 1 241.09 241.09 31.188 0.001401 **
Residuals 6 46.38 7.73
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05
'.' 0.1 ' ' 1
Error: subj:roi
Df Sum Sq Mean Sq F value Pr(>F)
roi 3 58.877 19.626 3.6647 0.03201 *
Residuals 18 96.396 5.355
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05
'.' 0.1 ' ' 1
Error: subj:cond:roi
Df Sum Sq Mean Sq F value Pr(>F)
cond:roi 3 2.3530 0.7843 0.9008 0.4601
Residuals 18 15.6730 0.8707
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
group 1 130.642 130.642 22.0233 2.275e-05 ***
cond:group 1 0.171 0.171 0.0287 0.8661
roi:group 3 37.479 12.493 2.1061 0.1118
cond:roi:group 3 2.782 0.927 0.1563 0.9251
Residuals 48 284.735 5.932
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05
'.' 0.1 ' ' 1
I compared this output to what SAS gives for the same Data.
all the mean square of all the tested effects are equal.
But all the calculated residual's Mean Sq differ (so all the F-values also
differ).
as another result all the df of the residuals are twice as large in the SAS
output compared to the R output.
So where did my lm go wrong?
is the Error(...) statment not good to tell R that subject is a random effect?
(I would prefer to work around the lmne Package, because I do not know how to
use it, especially how to model repeated measurement and nested models there)
is the +group expression wrong positioned at the end?
greetings
stefan
Please use better spacing to improve legibility.
roi.aov <- aov(mean ~ cond*roi*group + Error(subj/(cond*roi)),
data=roiData)
summary(roi.aov)
The +group you had is redundant. It is implied by cond*roi*group.
You can verify this by typing
terms(cond*roi*group)
Based on the df in tha ANOVA table, it looks like roi is a factor.
There are only two levels of group and cond, so 1 df doesn't clearly
distinguish whether you made them factors.
You didn't give the SAS statement, so I am guessing here.
SAS tests everything against the within residuals unless you
specifically give some test statements. Further, it doesn't separate
out the residuals at the various strata unless you tell it to.
In a repeated measures design you do not want the default tests,
you will need to specify the tests you have in mind.
The Error() function determines the tests by looking at the linear
dependencies among the subspaces implied by the factors.
Based on your description of this as a repeated measures design, the
ANOVA you have with the this R statement better matches the design than
the equivalent statement
roi.aov <- aov(mean ~ cond*roi*group,
data=roiData)
summary(roi.aov)
which I am guessing is the match to the SAS statement you used. This statement
does not isolate the various strata residuals.