[R] replicates in repeated ANOVA
Douglas Bates
bates at stat.wisc.edu
Sat Apr 14 21:10:52 CEST 2007
On 4/13/07, Michael Stevens <mstevens1107 at yahoo.com> wrote:
> Hi,
> I have sort of a newbie question. I've seriously put a lot of effort into how to handle simple replicates in a repeated ANOVA design, but haven't had much luck.
> I really liked reading "Notes on the use of R for psychology experiments and questionnaires", by Jonathan Baron and Yuelin Li ( http://www.psych.upenn.edu/~baron/rpsych/rpsych.html ) but still didn't run across an example using simple replicates.
> So, I made up the data below semi-borrowing the idea of a reaction time experiment involving noise from Maxwell, S. E. & Delaney, H. D. (1990) Designing Experiments and Analyzing Data: A model comparison perspective. Pacific Grove, CA: Brooks/Cole., which was referenced in the Baron and Li link above.
>
> The experimental concept I'm trying to envision is 2 groups of subjects (Treat and Control), 3 subjects in each. In one session, all 6 patients from both groups are tested for reaction time by making 3 replicate tests on some hypothetical RT test (I call this the "pre" testing phase below or one could call this baseline ). In a second session (the "post" phase), the subjects in the "Treat" Group are subjected to noise (or any treatment), while the other 3 "Control" subjects are not, (i.e. the Control subjects are basically tested exactly like they were in the "pre" testing session).
>
> I'm trying to set up the correct model for this experimental design to simply understand whether "noise" (or treatment) has an effect on reaction time. Can someone tell this newbie the proper name of this experimental design?
>
> By setting up the design this way, I'm hoping one could see if there was a "pre" session to "post" session effect (using the Control group) and then take into account any possible pre->post effect when deciding whether there was a Treatment (noise) effect.
>
> Unfortunately, whenever, I put the Group factor in the Error term (to take into account subj:Group as a random effect), I get a singular result: (see the data entry section below)
>
> > rt.aov <- aov(rt ~ Group*prepost + Error(subj/(prepost*Group)), data=rt.df)
> Warning message:
> Error() model is singular in: aov(rt ~ Group * prepost + Error(subj/(prepost * Group)), data = rt.df)
>
> plus, I'm not sure how to include the replicate factor ("rep") in my Error() term -- should it be something like
> ...+Error(subj*rep/(Group*prepost))?
> (this still gives the above error if Group is in the error term, but I'm pretty sure it should be there since all interactions given the individual subject are random effects, aren't they?)
> In my hypothetical experiment, I'm assuming the replicates are independent samples of reaction time -- although, admittedly, there could be a trend that should be looked for if one assumes that the subject "gets better" with each replicate.
>
[output deleted]
I'm not sure if this is exactly what you want but a model with fixed
effects for Group and prepost and for their interaction and with
random effects for subj can be fit using the lme4 package as shown in
the enclosed. (If your next question is, "Yes, but how do I get
p-values?" I'll defer to others on that. It's a long story.)
P.S. for Debian/Ubuntu experts. How do I set up the Mime types so
that the system knows that a file with a .Rout extension is
text/plain? Or is this a property of Firefox or Gmai.com? The
immediate problem is that when I try to attach a file with extension
.Rout to a message sent from gmail.com under Firefox off a Ubuntu
system it gets encoded as a binary file and stripped by the mailing
list software. I need to move it to a name ending in .txt before it
gets encoded as text/plain.
-------------- next part --------------
R version 2.5.0 beta (2007-04-14 r41163)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(lme4)
Loading required package: Matrix
Loading required package: lattice
>
> data <- c(
+ 287,283,261,298,302,280,
+ 211,272,222,285,253,252,
+ 266,252,287,266,255,269,
+ 299,310,285,296,310,301,
+ 288,265,273,285,252,259,
+ 295,299,285,288,281,303)
>
> rt.df <- data.frame(rt=data,
+ rep = factor(rep(paste("rep",1:3, sep=""),12)),
+ prepost = factor(rep(c(rep("pre",3),rep("post",3)),6)),
+ subj = factor(rep(paste("subj",1:6,sep=""),c(6,6,6,6,6,6))),
+ Group = factor(c(rep("Treat",18),rep("Control",18))))
>
> fm1 <- lmer(rt ~ Group*prepost + (1|subj), rt.df)
> fm1
Linear mixed-effects model fit by REML
Formula: rt ~ Group * prepost + (1 | subj)
Data: rt.df
AIC BIC logLik MLdeviance REMLdeviance
293.4 301.3 -141.7 307.6 283.4
Random effects:
Groups Name Variance Std.Dev.
subj (Intercept) 239.81 15.486
Residual 245.46 15.667
number of obs: 36, groups: subj, 6
Fixed effects:
Estimate Std. Error t value
(Intercept) 286.111 10.354 27.632
GroupTreat -12.778 14.643 -0.873
prepostpre 2.667 7.386 0.361
GroupTreat:prepostpre -15.889 10.445 -1.521
Correlation of Fixed Effects:
(Intr) GrpTrt prpstp
GroupTreat -0.707
prepostpre -0.357 0.252
GrpTrt:prps 0.252 -0.357 -0.707
>
> proc.time()
user system elapsed
6.956 0.188 7.140
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Stevens_R.txt
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070414/26654fa2/attachment.txt
More information about the R-help
mailing list