From 4e81ea427c9a21a7c2045f314e04af72413eed3c Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Tue, 17 Dec 2024 05:02:41 -0800 Subject: [PATCH] Use consistent constant names --- .../experiments/trends_statistics_v2_count.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/posthog/hogql_queries/experiments/trends_statistics_v2_count.py b/posthog/hogql_queries/experiments/trends_statistics_v2_count.py index 0a4802e3fc7ab..710be1a46aac2 100644 --- a/posthog/hogql_queries/experiments/trends_statistics_v2_count.py +++ b/posthog/hogql_queries/experiments/trends_statistics_v2_count.py @@ -7,9 +7,8 @@ import numpy as np # Prior parameters (minimal prior knowledge) -PRIOR_ALPHA = 1 -PRIOR_BETA = 1 - +ALPHA_0 = 1 +BETA_0 = 1 SAMPLE_SIZE = 10000 @@ -56,8 +55,8 @@ def calculate_probabilities_v2_count( raise ValidationError("Can't calculate experiment results for less than 2 variants", code="no_data") # Calculate posterior parameters for control - alpha_control = PRIOR_ALPHA + control_variant.count - beta_control = PRIOR_BETA + control_variant.absolute_exposure + alpha_control = ALPHA_0 + control_variant.count + beta_control = BETA_0 + control_variant.absolute_exposure # Draw samples from control posterior samples_control = gamma.rvs(alpha_control, scale=1 / beta_control, size=SAMPLE_SIZE) @@ -65,8 +64,8 @@ def calculate_probabilities_v2_count( # Draw samples for each test variant test_samples = [] for test in test_variants: - alpha_test = PRIOR_ALPHA + test.count - beta_test = PRIOR_BETA + test.absolute_exposure + alpha_test = ALPHA_0 + test.count + beta_test = BETA_0 + test.absolute_exposure test_samples.append(gamma.rvs(alpha_test, scale=1 / beta_test, size=SAMPLE_SIZE)) # Calculate probabilities @@ -187,8 +186,8 @@ def calculate_credible_intervals_v2_count(variants, lower_bound=0.025, upper_bou for variant in variants: try: # Calculate posterior parameters using absolute_exposure - alpha_posterior = PRIOR_ALPHA + variant.count - beta_posterior = PRIOR_BETA + variant.absolute_exposure + alpha_posterior = ALPHA_0 + variant.count + beta_posterior = BETA_0 + variant.absolute_exposure # Calculate credible intervals using the posterior distribution credible_interval = gamma.ppf([lower_bound, upper_bound], alpha_posterior, scale=1 / beta_posterior)