Two-proportion A/B test readout: z-test, confidence interval and practical significance in Python
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement `two_proportion_experiment_readout(conv_control, n_control, conv_treatment, n_treatment, alpha=0.05, practical_threshold=0.005)` in `solution.py`. Return a dict with exactly the keys `'rate_control'`, `'rate_treatment'`, `'absolute_lift'`, `'relative_lift'`, `'z_stat'`, `'p_value'`, `'ci_lower'`, `'ci_upper'`, `'reject'` and `'practically_significant'`.
- Rates and lifts: `p_c = conv_control / n_control`, `p_t = conv_treatment / n_treatment`, `absolute_lift = p_t - p_c`, `relative_lift = (p_t - p_c) / p_c`.
- Use the pooled standard error for the test: `p_bar = (conv_control + conv_treatment) / (n_control + n_treatment)`, `se_pool = sqrt(p_bar * (1 - p_bar) * (1 / n_control + 1 / n_treatment))`, `z_stat = (p_t - p_c) / se_pool`.
- Compute the two-sided p-value as `p_value = 2 * scipy.stats.norm.sf(abs(z_stat))`, not as `1 - norm.cdf(...)`.
- Use the unpooled standard error for the confidence interval: `se_unp = sqrt(p_c * (1 - p_c) / n_control + p_t * (1 - p_t) / n_treatment)`, `zc = norm.ppf(1 - alpha / 2)`, `ci_lower = (p_t - p_c) - zc * se_unp`, `ci_upper = (p_t - p_c) + zc * se_unp`.
- Set `reject = bool(p_value < alpha)` and `practically_significant = bool(ci_lower > practical_threshold)`. Both must be native Python `bool` values, not `numpy.bool_`.
For example, `two_proportion_experiment_readout(200, 2000, 240, 2000)` returns the following (floats rounded to 10 decimals here; your exact output will differ in the last digits):
```text
rate_control 0.1
rate_treatment 0.12
absolute_lift 0.02
relative_lift 0.2
z_stat 2.0213366465
p_value 0.0432449280
ci_lower 0.0006171552
ci_upper 0.0393828448
reject True
practically_significant False
```
```hint Two standard errors
The test statistic and the interval answer different questions. Ask which of them is computed as if the null hypothesis were true.
```
```hint Check the types
Look at the type of a value that comes back from scipy, and at the type of a comparison made with it.
```
### Constraints & Assumptions
- `scipy.stats` is available.
- All counts are positive and both rates are strictly between 0 and 1, so no divide-by-zero handling is needed.
- `practical_threshold` is an absolute lift: the default 0.005 is half a percentage point.
### What a Strong Answer Covers
- Per-arm rates and both lift definitions, with control as the baseline for the relative lift.
- The pooled standard error for the z statistic and the unpooled one for the interval, with the reason for each.
- A two-sided p-value from the survival function and a critical value derived from `alpha`.
- A dict with exactly the ten keys, plain floats, and native Python bools.
- Why a result can be statistically significant and still fail the practical threshold, as in the example.
### Follow-up Questions
- Why use the pooled standard error for the test but the unpooled one for the confidence interval?
- How would you extend this to sequential testing without inflating false positives?
- When would a normal approximation be inappropriate here?
- How would you put a confidence interval on the relative lift?
Overview: Write a Python function that reads out a conversion A/B test: per-arm rates, absolute and relative lift, a pooled z-test, an unpooled confidence interval, and a practical significance check. It tests the two-proportion z-test formulas and why the test and the interval use different standard errors.