# How to approach unbalanced data with unequal sample sizes for comparing means

I have a data with a continuous and two categorical (population and sex) variables. I want to test whether the means among the groups are significantly different. However, this is not an experimental design and the data is not very tidy.

The tibble below shows the number of cases in each population:sex interaction level. It is not a representation of the actual data. As stated above, actual data contains a continuous variable which is a measure of size.

# A tibble: 10 x 3
# Groups:   Site [5]
Site  Sex       n
<fct> <fct> <int>
1 GP1   F        21
2 GP1   M        29
3 GP2   F        16
4 GP2   M        13
5 GP3   F        12
6 GP3   M        14
7 GP4   F        16
8 GP4   M         8
9 GP5   F        29
10 GP5   M        21


My question is how can I approach this kind of data?

• Should I create a new balanced dataset with equal sample sizes using the minimum number of cases in population:sex (8)?
• Or, should I create a new unbalanced dataset with equal sample sizes using the minimum number of cases in population (24)?
• Both of these mean losing a lot of data. Is there a robust test I can use with all of the data without losing any?

I should note that according to Levene test there is no heteroskedasticity but the result of shapiro test on the residuals from anova using all data is non-significant, using equal sample sizes and unbalanced data non-significant, using equal sample sizes and balanced data significant. These subsets are generated by randomly sampling without replacement from the data.

• "I want to test whether the means among the groups are significantly different." - Which "means"? – KaPy3141 Feb 4 '20 at 14:04
• So, is your goal to compare sex-ratios among the groups? E.g. is the number 0.432 different from the number 0.543? – KaPy3141 Feb 4 '20 at 14:07
• I stated that I have a data with a "continuous" and two "categorical variables". The provided tibble is not the actual data, it is just to show the number of cases in each population:sex interaction levels. I should have made it clear in the post, sorry. Continuous variable is a measure of size. – krypt Feb 4 '20 at 14:14
• You say this is not experimental data. How did you obtain the data? – kjetil b halvorsen Feb 4 '20 at 14:24
• @kjetilbhalvorsen What I meant by that is we did not design an experiment for this data. For example decide on a population as a control group and compare the others to this. So, we didn't have any specific hypotheses for this variable. The data were gathered for a different purpose. It was decided after having gathered the data to look for differences in this variable. Is this information important for my question? I included it in the question as the reason why my data is unbalanced and unequal. I can remove it if it's misdirecting. – krypt Feb 4 '20 at 14:33

Whatever you do, you should not falsify your data by producing (somehow?) a new, balanced dataset. You have the data you have, and must live with it!

While anova methods are more powerful (and robust) with balanced data, they can work and be used with unbalanced data. And the unbalance in your dataset does not seem to be very bad. As for practical advice, look through this list of simlar Qs with answers.

• I've never thought subsetting the data as falsifying actually. Thanks for the realization! – krypt Feb 4 '20 at 14:56
• Would you say ANOVA is more powerful with balanced data, given that you have a fixed N total among groups (e.g. group 1 : N=50, group2: N=50, vs group 1 : N=30, group2: N=70), or would it also be preferred to have 50+50 over 50+60? – KaPy3141 Feb 4 '20 at 14:59
• Given a fixed total, equal n's is better, but 50/60 is better than 50/50 – kjetil b halvorsen Feb 4 '20 at 15:02

Keep the all data!

Making your groups "equally bad" serves no mathematical purpose! And in Biological context you wouldn't survive peer-review removing data without a strong justification! Never do that!

After doing Levene and Shapiro, it's legitimate to use ANOVA on different sample sizes!

• As I said in the comment to the other answer, I actually never thought of the implications of subsetting my data. A lot of texts on the subject warns about sample sizes and unbalanced designs so I had a tunnel vision on it I guess. Thanks for the answer. – krypt Feb 4 '20 at 14:59