[R] between-within anova: aov and lme
Spencer Graves
spencer.graves at pdf.com
Wed Aug 9 13:32:17 CEST 2006
I can't answer your question about 'aov', but have you tried the
following with 'lme':
lme(response~A*B*C,random=~1|subject)
This assumes that A, B, and C are fixed effects, either continuous
variables or factors present at only a very few levels whose effects are
not reasonably modeled as a random sample from some other distribution.
It also assumes that the effect of each level of subject can be
reasonable modeled as a random adjustment to the intercept following a
common distribution with mean 0 and variance = 'var.subj'.
The function 'aov' is old and mostly obsoleted by 'nlme'. There may
be things that can be done in 'aov' that can not be done more or less as
easily and usually better and more generally with 'lme', but I'm not
familiar with such cases.
Your question suggests you may not be familiar with Pinheiro and
Bates (2000) Mixed-Effects Models in S and S-Plus (Springer). The
standard R distribution comes with a directory "~library\nlme\scripts"
containing script files 'ch01.R', 'ch02.R', ..., 'ch06.R', and 'ch08.R'.
These contain R script files with the R code for each chapter in the
book. I've learned a lot from walking through the script files line by
line while reviewing the corresponding text in the book. Doing so
protects me from problems with silly typographical errors as well as
subtle problems where the S-Plus syntax in the book gives a different
answer in R because of the few differences in the syntax between S-Plus
and R.
Hope this helps.
Spencer Graves
William Simpson wrote:
> I have 2 questions on ANOVA with 1 between subjects factor and 2 within factors.
>
> 1. I am confused on how to do the analysis with aov because I have seen two examples
> on the web with different solutions.
>
> a) Jon Baron (http://www.psych.upenn.edu/~baron/rpsych/rpsych.html) does
> 6.8.5 Example 5: Stevens pp. 468 - 474 (one between, two within)
>
> between: gp
> within: drug, dose
> aov(effect ~ gp * drug * dose + Error(subj/(dose*drug)), data=Ela.uni)
>
> b) Bill Venables answered a question on R help as follows.
>
> - factor A between subjects
> - factors B*C within subjects.
>
> aov(response ~ A*B*C + Error(subject), Kirk)
> "An alternative formula would be response ~ A/(B*C) + Error(subject), which
> would only change things by grouping together some of the sums of squares."
>
> -------------------------------------------------------
> SO: which should I do????
> aov(response ~ A*B*C + Error(subject), Kirk)
> aov(response ~ A/(B*C) + Error(subject), Kirk)
> aov(response ~ A*B*C + Error(subject/(B*C)), Kirk)
> --------------------------------------------------------
>
> 2. How would I do the analysis in lme()?
> Something like
> lme(response~A*B*C,random=~1|subject/(B*C))???
>
>
> Thanks very much for any help!
> Bill Simpson
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list