Why the overall rate can flip: weighted means and Simpson’s paradox in R

Wait 5 sec.

[This article was first published on R on Stats and R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.IntroductionThe dataAn overall rate is a weighted meanThe result depends on the reference mixWhen exactly does the comparison flip?Which rate should you report?ReferencesNote: This post has been written in collaboration with the Easy Stat Calc Team.IntroductionMost readers learn that an overall average is “just the average”. The trouble starts when the data come in subgroups. An overall rate is not the plain average of the subgroup rates. It is a weighted mean of them, and the weights are the subgroup sizes. Change the weights and the answer changes, sometimes enough to reverse a comparison.That reversal is known as Simpson’s paradox. The classic illustration is the 1973 graduate admissions data from the University of California, Berkeley (Bickel et al. 1975), which ship with R as UCBAdmissions. This article does not stop at the familiar “women do better inside departments” table. It asks three questions the table leaves open:How much does the re-weighted result depend on which applicant mix we pick as the reference?At exactly what point does a small advantage inside every subgroup get cancelled out by differences in subgroup mix, and how often does a sample of a given size show the flip near that point?When is the overall rate the right number, and when is the subgroup rate the right number?Everything below uses base R, except for the plot, which is made with the {ggplot2} package. A seed is set at the start of the simulation code to ensure reproducibility.The dataUCBAdmissions is a 2 x 2 x 6 table: admission status, gender and department (the six largest departments, labelled A to F). We separate admitted counts from totals and compute department-level rates.adm