Thomas Eapen · Selected work

Weighted averages

Combine group averages using their underlying counts, then compare the answer with an ordinary mean.

Synthetic example · independently invented dataOne-page print edition · A3 landscape
01 Inspect the inputs02 Apply the method03 Check the result

INVENTED INPUTS

Different group sizes

Three invented groups
GroupMean · minCount
Group A48
Group B612
Group C920

Each mean describes its group. The counts determine how much that group contributes to the combined average.

SELECTED PYTHON

The working calculation

Pandas is pd, NumPy is np, and rows is the three-row input table.

groups = pd.DataFrame(rows)
weights = groups['count']
if weights.lt(0).any() or weights.sum() == 0:
    raise ValueError('Use non-negative, non-zero weights')
weighted = np.average(
    groups['mean_minutes'], weights=weights
)
ordinary = groups['mean_minutes'].mean()

The code shown here is executed to calculate this example’s results.

COMPUTED RESULT

Give each observation its weight

7.10minutes · weighted mean40 observations represented

284 ÷ 40 = 7.10

Weighted and ordinary meansWeighted: 7.10; Ordinary: 6.33.Weighted7.10Ordinary6.33

The ordinary mean gives each group equal influence. The larger, higher-valued group raises the weighted result.

What this demonstratesA mean of means can misrepresent the underlying observations when group sizes differ. Weighting preserves their contribution.

Check the boundaryReject negative weights and an all-zero denominator. This fixture uses complete means and positive counts; missing-data policy would need a separate decision.