hypothesis_testing_interview_guide Hypothesis Testing Interview Guide for Data Science A comprehensive collection of questions and answers covering both conceptual and mathematical aspects of hypothesis testing for data science interviews. Table of Contents 1. Conceptual Understanding 2. Technical Details 3. Practical Application 4. Advanced Topics 5. Mathematical Questions Probability and Distributions Sample Size and Power Calculations Test Statistics and Distributions Confidence Intervals Chi-Square Tests Bayesian Connection Conceptual Understanding Q: What is hypothesis testing and why do we use it? A: Hypothesis testing is a statistical method to make inferences about population parameters based on sample data. We use it to determine whether observed differences or relationships are statistically significant or likely due to random chance. It helps us make data-driven decisions with quantifiable confidence levels, which is crucial in business contexts like A/B testing, product launches, or validating model improvements. Q: Explain the null and alternative hypothesis. A: The null hypothesis (H₀) represents the status quo or no effect - it's what we assume to be true until we have sufficient evidence otherwise. The alternative hypothesis (H₁ or Hₐ) represents what we're trying to prove or the effect we're investigating. For example, if testing whether a new feature increases conversion rates, H₀ would be "the new feature has no effect on conversion" while H₁ would be "the new feature increases conversion rates." Q: What are Type I and Type II errors? A: A Type I error (false positive) occurs when we reject a true null hypothesis - concluding there's an effect when there isn't one. The probability of this is α (significance level), typically 0.05. A Type II error (false negative) occurs when we fail to reject a false null hypothesis - missing a real effect. Its probability is β, and (1-β) is called statistical power. In business terms: Type I might mean launching a feature that doesn't actually help, Type II means missing out on a beneficial feature. Technical Details Q: What is a p-value and how do you interpret it? A: The p-value is the probability of observing results as extreme as (or more extreme than) what we observed, assuming the null hypothesis is true. A small p-value (typically < 0.05) suggests our observed data is unlikely under H₀, providing evidence against it. Important caveat: p-value doesn't tell us the probability that H₀ is true, nor does it measure effect size. A p-value of 0.03 means "if there were truly no effect, we'd see results this extreme only 3% of the time." Q: What's the difference between one-tailed and two-tailed tests? A: A two-tailed test checks for differences in both directions (greater than or less than), while a one-tailed test only checks one direction. Use two-tailed when you care about any difference (e.g., "does this drug have any effect on blood pressure?"). Use one-tailed when you have a directional hypothesis and only care about one direction (e.g., "does this new algorithm reduce latency?"). Two-tailed tests are generally more conservative and commonly preferred unless there's strong justification for directionality. Q: How do you choose the right statistical test? A: The choice depends on several factors: the type of data (continuous, categorical), number of groups being compared, whether data is paired or independent, and whether assumptions like normality are met. Examples include t-tests for comparing means of two groups, ANOVA for multiple groups, chi-square for categorical data, and Mann-Whitney U for nonparametric alternatives when normality assumptions fail. Practical Application Q: Walk me through how you'd design an A/B test for a website feature. A: First, I'd define clear success metrics (conversion rate, revenue, engagement). Then formulate hypotheses - H₀: no difference between versions, H₁: version B performs better. Next, determine required sample size through power analysis, considering desired significance level (α=0.05), power (0.8), and minimum detectable effect size based on business requirements. Randomly assign users to control/treatment groups, ensuring proper randomization. Run the test for sufficient duration to account for temporal effects. Finally, analyze results using appropriate statistical test (likely z-test for proportions), check assumptions, and make recommendations based on both statistical and practical significance. Q: What is statistical power and why does it matter? A: Statistical power is the probability of correctly rejecting a false null hypothesis (detecting a real effect when it exists). It equals 1-β, typically set at 0.8 or 80%. Power matters because low power means you might miss important effects, wasting resources on inconclusive experiments. Power increases with larger sample sizes, larger effect sizes, and higher significance levels. In practice, we use power analysis before experiments to determine minimum sample sizes needed to detect meaningful effects. Q: What's the difference between statistical significance and practical significance? A: Statistical significance tells us whether an effect is likely real (not due to chance), while practical significance tells us whether the effect is large enough to matter in the real world. With large enough samples, tiny, trivial differences become statistically significant but may not justify implementation costs. For example, a feature might increase conversion from 10.0% to 10.1% (statistically significant with millions of users) but the 0.1% lift might not justify development costs. Always consider effect size, confidence intervals, and business context alongside p-values. Advanced Topics Q: What is multiple testing correction and when do you need it? A: When conducting multiple hypothesis tests simultaneously, the probability of at least one Type I error increases (family-wise error rate). If testing 20 hypotheses at α=0.05, we'd expect one false positive by chance. Multiple testing corrections like Bonferroni (divide α by number of tests) or Benjamini-Hochberg (controls false discovery rate) adjust significance thresholds to maintain overall error rates. This is critical in scenarios like A/B/C/D testing multiple variants, genomics studies, or analyzing multiple metrics simultaneously. Q: What assumptions underlie a t-test and what do you do if they're violated? A: T-tests assume: independence of observations, approximate normality of the sampling distribution, and equal variances for two-sample tests (though Welch's t-test relaxes this). If normality is violated with small samples, consider non-parametric alternatives like Mann-Whitney U test or permutation tests. For large samples, the Central Limit Theorem often ensures robustness. If independence is violated (like with time series data), you need different approaches accounting for autocorrelation. Always visualize data and test assumptions before choosing your method. Mathematical Questions Probability and Distributions Q: If you flip a coin 100 times and get 60 heads, is the coin fair? How would you test this mathematically? A: Under H₀ (fair coin), p = 0.5, so the number of heads follows a binomial distribution: X ~ Binomial(n=100, p=0.5). We can use a z-test since n is large: Expected heads: μ = np = 50 Standard deviation: σ = √(np(1-p)) = √25 = 5 Test statistic: z = (60-50)/5 = 2.0 For two-tailed test, p-value ≈ 0.046 Since p < 0.05, we'd reject H₀ at the 5% level, suggesting the coin might not be fair. Q: Derive the formula for the standard error of a proportion. A: For a proportion p̂ from a sample of size n: Each observation is Bernoulli: variance = p(1-p) Sample proportion p̂ is the mean of n Bernoulli trials By properties of variance: Var(p̂ ) = Var(∑Xi/n) = (1/n²)∑Var(Xi) = (1/n²) · n · p(1-p) = p(1-p)/n Standard error: SE(p̂ ) = √(p(1-p)/n) For practical use, we substitute the sample proportion: SE = √(p̂ (1-p̂ )/n) Q: What is the Central Limit Theorem and why is it important for hypothesis testing? A: The CLT states that for independent, identically distributed random variables with mean μ and variance σ², the sampling distribution of the sample mean approaches a normal distribution as n → ∞, specifically: X̄ ~ N(μ, σ²/n) for large n. This is crucial because it allows us to use z-tests and construct confidence intervals even when the underlying population isn't normal, as long as the sample size is sufficiently large (typically n ≥ 30). It justifies the normal approximation used in many hypothesis tests. Sample Size and Power Calculations Q: Calculate the minimum sample size needed to detect a 2% increase in conversion rate from a baseline of 10%, with 80% power and α = 0.05. A: For proportions comparison: p₁ = 0.10 (control), p₂ = 0.12 (treatment) Pooled proportion: p̄ = (p₁ + p₂)/2 = 0.11 Effect size: δ = p₂ - p₁ = 0.02 Using the formula: n = (Z₁₋α/₂ + Z₁₋β)² · [p₁(1-p₁) + p₂(1-p₂)] / δ² Where Z₀.₉₇₅ = 1.96 and Z₀.₈₀ = 0.84: n = (1.96 + 0.84)² · [0.10(0.90) + 0.12(0.88)] / (0.02)² n = 7.84 · [0.09 + 0.1056] / 0.0004 n = 7.84 · 0.1956 / 0.0004 ≈ 3,834 per group Q: How does increasing the significance level from 0.01 to 0.05 affect statistical power? A: Increasing α (making the test less stringent) increases power. Mathematically: Power = 1 - β = P(reject H₀ | H₁ is true) Critical value moves closer to H₀ mean as α increases This makes it easier to reject H₀, increasing the probability of detecting a true effect For a given sample size and effect size, if α increases from 0.01 to 0.05, the critical z-value decreases from 2.576 to 1.96, making the rejection region larger and thus increasing power. Test Statistics and Distributions Q: Derive the t-statistic for a one-sample test. A: We want to test H₀: μ = μ₀ given sample mean X̄ , sample standard deviation s, and sample size n. Starting from the z-statistic: z = (X̄ - μ)/(σ/√n) Since we don't know σ, we estimate it with s. This introduces additional uncertainty, so: t = (X̄ - μ₀)/(s/√n) This follows a t-distribution with (n-1) degrees of freedom, which has heavier tails than the normal distribution to account for the uncertainty in estimating σ. As n → ∞, the t-distribution approaches the standard normal. Q: Why do we use (n-1) degrees of freedom for sample variance? A: Degrees of freedom represent the number of independent pieces of information. When calculating sample variance: s² = ∑(Xᵢ - X̄ )² / (n-1) We use the sample mean X̄ , which itself is calculated from the data. This imposes one constraint: ∑(Xᵢ - X̄ ) = 0 So only (n-1) deviations are "free" to vary; the nth is determined by the others. Using (n-1) makes s² an unbiased estimator of σ² because E[s²] = σ². If we used n instead, we'd systematically underestimate the population variance. Q: Calculate the pooled variance for two groups with n₁=30, s₁²=16, n₂=40, s₂²=25. A: The pooled variance formula: s²pooled = [(n₁-1)s₁² + (n₂-1)s₂²] / (n₁+n₂-2) s²pooled = [(30-1)·16 + (40-1)·25] / (30+40-2) s²pooled = [29·16 + 39·25] / 68 s²pooled = [464 + 975] / 68 s²pooled = 1439 / 68 ≈ 21.16 Standard error for difference: SE = √[s²pooled(1/n₁ + 1/n₂)] = √[21.16(1/30 + 1/40)] ≈ 1.10 Confidence Intervals Q: Construct a 95% confidence interval for the difference in means given: Group A (n=50, X̄ =25, s=5) and Group B (n=60, X̄ =22, s=6). A: Difference in means: X̄ ₁ - X̄ ₂ = 25 - 22 = 3 Standard error: SE = √(s₁²/n₁ + s₂²/n₂) = √(25/50 + 36/60) = √(0.5 + 0.6) = √1.1 ≈ 1.049 Degrees of freedom (Welch's approximation): df ≈ (s₁²/n₁ + s₂²/n₂)² / [(s₁²/n₁)²/(n₁-1) + (s₂²/n₂)²/(n₂-1)] df ≈ 1.1² / [0.5²/49 + 0.6²/59] ≈ 107.8 ≈ 108 For df ≈ 108, t₀.₉₇₅ ≈ 1.98 95% CI = 3 ± 1.98(1.049) = 3 ± 2.08 = [0.92, 5.08] Since the interval doesn't contain 0, we can conclude the means are significantly different at the 5% level. Chi-Square Tests Q: Calculate the chi-square statistic for this 2×2 contingency table: Control Treatment Success Failure 40 60 55 45 A: χ² = ∑(Observed - Expected)² / Expected First, calculate expected values under H₀ (independence): Total: 200, Success total: 95, Failure total: 105 Expected (Control, Success) = (100·95)/200 = 47.5 Expected (Control, Failure) = (100·105)/200 = 52.5 Expected (Treatment, Success) = (100·95)/200 = 47.5 Expected (Treatment, Failure) = (100·105)/200 = 52.5 χ² = (40-47.5)²/47.5 + (60-52.5)²/52.5 + (55-47.5)²/47.5 + (45-52.5)²/52.5 χ² = 56.25/47.5 + 56.25/52.5 + 56.25/47.5 + 56.25/52.5 χ² = 1.184 + 1.071 + 1.184 + 1.071 = 4.51 With df = (2-1)(2-1) = 1, critical value at α=0.05 is 3.84. Since 4.51 > 3.84, we reject H₀ (p ≈ 0.034). Bayesian Connection Q: If a test has 95% sensitivity and 90% specificity, and disease prevalence is 1%, what's the probability someone has the disease given a positive test (using Bayes' theorem)? A: Let D = disease, + = positive test Given: P(+|D) = 0.95, P(-|no D) = 0.90 → P(+|no D) = 0.10, P(D) = 0.01 By Bayes' theorem: P(D|+) = P(+|D)·P(D) / P(+) Where P(+) = P(+|D)·P(D) + P(+|no D)·P(no D) P(+) = 0.95·0.01 + 0.10·0.99 = 0.0095 + 0.099 = 0.1085 P(D|+) = (0.95·0.01) / 0.1085 = 0.0095 / 0.1085 ≈ 0.0875 or 8.75% Despite a "positive" test with high sensitivity/specificity, the low prevalence means most positives are false positives—a key insight for interpreting test results. Summary This guide covers essential hypothesis testing concepts for data science interviews, from foundational principles to advanced mathematical derivations. Key takeaways: 1. Understand the fundamentals: Know your hypotheses, errors, and p-values 2. Master the mathematics: Be able to derive and calculate test statistics 3. Apply to real problems: Connect statistical concepts to business decisions 4. Consider assumptions: Always check and understand when tests are appropriate 5. Balance significance types: Statistical vs. practical significance matters Good luck with your interviews!
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )