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

CAUS-2: write CausalImpact shock-based estimator #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions causality/estimation/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@ def average_treatment_effect(self, X, start='Start', end='End', assignment='Assi
control_final = control['End']
del test, control

df = pd.DataFrame({'y' : test_initial,
'assignment' : [1. for i in test_initial],
df = pd.DataFrame({'y' : test_initial,
'assignment' : [1. for i in test_initial],
't' :[0. for i in test_initial] })
df = df.append(pd.DataFrame({'y' : test_final,
'assignment' : [1. for i in test_final],
df = df.append(pd.DataFrame({'y' : test_final,
'assignment' : [1. for i in test_final],
't' :[1. for i in test_final] }))

df = df.append(pd.DataFrame({'y' : control_initial,
'assignment' : [0. for i in control_initial],
df = df.append(pd.DataFrame({'y' : control_initial,
'assignment' : [0. for i in control_initial],
't' :[0. for i in control_initial] }))

df = df.append(pd.DataFrame({'y' : control_final,
'assignment' : [0. for i in control_final],
df = df.append(pd.DataFrame({'y' : control_final,
'assignment' : [0. for i in control_final],
't' :[1. for i in control_final] }))
del test_initial, test_final, control_initial, control_final
df['did'] = df['t'] * df['assignment']
df['did'] = df['t'] * df['assignment']
df['intercept'] = 1.

model = self.model(df['y'], df[['t', 'assignment','did', 'intercept']])
result = model.fit()
conf_int = result.conf_int().ix['did']
expected = result.params['did']
return conf_int[0], expected, conf_int[1]

def test_parallel_trend(self, X, start='Start', end='End', assignment='Assignment'):
"""
This will find the average treatment effect on
Expand All @@ -64,7 +64,7 @@ def test_parallel_trend(self, X, start='Start', end='End', assignment='Assignmen
that the average treatment effect between the test
and control groups when neither is treated is 0.

The format for this dataset is the same as that
The format for this dataset is the same as that
for the real estimation task, except that the start
time is some time before the experiment is run, and
the end time is the starting point for the experiment.
Expand Down Expand Up @@ -145,4 +145,9 @@ def estimate_ATC(self, X, assignment, outcome, confounder_types, n_neighbors=5):
def estimate_ATE(self, X, assignment, outcome, confounder_types, n_neighbors=5):
att = estimate_ATT(self, X, assignment, outcome, confounder_types, n_neighbors=n_neighbors)
atc = estimate_ATC(self, X, assignment, outcome, confounder_types, n_neighbors=n_neighbors)
return (atc+att)/2.
return (atc+att)/2.


class CausalImpact(object):
def __init__(self):
pass