[R] model formulation for the following ANOVA

stefan.premke at email.de stefan.premke at email.de
Thu May 11 18:57:11 CEST 2006


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




More information about the R-help mailing list