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

Required sample size #41

Merged
merged 2 commits into from
Sep 23, 2022
Merged

Required sample size #41

merged 2 commits into from
Sep 23, 2022

Conversation

jancervenka
Copy link
Collaborator

@jancervenka jancervenka commented Sep 19, 2022

Metrics now have an optional minimal_effect argument that is used to compute the sample size required to reach 80% power.

REST API example:
Screenshot 2022-09-20 at 9 30 22

Python API example:

from epstats.toolkit import Experiment, metric

experiment = Experiment(
    id="test-conversion-with-minimum-effect",
    control_variant="a",
    metrics=[
        Metric(
            id=1,
            name="Clicks per User",
            nominator="count(test_unit_type.unit.click)",
            denominator="count(test_unit_type.global.exposure)",
            minimum_effect=0.1,
        ),
        Metric(
            id=2,
            name="Purchases per user",
            nominator="count(test_unit_type.unit.purchase)",
            denominator="count(test_unit_type.global.exposure)",
            minimum_effect=0.1,
        ),
    ],
    checks=[],
    unit_type=test_unit_type,
)

Btw in the last PR #40, we talked about Bonferroni vs Holm-Bonferroni correction. Holm-Bonferroni can be applied here because we already have the $p$-values. However, it would result in each variant having very different required_sample_size because the correction depends on the $p$-value. I think it's better to just stick with the classic Bonferroni and use the most conservative $\alpha$ for all variants so that the required sizes are equal.

Consider an example with 4 variants and $p$-values $p_B = 0.001, p_C = 0.005, p_D = 0.01$.

variant $p$ Holm-Bonferroni Bonferroni Required size (Holm-Bonferroni) Required size (Bonferroni)
B 0.001 $\frac{\alpha}{3}=0.05/3$ $\frac{\alpha}{3}=0.05/3$ 4711 4711
C 0.005 $\frac{\alpha}{2}=0.05/2$ $\frac{\alpha}{3}=0.05/3$ 4277 4711
D 0.010 $\frac{\alpha}{1}=0.05$ $\frac{\alpha}{3}=0.05/3$ 3532 4711

id_counts = Counter(metric.id for metric in self.metrics)
for id_, count in id_counts.items():
if count > 1:
raise ValueError(f"Metric ids must be unique. Id={id_} found more than once.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Those are ids from EP UI? Because I believe we do have duplicate ids if it's metric with attribute (like CTR)

Copy link
Collaborator Author

@jancervenka jancervenka Sep 21, 2022

Choose a reason for hiding this comment

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

No, these are just internal ep-stats ids. They are always sequential starting from 1.

@marekbenes
Copy link
Collaborator

Agreed to use Bonferroni. Just please state in the documentation that we are more conservative for power calculation.

Copy link
Collaborator

@marekbenes marekbenes left a comment

Choose a reason for hiding this comment

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

👍

@jancervenka jancervenka merged commit c523f98 into master Sep 23, 2022
@jancervenka jancervenka deleted the required-sample-size branch September 23, 2022 06:49
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.

2 participants