[R] repeated measures ANOVA
John Vokey
vokey at uleth.ca
Tue Feb 28 18:03:08 CET 2006
Christian,
You need, first to factor() your factors in the data frame P.PA,
and then denote the error-terms in aov correctly, as follows:
> group <- rep(rep(1:2, c(5,5)), 3)
> time <- rep(1:3, rep(10,3))
> subject <- rep(1:10, 3)
> p.pa <- c(92, 44, 49, 52, 41, 34, 32, 65, 47, 58, 94, 82, 48, 60, 47,
+ 46, 41, 73, 60, 69, 95, 53, 44, 66, 62, 46, 53, 73, 84, 79)
> P.PA <- data.frame(subject, group, time, p.pa)
> # added code:
> P.PA$group=factor(P.PA$group)
> P.PA$time=factor(P.PA$time)
> P.PA$subject=factor(P.PA$subject)
> summary(aov(p.pa~group*time+Error(subject/time),data=P.PA))
Error: subject
Df Sum Sq Mean Sq F value Pr(>F)
group 1 158.7 158.7 0.1931 0.672
Residuals 8 6576.3 822.0
Error: subject:time
Df Sum Sq Mean Sq F value Pr(>F)
time 2 1078.07 539.03 7.6233 0.004726 **
group:time 2 216.60 108.30 1.5316 0.246251
Residuals 16 1131.33 70.71
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
On 28-Feb-06, at 4:00 AM, r-help-request at stat.math.ethz.ch wrote:
> Dear list members:
>
> I have the following data:
> group <- rep(rep(1:2, c(5,5)), 3)
> time <- rep(1:3, rep(10,3))
> subject <- rep(1:10, 3)
> p.pa <- c(92, 44, 49, 52, 41, 34, 32, 65, 47, 58, 94, 82, 48, 60, 47,
> 46, 41, 73, 60, 69, 95, 53, 44, 66, 62, 46, 53, 73, 84, 79)
> P.PA <- data.frame(subject, group, time, p.pa)
>
> The ten subjects were randomly assigned to one of two groups and
> measured three times. (The treatment changes after the second time
> point.)
>
> Now I am trying to find out the most adequate way for an analysis of
> main effects and interaction. Most social scientists would call this
> analysis a repeated measures ANOVA, but I understand that mixed-
> effects
> model is a more generic term for the same analysis. I did the analysis
> in four ways (one in SPSS, three in R):
>
> 1. In SPSS I used "general linear model, repeated measures",
> defining a
> "within-subject factor" for the three different time points. (The data
> frame is structured differently in SPSS so that there is one line for
> each subject, and each time point is a separate variable.)
> Time was significant.
>
> 2. Analogous to what is recommended in the first chapter of Pinheiro &
> Bates' "Mixed-Effects Models" book, I used
> library(nlme)
> summary(lme ( p.pa ~ time * group, random = ~ 1 | subject))
> Here, time was NOT significant. This was surprising not only in
> comparison with the result in SPSS, but also when looking at the
> graph:
> interaction.plot(time, group, p.pa)
>
> 3. I then tried a code for the lme4 package, as described by Douglas
> Bates in RNews 5(1), 2005 (p. 27-30). The result was the same as in 2.
> library(lme4)
> summary(lmer ( p.pa ~ time * group + (time*group | subject), P.PA ))
>
> 4. The I also tried what Jonathan Baron suggests in his "Notes on the
> use of R for psychology experiments and questionnaires" (on CRAN):
> summary( aov ( p.pa ~ time * group + Error(subject/(time * group)) ) )
> This gives me yet another result.
>
> So I am confused. Which one should I use?
>
> Thanks
>
> Christian
--
Please avoid sending me Word or PowerPoint attachments.
See <http://www.gnu.org/philosophy/no-word-attachments.html>
-Dr. John R. Vokey
More information about the R-help
mailing list