[R] anova leads to an error

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Fri May 22 17:18:52 CEST 2009


Skotara wrote:
> Dear R-list,
> 
> the following code had been running well over the last months:
> 
>       exam <- matrix(rnorm(100,0,1), 10, 10)
>       gg <- factor(c(rep("A", 5), rep("B", 5)))
>       mlmfit <- lm(exam ~ 1); mlmfitG <- lm(exam ~ gg)
>       result <- anova(mlmfitG, mlmfit, X=~0, M=~1)
> 
> Until, all of a sudden the following error occured:
> 
> Fehler in apply(abs(sapply(deltassd, function(X) diag((T %*% X %*%
> t(T))))),  :
>  dim(X) must have a positive length
> 
> I have not kept track of the changes in my R-version, so it might have
> to do with that.
> Now it is: R version 2.9.0 (2009-04-17).
> 
> Does anybody know more about this error? I would help me a lot!


Hmm, It didn't work in 2.8.1 either.

Anyways, the direct cause of the problem is that the construction

sapply(deltassd, function(X) diag((T %*% X %*% t(T))))

will return a vector, not matrix, if T is 1 x p. This happens inside

apply(abs(sapply(deltassd, function(X) diag((T %*% X %*% t(T))))), 1, max)

and obviously, apply() is confused. We need an as.matrix(), which we do
have at other points in the function.

For a quick workaround, use test="Spherical". It is really a univariate
problem so all the tests are equivalent (in fact,
anova(lm(rowMeans(exam) ~ gg)) also works).

> 
> Thank you very much!
> 
> Nils
> 
> ______________________________________________
> 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.


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list