Statistical Inference and Hypothesis Testing Questions
Reasoning about uncertainty in data and drawing formal conclusions from samples. Covers probability rules and common distributions, the Central Limit Theorem, sampling, standard error, confidence intervals, and Bayesian reasoning, together with the significance-testing framework: null and alternative hypotheses, p-values, statistical power, Type I and Type II errors, effect sizes, and choosing the right test (t-test, chi-square, non-parametric). Emphasizes correctly interpreting statistical results and avoiding common misreadings of significance in business and product contexts rather than memorizing formulas.
You observe a 3x4 contingency table summarizing device type (3 levels) by conversion bucket (4 levels). Explain when a chi-square test of independence is appropriate, state its assumptions, show how to compute expected cell counts, and describe alternatives when expected counts are small. Also describe a measure of effect size appropriate for contingency tables.
Sample Answer
Direct answer
A chi-square test of independence is appropriate when you have two categorical variables (here, device type with 3 levels and conversion bucket with 4 levels), the observations are independent, and you want to test whether the two variables are associated at all. Its validity depends on every expected cell count being reasonably large (a common rule of thumb: at least 5); when several expected counts are small, switch to Fisher's exact test (2x2 only) or a Monte Carlo/permutation-based p-value. Cramér's V is the standard effect-size measure for a table larger than 2x2.
Structured elaboration
Assumptions
- Independent observations: no repeated measures on the same unit contributing more than once.
- Counts, not proportions or percentages, as the input.
- Expected cell counts adequately large: the usual guidance is every expected count ≥5, or at most a small fraction of cells between 1 and 5 with none below 1.
Computing expected counts
For a table with row totals Ri, column totals Cj, and grand total N:
Eij=NRiCjthe product of the two marginal probabilities, scaled by N, i.e. what you'd expect in cell (i,j) if the row and column variables were independent.
Alternatives when expected counts are small
| Situation | Alternative |
|---|---|
| Small 2x2 table | Fisher's exact test (exact, no asymptotics needed) |
| Larger table (more than 2x2), sparse cells | Monte Carlo simulation of the null (draw simulated tables from the independence multinomial, compare the observed statistic to that simulated distribution) |
| Substantively defensible category merges | Collapse adjacent low-count categories to raise expected counts, if the merge doesn't erase a meaningful distinction |
Worked example
A 3 (device) by 4 (conversion bucket) table of observed counts:
| No purchase | Low | Medium | High | Row total | |
|---|---|---|---|---|---|
| Mobile | 250 | 120 | 60 | 20 | 450 |
| Desktop | 180 | 140 | 90 | 40 | 450 |
| Tablet | 70 | 50 | 30 | 10 | 160 |
| Column total | 500 | 310 | 180 | 70 | 1,060 |
Expected counts, e.g. mobile/no-purchase =(450)(500)/1,060=212.26; the full expected table (all cells ≥5, so the chi-square approximation is valid here):
| No purchase | Low | Medium | High | |
|---|---|---|---|---|
| Mobile | 212.26 | 131.60 | 76.42 | 29.72 |
| Desktop | 212.26 | 131.60 | 76.42 | 29.72 |
| Tablet | 75.47 | 46.79 | 27.17 | 10.57 |
(computed with scipy.stats.chi2_contingency)
Effect size (Cramér's V, k=min(rows,cols)−1=2):
V=N(k)χ2=(1,060)(2)26.79=0.112The association is statistically significant but small in magnitude (Cramér's V around 0.1 is conventionally a small effect), so device and conversion bucket are related, but device alone is a weak predictor of conversion outcome.
Trade-offs & pitfalls
- Statistical significance and effect-size magnitude answer different questions here just as they do for any test; a large N can make a small, practically unimportant association statistically significant (as in this example: p<0.001 but V≈0.11).
- Collapsing categories to fix small expected counts should be decided from domain reasoning before looking at which cells drove the result; collapsing after seeing the p-value is a form of data snooping.
- The chi-square test only tells you that an association exists, not where. standardized residuals per cell are needed to say which device/bucket combinations are driving the association.
- Fisher's exact test is a 2x2-specific tool in its standard formulation; reaching for Monte Carlo simulation, rather than trying to force Fisher's exact logic onto a larger sparse table, is the more scalable fix.
Explain Simpson's paradox and provide a concrete A/B testing example with hypothetical numbers where aggregating across segments yields the opposite conclusion from segment-level analysis. Describe how you would detect such paradoxes and resolve the correct interpretation for product decisions.
Sample Answer
Direct answer
Simpson's paradox is when a trend that appears in an aggregated dataset reverses, or disappears, once the data is broken into meaningful subgroups. It happens when a subgroup variable is both correlated with the outcome and unevenly distributed across the groups being compared, so the aggregate is really comparing different mixes of subgroups rather than like-for-like. In A/B testing this can flip an experiment's headline verdict if traffic composition differs between arms.
Structured elaboration
Mechanism. The paradox needs two ingredients: a segment (e.g. new vs returning users) whose baseline conversion rate differs a lot, and a segment mix that differs between the two experiment arms, whether from a randomization bug, non-random routing, or the arms genuinely attracting different user mixes (for example, if the treatment changes something only new users see first). When the high-baseline segment is overrepresented in one arm, that arm's aggregate gets pulled up regardless of the true within-segment treatment effect.
Two distinct causes worth separating. (1) A randomization or logging bug that skews segment composition between arms even though the metric itself has a uniform effect. This should be treated like Sample Ratio Mismatch: a data-quality problem to fix, not a real result to interpret. (2) A genuine, real segment-mix or heterogeneous-effect situation (e.g. the arms were deliberately targeted differently, or the treatment interacts with user tenure). This is a real result that needs segment-aware reporting, not a bug.
Worked example
Two segments with very different baseline conversion, and arms that got very different mixes of each:
| Segment | Control | Treatment |
|---|---|---|
| High-intent users | 380 / 900 = 42.2% | 45 / 100 = 45.0% |
| Low-intent users | 6 / 100 = 6.0% | 63 / 900 = 7.0% |
| Aggregate | 386 / 1,000 = 38.6% | 108 / 1,000 = 10.8% |
(All counts verified by direct computation.) Notice: treatment wins in both segments individually (45.0% > 42.2%, and 7.0% > 6.0%), but because control's traffic was mostly high-intent users (who convert well regardless of arm) and treatment's traffic was mostly low-intent users (who convert poorly regardless of arm), the aggregate makes it look like control is dramatically better. Reading only the aggregate row would lead to killing a feature that actually helped every segment it touched.
Detection. Treat segment-mix balance as a standard experiment health check alongside SRM: compare the proportion of each key segment (device, new/returning, geography) between arms, and flag if that mix itself differs significantly between arms (a chi-square test of segment distribution by arm is a direct way to check this). Separately, fit the metric with an interaction term, metric∼arm+segment+arm:segment, to see whether the treatment effect actually differs by segment (heterogeneity) as opposed to just the segment mix differing (composition).
Resolution. If the segment-mix imbalance traces back to a bug (bad routing, non-random assignment), that invalidates the experiment; the fix is to correct randomization and rerun, not to reweight around the bug. If the imbalance is real and expected (e.g. the two arms intentionally target different populations, or a feature launch changes what fraction of traffic is new users), report segment-level effects explicitly rather than a single aggregate number, and if a single summary number is still needed, use a standardized/weighted average that applies one fixed reference mix (e.g. last month's traffic composition) to both arms instead of letting each arm's own live mix drive the number.
Trade-offs & pitfalls
- Don't go looking for a favorable segment cut after seeing an unfavorable aggregate result; that's post-hoc fishing and needs the same multiple-comparisons discipline as any other exploratory subgroup analysis. Segment checks belong in the pre-registered analysis plan, run regardless of which way the aggregate goes.
- Trusting an aggregate number without ever looking at segment balance is the classic wrong turn, and it's especially dangerous because the aggregate looks perfectly clean (large N, tight CI) even while hiding a completely reversed within-segment story.
- Not every segment-level difference is Simpson's paradox; if segment mix is balanced across arms and the aggregate and segment-level conclusions agree, that's just a normal heterogeneous-effect finding, worth reporting, but not a paradox to resolve.
Demonstrate the Benjamini-Hochberg (BH) procedure on this list of p-values: [0.001, 0.02, 0.03, 0.2, 0.4] with alpha = 0.05. Show step-by-step how to compute BH thresholds and identify which hypotheses to reject. Explain intuitively why BH controls the expected false discovery rate (FDR) rather than family-wise error rate (FWER).
Sample Answer
Quick answer
The Benjamini-Hochberg (BH) procedure sorts p-values ascending, compares each one against a rank-dependent threshold miα, and rejects every hypothesis up to the largest rank where the p-value still falls below its threshold. It controls the expected proportion of false positives among the rejections (the false discovery rate, FDR), not the probability of making even one false positive across all tests (the family-wise error rate, FWER), which is why it rejects more hypotheses than Bonferroni for the same α.
Step-by-step derivation
Given p-values [0.001,0.02,0.03,0.2,0.4], already sorted ascending, with m=5 and α=0.05:
Step 1: compute the BH threshold for each rank i
threshold(i)=miα| Rank i | p(i) | Threshold 5i(0.05) | p(i)≤ threshold? |
|---|---|---|---|
| 1 | 0.001 | 0.010 | Yes |
| 2 | 0.02 | 0.020 | Yes |
| 3 | 0.03 | 0.030 | Yes |
| 4 | 0.2 | 0.040 | No |
| 5 | 0.4 | 0.050 | No |
Step 2: find the largest rank i where the comparison passes
Ranks 1, 2, and 3 pass; rank 4 is the first to fail. The largest passing rank is i∗=3.
Step 3: reject every hypothesis at rank ≤i∗
Reject the null hypotheses for p=0.001,0.02,0.03. Fail to reject for p=0.2,0.4, even though nothing in the rule inspects them individually beyond their own threshold; what matters is the largest surviving rank.
def bh_procedure(pvals, alpha=0.05):
m = len(pvals)
order = sorted(range(m), key=lambda i: pvals[i])
sorted_p = [pvals[i] for i in order]
thresholds = [(rank + 1) / m * alpha for rank in range(m)]
passing = [i for i, (p, t) in enumerate(zip(sorted_p, thresholds)) if p <= t]
k_star = max(passing) + 1 if passing else 0 # largest passing rank (1-indexed)
rejected = order[:k_star]
return k_star, sorted(pvals[i] for i in rejected)
pvals = [0.001, 0.02, 0.03, 0.2, 0.4]
k_star, rejected = bh_procedure(pvals)
print(f"largest passing rank = {k_star}, rejected p-values = {rejected}")
# largest passing rank = 3, rejected p-values = [0.001, 0.02, 0.03]
Why BH controls FDR, not FWER
| FWER (e.g. Bonferroni) | FDR (BH) | |
|---|---|---|
| Controls | P(at least one false rejection)≤α | E[RV]≤α, where V = false rejections, R = total rejections |
| Threshold per test | Fixed: α/m for every test | Increasing with rank: miα |
| Behavior as m grows | Gets much stricter, power collapses | Adapts: still allows a controlled fraction of the (larger) rejection set to be false |
| Best suited for | A handful of high-stakes tests (e.g. one pivotal trial) | Many simultaneous tests where some false positives are an acceptable cost (A/B test portfolios, feature selection, screening) |
Bonferroni compares every p-value to the same strict threshold α/m regardless of rank, controlling the probability of any false positive at all, which becomes extremely conservative as m grows. BH instead lets the threshold grow with rank, so it tolerates some false positives, but only up to a controlled expected fraction of the hypotheses it actually rejects. The intuition: if you're going to reject many hypotheses, it's the fraction of those rejections that are wrong that matters for downstream decisions, not the chance that any single one of the thousands of tests you ran was wrong.
Trade-offs and pitfalls
- BH assumes independence or positive dependence (PRDS) among test statistics. Under negative dependence, the guarantee can break; the Benjamini-Yekutieli correction is the conservative fix.
- BH is a step-up procedure, not per-test. A common mistake is comparing each raw p-value to α directly at its own rank threshold and stopping at the first failure; the correct rule looks for the largest passing rank across the whole sorted list, since a later, larger p-value can still be under its (looser) threshold even if an earlier one barely failed.
- FDR control is about the batch, not any individual rejected hypothesis. "5% FDR" does not mean each individual rejected hypothesis has a 5% chance of being wrong; it means, on average, 5% of the rejected set is expected to be false.
- Storey's q-value approach is the natural next step, estimating the proportion of true nulls from the data instead of assuming it's 1, which gives more power when many hypotheses are genuinely non-null (common in large-scale A/B testing portfolios).
Explain how hypothesis tests on regression coefficients relate to t-tests. Describe how multicollinearity affects coefficient inference and standard errors, how to detect it, and when to use robust (heteroskedasticity-consistent) or clustered standard errors instead of classical OLS SEs.
Sample Answer
Direct answer
In OLS, the hypothesis test on a single coefficient βj is literally a t-test: H0:βj=0 is assessed via t=β^j/SE(β^j), compared against a t-distribution with n−k degrees of freedom. Multicollinearity does not bias this point estimate, but it inflates SE(β^j), which shrinks the t-statistic and widens confidence intervals, making it harder to detect real effects. Separately, if the classical assumption of homoskedastic, independent errors fails, the formula for the standard error itself is wrong regardless of collinearity, which is what robust and clustered SEs fix.
Structured elaboration
Why it's a t-test
Under the classical linear model assumptions, β^j is normally distributed and its variance estimate uses the residual variance with n−k degrees of freedom, so:
t=SE(β^j)β^j−0∼tn−kunder H0:βj=0A two-sided p-value is 2×P(Tn−k>∣t∣).
How multicollinearity affects inference
When two or more regressors are highly correlated, the model cannot cleanly separate their individual contributions. This shows up as inflated variance, not bias:
Var(β^j)=(1−Rj2)∑i(xij−xˉj)2σ2where Rj2 is the R-squared from regressing xj on all other predictors. As Rj2→1 (near-perfect collinearity), the variance explodes.
Detecting it: Variance Inflation Factor
VIFj=1−Rj21Common rule of thumb: VIFj>5 (some use 10) flags concerning collinearity. Also check the correlation matrix directly, and condition indices on X⊤X (the ratio of the largest to each smaller eigenvalue of the scaled design matrix; a large ratio signals several predictors together, not just in pairs, are nearly linearly dependent) for multi-variable collinear sets that pairwise correlations miss.
Remedies for multicollinearity (roughly in the order a candidate should reach for them; the first row is the default, the rest are fallbacks worth naming but rarely the first move)
| Remedy | Trade-off |
|---|---|
| Drop or combine correlated predictors | Loses information if both are theoretically meaningful |
| Ridge regression | Introduces bias to reduce variance; coefficients are no longer unbiased |
| Principal components regression | Components can be hard to interpret substantively |
| Collect more / more varied data | Not always feasible on a fixed timeline |
Choosing the standard error type (a separate issue from multicollinearity)
| SE type | Use when |
|---|---|
| Classical OLS SE | Errors are homoskedastic and independent across observations |
| Heteroskedasticity-consistent (robust/White/sandwich) SE | Residual variance differs across observations (e.g. larger accounts have noisier outcomes), but observations are still independent |
| Clustered SE | Errors are correlated within groups (e.g. multiple observations per user, per store, per region); allows arbitrary correlation within a cluster while assuming independence across clusters |
Robust and clustered SEs correct the standard error formula; they do nothing for multicollinearity, which is about how much information the design matrix carries, not about the error structure.
Worked example
Simulated design with x1 and x2 correlated at about 0.88, and an independent x3, pinned seed:
import numpy as np
rng = np.random.default_rng(seed=7)
n = 200
x1 = rng.normal(0, 1, n)
x2 = 0.9 * x1 + rng.normal(0, np.sqrt(1 - 0.9**2), n)
x3 = rng.normal(0, 1, n)
def vif_of(target, others):
X = np.column_stack([others, np.ones(n)])
beta, *_ = np.linalg.lstsq(X, target, rcond=None)
resid = target - X @ beta
r2 = 1 - resid.var() / target.var()
return 1 / (1 - r2)
vif_x1 = vif_of(x1, np.column_stack([x2, x3])) # 4.58
vif_x2 = vif_of(x2, np.column_stack([x1, x3])) # 4.59
vif_x3 = vif_of(x3, np.column_stack([x1, x2])) # 1.02
Result: corr(x1,x2)≈0.88 gives VIF(x1)≈4.58 and VIF(x2)≈4.59, both near the 5.0 caution threshold, while the unrelated x3 has VIF(x3)≈1.02, essentially no inflation. This is the concrete signature of collinearity: the two correlated predictors' standard errors are being blown up by roughly 4.6≈2.1× relative to what they'd be with orthogonal regressors, while the unrelated predictor is unaffected.
Trade-offs & pitfalls
- Don't confuse "not significant due to collinearity" with "no effect." A predictor can have a real, meaningful coefficient that's simply un-estimable precisely alongside its correlated partner. Dropping it isn't obviously correct.
- VIF only measures linear collinearity among predictors, not model misspecification. A low VIF doesn't mean the model is well-specified.
- Ridge/PCA fix the variance problem by introducing bias. For pure prediction that trade-off is often worth it; for causal or coefficient-level interpretation it complicates interpretation directly.
- Clustered SEs need a real cluster structure, not a convenient one. Clustering on too fine a grain (or the wrong dimension) doesn't fix anything; clustering on too coarse a grain (few clusters) makes the sandwich estimator unstable (the variance formula clustered SEs use only behaves as its asymptotics promise once there are enough independent clusters). With fewer than about 30-50 clusters, a wild cluster bootstrap (repeatedly reweighting each cluster's residuals by a random +/-1 flip and refitting, to build an empirical distribution of the test statistic instead of trusting the asymptotic formula) is usually safer.
- Robust SEs fix the SE formula but not bias from omitted variables or reverse causality. Don't treat "I used robust SEs" as a substitute for a sound causal design.
You are reviewing an internal analysis that reports a large effect but only shows results for the significant subgroup analyses. Describe how you would audit the analysis to identify potential p-hacking or selective reporting. List concrete checks you would perform, and propose a robust reanalysis plan to produce defensible inference.
Sample Answer
Direct answer
An analysis that only shows the significant subgroup results, with no mention of how many subgroups were tried, is a textbook signature of p-hacking or selective reporting. Audit it by reconstructing the full set of comparisons that were actually run (not just the ones reported), re-testing that full set with a multiplicity correction, and re-running the analysis end to end on the raw data. The reanalysis plan should pre-specify a small, justified set of primary comparisons and report the complete picture, significant and non-significant alike, not a curated slice of it.
Structured elaboration
Concrete audit checks
| Check | What it reveals |
|---|---|
| Request the original analysis plan and code | Whether the reported subgroup was pre-specified or found by trying many and keeping the winner |
| Reproduce the reported numbers by running the code on the raw data | Whether the figures are even reproducible from the stated pipeline |
| Enumerate every subgroup, covariate combination, and outcome that plausibly could have been tested | The true "family" size the multiplicity correction needs to be computed over |
| Re-test the full family with a correction (Bonferroni or Benjamini-Hochberg) | Whether the reported effect survives once the full search is accounted for |
| Look for p-values clustered just under 0.05 | A classic fingerprint of stopping or specification choices made to cross the threshold |
| Check for undisclosed exclusions or covariate adjustments | Whether cherry-picked exclusions, not a real effect, are driving significance |
Robust reanalysis plan
- Reproduce the original result from raw data and code before doing anything else.
- List every comparison that was actually run, whether or not it appeared in the report.
- Apply a multiplicity correction (Bonferroni for a strict guarantee, Benjamini-Hochberg for a more powered but still principled one) across that full list, not just the reported subset.
- Report the complete table: every tested subgroup, its unadjusted and adjusted p-value, its effect size, and its sample size, so nothing is hidden by omission.
- Clearly separate confirmatory findings (survive correction) from exploratory ones (interesting, but not proven, and worth a dedicated follow-up test).
Worked example
Suppose 12 subgroup comparisons were actually run internally, but the report only surfaces the one with p=0.031. Re-testing the full family of 12 with Holm-Bonferroni (step-down, more powerful than flat Bonferroni but still FWER-controlling, meaning it keeps the family-wise error rate, the chance that even one of the reported findings is a false positive, at or below the target rate across all 12 comparisons, the same guarantee flat Bonferroni gives, just with more power):
| Rank | p-value (sorted) | Holm threshold α/(m−rank+1) | Passes? |
|---|---|---|---|
| 1 (smallest) | 0.031 | 0.00417 | No |
| 2 | 0.090 | 0.00455 | No |
| 3 | 0.120 | 0.00500 | No |
| ... | ... | ... | ... |
(with m=12 and α=0.05; computed directly from the Holm step-down formula)
The smallest p-value in the full family, 0.031, needed to clear 0.00417 to survive Holm-Bonferroni; it doesn't. The "significant" subgroup finding that made it into the report does not survive once the other 11 comparisons that were actually run are accounted for. This is exactly the pattern an audit is designed to catch, and it doesn't require re-collecting any data, only re-testing honestly against the full family.
Trade-offs & pitfalls
- The hardest part of this audit is usually not the statistics, it's getting an honest accounting of how many comparisons were actually tried; without that, no correction can be computed correctly, so insist on the code and logs, not just a verbal assurance.
- Correcting for multiplicity can occasionally kill a genuinely real effect along with the false ones; that's the acknowledged cost of FWER or FDR control, not a reason to skip it, but it's worth flagging any borderline case as "worth a dedicated confirmatory follow-up" rather than dismissing it outright.
- Presenting this audit to the original analysts or to leadership needs care: the goal is fixing the process (pre-registration, full reporting), not accusing anyone of misconduct, since selective reporting this way is frequently an unconscious byproduct of exploratory analysis rather than deliberate manipulation.
- A reanalysis that only tightens the statistics but keeps reporting only the "winning" comparisons repeats the original mistake in a more sophisticated wrapper; the fix has to include reporting the full family, not just applying a correction to the subset that was already selected.
Unlock Full Question Bank
Get access to all Statistical Inference and Hypothesis Testing interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.