Delta-Method Confidence Interval for Relative Lift
Quick Overview
Implement a delta-method confidence interval for the relative lift between two independent conversion rates in an A/B test. It tests propagating binomial variances through a ratio, picking the two-sided critical value, and knowing when a symmetric normal interval breaks down.
Delta-Method Confidence Interval for Relative Lift
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement `ci_relative_lift_delta(conv_control, n_control, conv_treatment, n_treatment, alpha=0.05)` in `solution.py`. For two independent arms, return a two-sided `(1 - alpha)` delta-method confidence interval `(lower, upper)` for the relative lift `p_treatment / p_control - 1`.
Build the interval exactly this way:
- Compute the rates `p_c = conv_control / n_control` and `p_t = conv_treatment / n_treatment`.
- Use the binomial variance `var = p * (1 - p) / n` for each arm.
- Form the ratio `R = p_t / p_c` and its standard error `se_R = R * sqrt(var_pt / p_t**2 + var_pc / p_c**2)`, with no covariance term.
- Take `z = scipy.stats.norm.ppf(1 - alpha / 2)` and return the symmetric interval `(R - 1 - z * se_R, R - 1 + z * se_R)`. Do not build the interval on a log or other transformed scale.
Example:
```python
ci_relative_lift_delta(200, 2000, 240, 2000)
# -> (-0.012545420396118917, 0.41254542039611886)
```
```hint Two-sided quantile
The interval is two-sided, so half of alpha goes in each tail. Check which argument you pass to `norm.ppf`.
```
```hint Test with unequal arms
Each arm's variance uses its own rate and its own sample size. The example has equal sample sizes, so it cannot catch a swapped `n`; try an unbalanced case too.
```
### Constraints & Assumptions
- `scipy` is available.
- `n_control` and `n_treatment` are positive, and both conversion rates are strictly between 0 and 1.
- The two arms are independent samples.
### What a Strong Answer Covers
- Computes each arm's rate and binomial variance with that arm's own sample size.
- Applies the delta-method standard error for a ratio and explains why independent arms need no covariance term.
- Uses the two-sided critical value and centers the symmetric interval on `R - 1`, reproducing the example output.
- Names the inputs where the approximation is weak, such as small counts or a control rate near 0.
### Follow-up Questions
- Why does building the interval on `log(R)` and exponentiating often give better coverage?
- What happens to the interval as `p_c` approaches 0, and what would you use instead?
- How would you check by simulation that this interval has close to `(1 - alpha)` coverage?
Overview: Implement a delta-method confidence interval for the relative lift between two independent conversion rates in an A/B test. It tests propagating binomial variances through a ratio, picking the two-sided critical value, and knowing when a symmetric normal interval breaks down.
Implement ci_relative_lift_delta(conv_control, n_control, conv_treatment, n_treatment, alpha=0.05) in solution.py. For two independent arms, return a two-sided (1 - alpha) delta-method confidence interval (lower, upper) for the relative lift p_treatment / p_control - 1.
Build the interval exactly this way:
Compute the rates
p_c = conv_control / n_control
and
p_t = conv_treatment / n_treatment
.
Use the binomial variance
var = p * (1 - p) / n
for each arm.
Form the ratio
R = p_t / p_c
and its standard error
se_R = R * sqrt(var_pt / p_t**2 + var_pc / p_c**2)
, with no covariance term.
Take
z = scipy.stats.norm.ppf(1 - alpha / 2)
and return the symmetric interval
(R - 1 - z * se_R, R - 1 + z * se_R)
. Do not build the interval on a log or other transformed scale.