Skip to content

Commit 9223308

Browse files
authored
Adds relative inferences for DAU statistic (#2047)
1 parent e0baba6 commit 9223308

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

jetstream/statistics.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,18 +510,35 @@ def transform(
510510

511511
results = []
512512
for branch in experiment.branches:
513-
branch_data = [
513+
# for absolute differences we report the absolute difference in per-user
514+
# sum(DAU) scaled by total user enrollment. The interpretation here is the
515+
# DAU gain achieved if we deploy this branch to the same population as the
516+
# experiment
517+
branch_data_abs = [
514518
x
515519
for x in bootstrap_results.__root__
516520
if x.branch == branch.slug and x.comparison == "difference"
517521
]
518-
for d in branch_data:
522+
for d in branch_data_abs:
519523
d.point = d.point * num_enrolled_clients
520524
d.upper = d.upper * num_enrolled_clients
521525
d.lower = d.lower * num_enrolled_clients
522526
d.statistic = "per_client_dau_impact"
523527

524528
results.append(d)
529+
530+
# for relative differences we simply report the relative difference in
531+
# per-user sum(DAU)
532+
branch_data_rel = [
533+
x
534+
for x in bootstrap_results.__root__
535+
if x.branch == branch.slug and x.comparison == "relative_uplift"
536+
]
537+
for d in branch_data_rel:
538+
d.statistic = "per_client_dau_impact"
539+
540+
results.append(d)
541+
525542
return StatisticResultCollection.parse_obj(results)
526543

527544

jetstream/tests/test_statistics.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,23 @@ def test_per_client_dau_impact(self):
205205
test_data, "value", "control", experiment, AnalysisBasis.ENROLLMENTS, "all"
206206
).__root__
207207

208-
difference = [r for r in result if r.comparison == "difference"][0]
208+
abs_difference = [r for r in result if r.comparison == "difference"][0]
209209
# analytically, we should see a point estimate of 10, with 95% CI of (7.155,12.844)
210210
# at these small sample sizes, mozanalysis's bootstrap can be quite variable
211211
# so use a large tolerance
212-
assert np.abs(difference.point - 10) < 1.0
213-
assert np.abs(difference.lower - 7.155) < 1.0
214-
assert np.abs(difference.upper - 12.844) < 1.0
212+
assert np.abs(abs_difference.point - 10) < 1.0
213+
assert np.abs(abs_difference.lower - 7.155) < 1.0
214+
assert np.abs(abs_difference.upper - 12.844) < 1.0
215+
216+
rel_difference = [r for r in result if r.comparison == "relative_uplift"][0]
217+
218+
# analytically, we should see a point estimate of 222%, with 95% CI of (108%,398%)
219+
# at these small sample sizes, mozanalysis's bootstrap can be quite variable
220+
# so use a large tolerance
221+
222+
assert np.isclose(rel_difference.point, 2.22, atol=0.25)
223+
assert np.isclose(rel_difference.lower, 1.08, atol=0.25)
224+
assert np.isclose(rel_difference.upper, 3.98, atol=0.25)
215225

216226
def test_binomial(self):
217227
stat = Binomial()

0 commit comments

Comments
 (0)