Implement a Confidence Interval for the Difference in Two Conversion Rates

Quick Overview

Implement a two-sided confidence interval in Python for the difference between treatment and control conversion rates using the unpooled Wald standard error. It tests whether you pick the right standard error for interval estimation, get the two-sided critical value right, and know where the Wald interval breaks down.

Implement a Confidence Interval for the Difference in Two Conversion Rates

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: easy

Interview Round: Other

Implement `ci_diff_proportions(conv_control, n_control, conv_treatment, n_treatment, alpha=0.05)` in `solution.py`. Return a two-sided `(1 - alpha)` confidence interval for the absolute difference in conversion rates (treatment minus control) as a `(lower, upper)` tuple of floats. `scipy` is available. The function must follow these rules: - Rates: `p_c = conv_control / n_control`, `p_t = conv_treatment / n_treatment`, `diff = p_t - p_c`. - Unpooled Wald SE: `SE = sqrt(p_c*(1-p_c)/n_c + p_t*(1-p_t)/n_t)` (never the pooled SE). - Critical value: `z = scipy.stats.norm.ppf(1 - alpha/2)`. - Return `(diff - z*SE, diff + z*SE)` in that order, unrounded. Example: ```python ci_diff_proportions(200, 2000, 240, 2000) # -> (0.0006171551968271217, 0.03938284480317286) ``` ```hint Watch the tail and the sign A two-sided interval splits alpha between both tails, so check which quantile you pass to `norm.ppf`. Keep the sign as treatment minus control so the lower bound comes first. ``` ### What a Strong Answer Covers - Computes the point estimate as treatment minus control and keeps that sign through to the returned tuple. - Estimates each arm's variance from its own observed rate and explains why the pooled SE does not belong in a confidence interval. - Takes the critical value from `alpha / 2` and returns the bounds unrounded in `(lower, upper)` order. - Names the edge cases: an empty arm, rates of exactly 0 or 1, and small samples where the Wald interval loses coverage. ### Follow-up Questions - Why does the CI use the unpooled SE while a hypothesis test often uses the pooled SE? - How would you produce a one-sided lower bound instead? - When does the Wald interval give poor coverage, and what would you use instead?

Overview: Implement a two-sided confidence interval in Python for the difference between treatment and control conversion rates using the unpooled Wald standard error. It tests whether you pick the right standard error for interval estimation, get the two-sided critical value right, and know where the Wald interval breaks down.

General logo
General
Nov 25, 2026
easyData ScientistOtherAnalytics & Experimentation
0
0

Implement ci_diff_proportions(conv_control, n_control, conv_treatment, n_treatment, alpha=0.05) in solution.py. Return a two-sided (1 - alpha) confidence interval for the absolute difference in conversion rates (treatment minus control) as a (lower, upper) tuple of floats. scipy is available.

The function must follow these rules:

  • Rates: p_c = conv_control / n_control , p_t = conv_treatment / n_treatment , diff = p_t - p_c .
  • Unpooled Wald SE: SE = sqrt(p_c*(1-p_c)/n_c + p_t*(1-p_t)/n_t) (never the pooled SE).
  • Critical value: z = scipy.stats.norm.ppf(1 - alpha/2) .
  • Return (diff - z*SE, diff + z*SE) in that order, unrounded.

Example:

ci_diff_proportions(200, 2000, 240, 2000)
# -> (0.0006171551968271217, 0.03938284480317286)

What a Strong Answer Covers Guidance

  • Computes the point estimate as treatment minus control and keeps that sign through to the returned tuple.
  • Estimates each arm's variance from its own observed rate and explains why the pooled SE does not belong in a confidence interval.
  • Takes the critical value from alpha / 2 and returns the bounds unrounded in (lower, upper) order.
  • Names the edge cases: an empty arm, rates of exactly 0 or 1, and small samples where the Wald interval loses coverage.

Follow-up Questions Guidance

  • Why does the CI use the unpooled SE while a hypothesis test often uses the pooled SE?
  • How would you produce a one-sided lower bound instead?
  • When does the Wald interval give poor coverage, and what would you use instead?