[R] "Estimate effects may be unbalanced" in aov()

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Mon Oct 22 16:48:11 CEST 2007


Max Manfrin wrote:
> On 22 Oct 2007, at 10:50, Prof Brian Ripley wrote:
>
>> On Mon, 22 Oct 2007, Max Manfrin wrote:
>>
>>> Can anybody explain me what does it mean "Estimated effects may be
>>> unbalanced", and what does it imply for the anova analysis?
>>
>> The help page does!  I suspect you intended to use factors, and have
>> not done so, and also that you did not intend to replicate res.
>>
>> Try
>>
>> D <- expand.grid(A=factor(c(0,1,2,3)),B=factor(c(0,1)),C=factor(c(0,1)))
>> aov(rnorm(16) ~ A * B * C, data = D)
>
> > D<-expand.grid(A=factor(c(0,1,2,3)),B=factor(c(0,1)),C=factor(c(0,1)))
> > D
>    A B C
> 1  0 0 0
> 2  1 0 0
> 3  2 0 0
> 4  3 0 0
> 5  0 1 0
> 6  1 1 0
> 7  2 1 0
> 8  3 1 0
> 9  0 0 1
> 10 1 0 1
> 11 2 0 1
> 12 3 0 1
> 13 0 1 1
> 14 1 1 1
> 15 2 1 1
> 16 3 1 1
> > aov(rnorm(16) ~ A*B*C, data=D)
> Call:
>    aov(formula = rnorm(16) ~ A * B * C, data = D)
>
> Terms:
>                        A        B        C      A:B      A:C     
> B:C    A:B:C
> Sum of Squares  9.327827 0.256657 0.172870 4.054674 0.079648 3.214687
> 2.828070
> Deg. of Freedom        3        1        1        3        3       
> 1        3
>
> Estimated effects may be unbalanced
> > !is.list(replications(formula=rnorm(16)~A*B*C,data=D))
> [1] TRUE
>
>
>
> The number of replicates for each factor is the same. I guess that the
> unbalanced refers to the number of observations that each level in a
> factor has, am I correct?
> For calculating HSDTukey confidence intervals for interaction plots in
> such unbalanced design, what should I do?
>
> Thanks in advance.
>

You need to set orthogonal contrasts.

(I'm a little confused here:  There is code inside aov() which looks
like it is intended to ensure that Helmert contrasts are used in the
calculations but they clearly are not?)

> options(contrasts = c("contr.helmert", "contr.poly"))
> aov(y ~ A*B*C, data=D)
Call:
   aov(formula = y ~ A * B * C, data = D)

Terms:
                       A        B        C      A:B      A:C      B:C   
A:B:C
Sum of Squares  1.865413 1.274867 0.649255 3.509371 0.679776 0.145896
4.278649
Deg. of Freedom        3        1        1        3        3       
1        3

Estimated effects are balanced


-- 
   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