Trigger dilution: compare the all-users and triggered-only treatment effect in pandas
Quick Overview
Write a pandas function that returns the treatment-minus-control difference in means over all users and over triggered users only. It tests how untriggered users dilute an A/B test effect and how to compute group means with a consistent sign convention.
Trigger dilution: compare the all-users and triggered-only treatment effect in pandas
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
Implement `def exposure_dilution(df: pd.DataFrame) -> tuple` in `solution.py`. The frame has one row per user with columns `user_id` (object), `variant` (object, either `'control'` or `'treatment'`), `triggered` (bool), and `value` (float64). Compare the treatment effect over all users with the effect over triggered users only.
- `effect_all` is mean(`value` | treatment) minus mean(`value` | control), computed over all users.
- `effect_triggered` is the same treatment-minus-control difference, restricted to users with `triggered == True` in both groups.
- Return `(effect_all, effect_triggered)` as two floats. Report point estimates only, with no significance testing.
Untriggered users never see the change, so in expectation the all-users effect is diluted toward zero and |`effect_all`| <= |`effect_triggered`|. Your function should not enforce or assert this: on a finite sample, noise among untriggered users can break it.
```hint One formula, two frames
The two effects use the same calculation. Write it once as a helper that takes a frame, then decide which rows each call should see.
```
### Constraints & Assumptions
- One row per user.
- `variant` contains only `'control'` and `'treatment'`.
- Each variant has at least one user and at least one triggered user, so every group mean exists.
- `triggered` is a boolean column.
- `pandas` is available.
### What a Strong Answer Covers
- Both effects use the same treatment-minus-control sign convention.
- The triggered filter is applied to both arms before grouping, so the second comparison is triggered treatment users against triggered control users.
- The function returns plain Python floats in the order `(effect_all, effect_triggered)`.
- A clear account of why untriggered users pull the all-users estimate toward zero, and when that expectation fails on real data.
- Linear running time and a note on the edge cases (missing values, label mismatches, non-boolean flags).
### Follow-up Questions
- How does the trigger rate relate `effect_all` to `effect_triggered`?
- What breaks if trigger rates differ between control and treatment?
- How would you attach a confidence interval to each estimate, and which of the two usually gives the more powerful test?
Overview: Write a pandas function that returns the treatment-minus-control difference in means over all users and over triggered users only. It tests how untriggered users dilute an A/B test effect and how to compute group means with a consistent sign convention.
Implement def exposure_dilution(df: pd.DataFrame) -> tuple in solution.py. The frame has one row per user with columns user_id (object), variant (object, either 'control' or 'treatment'), triggered (bool), and value (float64). Compare the treatment effect over all users with the effect over triggered users only.
effect_all
is mean(
value
| treatment) minus mean(
value
| control), computed over all users.
effect_triggered
is the same treatment-minus-control difference, restricted to users with
triggered == True
in both groups.
Return
(effect_all, effect_triggered)
as two floats. Report point estimates only, with no significance testing.
Untriggered users never see the change, so in expectation the all-users effect is diluted toward zero and |effect_all| <= |effect_triggered|. Your function should not enforce or assert this: on a finite sample, noise among untriggered users can break it.
Constraints & Assumptions
One row per user.
variant
contains only
'control'
and
'treatment'
.
Each variant has at least one user and at least one triggered user, so every group mean exists.
triggered
is a boolean column.
pandas
is available.
What a Strong Answer Covers Guidance
Both effects use the same treatment-minus-control sign convention.
The triggered filter is applied to both arms before grouping, so the second comparison is triggered treatment users against triggered control users.
The function returns plain Python floats in the order
(effect_all, effect_triggered)
.
A clear account of why untriggered users pull the all-users estimate toward zero, and when that expectation fails on real data.
Linear running time and a note on the edge cases (missing values, label mismatches, non-boolean flags).
Follow-up Questions Guidance
How does the trigger rate relate
effect_all
to
effect_triggered
?
What breaks if trigger rates differ between control and treatment?
How would you attach a confidence interval to each estimate, and which of the two usually gives the more powerful test?