Compute Pooled and Unpooled Standard Errors for a Difference in Conversion Rates
Quick Overview
Write a Python function that returns both the pooled and the unpooled standard error for the difference between two conversion rates in an A/B test. It tests whether you can translate each formula exactly, explain which one belongs to the hypothesis test and which to the confidence interval, and handle empty or zero-conversion arms.
Compute Pooled and Unpooled Standard Errors for a Difference in Conversion Rates
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
Implement `proportion_diff_ses(conv_control, n_control, conv_treatment, n_treatment)` in `solution.py`. Return a dict with exactly the keys `'pooled'` and `'unpooled'`: the two standard errors of the difference in conversion rates.
The function must follow these rules:
- Rates: `p_c = conv_control/n_control`, `p_t = conv_treatment/n_treatment`.
- Unpooled: `sqrt(p_c*(1-p_c)/n_c + p_t*(1-p_t)/n_t)`.
- Pooled: `p_bar = (conv_control + conv_treatment)/(n_control + n_treatment)`, then `sqrt(p_bar*(1-p_bar)*(1/n_control + 1/n_treatment))`.
- Return unrounded floats.
Example:
```python
proportion_diff_ses(200, 2000, 240, 2000)
# -> {'pooled': 0.00989444288477123, 'unpooled': 0.009889388252060894}
```
```hint Which rate feeds each variance
The two formulas differ only in the rate that goes into the variance. Build the combined rate from the summed counts, and use n (not n - 1) in every denominator.
```
### What a Strong Answer Covers
- Computes both per-arm rates and the combined rate `p_bar` from the summed successes and summed sample sizes.
- Applies each formula exactly and returns unrounded floats under exactly the keys `'pooled'` and `'unpooled'`.
- Explains which standard error belongs to the hypothesis test, which belongs to the confidence interval, and why.
- Handles the edge cases: an arm with zero users, and zero conversions in one or both arms.
### Follow-up Questions
- Why use the pooled SE for the test but the unpooled SE for the CI?
- What happens when an arm has zero conversions and how would you guard against it?
- With equal arm sizes, which of the two standard errors is larger? Does that still hold when the arms are unbalanced?
Overview: Write a Python function that returns both the pooled and the unpooled standard error for the difference between two conversion rates in an A/B test. It tests whether you can translate each formula exactly, explain which one belongs to the hypothesis test and which to the confidence interval, and handle empty or zero-conversion arms.
Implement proportion_diff_ses(conv_control, n_control, conv_treatment, n_treatment) in solution.py. Return a dict with exactly the keys 'pooled' and 'unpooled': the two standard errors of the difference in conversion rates.