[R] new to repeated measures anova in R

John Fox jfox at mcmaster.ca
Wed Mar 7 23:59:17 CET 2012


Dear Peter and Tamre,

I took a closer look at this today, and the infrastructure was there to do
the univariate tests even with a singular SSP matrix, so I modified
Anova.mlm() to accommodate this case. The updates are in the development
version of the car package on R-Forge.

An example (checked against SAS):

--------- snip ------------

> library(car)
Loading required package: MASS
Loading required package: nnet
> phase <- factor(rep(c("pretest", "posttest", "followup"), c(5, 5, 5)),
+ 		levels=c("pretest", "posttest", "followup"))
> hour <- ordered(rep(1:5, 3))
> idata <- data.frame(phase, hour)
> idata
      phase hour
1   pretest    1
2   pretest    2
3   pretest    3
4   pretest    4
5   pretest    5
6  posttest    1
7  posttest    2
8  posttest    3
9  posttest    4
10 posttest    5
11 followup    1
12 followup    2
13 followup    3
14 followup    4
15 followup    5
> 
> mod.ok <- lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5, 
+ 				post.1, post.2, post.3, post.4, post.5, 
+ 				fup.1, fup.2, fup.3, fup.4, fup.5) ~
gender, 
+ 		data=OBrienKaiser[1:5,])
> av.ok.2 <- Anova(mod.ok, idata=idata, idesign=~phase*hour)
> av.ok.3 <- Anova(mod.ok, idata=idata, idesign=~phase*hour, type=3)

> summary(av.ok.2, multivariate=FALSE)

Univariate Type II Repeated-Measures ANOVA Assuming Sphericity

                       SS num Df Error SS den Df       F    Pr(>F)    
(Intercept)       1323.00      1   91.111      3 43.5622   0.00708 ** 
gender               0.89      1   91.111      3  0.0293   0.87505    
phase                2.00      2   30.556      6  0.1964   0.82679    
gender:phase         7.44      2   30.556      6  0.7309   0.51990    
hour                35.07      4    6.333     12 16.6105 7.796e-05 ***
gender:hour          1.93      4    6.333     12  0.9158   0.48597    
phase:hour           3.73      8   41.667     24  0.2688   0.97012    
gender:phase:hour    5.27      8   41.667     24  0.3792   0.92125    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Warning message:
In summary.Anova.mlm(av.ok.2, multivariate = FALSE) :
  Singular error SSP matrix:
non-sphericity test and corrections not available

> summary(av.ok.3, multivariate=FALSE)

Univariate Type III Repeated-Measures ANOVA Assuming Sphericity

                       SS num Df Error SS den Df       F    Pr(>F)    
(Intercept)       1283.56      1   91.111      3 42.2634  0.007391 ** 
gender               0.89      1   91.111      3  0.0293  0.875049    
phase                0.78      2   30.556      6  0.0764  0.927365    
gender:phase         7.44      2   30.556      6  0.7309  0.519900    
hour                36.07      4    6.333     12 17.0842 6.779e-05 ***
gender:hour          1.93      4    6.333     12  0.9158  0.485966    
phase:hour           3.93      8   41.667     24  0.2832  0.965130    
gender:phase:hour    5.27      8   41.667     24  0.3792  0.921247    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Warning message:
In summary.Anova.mlm(av.ok.3, multivariate = FALSE) :
  Singular error SSP matrix:
non-sphericity test and corrections not available

--------- snip ------------

I think that it should also be possible to get the GG and HF epsilons but I
think that would require a different approach than is currently used.

Best,
 John

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of peter dalgaard
> Sent: March-05-12 11:29 AM
> To: Tamre Cardoso
> Cc: r-help at r-project.org; John Fox
> Subject: Re: [R] new to repeated measures anova in R
> 
> 
> On Mar 5, 2012, at 16:05 , Tamre Cardoso wrote:
> 
> > Thank you.
> >
> > I have attached the data:
> 
> The list software seems to have scrubbed it though...
> 
> > The error message from Anova is:
> >
> >> pressure.aov = Anova(multmodel, idata=fact.idata, idesign = ~Shoe *
> >> Region, type="III")
> > Error in linearHypothesis.mlm(mod, hyp.matrix, SSPE = SSPE, idata =
> idata,  :
> >  The error SSP matrix is apparently of deficient rank = 9 < 14
> 
> Oho. Yes that can be a problem. I it is not actually required to have a
> full rank SSP to do the F tests, but the design of Anova() is such that
> it tries to do multivariate analyses somewhere along the way, and I
> don't think there's a way to tell it not to (John?).
> 
> I don't think plain anova.mlm has this particular restriction. It's
> basically the same issue as this:
> 
> > X <- matrix(rnorm(12),3,4)
> > idata <- data.frame(gg = factor(1:4))
> > anova(m,idata=idata, X=~1, test="Spherical")
> Analysis of Variance Table
> 
> 
> Contrasts orthogonal to
> ~1
> 
> Greenhouse-Geisser epsilon: 0.4312
> Huynh-Feldt epsilon:        0.8876
> 
>             Df      F num Df den Df  Pr(>F)  G-G Pr  H-F Pr
> (Intercept)  1 0.3376      3      6 0.79935 0.66045 0.77968
> Residuals    2
> > Anova(m,idata=idata, idesign=~gg, type="III")
> Error in linearHypothesis.mlm(mod, hyp.matrix, SSPE = SSPE, idata =
> idata,  :
>   The error SSP matrix is apparently of deficient rank = 2 < 3
> > anova(m,idata=idata, X=~1) # Full MV test fails here too
> Error in anova.mlm(m, idata = idata, X = ~1) : residuals have rank 2 <
> 3
> 
> 
> --
> Peter Dalgaard, Professor
> Center for Statistics, Copenhagen Business School Solbjerg Plads 3,
> 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
> 
> ______________________________________________
> R-help at r-project.org 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