Core Statistical Inference and Distribution Fundamentals
Medium · Statistics & Math · Data Scientist · Onsite
Prompt
During a timed data science fundamentals screen, you are asked to answer five short probability and statistical inference questions concisely and accurately:
- For a random variable
X ~ Poisson(λ)with rate parameterλ > 0, what are its expected valueE[X]and its varianceVar(X)? - Suppose you collect
nindependent observations from a population whose true standard deviationσis known. Write the formula for a two-sided95%confidence interval around the unknown population meanμ. - Under what conditions should you run a two-sample
t-test rather than a two-samplez-test when comparing group means? - Give a precise statement of the Central Limit Theorem (CLT) and explain one concrete way it powers everyday analytics or experimentation work.
- Suppose a hypothesis test produces
p = 0.03. Explain clearly what that number means—and what common misinterpretations it does not support.
Scope & Expectations
- Exact formulas and conditions: State every mathematical expression, parameter assumption (such as independence, known vs. estimated spread, and finite variance), and tail cutoff cleanly without ambiguity.
- Intuition and quick sanity checks: Back up each formula or decision rule with brief structural reasoning (such as why
ttails are heavier or how standard error scales withn) and concrete numerical examples. - Sound statistical interpretation: Distinguish sampling distributions from raw data distributions, separate statistical significance from practical business magnitude, and call out common pitfalls like paired observations or inverse-probability fallacies.
Step-by-step walkthrough
1. Mean and variance of a Poisson(λ) count variable
A Poisson(λ) distribution models the number of events
Xoccurring in a fixed window of time or space when events happen independently at a constant average rateλ > 0per window (for example, customer support tickets per hour or profile lookups per second). Its probability mass function (the formula giving the exact probability of each whole-number countk) is:P(X = k) = e^(-λ) * λ^k / k! for k = 0, 1, 2, ...Direct answer: Both the expectation and the variance equal
λ: - Expectation (mean):E[X] = λ- Variance:Var(X) = λ(so the standard deviation isSD(X) = √λ)Why
E[X] = λ(zero skipped steps): By definition,E[X]is the weighted average of every possible countktimes its probability. Notice that thek = 0term contributes0 * P(X = 0) = 0, so we can start the sum atk = 1. Fork >= 1,k / k!simplifies to1 / (k - 1)!, andλ^k = λ * λ^(k - 1). Settingj = k - 1(sojruns0, 1, 2, ...) reveals the Taylor seriese^λ = Σ (j = 0 to ∞) λ^j / j!:E[X] = Σ (k = 0 to ∞) k * e^(-λ) * λ^k / k! = Σ (k = 1 to ∞) e^(-λ) * λ * λ^(k - 1) / (k - 1)! = λ * e^(-λ) * Σ (j = 0 to ∞) λ^j / j! = λ * e^(-λ) * e^λ = λWhy
Var(X) = λ: Using the same factorial-cancellation trick onX * (X - 1)knocks out bothk = 0andk = 1, leavingj = k - 2:E[X(X - 1)] = Σ (k = 2 to ∞) k(k - 1) * e^(-λ) * λ^k / k! = λ^2 * e^(-λ) * Σ (j = 0 to ∞) λ^j / j! = λ^2 * e^(-λ) * e^λ = λ^2 Since E[X(X - 1)] = E[X^2] - E[X], we get E[X^2] = λ^2 + λ. Therefore: Var(X) = E[X^2] - (E[X])^2 = (λ^2 + λ) - λ^2 = λ.Worked numeric example (
λ = 4): Suppose a search endpoint receives an average ofλ = 4queries per second. Its mean is4, its variance is4, and its standard deviation is√4 = 2. The chance of zero queries in a second ise^(-4) ≈ 0.0183(1.83%), and the chance of seeing exactly 4 queries ise^(-4) * 4^4 / 4! ≈ 0.1954(19.54%). In real datasets, if the sample variance is much larger than the sample mean (overdispersion), events are arriving in bursts or rates vary across users, so a Negative Binomial model fits better than plain Poisson.import math lam = 4.0 # Sum up to k = 59 (tail beyond 59 for lambda = 4 is below 10^-30) pmf = [math.exp(-lam) * (lam ** k) / math.factorial(k) for k in range(60)] mean = sum(k * p for k, p in enumerate(pmf)) variance = sum(((k - mean) ** 2) * p for k, p in enumerate(pmf)) print(round(mean, 6), round(variance, 6)) # 4.0 4.02. Known-σ 95% confidence interval for a population mean
Given a sample of
nindependent observations with sample meanx̄and known population standard deviationσ, the two-sided 95% confidence interval for the true population meanμis:x̄ ± z_(0.975) * (σ / √n) ≈ x̄ ± 1.96 * (σ / √n)Where each piece comes from: -
σ / √nis the standard error (SE) ofx̄: while single observations bounce around with spreadσ, averagingnindependent observations cancels out random highs and lows so the sample mean has varianceσ^2 / nand standard deviationσ / √n. -1.96is the two-sided 95% normal cutoff (z_(0.975)): to capture the middle95%of a standard normalN(0, 1)bell curve, we leave5%total outside the interval—split symmetrically into2.5%in the left tail and2.5%in the right tail. Thus the upper cutoff is the97.5thpercentile (1.96), not the95thpercentile (1.645).Standard Normal N(0, 1) _.-""""-._ .' '. / 95% area \ 2.5% tail/ \2.5% tail ─────────┼──────┼────────┼────┼─────────▶ z -1.96 0 +1.96- When is this formula valid? It is exact if the underlying population is Normal, and an accurate approximation for non-normal populations once
nis large enough for the Central Limit Theorem to apply.
Worked numeric example: With
n = 100users, knownσ = 10seconds, and observedx̄ = 50seconds: - Standard error:SE = 10 / √100 = 10 / 10 = 1.0- Margin of error:1.96 * 1.0 = 1.96- 95% CI:50 ± 1.96 = [48.04, 51.96]Notice the
√nscaling law: shrinking the margin of error in half (from±1.96to±0.98) requires4×as many observations (n = 400). And in frequentist statistics,μis a fixed unknown constant—so "95% confidence" means 95% of intervals constructed by this recipe across repeated random samples will cover the trueμ, not thatμis jumping around inside[48.04, 51.96].- When is this formula valid? It is exact if the underlying population is Normal, and an accurate approximation for non-normal populations once
3. Choosing a two-sample t-test over a z-test
The core distinction is whether the population standard deviations
σ_1, σ_2are known ahead of time or estimated from the samples ass_1, s_2:- Use a two-sample t-test when comparing the means of two independent groups (such as Control vs. Treatment users) and the true population standard deviations
σ_1, σ_2are unknown, so you plug in the sample standard deviationss_1, s_2. Becauses_1ands_2are themselves noisy estimates, dividing by the estimated standard error produces extra variability—especially at small or moderate sample sizes—giving a Student'st-distribution with heavier tails controlled by the degrees of freedom (df). Since trueσis almost never known in real experiments, Welch's two-sample t-test (which does not assumeσ_1 = σ_2) is the standard default. - Use a z-test when
σ_1, σ_2are genuinely known, when both sample sizes are very large (say several hundred or more per group, where thetcritical value is virtually indistinguishable from1.96), or in a two-proportion test where a Bernoulli variable's variancep(1 - p)is completely determined by its meanpunder the null hypothesis. - Watch out for paired data: If the two measurements come from the same users (e.g., latency before vs. after an upgrade on the same 30 accounts), neither a two-sample t-test nor a two-sample z-test is right—compute within-user differences
d_i = y_i - x_iand run a paired t-test.
How much the heavier
ttails matter (97.5thpercentilet*vs.z* = 1.960):Degrees of freedom (df) 9 17 29 99 198 ∞ (z) Two-sided 95% cutoff 2.262 2.110 2.045 1.984 1.972 1.960If you have only 10 users per group and mistakenly use
z* = 1.96instead oft* ≈ 2.11, your rejection threshold is too loose and your false-positive rate rises above the promised 5% (to roughly 6.6%).Worked numeric example (Welch's t-test): Group A has
x̄_A = 12, s_A = 3, n_A = 10; Group B hasx̄_B = 10, s_B = 4, n_B = 10:SE = √(s_A^2 / n_A + s_B^2 / n_B) = √(9/10 + 16/10) = √2.5 ≈ 1.581 t = (12 - 10) / 1.581 ≈ 1.265 df ≈ 16.7 (Welch-Satterthwaite) -> |t| = 1.265 < 2.11, two-sided p ≈ 0.22 (do not reject H_0)import math def welch_two_sample_t(mean_a, sd_a, n_a, mean_b, sd_b, n_b): var_a = (sd_a ** 2) / n_a var_b = (sd_b ** 2) / n_b se = math.sqrt(var_a + var_b) t_stat = (mean_a - mean_b) / se df = ((var_a + var_b) ** 2) / ((var_a ** 2) / (n_a - 1) + (var_b ** 2) / (n_b - 1)) return t_stat, df t_val, df_val = welch_two_sample_t(12, 3, 10, 10, 4, 10) print(round(t_val, 3), round(df_val, 1)) # 1.265 16.7- Use a two-sample t-test when comparing the means of two independent groups (such as Control vs. Treatment users) and the true population standard deviations
4. Central Limit Theorem statement and practical impact
Formal statement: Let
X_1, X_2, ..., X_nbe independent and identically distributed (i.i.d.) random variables with finite meanE[X_i] = μand finite, positive variance0 < Var(X_i) = σ^2 < ∞. As the sample sizen -> ∞, the standardized sample mean converges in distribution to a standard normal variable:√n * (X̄_n - μ) / σ ──(in distribution)──▶ N(0, 1)Equivalently, for large
n, the sampling distribution of the sample meanX̄_nis approximatelyN(μ, σ^2 / n)regardless of the shape of the individualX_i(binary, discrete counts, or skewed), provided the variance is finite. Note what becomes normal: the distribution of the averageX̄_nacross repeated samples becomes bell-shaped—the raw individual data pointsX_ikeep their original skewed or discrete shape.Practical implication in data science: Most business and product metrics—such as revenue per visitor, searches per session, or binary conversion (
0or1)—are nowhere near Normal at the individual-user level. Thanks to the CLT, online A/B testing platforms can still use normal/t confidence intervals and two-sample t/z tests on the difference in sample means when sample sizes are sufficiently large.Worked numeric example & caveat on
n: Suppose individual order values follow a heavily right-skewed Exponential distribution with meanμ = $20, standard deviationσ = $20, and skewness2.0. Acrossn = 400independent orders: - The sample meanX̄_400has mean$20and standard error$20 / √400 = $1.00. - The skewness ofX̄_400shrinks by1 / √nto2.0 / √400 = 0.10—nearly symmetric! - Caveat: the textbook "n >= 30" rule of thumb works for roughly symmetric distributions, while heavily skewed or whale-dominated revenue metrics can require hundreds or thousands of users per arm (or variance-reduction/bootstrap checks) before normal approximations achieve full 95% coverage.5. What p = 0.03 means in hypothesis testing
Exact definition: A p-value of 0.03 means that if the null hypothesis
H_0were true (for example,H_0: μ_treatment = μ_control, no real effect) and all test assumptions held, there would be a 3% probability of observing a test statistic at least as extreme as the one observed in our sample purely from random sampling variation.Sampling distribution of test statistic Z assuming H_0 is TRUE: _.-""""-._ .' '. 1.5% tail / \ 1.5% tail Total shaded tail area ▒▒▒▒▒▒▒▒▒▒▒┼───────┼────────┼▒▒▒▒▒▒▒▒▒▒▒▶ = 0.015 + 0.015 = 0.03 -2.17 0 +2.17How to act on and communicate
p = 0.03: 1. Compare against pre-chosenα: At the standard significance levelα = 0.05, since0.03 < 0.05, we rejectH_0(the difference is statistically significant at the 5% level, and the matching two-sided 95% confidence interval excludes0). At a stricter thresholdα = 0.01(common when testing many metrics),0.03 > 0.01, so we fail to rejectH_0. 2. What it does NOT mean about probability of truth:p = 0.03isP(data at least this extreme | H_0 is true), notP(H_0 is true | data). Claiming "there is a 3% chance the null is true" or "a 97% chance the feature really works" is a classic logical error; computing the probability that an effect is real requires Bayes' rule and a prior belief about how often tested ideas succeed. 3. What it does NOT mean about business impact: A p-value blends effect size and sample size (z = effect / SE). With 10 million visitors, a tiny+0.02%lift can yieldz = 2.17(p = 0.030) while not being worth engineering maintenance; with 50 visitors, a huge+15%lift might yieldp = 0.18simply due to noise. Always report the estimated effect size and its 95% confidence interval alongsidep = 0.03.import math def two_sided_p_from_z(z_stat): # erfc(|z| / sqrt(2)) equals 2 * (1 - Phi(|z|)) for a standard normal Z return math.erfc(abs(z_stat) / math.sqrt(2.0)) print(round(two_sided_p_from_z(2.17), 4)) # 0.03
Intuition & how it works
Think of these five quiz questions as the complete pipeline of statistical inference from raw events to a product decision:
1. Model raw counts (Poisson(λ)): Count how many independent events happen in a fixed window at average rate λ—remarkably, both the average count and the variance equal λ.
2. Summarize many observations (Central Limit Theorem): Even when single user counts or purchases are lopsided, averaging n independent users smooths out individual quirks so the sample mean X̄ behaves like a bell curve with standard error σ / √n (the standard deviation of the sample mean across repeated samples).
3. Attach error bars when spread is known (95% z-interval): Stretching 1.96 standard errors on each side of x̄ (x̄ ± 1.96 * σ / √n) builds a recipe that traps the true mean μ 95% of the time.
4. Adjust error bars when spread is estimated (two-sample t-test): In real A/B tests we rarely know true σ; plugging in noisy sample standard deviations s_1, s_2 adds extra uncertainty, so we swap the normal z curve for the heavier-tailed Student's t curve.
5. Weigh surprise under "nothing changed" (p = 0.03): A p-value (the probability, assuming the null hypothesis H_0 of zero true effect holds, of seeing a test statistic at least as extreme as ours) measures how surprising our data would be under pure luck.
Relying on quick memorization without this chain leads to classic interview slips: mixing up Poisson variance (λ) with standard deviation (√λ), dividing by n instead of √n, plugging a small-sample s into 1.96, saying the CLT turns raw skewed data normal, or calling p = 0.03 "a 3% chance H_0 is true."
Walk through one concrete mini-example tying the ideas together: suppose baseline users make Poisson(λ = 4) searches per visit (mean = 4, variance = 4, σ = √4 = 2). We test a new layout on n = 100 independent users and observe x̄ = 4.434 searches. If σ = 2 were known, the standard error would be 2 / √100 = 0.20, the 95% confidence interval would be 4.434 ± 1.96 * 0.20 = [4.042, 4.826], and the test statistic against μ_0 = 4 would be z = (4.434 - 4.0) / 0.20 = 2.17, giving a two-sided p-value of 0.03—surprising enough to reject H_0 at α = 0.05.
Key points
Poisson(λ)moments:E[X] = λandVar(X) = λ(soSD(X) = √λ). Checking whether sample variance roughly equals sample mean is a fast diagnostic for overdispersion (variance exceeding the mean because event rates vary across users or bursts occur).- 95% confidence interval with known
σ:x̄ ± 1.96 * (σ / √n). Because interval width scales with1 / √n, cutting uncertainty in half requires4×the sample size. Under frequentist inference,95%is the long-run hit rate of the interval-building procedure across repeated samples, not a probability distribution over a movingμ. - Two-sample
t-test vs.z-test: Use a two-samplet-test (specifically Welch's t-test, the version that allows unequal group variances) when comparing means of two independent groups with unknown population standard deviations estimated bys_1, s_2, especially at small or moderatenwhere limited degrees of freedom (the effective number of independent pieces of information used to estimate variance) makettails noticeably wider thanN(0, 1). Reservez-tests for knownσ, very large samples, or two-proportion tests. - Central Limit Theorem (CLT): For i.i.d. (independent and identically distributed—drawn independently from the same distribution) variables with finite mean
μand finite varianceσ^2 > 0,√n * (X̄_n - μ) / σconverges in distribution (its cumulative probabilities approach those of the target curve asn -> ∞) toN(0, 1). Practically, this lets data scientists run normal/t inference on averages of skewed product metrics like revenue or session duration oncenis large enough. - Interpreting
p = 0.03: AssumingH_0is true and every model assumption holds, a test statistic at least as extreme as observed happens 3% of the time by random chance. RejectH_0atα = 0.05(fail to reject atα = 0.01), and always pairpwith the estimated lift and confidence interval because statistical significance does not measure practical size.
Common mistakes
- Confusing variance (
λ) with standard deviation (√λ) forPoisson(λ): Always state both explicitly in a quiz (E[X] = λ,Var(X) = λ,SD(X) = √λ) so there is zero ambiguity. - Writing
σ / ninstead ofσ / √n, or1.645instead of1.96: Variance divides byn(σ^2 / n), so its square root—the standard error—divides by√n;1.645leaves5%in each tail (90%two-sided CI), whereas1.96leaves2.5%in each tail (95%two-sided CI). - Using a two-sample test on paired observations: When measuring the same users before and after a change, positive within-user correlation cancels out in a paired t-test on
d_i = after_i - before_i; treating them as two independent groups inflates the standard error and wastes statistical power (the probability of detecting a true effect when one exists). - Claiming the CLT makes the raw data normal or forgetting finite variance: Histogramming 100,000 exponential session lengths still shows a sharp right skew—only the distribution of sample averages becomes normal. And heavy-tailed distributions with infinite variance (such as the Cauchy or Pareto with tail exponent
α <= 2) violate the CLT completely. - The inverse-probability ("prosecutor's") fallacy on p-values: Saying "
p = 0.03means a 3% chanceH_0is true" swapsP(data | H_0)forP(H_0 | data). If you test 100 long-shot ideas where only 5% truly work (80% power,α = 0.05), a significant p-value around0.03–0.05still has a substantial false-discovery rate! - Running many tests and celebrating a single
p = 0.03: Across 20 independent true-null metrics tested atα = 0.05, the chance of seeing at least onep < 0.05by pure luck is1 - 0.95^20 ≈ 64%. Control false positives with pre-declared primary metrics, Bonferroni, or Benjamini-Hochberg false-discovery-rate adjustments.
Follow-up questions
- How does the 95% confidence interval formula change when the population standard deviation is unknown? Replace the unknown population
σwith the sample standard deviations = √(Σ(x_i - x̄)^2 / (n - 1))and replace1.96with the97.5thpercentile of Student'st-distribution withn - 1degrees of freedom:x̄ ± t_(0.975, n-1) * (s / √n). For instance, withn = 10,x̄ = 50, ands = 10,t_(0.975, 9) = 2.262ands / √10 ≈ 3.162, giving50 ± 7.15—noticeably wider than the50 ± 6.20you would get from1.96to account for uncertainty in estimatings. - How would you construct a 95% confidence interval for a Poisson rate parameter from observed counts? Suppose you observe
C = 40events overT = 10hours; the maximum-likelihood estimate (the parameter value making the observed data most probable) isλ̂ = C / T = 4.0per hour. BecauseC ~ Poisson(λ * T)has varianceλ * T, the standard error ofλ̂is√(λ̂ / T) = √(4.0 / 10) ≈ 0.632, giving a large-count normal interval4.0 ± 1.96 * 0.632 = [2.76, 5.24]; when total countsCare small (say under 20), use the exact chi-square (Garwood) interval so lower bounds never go negative and tail coverage stays accurate. - When is a sample size of 30 insufficient for the Central Limit Theorem in an online experiment? Whenever a metric has extreme skewness or rare high-spend "whales"—for example, if 99% of visitors spend
$0and a handful spend$500, a sample ofn = 30will often contain zero buyers (s = 0), causing nominal 95% t-intervals to severely undercover the true mean. You can diagnose requirednvia bootstrap resampling or simulation on historical data, and mitigate extreme skew using pre-experiment covariates (CUPED), capping extreme outliers (winsorization), or testing conversion rate and spend-among-buyers separately.
Follow-up questions
- How does the 95% confidence interval formula change when the population standard deviation is unknown?
- How would you construct a 95% confidence interval for a Poisson rate parameter from observed counts?
- When is a sample size of 30 insufficient for the Central Limit Theorem in an online experiment?
Similar questions
- Six Algorithmic Logic and Math Puzzle Solvers
- 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