On Mon, 19 Nov 2001 Olivier.Renaud@pse.unige.ch wrote:
>
> Hi,
> Dealing with a repeated measure ANOVA with NAs, I am a bit surprised by S+
> output (S+6 as well as S+2000 on Win98). Example:
>
> ## anova with repeated measure. Works fine
> > summary (aov(formula = mctend ~ Time + Error(Sujet/Time), data = c3))
What did you intend here? Is Time a factor? Is there any replication
within Time? Looks to me as if you have 40 subjects measured 3 times
each, and so you don't need a Time random effect.
> Error: Sujet
> Df Sum of Sq Mean Sq F Value Pr(F)
> Residuals 39 37.72124 0.9672114
>
> Error: Time %in% Sujet
> Df Sum of Sq Mean Sq F Value Pr(F)
> Time 2 0.81571 0.407857 0.3797048 0.6853207
> Residuals 78 83.78317 1.074143
>
> ## Adding an NA
> > c3$mctend[45] <- NA
> ## without specification for the treatment of the NA, the procedure stop. Fine
> > summary (aov(formula = mctend ~ Time + Error(Sujet/Time), data = c3))
> Error in function(object, ...): missing values not allowed: found in mctend
>
> ## But when we exclude the NA, the error is divided in 3 parts (including an
> na.action!), and the factor Time is tested twice !!
> > summary (aov(formula = mctend ~ Time + Error(Sujet/Time), data = c3,
> > na.action=na.exclude))
> Error: Sujet
> Df Sum of Sq Mean Sq F Value Pr(F)
> Time 1 0.59182 0.5918184 0.6126098 0.4386575
> Residuals 38 36.71031 0.9660609
>
> Error: Time %in% Sujet
> Df Sum of Sq Mean Sq F Value Pr(F)
> Time 2 0.80665 0.403327 0.3706737 0.6914941
> Residuals 77 83.78298 1.088091
>
> Error: na.action
> Min. 1st Qu. Median Mean 3rd Qu. Max.
> 45 45 45 45 45 45
>
> Is this a bug or my misunderstanding of repeated measure? In the
first case, is it possible to compute separately the covariance matrix
with an EM-algorithm for the missing values and to feed aov with it?
Any other solution is also welcomed.
One misunderstanding: aov is the function for balanced designs, not for
repeated measures. In the unbalanced case (including most with missing
values), lme would be more appropriate.
aov does not work on covariance matrices, BTW. It projects data onto
strata.
I think you intend na.action=na.omit, not na.exclude (since you are not
doing predictions). I can reproduce this in S+6:
c3 <- data.frame(Sujet=factor(rep(1:40, 3)), Time=factor(rep(1:3,
rep(40,3))), mctend=rnorm(120))
summary (aov(formula = mctend ~ Time + Error(Sujet/Time), data = c3))
Error: Sujet
Df Sum of Sq Mean Sq F Value Pr(F)
Residuals 39 45.5 1.166667
Error: Time %in% Sujet
Df Sum of Sq Mean Sq F Value Pr(F)
Time 2 1.17826 0.589128 0.5646303 0.5708767
Residuals 78 81.38417 1.043387
c3$mctend[45] <- NA
summary (aov(formula = mctend ~ Time + Error(Sujet/Time), data = c3,
na.action=na.exclude))
Error: Sujet
Df Sum of Sq Mean Sq F Value Pr(F)
Time 1 4.22568 4.225679 3.829483 0.05773523
Residuals 38 41.93145 1.103459
Error: Time %in% Sujet
Df Sum of Sq Mean Sq F Value Pr(F)
Time 2 1.17877 0.589387 0.5630613 0.5717899
Residuals 77 80.60004 1.046754
Error: na.action
Min. 1st Qu. Median Mean 3rd Qu. Max.
45 45 45 45 45 45
That's a bug, stemming from
if(!is.null(attr(mf, "na.action")))
result$na.action <- attr(mf, "na.action")
This should be put on each component of a list, or on the single
component of a single result.
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
|