Skip to content

Commit

Permalink
#4 starting time series work with data generation + notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
drbenvincent committed Sep 28, 2022
1 parent beb93e4 commit 424c305
Show file tree
Hide file tree
Showing 3 changed files with 540 additions and 612 deletions.
23 changes: 23 additions & 0 deletions causal_impact/simulate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,26 @@ def generate_interrupted_time_series_data(
df["intercept"] = np.ones(df.shape[0])

return df


def generate_time_series_data(treatment_time):
dates = pd.date_range(
start=pd.to_datetime("2010-01-01"), end=pd.to_datetime("2020-01-01"), freq="M"
)
df = pd.DataFrame(data={"date": dates})
df = df.assign(
year=lambda x: x["date"].dt.year,
month=lambda x: x["date"].dt.month,
linear_trend=df.index,
).set_index("date", drop=True)
month_effect = np.array([11, 13, 12, 15, 19, 23, 21, 28, 20, 17, 15, 12])
df["timeseries"] = df["linear_trend"] + month_effect[df.month.values - 1]

N = df.shape[0]
idx = np.arange(N)[df.index > treatment_time]
df["causal effect"] = 100 * gamma(10).pdf(np.arange(0, N, 1) - np.min(idx))

df["timeseries"] += df["causal effect"]
# add intercept
df["intercept"] = np.ones(df.shape[0])
return df
612 changes: 0 additions & 612 deletions notebooks/interrupted_time_series.ipynb

This file was deleted.

517 changes: 517 additions & 0 deletions notebooks/interrupted_time_series_no_predictors.ipynb

Large diffs are not rendered by default.

0 comments on commit 424c305

Please sign in to comment.