-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow users to run one tailed experiments #137
Conversation
Why I can't see the tests? Do I need to deploy the branch? |
tests/analysis/test_ols_analysis.py
Outdated
@@ -14,5 +14,5 @@ def test_binary_treatment(): | |||
|
|||
def test_get_pvalue(): | |||
analysis_df_full = pd.concat([analysis_df for _ in range(100)]) | |||
analyser = OLSAnalysis() | |||
analyser = OLSAnalysis(hypothesis="left_tailed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a separate test, and I'd test the functionality itself of the p-value transformer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as in, check that it is dividing by 2 or doing the other stuff when necessary
.pre-commit-config.yaml
Outdated
@@ -12,7 +12,7 @@ repos: | |||
rev: 22.12.0 | |||
hooks: | |||
- id: black | |||
language_version: python3.8 | |||
language_version: python3.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this for your local developement? or is it because of github actions?
Another comment: to me it's a bit hard to remember what does left and right-sided test mean, I'd try to document very well which sign of the effect does it belong to, even creating some notebook in docs that shows the power of the 3 sides for a similar setting |
I found a better way to do this. We can replicate scipy approach to it:
|
elif self.hypothesis == "greater": | ||
p_value = p_value_half if treatment_effect >= 0 else 1 - p_value_half | ||
elif self.hypothesis == "two-sided": | ||
p_value = model_result.pvalues[self.treatment_col] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we do this, I understand we are not using enum, right? Then I would remove the Enum code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, an else clause is missing here raising an error
@@ -612,7 +647,9 @@ def analysis_pvalue(self, df: pd.DataFrame, verbose: bool = False) -> float: | |||
if verbose: | |||
print(results_mlm.summary()) | |||
|
|||
return results_mlm.pvalues[self.treatment_col] | |||
p_value = self.pvalue_based_on_hypothesis(results_mlm) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency
tests/analysis/test_ols_analysis.py
Outdated
|
||
|
||
@pytest.mark.parametrize("hypothesis", ["one_sided", "two_sided"]) | ||
def test_get_pvalue_hypothesis(hypothesis): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add tests for the pvalue_based_on_hypothesis method too, since it has some logic
15cb1b1
to
92eacb8
Compare
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #137 +/- ##
==========================================
- Coverage 96.99% 96.96% -0.03%
==========================================
Files 9 9
Lines 864 890 +26
==========================================
+ Hits 838 863 +25
- Misses 26 27 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Some things missing:
- There's some commented code in the notebook, I'd remove it
- You need to add the notebook in mkdocs.yml
- You need to increase the library version (I'd change from 0.10.2 to 0.11.0 or something like this)
This PR aims to allow users to run 1 tailed power analyses. Currently, there's only the possibility of running 2 tailed.
This is the rationale for the adaptation:
From my perspective, the best way is that in case of one-tailed experiments, the user inputs the desired direction (left or right, instead of just 'one-tailed'). In case we want accept 'one-sided', we could guess the side by the sign of the average_effect input. However, there would be a challenge as with current design the analysis class doesn't have the effect information.