[R] Manually calculating values from aov() result

Brian Smith br|@n@m|th199312 @end|ng |rom gm@||@com
Wed Aug 7 14:27:48 CEST 2024


Hi,

Thanks for this information. Is there any way to force R to use Type-1
SS? I think most textbooks use this only.

Thanks and regards,

On Wed, 7 Aug 2024 at 17:00, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>
> On 2024-08-07 6:06 a.m., Brian Smith wrote:
> > Hi,
> >
> > I have performed ANOVA as below
> >
> > dat = data.frame(
> > 'A' = c(-0.3960025, -0.3492880, -1.5893792, -1.4579074, -4.9214873,
> > -0.8575018, -2.5551363, -0.9366557, -1.4307489, -0.3943704),
> > 'B' = c(2,1,2,2,1,2,2,2,2,2),
> > 'C' = c(0,1,1,1,1,1,1,0,1,1))
> >
> > summary(aov(A ~ B * C, dat))
> >
> > However now I also tried to calculate SSE for factor C
> >
> > Mean = sapply(split(dat, dat$C), function(x) mean(x$A))
> > N = sapply(split(dat, dat$C), function(x) dim(x)[1])
> >
> > N[1] * (Mean[1] - mean(dat$A))^2 + N[2] * (Mean[2] - mean(dat$A))^2
> > #1.691
> >
> > But in ANOVA table the sum-square for C is reported as 0.77.
> >
> > Could you please help how exactly this C = 0.77 is obtained from aov()
>
> Your design isn't balanced, so there are several ways to calculate the
> SS for C.  What you have calculated looks like the "Type I SS" in SAS
> notation, if I remember correctly, assuming that C enters the model
> before B.  That's not what R uses; I think it is Type II SS.
>
> For some details about this, see
> https://mcfromnz.wordpress.com/2011/03/02/anova-type-iiiiii-ss-explained/
>



More information about the R-help mailing list