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

feat(experiments): Apply new Trends continuous stats methods #26835

Merged
merged 40 commits into from
Dec 20, 2024

Conversation

danielbachhuber
Copy link
Contributor

@danielbachhuber danielbachhuber commented Dec 11, 2024

See #26713

Changes

Introduces a new set of methods for calculating Trends continuous values:

  • calculate_probabilities_v2_continuous
  • are_results_significant_v2_continuous
  • calculate_credible_intervals_v2_continuous
  • calculate_expected_loss_v2_continuous

Uses the Trends continuous methods when stats_version=2.

Also introduces expected loss calculation for Trends count.

How did you test this code?

Tests should pass.

@danielbachhuber
Copy link
Contributor Author

@andehen It would be really helpful if you could produce some sample values with your notebook. I can then implement those in tests and we can see where we're at for the log_variance value.

@danielbachhuber
Copy link
Contributor Author

It would be really helpful if you could produce some sample values with your notebook. I can then implement those in tests and we can see where we're at for the log_variance value.

@andehen log_variance = 2 seems to work well for these test cases. I'd be curious to hear your opinion on that, and what you think the delta value should be for these tests.

@danielbachhuber danielbachhuber requested a review from a team December 13, 2024 22:01
@danielbachhuber danielbachhuber marked this pull request as ready for review December 13, 2024 22:01
Copy link
Contributor

@jurajmajerik jurajmajerik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Why not already plug it into the query runner though?

if self.stats_version == 2:
probabilities = calculate_probabilities_v2_count(control_variant, test_variants)

@danielbachhuber
Copy link
Contributor Author

Why not already plug it into the query runner though?

My thought on Friday was to ship what I have incrementally.

@danielbachhuber danielbachhuber requested a review from a team December 19, 2024 23:56
Copy link
Contributor

@andehen andehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍 Didn't spot any errors in the code it self.

As we have talked about, the key issue to address further is the assumption of a fixed variance. If one run test now, where the actual variance in the data is higher, we will claim that the results are significant when they should not be. We can use a higher value to protect against this, at the cost of saying "not significant" when we likely could (in the event that variance is lower than we assume). Really hard to say what the value should be without doing an analysis on actual data 🤷

Copy link
Contributor

@jurajmajerik jurajmajerik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for doing this!

@andehen, could you please create an issue with a detailed description to track the concern mentioned in your comment? It's important to keep track of this, though I consider it non-blocking for now. This calculation is already a big improvement over the current state of things :)

@danielbachhuber danielbachhuber merged commit 1979d74 into master Dec 20, 2024
92 checks passed
@danielbachhuber danielbachhuber deleted the experiments/trends-continuous branch December 20, 2024 12:45
@jurajmajerik
Copy link
Contributor

@danielbachhuber there's an issue here I've only spotted now:

https://github.com/PostHog/posthog/blob/master/posthog/hogql_queries/experiments/experiment_trends_query_runner.py#L134-L138

We're still overwriting the math property from AVG to SUM. So the new probability method will never receive AVG. This went unnoticed because we're only unit-testing the probability method, and not including it in a more integrated query runner test. Would be nice to have a small test within test_experiment_trends_query_runner.py to ensure the correct AVG value is received.

@danielbachhuber
Copy link
Contributor Author

there's an issue here I've only spotted now:

Resolved with #27133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants