Skip to main content

Mister P

Causes, samples and populations
Method or technique
Advanced
Multilevel regression and poststratification.
Published

November 9, 2026

Modified

November 13, 2026

Entry #1 in Andrew Gelman’s Handy Statistical Lexicon. Original discussion: The Next Supreme Court Justice.

Filed under Causes, samples and populations · Method or technique · Advanced.

Related terms: MRP, multilevel regression and poststratification, small-area estimation, survey weighting.

Source check: ✓ The explanation was checked against the source. The linked post mentions the method in passing; the explanation of it is ours.

What it is

The lexicon links to a 2009 post, “The Next Supreme Court Justice”, about work by Gelman’s Columbia colleagues John Kastellec, Jeff Lax and Justin Phillips on public opinion and Senate votes on Supreme Court nominees. They “use the method of multilevel regression and poststratification (Mister P, as we call it) to estimate public opinion by state, which is important for their goal of connecting state opinion to Senators’ votes.” The post mentions the method in passing; the explanation below is ours.

“Mister P” (MRP) is a two-step method for turning a survey sample that is non-representative or thin into estimates for a population and its subgroups, such as states, age groups or districts.

  1. Multilevel regression. Model the survey response as a function of demographics and geography. Group-level effects are partially pooled: a state with 15 respondents borrows strength from the other states, while a state with 1,500 mostly speaks for itself.
  2. Poststratification. Use the model to predict every demographic-by-geography cell. Then average those predictions, weighted by how many people the census says live in each cell.

Why it matters

Nearly every real survey is unrepresentative. Some groups answer more than others, and most small areas have too few respondents for a direct estimate. Raw subgroup means are noisy, while simple weighting fixes the demographics but becomes unstable when cells are small or empty. MRP handles both problems at once. It is the standard tool for state-level opinion from national polls, for election forecasting from opt-in panels, and for small-area estimation generally.

How it works

For cell \(j\) (for example, young people in state s), the regression gives a predicted outcome \(\hat\theta_j\). With census counts \(N_j\), the estimate for any larger group \(S\) is

\[ \hat\theta_S^{\text{MRP}} = \frac{\sum_{j \in S} N_j\, \hat\theta_j}{\sum_{j \in S} N_j}. \]

The multilevel part pulls each state’s intercept toward the overall mean. It pulls harder when the state has few respondents, which keeps small-sample noise out of the estimates. The poststratification part corrects for the sample having the wrong demographic mix. The simulation below uses a simplified version of both steps: empirical-Bayes shrinkage of the state effects, plus a common age effect.

Simulated example

Fifty states have different true support for a policy, and young people support it more than old people. The survey over-samples older respondents, and some states get only a handful of interviews. Compare the raw state means with MRP estimates.

Show simulation code

The R version uses base R, and the Python version uses NumPy and Matplotlib. Where the simulation draws random numbers, each language draws its own, so exact numbers differ slightly but show the same pattern. The numbered markers in the R code are explained under it.

import {rng, range, mean, sum, fmt} from "../js/stats.js"

viewof nTotal = Inputs.range([300, 5000], {value: 1200, step: 100, label: "Total sample size"})
viewof oldShare = Inputs.range([0.3, 0.9], {value: 0.75, step: 0.05, label: "Share of sample that is old"})
viewof seed = Inputs.range([1, 500], {value: 7, step: 1, label: "Random seed"})

mrp = {
  const r = rng(seed);
  const S = 50, ageGap = 0.15;           // young support 15 points higher than old
  const states = range(S).map(s => {
    const base = 0.45 + r.normal(0, 0.08); // old-person support in the state
    const youngShare = r.uniform(0.3, 0.6); // census share young
    const size = r.lognormal(0, 0.8);       // relative population
    const truth = youngShare * (base + ageGap) + (1 - youngShare) * base;
    return {s, base, youngShare, size, truth};
  });
  const totalSize = sum(states.map(d => d.size));
  // Draw respondents: state proportional to size, age skewed old.
  const resp = range(nTotal).map(() => {
    let u = r() * totalSize, s = 0;
    while (u > states[s].size) { u -= states[s].size; s++; }
    const young = r() > oldShare ? 1 : 0;
    const p = states[s].base + ageGap * young;
    return {s, young, y: r.bernoulli(p)};
  });
  // Step 1a: common age effect from pooled data (difference of within-state means is overkill here).
  const yy = resp.filter(d => d.young), yo = resp.filter(d => !d.young);
  const ageEff = mean(yy.map(d => d.y)) - mean(yo.map(d => d.y));
  // Step 1b: state intercepts on the "old" scale, partially pooled.
  const rows = states.map(st => {
    const rs = resp.filter(d => d.s === st.s);
    const n = rs.length;
    const raw = n ? mean(rs.map(d => d.y)) : NaN;
    const resid = n ? mean(rs.map(d => d.y - ageEff * d.young)) : NaN;
    return {...st, n, raw, resid};
  });
  const ok = rows.filter(d => d.n > 0);
  const mu = sum(ok.map(d => d.resid * d.n)) / sum(ok.map(d => d.n));
  const v = 0.25;
  const tau2 = Math.max(0.0005, mean(ok.map(d => (d.resid - mu) ** 2)) - mean(ok.map(d => v / d.n)));
  return rows.map(d => {
    const w = d.n ? tau2 / (tau2 + v / d.n) : 0;
    const old = mu + w * ((d.n ? d.resid : mu) - mu);
    // Step 2: poststratify with census age shares.
    const mrpEst = d.youngShare * (old + ageEff) + (1 - d.youngShare) * old;
    return {...d, mrpEst, shrink: 1 - w};
  });
}

long = mrp.flatMap(d => [
  {method: "Raw state mean", truth: d.truth, est: d.raw, n: d.n},
  {method: "MRP", truth: d.truth, est: d.mrpEst, n: d.n}
]).filter(d => Number.isFinite(d.est))

Plot.plot({
  ariaLabel: "Mister P: simulation chart",
  ariaDescription: "Horizontal axis: True state support. Vertical axis: Estimate. The chart updates with the controls above it, and the summary below the charts states the result in words.",
  height: 340,
  grid: true,
  facet: {data: long, x: "method"},
  x: {label: "True state support", domain: [0.2, 0.9]},
  y: {label: "Estimate", domain: [0, 1]},
  r: {range: [1.5, 8]},
  marks: [
    Plot.line([[0.2, 0.2], [0.9, 0.9]], {stroke: "#8a8a8a", strokeDasharray: "4 3"}),
    Plot.dot(long, {x: "truth", y: "est", r: "n", fill: d => d.method === "MRP" ? "#2166ac" : "#d6604d", fillOpacity: 0.6})
  ]
})
# Mister P: multilevel regression and poststratification for state opinion.
1n_total <- 1200 # total sample size
old_share <- 0.75 # share of the sample that is old
2set.seed(7)

S <- 50
age_gap <- 0.15 # young support 15 points higher than old
base <- 0.45 + rnorm(S, 0, 0.08) # old-person support in each state
young_share <- runif(S, 0.3, 0.6) # census share young
size <- rlnorm(S, 0, 0.8) # relative population
3truth <- young_share * (base + age_gap) + (1 - young_share) * base

# Respondents: state proportional to size, age skewed old
state <- sample(S, n_total, replace = TRUE, prob = size)
4young <- as.numeric(runif(n_total) > old_share)
y <- rbinom(n_total, 1, base[state] + age_gap * young)

# Step 1: common age effect, then partially pooled state intercepts
5age_eff <- mean(y[young == 1]) - mean(y[young == 0])
n <- tabulate(state, S)
raw <- tapply(y, factor(state, levels = 1:S), mean)
resid <- tapply(y - age_eff * young, factor(state, levels = 1:S), mean)
ok <- n > 0
mu <- sum(resid[ok] * n[ok]) / sum(n[ok])
v <- 0.25
tau2 <- max(0.0005, mean((resid[ok] - mu)^2) - mean(v / n[ok]))
w <- ifelse(ok, tau2 / (tau2 + v / n), 0)
6old <- mu + w * (ifelse(ok, resid, mu) - mu)
# Step 2: poststratify with census age shares
7mrp <- young_share * (old + age_eff) + (1 - young_share) * old

rmse <- function(est) sqrt(mean((est - truth)^2, na.rm = TRUE))
cat("Error (RMSE, percentage points): raw state means ",
  round(100 * rmse(raw), 1), ", MRP ", round(100 * rmse(mrp), 1),
  "\nStates with no respondents: ", sum(!ok), "\n",
  sep = ""
)

8plot(truth, raw,
  pch = 1, col = "grey50", cex = 0.5 + sqrt(n) / 4,
  xlim = c(0.2, 0.9), ylim = c(0, 1), xlab = "True state support",
  ylab = "Estimate"
)
points(truth, mrp, pch = 19, col = "#2166ac")
abline(0, 1, lty = 2)
legend("topleft", c("Raw state mean", "MRP"),
  pch = c(1, 19),
  col = c("grey50", "#2166ac"), bty = "n"
)
1
The page’s controls: the total sample size and the share of the sample that is old.
2
Fixes the random numbers so the run is reproducible.
3
Each state’s true support: its young and old residents, weighted by the census share of each.
4
The survey over-samples the old, and small states get few respondents.
5
Step 1a: a common age effect, estimated from everyone.
6
Step 1b: each state’s intercept, partially pooled toward the national mean. States with few respondents are pulled hardest.
7
Step 2: poststratify, weighting each state’s young and old predictions by its census shares.
8
Raw state means (open circles, sized by sample) and MRP estimates against the truth. The small circles scatter widely; the pooled estimates don’t.
# Mister P: multilevel regression and poststratification for state opinion.
import numpy as np
import matplotlib.pyplot as plt

n_total = 1200   # total sample size
old_share = 0.75  # share of the sample that is old
rng = np.random.default_rng(7)

S, age_gap = 50, 0.15                  # young support 15 points higher
base = 0.45 + rng.normal(0, 0.08, S)   # old-person support in each state
young_share = rng.uniform(0.3, 0.6, S)  # census share young
size = rng.lognormal(0, 0.8, S)         # relative population
truth = young_share * (base + age_gap) + (1 - young_share) * base

# Respondents: state proportional to size, age skewed old
state = rng.choice(S, n_total, p=size / size.sum())
young = (rng.uniform(size=n_total) > old_share).astype(float)
y = rng.binomial(1, np.clip(base[state] + age_gap * young, 0, 1))

# Step 1: common age effect, then partially pooled state intercepts
age_eff = y[young == 1].mean() - y[young == 0].mean()
n = np.bincount(state, minlength=S)
ok = n > 0
safe_n = np.maximum(n, 1)
raw = np.where(ok, np.bincount(state, y, S) / safe_n, np.nan)
resid = np.where(ok, np.bincount(state, y - age_eff * young, S) / safe_n,
                 np.nan)
mu = np.sum(resid[ok] * n[ok]) / n[ok].sum()
v = 0.25
tau2 = max(0.0005, np.mean((resid[ok] - mu) ** 2) - np.mean(v / n[ok]))
w = np.where(ok, tau2 / (tau2 + v / safe_n), 0)
old = mu + w * (np.where(ok, resid, mu) - mu)
# Step 2: poststratify with census age shares
mrp = young_share * (old + age_eff) + (1 - young_share) * old


def rmse(est):
    return np.sqrt(np.nanmean((est - truth) ** 2))


print(f"Error (RMSE, percentage points): raw state means "
      f"{100 * rmse(raw):.1f}, MRP {100 * rmse(mrp):.1f}")
print(f"States with no respondents: {np.sum(~ok)}")

plt.scatter(truth, raw, s=10 + 3 * n, facecolors="none", edgecolors="0.5",
            label="Raw state mean")
plt.scatter(truth, mrp, color="#2166ac", label="MRP")
plt.plot([0, 1], [0, 1], "k--")
plt.xlim(0.2, 0.9)
plt.ylim(0, 1)
plt.xlabel("True state support")
plt.ylabel("Estimate")
plt.legend()
plt.show()

Key takeaways

  • Partial pooling stabilizes estimates for small groups without throwing away the information that large groups provide.
  • Poststratification corrects for a sample with the wrong demographic mix, as long as you model the variables that drive non-response.
  • MRP is only as good as its adjustment variables (see The Groovy Grandma Problem).

Source

Back to top