Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:SocialChangeLab/media-impact-monitor…
Browse files Browse the repository at this point in the history
… into dev
  • Loading branch information
vogelino committed Aug 19, 2024
2 parents 69b39ec + 8c5fa9b commit df991ee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend-python/media_impact_monitor/impact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import pandas as pd

from media_impact_monitor.events import get_events
Expand Down Expand Up @@ -87,6 +86,7 @@ def get_impact(q: ImpactSearch) -> Impact:
mean=impact["mean"].loc[n_days],
ci_upper=impact["ci_upper"].loc[n_days],
ci_lower=impact["ci_lower"].loc[n_days],
p_value=impact["p_value"].loc[n_days],
),
absolute_impact_time_series=[
DatedMeanWithUncertainty(**d)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,10 @@ def estimate_mean_impact(
lambda x: confidence_interval_ttest(x.dropna(), 0.95)[1], axis=1
)
return pd.DataFrame(
{"mean": average, "ci_lower": ci_lower, "ci_upper": ci_upper}
{
"mean": average,
"ci_lower": ci_lower,
"ci_upper": ci_upper,
"p_value": 1, # TODO
}
), warnings
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_mean_impact_estimates():
assert impacts_df.index[0] == -4
assert impacts_df.index[-1] == 6
assert len(impacts_df) == 4 + 7
assert set(impacts_df.columns) == {"mean", "ci_lower", "ci_upper"}
assert set(impacts_df.columns) == {"mean", "ci_lower", "ci_upper", "p_value"}
for i in range(-4, -1):
mean = impacts_df.loc[i, "mean"]
assert -50 <= mean <= 50
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import pandas as pd
import statsmodels.api as sm

Expand Down Expand Up @@ -69,7 +68,7 @@ def regress(
return {
"date": day,
"mean": model.params[treatment],
"p": model.pvalues[treatment],
"p_value": model.pvalues[treatment],
"ci_lower": model.conf_int(alpha=alpha)[0][treatment],
"ci_upper": model.conf_int(alpha=alpha)[1][treatment],
}
Expand Down Expand Up @@ -103,5 +102,5 @@ def estimate_impact(
for day in outcome_days
]
)
impacts = impacts.set_index("date")[["mean", "ci_lower", "ci_upper"]]
impacts = impacts.set_index("date")[["mean", "ci_lower", "ci_upper", "p_value"]]
return impacts, limitations
2 changes: 2 additions & 0 deletions backend-python/media_impact_monitor/types_.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,15 @@ class MeanWithUncertainty(BaseModel):
mean: float = Field(description="Mean estimate.")
ci_upper: float = Field(description="Upper bound of the 95% confidence interval.")
ci_lower: float = Field(description="Lower bound of the 95% confidence interval.")
p_value: float = Field(description="P-value.")


class DatedMeanWithUncertainty(BaseModel):
date: int | date
mean: float
ci_upper: float
ci_lower: float
p_value: float


class ImpactEstimate(BaseModel):
Expand Down

0 comments on commit df991ee

Please sign in to comment.