[R] extraction of mean square value from ANOVA

Rolf Turner rolf.turner at xtra.co.nz
Fri May 20 04:40:57 CEST 2011


On 20/05/11 13:46, Cheryl Johnson wrote:
> Hello,
>
> I am randomly generating values and then using an ANOVA table to find the
> mean square value. I would like to form a loop that extracts the mean square
> value from ANOVA in each iteration. Below is an example of what I am doing.
>
> a<-rnorm(10)
> b<-factor(c(1,1,2,2,3,3,4,4,5,5))
> c<-factor(c(1,2,1,2,1,2,1,2,1,2))
>
> mylm<-lm(a~b+c)
> anova(mylm)
>
> Since I would like to use a loop to generate this several times it would be
> helpful to know how to extract the mean square value from ANOVA.

anova(mylm)[["Mean Sq"]]

strangely enough. :-)

This gives you a *vector* (of length 3 in your setting), the last
entry of which is the error (or residual) mean square, which is
probably what you want since you refer the ``mean square value''
(singular).

     cheers,

         Rolf Turner



More information about the R-help mailing list