Log-Transform Confidence Interval for Relative Lift

Quick Overview

Implement a confidence interval for the relative lift between two conversion rates by working on the log of the rate ratio and mapping the bounds back. It tests the delta method for a log ratio, why the resulting interval is asymmetric, and how to handle an arm with zero conversions.

Log-Transform Confidence Interval for Relative Lift

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: medium

Interview Round: Other

Implement `ci_relative_lift_log(conv_control, n_control, conv_treatment, n_treatment, alpha=0.05)` in `solution.py`. Return a two-sided `(1 - alpha)` confidence interval for the relative lift `p_treatment / p_control - 1` as a `(lower, upper)` tuple, built on the log scale and exponentiated back. The interval must follow these definitions: - `p_c = conv_control / n_control`, `p_t = conv_treatment / n_treatment`, `R = p_t / p_c` - `var_pt = p_t * (1 - p_t) / n_treatment`, `var_pc = p_c * (1 - p_c) / n_control` - `se_logR = sqrt(var_pt / p_t**2 + var_pc / p_c**2)` (no covariance term) - `z = scipy.stats.norm.ppf(1 - alpha / 2)` - `lower = exp(log(R) - z * se_logR) - 1`, `upper = exp(log(R) + z * se_logR) - 1` Example: ```python ci_relative_lift_log(200, 2000, 240, 2000) # -> (0.00521391854108777, 0.4325309005768012) ``` ```hint Order of operations The symmetric part of the interval lives on the log scale. Exponentiate each bound on its own, and only then subtract 1. ``` ```hint Sanity check the shape The point estimate for the example is a lift of 0.2. Look at how far it sits from each bound; the two distances should not be equal. ``` ### Constraints & Assumptions - `scipy.stats` is available. - All counts are positive, so rates and logs are well-defined. - The two arms are independent samples. ### What a Strong Answer Covers - Uses the delta-method standard error of `log(R) = log(p_t) - log(p_c)` and explains why independent arms need no covariance term. - Builds a symmetric interval on the log scale, exponentiates each bound, and subtracts 1. - Explains why the result is asymmetric around the point estimate and can never fall below -1. - Reproduces the example output and returns the bounds as plain floats. ### Follow-up Questions - Why is the log-transform interval preferred over the delta-method interval for a ratio? - How would you handle `conv_control == 0` or a zero-rate arm? - When does this interval exclude a lift of 0, and how does that relate to a z-test on `log(R)`?

Overview: Implement a confidence interval for the relative lift between two conversion rates by working on the log of the rate ratio and mapping the bounds back. It tests the delta method for a log ratio, why the resulting interval is asymmetric, and how to handle an arm with zero conversions.

Nov 24, 2026
mediumData ScientistOtherAnalytics & Experimentation
0
0

Implement ci_relative_lift_log(conv_control, n_control, conv_treatment, n_treatment, alpha=0.05) in solution.py. Return a two-sided (1 - alpha) confidence interval for the relative lift p_treatment / p_control - 1 as a (lower, upper) tuple, built on the log scale and exponentiated back.

The interval must follow these definitions:

  • p_c = conv_control / n_control , p_t = conv_treatment / n_treatment , R = p_t / p_c
  • var_pt = p_t * (1 - p_t) / n_treatment , var_pc = p_c * (1 - p_c) / n_control
  • se_logR = sqrt(var_pt / p_t**2 + var_pc / p_c**2) (no covariance term)
  • z = scipy.stats.norm.ppf(1 - alpha / 2)
  • lower = exp(log(R) - z * se_logR) - 1 , upper = exp(log(R) + z * se_logR) - 1

Example:

ci_relative_lift_log(200, 2000, 240, 2000)
# -> (0.00521391854108777, 0.4325309005768012)

Constraints & Assumptions

  • scipy.stats is available.
  • All counts are positive, so rates and logs are well-defined.
  • The two arms are independent samples.

What a Strong Answer Covers Guidance

  • Uses the delta-method standard error of log(R) = log(p_t) - log(p_c) and explains why independent arms need no covariance term.
  • Builds a symmetric interval on the log scale, exponentiates each bound, and subtracts 1.
  • Explains why the result is asymmetric around the point estimate and can never fall below -1.
  • Reproduces the example output and returns the bounds as plain floats.

Follow-up Questions Guidance

  • Why is the log-transform interval preferred over the delta-method interval for a ratio?
  • How would you handle conv_control == 0 or a zero-rate arm?
  • When does this interval exclude a lift of 0, and how does that relate to a z-test on log(R) ?