How to deal with unbalanced group sizes in mixed design analysis?

I have 2 x 2 x 2 mixed design with two between subject factors (sex, organizer) and one within subjects factor (task). The group sizes of the ‘sex’-factor is unequal. When I perform a factorial repeated measures ANOVA, I get the following warning message:

Warning: Data is unbalanced (unequal N per group). Make sure you
specified a well-considered value for the type argument to ezANOVA().

I used the following model in R:

model <- ezANOVA(data=df, dv=.(top_start), wid=.(id), between=.(sex, org),
                         within=.(task), type = 3, detailed = TRUE)

I used type = 3 for the Anova because, as I understood, it is suited for unbalanced group sizes.

I have the following questions:

  • Do I need to code contrasts when all my factors have only two levels?
  • Did I use the right type of Anova?
  • Are there other ways to do this analysis?


If you use type 3 for ANOVAs it is critical in R that you set the contrast to effect coding (i.e., "contr.sum").

The default contrast in R is dummy coding (or in R parlance, treatment coding) in which 0 represents the first factor level. This doesn’t make too much sense when having interactions as explaind on the page I linked to.

To set effect coding, run the following:


Alternatively, you can use the afex package, which has similar goals as ez, with the difference that it automatically sets the contrasts to effects coding and uses type 3 as default.

Source : Link , Question Author : Jaap , Answer Author : Henrik

Leave a Comment