Diagnose a Skewed Revenue Distribution and Pick the Right Test
Statistics & ExperimentsModel answerLast updated
Read five summary statistics from a zero-heavy e-commerce dataset, name the distribution, and choose appropriate metrics and tests for an A/B experiment.
Setup
A data science team hands you the following summary of 10,000 session-level revenue observations from an online store. No raw data, just these numbers:
| Statistic | Value |
|---|---|
| Count | 10,000 |
| Mean | $12.50 |
| Std dev | $45.00 |
| P50 (median) | $0.00 |
| P75 | $0.00 |
| P90 | $15.00 |
| P99 | $250.00 |
All values are non-negative. Your job is to reason about what these numbers reveal, explain the pitfalls of naive analysis, and design a sound comparison strategy.
Questions
-
Name and characterize the distribution. What do the percentiles tell you about the shape? Estimate roughly what fraction of sessions have zero revenue, and what a typical buying session looks like.
-
Critique a standard t-test on the raw means. A colleague suggests running a two-sample t-test to compare mean revenue between a control and a treatment group. What are the specific failure modes here? Be precise — "the data aren't normal" is not sufficient.
-
Report a "typical user" value. A product manager asks for a single number representing the typical session. Why is the mean misleading, and why is the median equally uninformative? What would you report instead?
-
Design a robust A/B comparison. Propose a concrete testing strategy for comparing two groups of this revenue data in an experiment. Address how you handle zeros, outliers, and the choice of estimand.
Constraints
- Revenue is non-negative; zeros represent real non-purchasing sessions, not missing data.
- Outliers should be handled, not discarded.
- Your chosen test or metric should remain tied to a business-meaningful quantity.
Hints
Hint 1
Work through the percentiles sequentially. P50 = P75 = $0 tells you the zero share is above 75%. P90 = $15 means it's below 90%. That range is your first concrete fact. Then compute implied average spend among buyers as mean / (1 - zero_share) to get a number stakeholders can actually use.
Hint 2
The t-test's validity rests on the sample mean being approximately normal, not the underlying data. The real issues are skewness slowing CLT convergence, a few very large sessions dominating the variance, and the equal-variance assumption breaking if treatment affects the tail. Think about each of these separately.
Hint 3
A decomposition beats any single metric here. Splitting revenue per session into (conversion rate) × (revenue given purchase) tells you *why* a change happened — more buyers, bigger baskets, or both. Build your testing strategy around that decomposition rather than searching for one magic test.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Reading the Distribution
Start with the percentiles rather than the mean.
- P50 = P75 = $0 means at least 75% of sessions have zero revenue.
- P90 = $15 means the zero share is below 90%. So somewhere between 75% and 90% of sessions are zeros — call it roughly 80%.
- P99 = $250 is about 17× P90, indicating a very long right tail.
- Mean $12.50 vs. median $0. The entire mean is pulled by the minority of sessions that purchase anything.
- Coefficient of variation = 45 / 12.5 = 3.6. Extreme dispersion.
With p₀ ≈ 0.80, average spend among buyers is 12.50 / 0.20 ≈ $62.50 — a much more grounded number than the overall mean.
This is a semicontinuous or zero-inflated distribution: a point mass at zero (non-purchasers) combined with a continuous, heavily right-skewed distribution over positive values. Standard parametric models are a hurdle model (Bernoulli for purchase × positive distribution for amount) or a Tweedie distribution with power parameter between 1 and 2.
Why a Naive t-Test Breaks Down
"The data aren't normal, so the t-test is invalid" is the most common wrong answer. The t-test requires the sample mean to be approximately normal, not the raw data. With n = 10,000 the CLT does apply — eventually. The actual problems are more specific:
-
Slow CLT convergence under heavy skew. The normal approximation error scales with skewness / √n. With ~80% of values at zero and a P99 of $250, skewness is very large. Type I error rates and confidence interval coverage can be off, especially in subgroup analyses or at early stopping points.
-
Variance dominated by a small number of high spenders. A handful of sessions at $500–$1,000+ can shift a group mean by more than the entire treatment effect. A single "whale" landing in one arm can flip the result.
-
Low statistical power. Standard error of the difference ≈ 45 · √(2/10,000) ≈ $0.64. Minimum detectable effect at α = 0.05, 80% power is roughly $1.78 — about a 14% relative lift. Most realistic product changes are smaller than that.
-
Equal-variance Student's t is wrong by construction if the treatment changes the tail shape. Welch's t-test is the minimum acceptable version.
Reporting a "Typical User" Value
The mean ($12.50) describes no real user: ~80% spend $0 and buyers average ~$62. It's also unstable — a few large orders can move it substantially.
The median ($0) is accurate but useless. It conveys only that the majority don't buy.
Report a decomposition instead:
| Metric | Interpretation |
|---|---|
| Conversion rate (~20%) | How often a session results in a purchase |
| Median spend among buyers (~$30–40, estimated) | Typical purchase size |
| Mean revenue per session ($12.50) | Driver of total revenue; keep it but label it clearly |
| Revenue concentration (e.g., top 1% share) | Conveys tail risk |
A winsorized mean — capping at P99 on the combined distribution — is a good robust single-number summary that stays meaningful in dollars.
A/B Test Design
Decide the estimand first. The business almost always cares about total revenue, which is the mean. Testing a different quantity (ranks, medians) can show "significance" while revenue is flat. Anchor on revenue per session.
Primary metric: robust mean comparison
- Winsorize at a fixed cap (P99 or P99.9) computed on the pooled pre-experiment data so the same cap applies to both arms.
- Run a Welch t-test or percentile bootstrap on the capped values.
- Apply CUPED using pre-period revenue as a covariate to reduce variance and shorten experiment runtime.
Diagnostic decomposition (handles zeros explicitly)
- Conversion rate: two-proportion z-test or chi-square on P(Y > 0).
- Spend given purchase: Welch t-test on log(Y) or Mann-Whitney on positive values only.
This tells you why revenue moved: more buyers, larger baskets, or both.
What to avoid
- Mann-Whitney on all data mostly re-tests conversion when 80% of values are tied at zero. It tests stochastic dominance, not the mean. Use it as a secondary check at most.
- log(1 + Y) transform compresses variance but shifts the estimand off the dollar scale and is sensitive to the "+1" constant.
import numpy as np
from scipy import stats
def compare_revenue(control, treatment, cap_quantile=0.99, n_boot=5000, seed=42):
a = np.asarray(control, float)
b = np.asarray(treatment, float)
# Winsorization cap computed on pooled data
cap = np.quantile(np.concatenate([a, b]), cap_quantile)
aw, bw = np.minimum(a, cap), np.minimum(b, cap)
# 1. Welch t-test on winsorized means
welch = stats.ttest_ind(bw, aw, equal_var=False)
# Bootstrap CI for the mean difference
rng = np.random.default_rng(seed)
diffs = [
rng.choice(bw, bw.size, replace=True).mean()
- rng.choice(aw, aw.size, replace=True).mean()
for _ in range(n_boot)
]
ci = np.percentile(diffs, [2.5, 97.5])
# 2. Conversion rate (two-proportion z-test)
conv_a = (a > 0).mean()
conv_b = (b > 0).mean()
p_pool = ((a > 0).sum() + (b > 0).sum()) / (a.size + b.size)
se_conv = np.sqrt(p_pool * (1 - p_pool) * (1 / a.size + 1 / b.size))
z_conv = (conv_b - conv_a) / se_conv
p_conversion = 2 * stats.norm.sf(abs(z_conv))
# 3. Spend among buyers (log scale Welch t-test)
pos_a, pos_b = a[a > 0], b[b > 0]
p_spend = stats.ttest_ind(np.log(pos_b), np.log(pos_a), equal_var=False).pvalue
return {
"mean_diff_winsorized": bw.mean() - aw.mean(),
"bootstrap_ci_95": ci,
"p_mean": welch.pvalue,
"conversion_control": conv_a,
"conversion_treatment": conv_b,
"p_conversion": p_conversion,
"p_spend_given_purchase": p_spend,
}
Common Mistakes
- Calling the t-test invalid purely because the data are non-normal.
- Reporting Mann-Whitney results as "revenue increased."
- Dropping outliers rather than capping them — this changes the population definition and biases results if treatment genuinely creates high spenders.
- Setting the winsorization cap separately per arm, which can introduce bias.
- Reporting the median ($0) as the typical user value without noting it is entirely uninformative here.
- Ignoring the decomposition and searching for a single omnibus test — the decomposition is often more actionable than any single p-value.