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.
Explain the difference between user-level, session-level, and event-level units of analysis. Give an example where using event-level aggregation would mislead a product decision, and recommend the correct unit-of-analysis for measuring feature adoption.
Sample Answer
Direct answer
The unit of analysis is the entity you count and average over when computing a metric. Event-level counts every individual action, session-level counts per visit, and user-level counts per unique person. For measuring feature adoption specifically, the correct unit is user-level, because adoption is a question about how many people used a feature, and event-level or session-level aggregation lets a small number of heavy users dominate the number and make adoption look far higher than it really is.
Structured elaboration
- Event-level. Each recorded action is one row (e.g. every
chat_sendevent). Good for measuring volume and throughput, but says nothing about how many distinct people generated that volume. - Session-level. A time-bounded visit is the unit (e.g. actions per session, session duration). Good for engagement intensity within a visit, but a user with 10 sessions counts 10 times.
- User-level. Each unique person, over a defined window, is the unit (e.g. percent of monthly active users who used a feature at least once). Good for adoption, retention, and anything answering "how many people."
The reason event-level aggregation misleads for adoption specifically is a units mismatch: "adoption" is inherently a statement about people, but a raw event count is dominated by whoever generates the most events, which is rarely a representative measure of how widely a feature spread across the user base.
Worked example
Suppose a new chat feature is live for a product with 10,000 monthly active users. In one month, the feature generates 597 chat_send events. If those events came from 300 distinct users sending on average ~2 messages each, an event-level headline of "597 uses this month" and a user-level headline of "300 of 10,000 users adopted the feature (3.0%)" describe the same underlying data very differently. Now suppose most of that volume is concentrated: 3 power users (support agents testing the feature, or a bot account) send 100 messages each (300 events), and the remaining 297 events come from 297 distinct users sending one message each. Event-level volume (597) barely tells you anything about reach. User-level adoption is unambiguous: 300/10,000=3.0% of MAU tried the feature at least once, which is the number a PM deciding whether to invest further in the feature actually needs. Reporting "597 uses" to that PM without the user-level breakdown risks a decision to double down on a feature that only 3% of the base has touched.
Trade-offs & pitfalls
User-level adoption is the right primary metric, but it should be paired with a session- or event-level intensity metric (actions per active user, or per session) to distinguish "many people tried it once" from "many people use it repeatedly," since those imply very different next steps. A common mistake is picking the time window inconsistently with the metric's intent: reporting "monthly adoption" but computing it over a 7-day window inflates apparent adoption relative to the stated period. It is also worth deduplicating bot or internal-test accounts before computing user-level adoption, since a handful of automated accounts generating disproportionate event volume can distort even a correctly-chosen user-level metric if they are not excluded.
You track "revenue per user" as a primary metric. Explain the pitfalls of ratio metrics, and propose robust alternatives or preprocessing plus how you would analyze and communicate them in experiment results.
Sample Answer
Direct answer
Ratio metrics like revenue per user are dangerous because they collapse two moving parts (a numerator and a denominator) into one number, and because revenue-like numerators are almost always heavy-tailed: a handful of large purchases can dominate the mean and make an experiment look like a clear win or loss when the typical user didn't change at all. The fix is to report a robust summary alongside the mean (median, trimmed mean, or a capped/winsorized version), define the denominator precisely and consistently across arms, and segment before concluding "the metric moved."
Structured elaboration
Pitfalls of ratio metrics
| Pitfall | Mechanism |
|---|---|
| Denominator drift | If "users" is defined differently between control and treatment (e.g. active users vs. all assigned users), the ratio changes mechanically, not because behavior changed |
| Heavy tails / whales | A small number of large-spend users can move the mean revenue-per-user substantially while the median user is unaffected |
| Simpson's paradox | If treatment shifts the mix of users (e.g. more new, low-spend users enter the treatment arm), the aggregate ratio can move in a direction opposite to every individual segment's true effect |
| Zero-inflation | Many products have a large mass of $0 users; the ratio's distribution is a mixture of "never pays" and "pays something," which a single mean glosses over |
Robust alternatives and preprocessing
- Median or other percentiles (P50, P90): insensitive to a handful of extreme values, at the cost of ignoring exactly how much the tail moved.
- Trimmed or winsorized mean: cap or remove the top X% before averaging; keeps more information than the median while limiting whale influence.
- Log-transform (e.g. log(1+revenue)): compresses the tail and stabilizes variance for a mean-based test; interpret results multiplicatively (geometric-mean-like) rather than additively.
- Fixed, pre-registered denominator: define "user" identically in both arms (e.g. "assigned at randomization," not "active during the window") so the denominator can't drift with treatment-induced behavior.
Analyzing and communicating results
- Pre-specify the primary metric and its exact numerator/denominator/transform before the experiment runs.
- Report mean, median, and a capped/winsorized mean together, plus a bootstrap CI for each (since ratio-metric sampling distributions are rarely well approximated by a simple closed-form CI).
- Check whether the treatment changed the user mix (e.g. share of new vs. returning users); if so, present both the raw aggregate and a mix-adjusted (segment-weighted) comparison.
- In the writeup, lead with whichever statistic best reflects the decision at hand, but always show all of them side by side so a stakeholder can see whether a "win" is broad-based or driven by a few large accounts.
Worked example
Simulated per-user revenue in a control arm (mostly small or zero purchases), and a treatment arm identical except for one added large ("whale") purchase, pinned seed:
import numpy as np
rng = np.random.default_rng(seed=99)
n = 1000
control = rng.choice([0, 0, 0, 5, 10, 20], size=n,
p=[0.5, 0.2, 0.1, 0.1, 0.06, 0.04]).astype(float)
treatment = control.copy()
rng.shuffle(treatment)
treatment[0] += 5000 # one large purchase added
mean_c, median_c = control.mean(), np.median(control) # 2.195, 0.0
mean_t, median_t = treatment.mean(), np.median(treatment) # 7.195, 0.0
lift_mean = (mean_t - mean_c) / mean_c * 100 # 227.8%
cap = np.percentile(control, 99) # 20.0
treat_wins = np.clip(treatment, None, cap)
lift_winsorized = (treat_wins.mean() - mean_c) / mean_c * 100 # 0.7%
The mean shows a 227.8% lift in revenue per user (from 2.195 to 7.195), which looks like a spectacular win. The median lift is 0%: the typical user's behavior is completely unchanged. Winsorizing at the control arm's 99th percentile (capping treatment at 20) brings the "lift" down to 0.7%, essentially nothing. All three numbers come from the exact same underlying data; the only difference is one added $5,000 purchase in a sample of 1,000 users. Reporting the mean alone would tell a story about broad-based product improvement that the data doesn't actually support.
Trade-offs & pitfalls
- Don't pick whichever statistic tells the story you want. Report mean, median, and a robust variant together as standard practice, not as a reaction to a surprising result.
- Winsorizing/trimming thresholds should be set from a pre-specified rule (e.g. control-arm percentile), not tuned after seeing the treatment data, or you've reintroduced exactly the kind of post-hoc flexibility that inflates false positives.
- Log-transforms complicate interpretation for stakeholders; a "12% lift in log-revenue" needs translation into a business-meaningful statement (roughly a 12% multiplicative lift in revenue, not an additive one), and zero values break a plain log transform (hence log(1+x)).
- If most of a real lift genuinely comes from a small number of high-value users, that's not automatically a false positive. It changes what to do next: consider whether that's the intended (e.g. a premium-tier feature) or unintended (e.g. one enterprise account skewing an SMB experiment) outcome, rather than assuming the whale should always be excluded.
- Segment-level Simpson's paradox checks matter as much as the tail-robustness fixes. A metric can be tail-robust and still misleading if the treatment changed who's in the denominator.
Define Type I and Type II errors in hypothesis testing. Give concrete business examples where each error would be costly. Explain how the significance level alpha and beta relate to these errors and how business costs can inform the choice of alpha.
Sample Answer
Direct answer
A Type I error is rejecting a true null hypothesis (a false positive: concluding there's an effect when there isn't one); a Type II error is failing to reject a false null (a false negative: missing a real effect). The significance level alpha (α) is the Type I error rate you're willing to accept; beta (β) is the Type II error rate, and power (1−β) is the chance of detecting a true effect. The right alpha is not a universal default. It should reflect how expensive a false positive is relative to a false negative for the specific decision being made.
Structured elaboration
The error matrix
| H0 actually true (no real effect) | H0 actually false (real effect exists) | |
|---|---|---|
| Test rejects H0 | Type I error (false positive), probability α | Correct decision, probability 1−β (power) |
| Test fails to reject H0 | Correct decision, probability 1−α | Type II error (false negative), probability β |
Business examples
- Type I error (false positive) is costly: shipping an expensive personalization system because a test showed a "significant" lift that was actually noise. You pay ongoing engineering and infrastructure cost, plus the opportunity cost of the team not working on something that actually helps.
- Type II error (false negative) is costly: killing a checkout redesign because the test result wasn't significant, when the redesign truly would have lifted conversion. You lose the revenue and any competitive advantage from never shipping it.
Setting alpha and beta from cost, not convention
For a fixed sample size, α and β trade off against each other: tightening α (fewer false positives) pushes power down (more false negatives) unless you also grow n. The textbook defaults (α=0.05, power =0.80) are a starting point, not a business decision. Set α lower when a false positive is expensive to reverse (a payments flow, a compliance-adjacent surface, a change that's hard to roll back); accept a higher α, or invest in a larger sample, when missing a true win is the more expensive mistake.
Worked example
A team wants to detect a 2 percentage-point lift on a checkout metric, baseline p0=0.20, p1=0.22, with n=2,000 users already collected per arm (fixed. This cohort won't grow before the decision is needed).
Holding n fixed, power at two different alpha values (two-sided z-test for two proportions):
| α | z1−α/2 | Power (1−β) | β |
|---|---|---|---|
| 0.05 | 1.9600 | 0.342 | 0.658 |
| 0.01 | 2.5758 | 0.153 | 0.847 |
(computed from the standard two-proportion power formula with scipy.stats.norm)
Insisting on α=0.01 for this "high-stakes" surface, without collecting more data, drops power from 34% to 15%: an 85% chance of missing a real 2-point lift entirely. If the team genuinely needs α=0.01, the fix is a larger n, not accepting a test that's this underpowered.
Trade-offs & pitfalls
- Alpha and beta are symmetric-looking numbers with asymmetric real-world stakes; picking α=0.05 by convention without asking what each error costs is the most common mistake.
- Tightening alpha without growing the sample size silently starves the test of power. Teams sometimes do this and then are surprised the "safer" test never finds anything.
- Failing to reject H0 is not proof of no effect. It can just as easily mean the test was underpowered for the true effect size, so a null result should be read alongside the achieved power, not treated as a settled "no."
Explain in plain language what a p-value represents in hypothesis testing and list three common misconceptions about p-values that you should avoid when communicating results to stakeholders. Provide an example sentence illustrating correct reporting of a p-value along with effect size and confidence interval.
Sample Answer
Direct answer
A p-value is the probability, computed assuming the null hypothesis H0 is true, of observing a test statistic at least as extreme as the one actually observed. It is a statement about the data given the null, not a statement about the probability that the null (or the alternative) is true. A small p-value is evidence against H0, but by itself it says nothing about how large or important the underlying effect is.
Structured elaboration
Formal definition
For an observed test statistic Tobs computed from the data:
p=P(T≥Tobs H0 true)(one-sided; a two-sided p-value sums both tails). The p-value depends on the chosen test statistic and the definition of "extreme," so two valid tests on the same data can report different p-values.
Common misconceptions
| Misconception | Why it's wrong |
|---|---|
| "p is the probability H0 is true" | p=P(data∣H0), not P(H0∣data). Confusing the two is the inverse-probability fallacy; getting from one to the other requires a prior on H0, which frequentist p-values don't supply. |
| "A tiny p means a large, important effect" | p is driven jointly by effect size and sample size. A trivial effect can produce a minuscule p if n is large enough (see the worked example). |
| "A large p (non-significant) means there is no effect" | Failing to reject H0 can just as easily mean the test was underpowered, the sample was too small, or the data were noisy. Absence of evidence is not evidence of absence. |
| "A significant result will replicate" | Significance is a property of one sample under sampling variability; it says nothing about how the effect will look in a fresh sample, especially near the threshold. |
What to report instead of a p-value alone
Pair every p-value with an effect size (the actual magnitude of the difference, in business units) and a confidence interval (the range of plausible effect sizes given the data). The p-value answers "is this compatible with pure chance," the effect size and interval answer "how big is it, and how sure are we."
Worked example
Two groups, n=10,000 per group, common standard deviation σ=1, observed mean difference =0.10.
Standard error of the difference:
SE=n2σ2=10,0002(1)2=0.014142Test statistic and two-sided p-value:
z=0.0141420.10=7.0711⇒p≈1.5×10−12(verified with scipy.stats.norm.sf: 2 * norm.sf(7.0711) = 1.537e-12)
95% CI for the difference: 0.10±1.96(0.014142)=[0.0723, 0.1277].
Cohen's d (standardized effect size) is 0.10/1=0.10, conventionally a small-to-negligible effect.
Correctly-reported sentence: "Treatment increased the metric by 0.10 units (Cohen's d = 0.10, a small effect), 95% CI [0.072, 0.128], p < 0.001; the effect is real but modest, so ship/no-ship should hinge on whether a 0.10-unit change is worth the cost, not on the size of the p-value."
Trade-offs & pitfalls
- With enough data, essentially any non-zero effect becomes statistically significant, so at large n the p-value stops discriminating between "trivial" and "important" and the effect size has to do that work.
- Reporting p-values without an effect size and interval invites exactly the "significant equals important" misreading this answer warns against.
- The one-sided vs. two-sided choice, and the definition of "extreme," must be fixed before looking at the data. Changing either after seeing results inflates the true error rate above the stated p-value.
Design an A/B test to evaluate a product change expected to affect a key engagement metric (for example, click-through rate). Specify: primary and secondary metrics, randomization scheme and unit of analysis, blocking or stratification if any, the sample-size estimation approach, experiment duration rules, data collection and logging requirements, and guardrails to detect biased metrics or instrumentation issues.
Sample Answer
Designing an A/B test end to end means fixing, before any data is collected: one primary metric with a pre-computed sample size, the randomization unit and any stratification needed to reduce variance, how long the test must run, exactly what gets logged, and a set of guardrail checks that would catch broken or biased instrumentation before the result is trusted.
Structured elaboration
Flow
flowchart LR
A[Define primary + guardrail metrics] --> B[Compute required sample size]
B --> C[Randomize users into control/treatment]
C --> D[Run for planned duration]
D --> E{Guardrails clean?}
E -->|yes| F[Analyze primary metric]
E -->|no| G[Investigate and pause]
F --> H[Decision: ship, hold, or iterate]
The pieces
- Primary and secondary metrics: one primary metric the test is powered on and used for the go/no-go decision (for example, click-through rate); secondary metrics that describe downstream health (conversion, retention) without being the statistical decision criterion.
- Randomization scheme and unit of analysis: randomize at the level that matches how the effect actually plays out (user-id for anything a user experiences repeatedly, so the same person is not split across both arms) and persist the assignment for the life of the experiment.
- Blocking or stratification: stratify the randomization by covariates expected to add variance (device type, region, traffic source) so both arms stay balanced on those dimensions even at moderate sample sizes, which increases power.
- Sample-size estimation: compute the minimum n per arm from a baseline rate, a minimum detectable effect, alpha, and target power, before the test starts.
- Duration rules: run at least until the computed sample size is reached in every stratum, and for enough calendar time (commonly at least one full weekly cycle, often two) to average out day-of-week and other periodic effects; avoid stopping purely because a dashboard "looks done" early.
- Data collection and logging: log raw events (impression, click, timestamp, bucket assignment, device, locale) rather than only pre-aggregated metrics, so mistakes can be diagnosed and metrics recomputed after the fact.
- Guardrails: invariant checks that should not move between arms if randomization and instrumentation are healthy (traffic volume split, covariate balance, error rates), used to catch a broken test before its primary-metric result is trusted at all.
Worked example
A checkout team wants to detect a 10% relative lift in click-through rate over a baseline of 8% (p0 = 0.08, p1 = 0.088), with alpha = 0.05 (two-sided) and power = 0.80:
n=(p1−p0)2(zα/2+zβ)2[p0(1−p0)+p1(1−p1)]
With z_{0.025} = 1.9600 and z_beta = 0.8416:
n is about 18,869 per arm (computed with python3 from the closed-form expression above).
At 1,500 eligible users per arm per day, that sample size alone needs 13 days; the team rounds up to a minimum of 14 days (two full weeks) to also cover a full weekly cycle, since checkout behavior differs meaningfully between weekdays and weekends. The primary metric is click-through rate; guardrails include total daily traffic per arm (should track the expected 50/50 split within normal noise) and the server error rate (should not increase in the treatment arm), both checked before the primary-metric result is interpreted.
Trade-offs & pitfalls
- Stopping as soon as the sample-size target is technically hit, without also covering a full weekly cycle, risks a result that is really a "which day did the test happen to end on" artifact rather than a stable effect.
- Randomizing at the wrong unit (session instead of user, when the same user returns multiple times) contaminates both arms with the same users and biases the effect toward zero, because users partially experience both conditions.
- A guardrail check is only useful if it is defined and its acceptable range set before the test runs; picking guardrail thresholds after seeing a concerning result is the same p-hacking problem as post-hoc peeking.
- Logging only pre-aggregated metrics instead of raw events makes it impossible to diagnose an instrumentation bug after the fact; keep the raw event stream even if the day-to-day dashboard only shows aggregates.
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.