Skip to content

Commit

Permalink
Use absolute_exposure not relative exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Dec 12, 2024
1 parent aa2a026 commit e9131a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
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

0 comments on commit e9131a0

Please sign in to comment.