Statistical Inference: Hypothesis Tests, CIs, and Sampling Strategies
Statistics & ExperimentsModel answerLast updated
Apply fundamental statistical inference techniques including hypothesis testing, confidence intervals, sample size calculations, tail probability estimation, and parameter estimation.
You're working through several statistical inference problems that require applying core concepts in different scenarios.
Part 1: Hypothesis Testing
You've gathered sample data to determine whether a population mean equals zero. If your analysis yields a p-value of x%, explain what this value represents in the context of hypothesis testing.
Part 2: Confidence Interval Construction
Your sample produces a mean of 1 with a standard error of 0.1. Construct a 95% confidence interval for the true population mean.
Part 3: Standard Error Control
How many observations would you need to reduce your standard error from 0.1 to 0.01? If collecting additional data is infeasible, what alternative approaches could reduce estimation uncertainty?
Part 4: Tail Probability Estimation
You have independent observations X₁, X₂, ..., Xₙ from some distribution. Design an estimator for the probability that X exceeds 10, then build a 95% confidence interval for this probability. Explain what your confidence interval tells you about the true probability.
Part 5: Conversion Rate Estimation Strategy
You need to estimate an overall conversion rate when 1,000 binary features describe each user. Describe your sampling and estimation approach.
Part 6: Truncated Distribution Parameter Estimation
Suppose observations come from a normal distribution N(μ, σ²), but you only observe values exceeding 3 (truncated normal). How would you estimate μ and σ²? How would you construct 95% confidence intervals for these parameters given the truncation?
Hints
Hint 1
For p-values, focus on the conditional probability statement and what assumptions it requires
Hint 2
Standard error scales with the square root of sample size
Hint 3
For rare event probabilities, the empirical proportion works but consider boundary cases
Hint 4
Stratified sampling can reduce variance when features correlate with the outcome
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
Part 1: Interpreting the p-value
Setup: Testing H₀: μ = 0 against H₁: μ ≠ 0 using test statistic T = x̄ / SE.
Definition: The p-value represents the probability of observing a test statistic at least as extreme as yours, assuming the null hypothesis is true. For a two-sided test: p = P(|T| ≥ |t_observed| | H₀).
A p-value of x% means: if the true population mean were actually 0, only x% of random samples would produce results this far from zero or farther. Standard practice rejects H₀ when p < α (commonly α = 0.05).
Common misinterpretations to avoid:
- The p-value is NOT the probability that H₀ is true given your data
- It does NOT measure the probability your result occurred "by chance"
- It provides no information about practical significance or effect magnitude
Part 2: 95% Confidence Interval
With x̄ = 1 and SE = 0.1:
CI = x̄ ± z₀.₉₇₅ × SE = 1 ± 1.96 × 0.1 = [0.804, 1.196]
Notes:
- For small samples, substitute the t-critical value t_{n-1, 0.975} for 1.96
- This interval excludes zero, consistent with z = 1/0.1 = 10 (p < 0.001)
- The interval means: 95% of intervals constructed this way will contain the true population mean
Part 3: Sample Size Requirements
Since SE = s/√n, standard error is inversely proportional to the square root of sample size. Reducing SE by a factor of 10 requires multiplying sample size by 100.
General formula: n_new = n_old × (SE_old / SE_new)²
Alternative approaches when increasing sample size isn't possible:
-
Covariate adjustment (CUPED): Use a correlated pre-treatment variable to reduce residual variance by factor (1 - ρ²)
-
Stratification: Remove between-group variance by blocking on known characteristics
-
Paired/matched designs: Each unit serves as its own control, eliminating individual-level variation
-
Reduce measurement error: Improve instrumentation or average multiple measurements per unit
-
Handle outliers: Winsorize extreme values, use robust estimators, or apply appropriate transformations
-
Accept wider intervals or lower confidence: Trade precision for feasibility (document this choice clearly)
Part 4: Tail Probability Estimation
Estimator: Use the sample proportion:
p̂ = (1/n) Σ I(Xᵢ > 10)
This is unbiased: E[p̂] = p, with variance p(1-p)/n. No distributional assumptions required.
95% Confidence Interval options:
-
Normal approximation: p̂ ± 1.96√(p̂(1-p̂)/n) — valid when np̂ > 10 and n(1-p̂) > 10
-
Wilson interval (preferred for rare events):
[p̂ + z²/(2n) ± z√(p̂(1-p̂)/n + z²/(4n²))] / (1 + z²/n)where z = 1.96
-
When p̂ = 0: Wilson or "rule of three" gives upper bound ≈ 3/n
Interpretation of interval [a, b]: The procedure produces intervals that contain the true (fixed) probability p in 95% of repeated samples. This is a statement about the procedure's long-run frequency, not about this specific interval. Avoid saying "95% probability that p lies in [a, b]" — that's a Bayesian interpretation.
Model-based alternative: If you assume X ~ N(μ, σ²), then p = 1 - Φ((10-μ)/σ). Plug in estimates μ̂, σ̂ and use the delta method or bootstrap for the CI. This is more efficient for rare tails but depends entirely on model correctness.
Part 5: Conversion Rate with 1,000 Features
Clarifications needed:
- Full population or sample?
- Representative sample or biased?
- Overall rate or segmented rates?
Recommended strategy:
-
Baseline: Simple random sample
- Estimator: p̂ = conversions/n
- Sample size for margin E: n = z²p(1-p)/E²
- Example: For p ≈ 0.05, E = 0.005, need n ≈ 7,300
-
Variance reduction via stratification
- With 2¹⁰⁰⁰ possible feature combinations, full cross-classification is impossible
- Use feature selection: identify 3-5 features most predictive of conversion (mutual information, L1-penalized logistic regression on pilot data)
- Create 5-20 strata based on these key features or predicted conversion scores
- Weighted estimator: p̂ = Σ Wₕ p̂ₕ, where Wₕ is stratum h's population proportion
- Allocate samples via Neyman allocation: nₕ ∝ Wₕ√(pₕ(1-pₕ))
- Variance formula: Var(p̂) = Σ Wₕ² pₕ(1-pₕ)/nₕ
-
Handle non-representative samples
- Post-stratification weighting to known population margins
- Model-based estimation: fit logistic regression, predict for full population, average predictions
- Monitor design effect: 1 + CV(weights)², which reduces effective sample size
-
Uncertainty quantification
- Use stratified variance formula or bootstrap within strata
- Watch for extreme weights indicating poor overlap
Part 6: Truncated Normal Estimation
The challenge: Observing Y = X | X > 3 where X ~ N(μ, σ²) biases naive estimators. The sample mean overestimates μ and sample variance underestimates σ².
Why this occurs: Let α = (3-μ)/σ and λ(α) = φ(α)/(1-Φ(α)) be the inverse Mills ratio. Then:
- E[Y] = μ + σλ(α)
- Var(Y) = σ²[1 + αλ(α) - λ(α)²]
Estimation approach:
Maximum Likelihood (recommended): The density for y > 3 is:
f(y; μ, σ) = φ((y-μ)/σ) / [σ(1-Φ((3-μ)/σ))]
Log-likelihood:
ℓ(μ, σ) = -n log σ - Σ(yᵢ-μ)²/(2σ²) - n log(1-Φ((3-μ)/σ))
No closed form exists. Optimize numerically:
- Parameterize as (μ, log σ) to ensure σ > 0
- Use quasi-Newton methods (L-BFGS)
- Initialize with method-of-moments estimates
Confidence intervals:
-
Wald intervals from Fisher information:
- Compute observed Fisher information (negative Hessian at MLE)
- For μ: μ̂ ± 1.96 × SE(μ̂)
- For σ²: construct CI on log σ scale, then exponentiate: [e^(2L), e^(2U)]
-
Profile likelihood intervals (better for asymmetry):
- {θ : 2[ℓ(θ̂) - ℓ_profile(θ)] ≤ χ²₁,₀.₉₅ = 3.84}
-
Parametric bootstrap (robust for small n):
- Simulate datasets from TN(μ̂, σ̂², 3)
- Re-estimate parameters for each simulation
- Take 2.5th and 97.5th percentiles
Critical assumptions:
- The truncation point (3) must be known precisely
- If μ ≪ 3, most mass lies below the threshold — only a thin tail is observed, making μ and σ nearly unidentifiable. Confidence intervals will be extremely wide. State this limitation explicitly.
import numpy as np
from scipy.optimize import minimize
from scipy.stats import norm
def truncated_normal_mle(y, cutoff=3.0):
y = np.asarray(y)
def neg_log_likelihood(params):
mu, log_sigma = params
sigma = np.exp(log_sigma)
alpha = (cutoff - mu) / sigma
nll = (len(y) * log_sigma +
np.sum((y - mu)**2) / (2 * sigma**2) +
len(y) * np.log(1 - norm.cdf(alpha)))
return nll
# Initialize with method of moments approximation
y_mean, y_std = np.mean(y), np.std(y)
init = [y_mean, np.log(y_std)]
result = minimize(neg_log_likelihood, init, method='L-BFGS-B')
mu_hat, log_sigma_hat = result.x
sigma_hat = np.exp(log_sigma_hat)
return mu_hat, sigma_hat
Common mistakes to avoid:
- Using uncorrected sample mean and variance
- Ignoring that the truncation point must be known
- Claiming the CI gives probability statements about fixed parameters
- Not checking identifiability when truncation is severe