If I have calculated the mean for 4 data sets (which do have different sample sizes), can I then obtain an "overall mean" by calculating the "mean of the means"? If yes, will this "mean of the means" be the same as if I had combined the data from all 4 sets and then calculated the mean?
-
4Have you tried it both ways ;-)? (No.) – gung - Reinstate Monica Jan 12 '15 at 18:03
5 Answers
No, the averages of the averages of subsets is not the same as the average of the whole set. It will only be the same value if the subsets are the same sample size. If you want the average of the population, multiply each average by the size of the sample it came from to get the population total, then divide by the total number of data points (population size).
See the batting averages example on Simpson’s paradox for a good illustration of why averaging averages does not usually work.
- 5,572
- 1,042
- 2
- 11
- 30
Let's try it and see if we can figure it out. The following example is coded in R, which is free and will let you reproduce the example, but hopefully the code is self-explanatory:
group1 = c(1,2,3)
group2 = c(4,5,6,7,8,9)
mean(group1)
# 2
mean(group2)
# 6.5
mean(c(group1, group2))
# 5
mean(c(mean(group1), mean(group2)))
# 4.25
So what we see is that you certainly can calculate the mean of the means, but the mean of the means and the mean of all the raw data don't match. We can also try a weighted average using @BilltheLizard's suggestion to use each group's sample size as a weight (the weights are indicated with the w argument):
weighted.mean(c(mean(group1), mean(group2)), w=c(3,6))
# 5
This now gives us the same answer.
- 145,122
In general, if you have a set of $m$ groups with respective sizes $n_1,...,n_m$ and means $\bar{x}_1,...,\bar{x}_m$ then the overall sample mean of all the data is:
$$\bar{x} = \sum_{k=1}^m \frac{n_k}{n} \cdot \bar{x}_k \quad \quad \quad \quad \quad n = \sum_{i=1}^m n_k.$$
Thus, the overall mean is always a weighted average of the samples means of the groups. In the special case where all the groups are the same size ($n_1 = \cdots = n_m$), all the weights will be the same and so the overall sample mean will be the mean of the group sample means.
- 124,856
-
See also the Law of total expectation: "If $\left{A_i\right}_i$ is a finite or countable partition of the sample space, then $\mathrm{E}(X)=\sum_i \mathrm{E}\left(X \mid A_i\right) \mathrm{P}\left(A_i\right)$" – ngmir May 26 '23 at 10:53
Just want to give an (extreme) example: if we have a hit rate of (1/10000) in one sample, and a hit rate of (1/2) in another example, then $\sum \frac{hit_i}{total_i} \neq \frac{\sum hit_i}{\sum total_i}$. In the first case (mean of means), we have an "average" hit rate of 0.5001/2 while in the second case (mean of total) we have 3/10003, and these two numbers are not the same. Whether one is more appropriate or correct depends on your use case.
Here's a simple counter-example that shows that the relation in the posted question cannot be true in general. Let us begin by defining the function mean that simply takes a set of outcomes and outputs the mean of those outcomes:
mean({x_1, ..., x_n}) := (x_1 + ... + x_n)/n,
where n = #{x_1, ..., x_n} (number of elements in the set).
Assume that your set is the outcomes {1,2,3}. Then,
mean({mean({1}), mean({2,3})}) = 1.75,
mean({1,2,3}) = 2,
mean({mean({1,2}), mean({3})}) = 2.25,
that is depending on how you calculate the mean of the means (of the subsets), you can arrive at a value smaller or larger than the overall mean.
The above calculations also demonstrate that there is no general order between the mean of the means and the overall mean. In other words, the hypotheses "mean of means is always greater/lesser than or equal to overall mean" are also invalid.
- 101