Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(experiments): Use absolute_exposure not relative exposure #26872

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions posthog/hogql_queries/experiments/test/test_trends_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,10 @@ def run_test(stats_version, calculate_probabilities, are_results_significant, ca
intervals = calculate_credible_intervals([control, test])

self.assertEqual(len(probabilities), 2)
if stats_version == 2:
self.assertTrue(probabilities[0] < 0.1)
self.assertTrue(0.9 < probabilities[1])
self.assertEqual(significance, ExperimentSignificanceCode.SIGNIFICANT)
self.assertEqual(p_value, 0)
else:
self.assertTrue(0.4 < probabilities[0] < 0.6) # Close to 50/50
self.assertTrue(0.4 < probabilities[1] < 0.6) # Close to 50/50
self.assertEqual(significance, ExperimentSignificanceCode.LOW_WIN_PROBABILITY)
self.assertEqual(p_value, 1)
self.assertTrue(0.4 < probabilities[0] < 0.6) # Close to 50/50
self.assertTrue(0.4 < probabilities[1] < 0.6) # Close to 50/50
self.assertEqual(significance, ExperimentSignificanceCode.LOW_WIN_PROBABILITY)
self.assertEqual(p_value, 1)

# Control at ~10% conversion rate
self.assertAlmostEqual(intervals["control"][0], 0.094, places=2)
Expand Down
4 changes: 2 additions & 2 deletions posthog/hogql_queries/experiments/trends_statistics_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def calculate_probabilities_v2(

# Calculate posterior parameters for control
alpha_control = PRIOR_ALPHA + control_variant.count
beta_control = PRIOR_BETA + control_variant.exposure
beta_control = PRIOR_BETA + control_variant.absolute_exposure

# Draw samples from control posterior
samples_control = gamma.rvs(alpha_control, scale=1 / beta_control, size=SAMPLE_SIZE)
Expand All @@ -66,7 +66,7 @@ def calculate_probabilities_v2(
test_samples = []
for test in test_variants:
alpha_test = PRIOR_ALPHA + test.count
beta_test = PRIOR_BETA + test.exposure
beta_test = PRIOR_BETA + test.absolute_exposure
test_samples.append(gamma.rvs(alpha_test, scale=1 / beta_test, size=SAMPLE_SIZE))

# Calculate probabilities
Expand Down
Loading