Binomial Coin-Bias Estimation and Overdispersion Diagnostics
Medium · Statistics & Math · Data Scientist · Technical Screen
Prompt
Work through both parts of the following probability and statistical modeling scenario:
Part 1: Estimating Coin Bias and Batch Moments
Suppose an experiment records 80 independent, identically distributed (i.i.d.) tosses of a single coin, and 56 of those tosses land Heads.
- Derive the Maximum Likelihood Estimate (
p_hat) for the coin's probability of landing Heads. - Treating
p_hatas the coin's Heads probability, compute the expected count of Heads and the variance across a new sequence of8tosses. - Name the probability distribution governing that
8-toss count, list the assumptions needed for the distribution to hold, and explain what goes wrong with estimation and uncertainty if your initial experiment had only2tosses instead of80.
Part 2: Diagnosing Batch-Level Count Dispersion
Next, you inspect an observational table of 800 separate batches, where every batch records the number of Heads observed across 8 coin tosses. Across the 800 batches, the sample mean is 4.0 Heads and the sample variance is 5.5.
- Could a standard Binomial model plausibly generate this dataset? Support your answer mathematically using the Binomial variance identity
Var(X) = n * p * (1 - p). - Name the statistical phenomenon shown by this mismatch between mean and variance, explain what broken physical assumption could cause it, and propose an appropriate model adjustment.
Scope & Expectations
- Derive
p_hatdirectly from the log-likelihood function rather than quoting the sample fraction without proof, and distinguish a single Bernoulli trial from a Binomial sum. - Check all four Binomial validity conditions explicitly and analyze boundary collapse when the initial sample has only
2tosses. - Prove why no probability
plets an8-toss Binomial model reach variance5.5, then connect the excess variation to hierarchical or correlated-trial count models.
Step-by-step walkthrough
Part 1: Name the Binomial model and its four assumptions
Start from a single toss and build up to a batch of
ntosses:- A Bernoulli(p) trial models one coin toss with two possible outcomes:
1(Heads) with probabilityp, and0(Tails) with probability1 - p. Its expected value ispand its variance isp * (1 - p). - Adding up
nsuch tosses givesX = X_1 + X_2 + ... + X_n, the total count of Heads inntosses. When the tosses are independent and identically distributed (i.i.d.) — meaning no toss influences another and every toss shares the exact same Heads probabilityp—Xfollows a Binomial(n, p) distribution:
P(X = k) = C(n, k) * p^k * (1 - p)^(n - k) for k = 0, 1, ..., n E[X] = n * p Var(X) = n * p * (1 - p)where
C(n, k) = n! / (k! * (n - k)!)counts how many sequences ofntosses contain exactlykHeads.You can remember the four assumptions required for
Binomial(n, p)to be valid with BINS:- Binary outcomes: Every toss lands either Heads or Tails (no edge stands or missing trials).
- Independent trials: Learning the outcome of one toss does not change the probability of Heads on any other toss (no streak or alternation effects).
- Number of trials
nfixed in advance: You decide to tossntimes before starting (as opposed to tossing until you see 4 Heads, which would follow a Negative Binomial model). - Same probability
pon every trial: The coin and tossing mechanism stay identical across all tosses (no coin wear, swapping coins, or changing tossers).
- A Bernoulli(p) trial models one coin toss with two possible outcomes:
Part 1: Derive the Maximum Likelihood Estimate (p_hat = 0.70)
Maximum Likelihood Estimation (MLE) finds the parameter value
pthat makes the observed data (56Heads and24Tails across80tosses) as probable as possible.Write the likelihood function
L(p)— the probability of observing56Heads out of80tosses treated as a function of the unknownp— and take its natural logarithm so exponents turn into easy sums (becauselogis strictly increasing,log L(p)andL(p)peak at the exact samep):L(p) = C(80, 56) * p^56 * (1 - p)^24 log L(p) = log C(80, 56) + 56 * log(p) + 24 * log(1 - p) Differentiate with respect to p and set to 0: d/dp log L(p) = 56 / p - 24 / (1 - p) = 0 56 * (1 - p) = 24 * p 56 - 56 * p = 24 * p 56 = 80 * p p_hat = 56 / 80 = 0.70To verify this critical point is a maximum rather than a minimum, check the second derivative:
-56 / p^2 - 24 / (1 - p)^2is strictly negative for everypin(0, 1)(and at the boundariesp = 0orp = 1,L(p) = 0). In general, the Binomial MLE is always the sample proportionheads / tosses.In an interview, pair any point estimate with its standard error (
SE) — the typical sampling wiggle ofp_hatacross repeated 80-toss experiments:import math heads = 56 tosses = 80 p_hat = heads / tosses standard_error = math.sqrt(p_hat * (1.0 - p_hat) / tosses) ci_low = p_hat - 1.96 * standard_error ci_high = p_hat + 1.96 * standard_error print(p_hat, round(standard_error, 4)) # 0.7 0.0512 print(round(ci_low, 3), round(ci_high, 3)) # 0.6 0.8Part 1: Expected Heads and variance in 8 tosses (plus the 2-toss edge case)
Now toss this coin
n = 8times, treatingp = p_hat = 0.70as the coin's Heads probability, soX ~ Binomial(8, 0.70). Because expectations always add (E[X_1 + ... + X_8] = 8 * E[X_1]) and variances add when variables are independent (Var(X_1 + ... + X_8) = 8 * Var(X_1)):Expected Heads: E[X] = n * p = 8 * 0.70 = 5.6 Heads Variance: Var(X) = n * p * (1 - p) = 8 * 0.70 * 0.30 = 1.68 Standard dev.: SD(X) = sqrt(1.68) ≈ 1.30 Heads(As a bonus detail:
1.68treatsp = 0.70as known without error; if you propagate the estimation uncertainty from our 80-toss sample using a uniformBeta(1, 1)prior, the predictive variance rises slightly by about9.4%to1.84.)Edge case — what if Part 1 had only
n = 2tosses? With2tosses,p_hatcan only take three values:0.0(0Heads),0.5(1Head), or1.0(2Heads). Even a completely unbiased coin (p = 0.5) lands Heads twice0.5^2 = 25%of the time and Tails twice another25%of the time — meaning half the time (50%), MLE hits a boundary (0or1)! If you observe2Heads out of2:p_hat = 1.0, so the plug-in Binomial formula predicts8.0Heads in8tosses with zero variance (8 * 1.0 * 0.0 = 0) and zero standard error (sqrt(1.0 * 0.0 / 2) = 0), claiming total certainty from two tosses!- How to fix tiny-sample collapse: Report an exact Clopper-Pearson 95% confidence interval (
[0.025^(1/2), 1.0] = [0.158, 1.000]for2/2Heads) or use Bayesian smoothing (for example, Laplace's uniformBeta(1, 1)prior adds one pseudo-Head and one pseudo-Tail, pulling the estimate from2/2 = 1.0toward(2 + 1) / (2 + 2) = 0.75).
Part 2: Why variance 5.5 is impossible for any Binomial(8, p)
In Part 2, we observe
N = 800batches ofn = 8tosses with sample mean4.0and sample variance5.5. This dataset cannot come from a standardBinomial(8, p)distribution, for three reinforcing reasons:- Matching the mean breaks the variance: For
Binomial(8, p),E[X] = 8 * p = 4.0pinsp = 0.5. Pluggingn = 8andp = 0.5intoVar(X) = n * p * (1 - p)gives8 * 0.5 * 0.5 = 2.0. The observed variance5.5is5.5 / 2.0 = 2.75times too large. - Universal variance ceiling for
n = 8: Even if you tried changingp, note thatp * (1 - p) = 0.25 - (p - 0.5)^2 <= 0.25for every probabilitypin[0, 1]. Therefore, noBinomial(8, p)distribution can ever have a variance above8 * 0.25 = 2.0! - Far outside 800-batch sampling noise: Under
Binomial(8, 0.5), the fourth central momentE[(X - 4)^4]is11.0, so the sample variance across800independent batches has a standard error ofsqrt((11.0 - 2.0^2) / 800) ≈ 0.0935. Observing5.5instead of2.0is over 37 standard errors away (equivalently, the classical dispersion statisticD = (N - 1) * s^2 / 2.0 = 799 * 5.5 / 2.0 = 2,197.25sits enormously above its expected value of799).
import math num_batches = 800 batch_size = 8 sample_mean = 4.0 sample_var = 5.5 p_implied = sample_mean / batch_size binomial_var = batch_size * p_implied * (1.0 - p_implied) # 2.0 (max possible) # Exact SE of s^2 under Binomial(8, 0.5), where fourth central moment mu_4 = 11.0 mu_4 = binomial_var * (1.0 + (3 * batch_size - 6) * p_implied * (1.0 - p_implied)) se_sample_var = math.sqrt((mu_4 - binomial_var ** 2) / num_batches) z_exact = (sample_var - binomial_var) / se_sample_var print(binomial_var, round(se_sample_var, 4), round(z_exact, 1)) # 2.0 0.0935 37.4- Matching the mean breaks the variance: For
Part 2: Diagnose overdispersion and see how broken assumptions create it
When observed count variance exceeds the theoretical variance allowed by the assumed distribution, the phenomenon is called overdispersion (or extra-binomial variation). Note a helpful nuance: "variance > mean" is the threshold for Poisson overdispersion (where
Var = mean). For a Binomial distribution,Var = n * p * (1 - p)is already smaller thanmean = n * p— and here5.5exceeds both2.0and4.0!Visually, both distributions center at
4.0, but overdispersion hollows out the middle and pushes far more batches into the extreme tails (0, 1, 7, 8Heads):Expected batch counts across 800 batches of 8 tosses (both have mean = 4.0): Heads k : 0 1 2 3 4 5 6 7 8 Binomial: 3 25 88 175 219 175 88 25 3 (Var = 2.0) Beta-Bin: 59 84 98 105 108 105 98 84 59 (Var = 5.5)Overdispersion tells us that assumption I (independence) or assumption S (same
p) of BINS failed:- Cause A —
pvaries from batch to batch (heterogeneity): Different batches use coins with different biases (for example, warped coins or different mechanical flippers). If batch biases have averageE[p] = muand spreadVar(p), the law of total variance (Var(X) = E[Var(X | p)] + Var(E[X | p])) simplifies to:
Var(X) = n * mu * (1 - mu) + n * (n - 1) * Var(p)Plugging in `n = 8`, `mu = 0.5`, and `Var(X) = 5.5` gives `2.0 + 56 * Var(p) = 5.5`, so `Var(p) = 3.5 / 56 = 0.0625`. For instance, a 50/50 mix of two trick coins with `p = 0.25` and `p = 0.75` produces exact overall mean `4.0` and exact variance `5.5`!- Cause B — Positive correlation within each batch (streaks): Every coin has marginal
p = 0.5, but tosses inside the same 8-toss batch tend to repeat (Cov(X_i, X_j) > 0). With common pairwise correlationrhobetween any two tosses in a batch:
Var(X) = n * p * (1 - p) * (1 + (n - 1) * rho)Setting `2.0 * (1 + 7 * rho) = 5.5` yields `rho = 1.75 / 7 = 0.25`.- Cause A —
Part 2: Adjust the model with a Beta-Binomial or overdispersed GLM
To model bounded counts in
{0, 1, ..., 8}with extra spread, replace the single-parameter Binomial with one of three standard extensions (after first verifying data hygiene — confirming every batch really had8tosses rather than mixed batch sizes!):- Beta-Binomial model (primary generative fix): A two-stage hierarchical model where each batch first draws its own bias
p_i ~ Beta(alpha, beta)on[0, 1]and then generatesX_i | p_i ~ Binomial(n, p_i). Writingmu = alpha / (alpha + beta)for the mean probability andrho = 1 / (alpha + beta + 1)for the intra-batch correlation givesE[X] = n * muandVar(X) = n * mu * (1 - mu) * (1 + (n - 1) * rho). Matching the sample mean (4.0) and variance (5.5) givesalpha = beta = 1.5exactly (and in production you refine(alpha, beta)via maximum likelihood across all800batch counts):
batch_size = 8 sample_mean = 4.0 sample_var = 5.5 mu = sample_mean / batch_size # 0.5 base_var = batch_size * mu * (1.0 - mu) # 2.0 rho = (sample_var / base_var - 1.0) / (batch_size - 1) # 0.25 concentration = 1.0 / rho - 1.0 # alpha + beta = 3.0 alpha = mu * concentration beta = (1.0 - mu) * concentration print(round(rho, 3), round(alpha, 2), round(beta, 2)) # 0.25 1.5 1.5- Quasi-Binomial GLM (for regression and inference): Keep the Binomial mean
n * pwhile scaling the variance tophi * n * p * (1 - p)with estimated dispersion factorphi = 5.5 / 2.0 = 2.75. Regression coefficients stay unchanged, while standard errors are multiplied bysqrt(2.75) ≈ 1.66so confidence intervals and p-values stop being falsely narrow. - Binomial Generalized Linear Mixed Model (GLMM) or Markov model: Add a batch-level random intercept
logit(p_i) = beta_0 + u_iwithu_i ~ Normal(0, sigma^2)when batch covariates exist, or fit a Markov transition chain if ordered toss sequences show within-batch streaks.
- Beta-Binomial model (primary generative fix): A two-stage hierarchical model where each batch first draws its own bias
Intuition & how it works
Imagine comparing two rooms where 800 people each toss a coin 8 times. In Room A, everyone flips an identical unbiased coin (p = 0.5), so almost every batch lands near the middle (2 to 6 Heads) and 0 or 8 Heads rarely occurs. In Room B, half the people secretly hold a tails-heavy coin (p = 0.25) and half hold a heads-heavy coin (p = 0.75): the room-wide average is still 4.0 Heads per batch, yet outcomes scatter heavily toward 0, 1 and 7, 8! Checking only the average makes Room A and Room B look identical; checking the variance (the average squared distance from the mean) immediately exposes the hidden mix.
A naive analyst sees an average of 4.0 Heads out of 8 tosses and blindly fits Binomial(8, 0.5) because the sample mean matches a fair coin. That fails because in a Binomial(n, p) distribution — the distribution of total successes across n independent binary trials sharing the same success probability p — a single parameter p locks both the mean (n * p) and the variance (n * p * (1 - p)). Once n = 8 is fixed, no single value of p can ever produce a variance larger than 8 * 0.5 * 0.5 = 2.0, so an observed variance of 5.5 proves the single-coin i.i.d. assumptions are broken.
Walk through the numbers across both parts step by step:
- Part 1 (
56Heads in80i.i.d. tosses): Maximum Likelihood Estimation (MLE) — choosingpto maximize the probability of the observed sample — givesp_hat = 56 / 80 = 0.70. Across8future tosses of that coin (Binomial(8, 0.70)), expected Heads is8 * 0.70 = 5.6and variance is8 * 0.70 * 0.30 = 1.68. - Part 2 (
800batches of8tosses, mean4.0, variance5.5): Mean4.0impliesp = 0.5and theoretical Binomial variance2.0. Observed variance5.5is2.75xhigher (overdispersion), so we switch to a Beta-Binomial distribution — a hierarchical model where each batch draws its ownp ~ Beta(1.5, 1.5)before tossing8times — which matches both mean4.0and variance5.5.
Key points
- Bernoulli vs. Binomial & BINS assumptions: One toss is a Bernoulli(p) variable (
1with probabilityp,0with probability1 - p); the sum ofntosses is Binomial(n, p) provided all four BINS assumptions hold: Binary outcomes, Independent trials, Number of trialsnfixed in advance, and Samepacross all tosses (i.i.d.). - Part 1 MLE and uncertainty: Maximizing
log L(p) = const + 56 * log(p) + 24 * log(1 - p)givesp_hat = 56 / 80 = 0.70, with standard error (typical sampling fluctuation of the estimator)sqrt(0.70 * 0.30 / 80) ≈ 0.0512and approximate95%confidence interval[0.600, 0.800]. - Part 1 8-toss moments & 2-toss edge case: Under
Binomial(8, 0.70),E[X] = 5.6andVar(X) = 1.68(SD ≈ 1.30). If Part 1 only had2tosses,p_hatcould only be0, 0.5,or1.0, and observing2/2Heads (25%chance even for an unbiased coin!) collapses plug-in variance and Wald standard error to0; use exact Clopper-Pearson intervals ([0.158, 1.0]) or a Bayesian prior (Beta(1, 1)shrinks2/2to0.75). - Part 2 Binomial impossibility: Because
p * (1 - p) <= 0.25for allp,Binomial(8, p)variance is capped at2.0. Across800batches, sample variance has a standard error of~0.0935, so5.5sits over37standard errors above2.0— ruling out random noise completely. - Overdispersion causes and Beta-Binomial fix: Overdispersion (observed count variance exceeding the model's theoretical variance) arises either when
pvaries across batches (Var(X) = 2.0 + 56 * Var(p)givesVar(p) = 0.0625) or when tosses within a batch correlate positively (Var(X) = 2.0 * (1 + 7 * rho)givesrho = 0.25). Fit aBeta-Binomial(n=8, alpha=1.5, beta=1.5)model, a Quasi-Binomial GLM (phi = 2.75, inflating standard errors bysqrt(2.75) ≈ 1.66), or a mixed-effects logistic model.
Common mistakes
- Trying to pick a different
pto makeBinomial(8, p)reach variance5.5: Not realizingn * p * (1 - p)peaks atp = 0.5(Var = 2.0) and only gets smaller aspmoves toward0or1. - Applying Poisson or unbounded Normal distributions to 8-toss counts: Counts in
{0, ..., 8}have a hard ceiling at8; a Poisson distribution assumes unbounded counts (and at mean4.0predicts variance4.0, which still misses5.5). - Confusing
Var(X_1 + ... + X_8)withVar(8 * X_1): Summing8independent tosses gives8 * p * (1 - p) = 1.68, whereas8^2 * p * (1 - p) = 13.44would mean flipping one coin once and multiplying the result by8(perfect correlationrho = 1). - Trusting plug-in MLE and Wald intervals at tiny sample sizes (
n = 2): Reportingp_hat = 1.0 ± 0.0after2Heads ignores severe boundary collapse. - Using naive Binomial standard errors on overdispersed batch data: Pooling
800batches as6,400independent tosses understates the true standard error of the overall mean bysqrt(2.75) ≈ 1.66x, inflating false-positive rates in hypothesis tests and confidence intervals.
Follow-up questions
- How would you run a formal statistical test to check whether the coin in Part 1 is unbiased? Set the null hypothesis
H0: p = 0.5against the two-sided alternativeH1: p != 0.5at significance levelalpha = 0.05before inspecting the outcomes. UnderBinomial(80, 0.5), summing the exact upper-tail probabilities fork >= 56and doubling for both tails gives a p-value (the probability underH0of seeing an outcome at least as extreme as56Heads) of0.00045. A normal-approximation z-test with null standard errorsqrt(0.5 * 0.5 / 80) ≈ 0.0559yieldsz = (0.70 - 0.50) / 0.0559 ≈ 3.58(p = 0.00035, or0.00053with continuity correction); sincep < 0.05, we rejectH0and conclude the coin favors Heads. - How does positive serial correlation between tosses (such as hot-hand streaks) change the batch variance formula? When tosses correlate, the variance of the sum includes all pairwise covariance terms:
Var(X) = sum Var(X_i) + 2 * sum_{i < j} Cov(X_i, X_j). If every pair of tosses in an 8-toss batch shares positive correlationrho, variance inflates ton * p * (1 - p) * (1 + (n - 1) * rho)— for instance,rho = 0.2atp = 0.5lifts variance from2.0to2.0 * 2.4 = 4.8(and a Markov streak chain that repeats the previous toss70%of the time lifts variance to~4.11). Although the sample proportionp_hatremains unbiased when marginalpstays constant, effective sample size shrinks to roughlyn / (1 + (n - 1) * rho), making naive Binomial standard errors overly optimistic. - In a Bayesian analysis, how does the choice of prior shape your estimate of p when only a handful of tosses are available? Placing a conjugate prior distribution
Beta(alpha, beta)(representing initial beliefs before data asalphapseudo-Heads andbetapseudo-Tails) onpproduces a posterior distributionBeta(alpha + h, beta + n - h)after seeinghHeads inntosses. Its posterior mean(alpha + h) / (alpha + beta + n)blends the prior mean andp_hat, weighting the data byn / (alpha + beta + n). With2Heads in2tosses (p_hat = 1.0), a uniformBeta(1, 1)prior pulls the estimate to3 / 4 = 0.75and a skepticalBeta(10, 10)prior pulls it to12 / 22 ≈ 0.545; byn = 80(56Heads), the observed data dominate and both priors settle nearp_hat(0.695and0.660vs.0.700).
Follow-up questions
- How would you run a formal statistical test to check whether the coin in Part 1 is unbiased?
- How does positive serial correlation between tosses (such as hot-hand streaks) change the batch variance formula?
- In a Bayesian analysis, how does the choice of prior shape your estimate of p when only a handful of tosses are available?
Similar questions
- In-Place Character List Reversal
- Handling an Inconclusive A/B Test Readout
- Ad Serving Economics, Mixture Variance, and Waiting Times
- Target Bankroll Probability with Biased Flips
- Statistical Inference and Sizing for Trip Cancellations
- Impact of Dataset Duplication on OLS and Large-Sample Inference