KatInterview

Deciding Whether Two Samples Share the Same Distribution

Statistics & ExperimentsModel answer
MediumModel answerStatistics & Experimentshypothesis-testingtwo-sample-testsmultivariate

Last updated

Walk through univariate and multivariate methods for comparing two distributions, covering test selection, effect sizes, multiple-testing control, and sampling design.

You have collected data from two separate systems or populations and want to know whether they follow the same underlying distribution.

Explain how you would approach this comparison, starting from a single variable and scaling up to many features at once. Also describe how sampling design affects the validity of the comparison.

Constraints and Assumptions

  • State your null and alternative hypotheses explicitly.
  • Choose your test based on variable type and what aspect of the distribution matters (mean, tails, full shape, proportions).
  • Discuss when standard independence assumptions break down.
  • Pair any significant p-value with a measure of practical importance.
  • Address multiple comparisons, statistical power, and how the data were collected.

Clarifying Questions Worth Asking

  • What decision will follow from this test?
  • Are observations independent, or are they grouped by some unit such as a user, region, or time window?
  • Should both samples represent the same target population?
  • Are we comparing one variable or many?
  • Do rare events or tail behavior matter more than the average?

Part 1 — Single-Variable Testing

How would you test whether two samples come from the same distribution for a single feature?

Cover at minimum:

  • How to write down H₀ and H₁.
  • At least two tests suited to continuous variables.
  • At least one test suited to categorical variables.
  • When a mean-comparison test is sufficient versus when you need a full-distribution test.

Part 2 — Comparing High-Dimensional Samples

How would you extend the comparison when you have many features simultaneously?

Cover at minimum:

  • At least two methods that work in high dimensions without strong distributional assumptions.
  • One method that does require distributional assumptions and what those are.
  • How to diagnose which features drive any detected difference.

Part 3 — Interpreting Results and Handling Practical Complications

A test returns a small p-value. What do you do next?

Cover at minimum:

  • Effect size and confidence intervals.
  • How to set a business-relevant threshold for "meaningful" difference.
  • What to do when you are testing many features at once.
  • How to handle clustered or non-independent observations.
  • How to reason about statistical power when the sample is small.

Part 4 — Sampling Design

What sampling strategies are available when you get to decide how evaluation data are collected, and how do they affect the comparison?

Cover at minimum:

  • Simple random, stratified, cluster, and systematic sampling.
  • Reservoir sampling for streaming data.
  • Importance or weighted sampling and when you would reweight.
  • The risk of convenience sampling and how to spot it.

Hints

Hint 1

Start by asking what the test needs to decide. A narrow question about means calls for a t-test; a question about full distributional shape calls for KS or energy distance. Matching the test to the question avoids over- or under-powered conclusions.

Hint 2

For high-dimensional data, consider training a binary classifier to separate the two samples. If it achieves accuracy well above 50%, the distributions differ in some detectable way. The features with the highest importance scores then tell you where the difference lives.

Hint 3

A statistically significant result is not automatically a meaningful one. With large samples even a negligible shift produces a tiny p-value. Always report an effect size — Cohen's d, Wasserstein distance, or a lift percentage — alongside the p-value so a stakeholder can judge whether the gap actually matters.