Continuous Metric A/B Readout With Welch's t-Test and a Practical Significance Check
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement `continuous_experiment_readout(control, treatment, alpha=0.05, practical_threshold=1.0)` in `solution.py`. Given two arrays of per-user metric values (NumPy arrays or plain lists, as in the example), return an A/B readout dict combining Welch significance with a practical-significance check. Effect direction is `treatment - control`, two-sided.
Requirements:
- Return exactly these keys: `'mean_control', 'mean_treatment', 'absolute_lift', 'relative_lift', 't_stat', 'p_value', 'ci_lower', 'ci_upper', 'reject', 'practically_significant'`.
- `absolute_lift = mean_treatment - mean_control` and `relative_lift = (mean_treatment - mean_control) / mean_control`.
- `t_stat` and `p_value` come from `scipy.stats.ttest_ind(treatment, control, equal_var=False)`.
- The confidence interval uses the Welch standard error (variances with `ddof=1`) and the Welch-Satterthwaite degrees of freedom, computed as below.
- `reject = bool(p_value < alpha)` and `practically_significant = bool(ci_lower > practical_threshold)`. Both must be native Python `bool` values; a `numpy.bool_` does not meet the contract.
Confidence interval computation:
```python
s_c2, s_t2 = control.var(ddof=1), treatment.var(ddof=1)
se = sqrt(s_c2/n_c + s_t2/n_t)
df = (s_c2/n_c + s_t2/n_t)**2 / ((s_c2/n_c)**2/(n_c-1) + (s_t2/n_t)**2/(n_t-1))
tcrit = scipy.stats.t.ppf(1 - alpha/2, df)
ci_lower = absolute_lift - tcrit*se
ci_upper = absolute_lift + tcrit*se
```
Example:
```python
control = [10,12,9,11,13,8,10,12,11,9]
treatment = [12,14,11,13,15,10,13,14,12,11]
continuous_experiment_readout(control, treatment) -> {
'mean_control': 10.5,
'mean_treatment': 12.5,
'absolute_lift': 2.0,
'relative_lift': 0.19047619047619047,
't_stat': 2.82842712474619,
'p_value': 0.01113641309585439,
'ci_lower': 0.5144237786013404,
'ci_upper': 3.4855762213986594,
'reject': True,
'practically_significant': False
}
```
```hint Test and interval must agree
The test and the interval use the same standard error and degrees of freedom, so `reject` should be True exactly when the interval excludes zero. Use that to check your output.
```
```hint Return types
NumPy reductions and comparisons return NumPy scalars. Check the actual type of every value you put in the dict.
```
### Constraints & Assumptions
- `scipy` and `numpy` are available.
- Each arm has at least 2 observations, and the two arms may have different sizes.
- A positive lift means treatment is better.
- `practical_threshold` is in the metric's own units and is compared with the lower bound of the interval for the absolute lift.
### What a Strong Answer Covers
- Computes the means, lifts, Welch test and Welch interval with one consistent direction (treatment minus control) and one set of assumptions.
- Implements the Welch-Satterthwaite degrees of freedom and the two-sided critical value correctly, with sample variances (`ddof=1`).
- Returns exactly the ten keys, holding native Python `float` and `bool` values.
- Explains why practical significance is judged on the interval's lower bound, and reads the example correctly.
- Names the inputs that break the formulas, such as a zero control mean or two constant arms.
### Follow-up Questions
- What do the confidence interval and the practical threshold tell you that the `p_value` alone does not?
- How would you extend this readout to guard against peeking at repeated interim looks?
- Revenue per user is heavily skewed. Is Welch's t-test still appropriate?
Overview: Implement an A/B test readout for a continuous per-user metric using Welch's t-test, a Welch-Satterthwaite confidence interval and a practical significance threshold. It tests careful statistical computation, a consistent effect direction, and the difference between a statistically and a practically significant result.