Skip to content

Commit

Permalink
Use consistent constant names
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Dec 17, 2024
1 parent 838067a commit 4e81ea4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions posthog/hogql_queries/experiments/trends_statistics_v2_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -56,17 +55,17 @@ 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)

# 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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4e81ea4

Please sign in to comment.