# Compare several means with different sample sizes (greater than 2)

I have seven different groups with different sample sizes and variances and I want to compare the means of their data. I'm not very informed in statistics, so could anyone help me out here? I've only seen answers to comparing means with only two groups, so I had to ask what happens when there are more than two groups.

• Are the data continuous & normally distributed? What are the Ns & variances? – gung Apr 3 '16 at 19:19
• To the first question, no. Secondly, the variances and Ns, respectively, are: 27.0595924644 and 51, 59.900591716 and 65, 250.234375 and 8, 17.3786848073 and 21, 7.22535211268 58.0337234676 and 71 – Abhi V Apr 3 '16 at 21:07
• Do you need to compare the means themselves, or would it be enough to say that some groups tend to be higher than others? – gung Apr 3 '16 at 22:19
• I think the latter would work, but what if one group has a very small sample size? Would this still work? – Abhi V Apr 3 '16 at 22:31
• Your smallest group has N = 8, that's not catastrophic. It will just affect your power would be affected, but that's all. – gung Apr 3 '16 at 22:37

## 1 Answer

You can test your data with the Kruskal-Wallis test. This does not assume that the within group data are normally distributed or that the variance is constant. It also does not require that the $N$s are equal. One thing to bear in mind is that the test isn't quite to see if the means are equal. Instead it is to see if any groups are stochastically dominant over any others, that is, if any group tends to have larger numbers.

To demonstrate, here is a simple example (coded in R):

d = read.table(text="7.0595924644  51
59.900591716  65
250.234375  8
17.3786848073  21
7.22535211268  5
58.0337234676  71")

set.seed(5158)
y = c()
for(i in 1:6){  y = c(y, rnorm(d[i,2], mean=i, sd=sqrt(d[i,1])))}
g = rep(1:6, times=d[,2])
kruskal.test(y~g)
#  Kruskal-Wallis rank sum test
#
# data:  y by g
# Kruskal-Wallis chi-squared = 33.066, df = 5, p-value = 3.651e-06

• Actually, is there a formula for comparing the means themselves? The Kruskal-Wallis test works but because it does not indicate which set is dominant I'm not sure I can use it because I need to give each data set a relative rank compared to the other data sets based on which is generally larger – Abhi V Apr 4 '16 at 1:37
• There is no formula for comparing the means that doesn't make distributional assumptions; you could bootstrap. However, you can do follow up post hoc tests after KW using the dunn-test. – gung Apr 4 '16 at 3:07