Combining means of groups (source code)

= Combining means of groups
{title2=$\bar x=\sum_j n_j\bar x_j/\sum_jn_j$}

Suppose disjoint nonempty groups have sizes $n_j$ and <arithmetic means> $\bar x_j$. The <arithmetic mean> of all observations is
$$
\boxed{\bar x=\frac{\sum_j n_j\bar x_j}{\sum_j n_j}.}
$$
Each group contributes the <sum> $n_j\bar x_j$; add those totals before dividing by the overall count. This is exactly a <weighted mean> of group means with weights equal to group sizes. https://openstax.org/books/introductory-statistics-2e/pages/2-5-measures-of-the-center-of-the-data[OpenStax Introductory Statistics 2e, §2.5: means from frequencies]{ref}

Take a synthetic example with two observations equal to $90$ and eight equal to $60$. The two group means are $90$ and $60$, and the combined mean is $66$. Giving the two groups equal weights instead produces $(90+60)/2=75$, which summarizes the two group means with equal influence. To summarize all ten individuals with equal influence, use their group counts.

\Image[/weighted-mean-group-sizes.png]
{title=Group size determines each group mean's influence on the combined individual mean}
{description=Two synthetic observations are $90$ and eight are $60$. Their combined <arithmetic mean> is $66$; the equal-weight average of the two group means is $75$.}

The group means and counts determine the combined <arithmetic mean>, but do not generally determine the combined <variance>. Variation within the groups is additional information.