P-values, Confidence Intervals, and Hypothesis Test Selection
Statistics & ExperimentsModel answerLast updated
Explain p-values vs. confidence intervals, when to use t-tests vs. chi-square tests, and define Type I and Type II errors with examples.
You're interviewing for a data science or analytics role and the interviewer wants to verify your understanding of core statistical concepts.
Answer the following:
-
What is the difference between a p-value and a confidence interval? Explain what each one tells you and how they relate to each other.
-
When would you choose a t-test versus a chi-square test? Describe the scenarios, data types, and assumptions for each.
-
Define Type I and Type II errors. Provide concrete examples of each in a practical context.
Your answer should include precise definitions, correct interpretation, and demonstrate awareness of common misunderstandings.
Hints
Hint 1
Start with formal definitions, then translate into plain language with examples
Hint 2
Clarify what each metric does and doesn't tell you—many practitioners misinterpret p-values
Hint 3
Match the test to the data type: continuous outcomes suggest one family of tests, categorical counts suggest another
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
This question tests whether you understand foundational inference concepts, can state definitions precisely, and know how to interpret results correctly. A strong answer gives the formal definition, explains it in plain terms, and highlights common pitfalls.
1. P-value vs. Confidence Interval
P-value:
A p-value is the probability of observing a test statistic at least as extreme as the one calculated from your data, assuming the null hypothesis is true.
Formally: p = P(T ≥ t_observed | H₀)
What it tells you: How consistent your data is with the null hypothesis. A small p-value suggests the observed data would be surprising if H₀ were true. You compare it against a threshold α (commonly 0.05): if p ≤ α, you reject H₀; otherwise, you fail to reject it.
Critical misconceptions:
- It is not the probability that H₀ is true given your data.
- It does not tell you the size or importance of an effect—large samples can yield tiny p-values for trivial differences.
- "Fail to reject" does not mean you accept H₀.
Confidence Interval:
A 95% confidence interval is produced by a procedure that, if repeated across many samples, would contain the true parameter value 95% of the time.
For a mean: x̄ ± t_(α/2, df) · (s/√n)
What it tells you: A plausible range for the parameter, expressed in the original units. It shows both the magnitude and the precision of your estimate.
Important clarification: The 95% describes the method's long-run performance, not the probability that this specific interval contains the parameter. Once computed, the true value either is or isn't inside.
How they relate:
For a two-sided test at level α, you reject H₀: θ = θ₀ if and only if θ₀ falls outside the (1 − α)% confidence interval. They are mathematically dual.
Why intervals are often more useful: Suppose an A/B test shows a conversion lift of 0.8% with p = 0.03 and a 95% CI of [0.1%, 1.5%]. The p-value says the effect is statistically significant, but the CI reveals the effect might be as small as 0.1%—which may not justify rollout costs. The interval communicates both significance and practical relevance.
2. t-test vs. Chi-square Test
The choice depends on your data type and what parameter you're testing.
t-test: for comparing means of continuous data
- One-sample t-test: Is the mean of one group equal to a known value?
- Independent two-sample t-test: Do two groups have the same mean? Use Welch's t-test by default—it doesn't assume equal variances.
- Paired t-test: Compare measurements on the same subjects before and after treatment. Essentially a one-sample test on differences.
Assumptions:
- Observations are independent.
- Data (or the sampling distribution of the mean) is approximately normal. The Central Limit Theorem helps here for moderate sample sizes unless data is heavily skewed or has outliers.
- Classic Student's t-test assumes equal variances; Welch's does not.
Why "t" not "z"? You're estimating the population variance from the sample, which adds uncertainty. The t-distribution with n−1 degrees of freedom accounts for this. As n increases, t approaches the standard normal.
Example: Testing whether mean session duration differs between two app versions.
Chi-square test: for categorical data (counts)
χ² = Σ (Observed − Expected)² / Expected
- Goodness-of-fit test: Does one categorical variable follow a hypothesized distribution? E.g., are website visits uniform across days of the week? (df = k − 1)
- Test of independence: Are two categorical variables related? E.g., is device type associated with conversion? (df = (rows − 1)(cols − 1))
Assumptions:
- Observations are independent.
- Data are counts, not proportions or averages.
- Expected count in each cell should be at least 5. For smaller counts, use Fisher's exact test.
Rule of thumb: Continuous outcome + question about means → t-test (or ANOVA for 3+ groups). Categorical outcome summarized as counts in a table → chi-square test.
3. Type I and Type II Errors
| H₀ is True | H₀ is False | |
|---|---|---|
| Reject H₀ | Type I error (α) | Correct (power = 1 − β) |
| Fail to reject | Correct (1 − α) | Type II error (β) |
Type I error (false positive): Rejecting a true null hypothesis. Probability = α, which you set (commonly 0.05).
Type II error (false negative): Failing to reject a false null hypothesis. Probability = β, which depends on sample size, effect size, variance, and α.
Power = 1 − β is the probability of correctly detecting a real effect. Studies typically aim for 80% power.
Examples:
-
Medical test (H₀: patient is healthy)
- Type I: diagnosing a healthy person as sick → unnecessary stress and follow-up procedures.
- Type II: missing a disease in a sick patient → delayed treatment, often the more serious error.
-
A/B test (H₀: no difference between variants)
- Type I: launching a feature that doesn't actually improve metrics, wasting engineering resources.
- Type II: abandoning a feature that truly would have increased engagement, because the test lacked power.
-
Spam filter (H₀: email is legitimate)
- Type I: marking real email as spam → user misses important messages.
- Type II: letting spam into the inbox → user annoyance, potential security risk.
Trade-off: At fixed sample size, lowering α increases β. The only way to reduce both errors is to increase sample size or reduce variance (e.g., paired designs, stratification, or covariate adjustment like CUPED). In practice, choose α based on the relative cost of each error type.
Summary
- P-value: Probability of seeing data this extreme under H₀. Tells you whether to reject, not effect size or importance.
- Confidence interval: Range that captures the true parameter with stated long-run frequency. Shows magnitude and precision.
- Relationship: A value outside the (1 − α) CI corresponds to p < α.
- t-test: Continuous data, questions about means. Check normality and independence.
- Chi-square: Categorical counts, questions about distributions or independence. Ensure adequate expected counts.
- Type I error: False positive, controlled by α.
- Type II error: False negative, depends on power, which you design for via sample size and variance reduction.