@@ -161,13 +161,16 @@ def estimate(self, data: pd.DataFrame, adjustment_config: dict = None) -> Regres
161
161
# x = x[model.params.index]
162
162
return model .predict (x )
163
163
164
- def estimate_control_treatment (self , bootstrap_size , adjustment_config ) -> tuple [pd .Series , pd .Series ]:
164
+ def estimate_control_treatment (
165
+ self , adjustment_config : dict = None , bootstrap_size : int = 100
166
+ ) -> tuple [pd .Series , pd .Series ]:
165
167
"""Estimate the outcomes under control and treatment.
166
168
167
169
:return: The estimated control and treatment values and their confidence
168
170
intervals in the form ((ci_low, control, ci_high), (ci_low, treatment, ci_high)).
169
171
"""
170
-
172
+ if adjustment_config is None :
173
+ adjustment_config = {}
171
174
y = self .estimate (self .df , adjustment_config = adjustment_config )
172
175
173
176
try :
@@ -197,18 +200,16 @@ def estimate_control_treatment(self, bootstrap_size, adjustment_config) -> tuple
197
200
198
201
return (y .iloc [1 ], np .array (control )), (y .iloc [0 ], np .array (treatment ))
199
202
200
- def estimate_ate (self , estimator_params : dict = None ) -> float :
203
+ def estimate_ate (self , adjustment_config : dict = None , bootstrap_size : int = 100 ) -> float :
201
204
"""Estimate the ate effect of the treatment on the outcome. That is, the change in outcome caused
202
205
by changing the treatment variable from the control value to the treatment value. Here, we actually
203
206
calculate the expected outcomes under control and treatment and take one away from the other. This
204
207
allows for custom terms to be put in such as squares, inverses, products, etc.
205
208
206
209
:return: The estimated average treatment effect and 95% confidence intervals
207
210
"""
208
- if estimator_params is None :
209
- estimator_params = {}
210
- bootstrap_size = estimator_params .get ("bootstrap_size" , 100 )
211
- adjustment_config = estimator_params .get ("adjustment_config" , None )
211
+ if adjustment_config is None :
212
+ adjustment_config = {}
212
213
(control_outcome , control_bootstraps ), (
213
214
treatment_outcome ,
214
215
treatment_bootstraps ,
@@ -231,18 +232,16 @@ def estimate_ate(self, estimator_params: dict = None) -> float:
231
232
232
233
return estimate , (ci_low , ci_high )
233
234
234
- def estimate_risk_ratio (self , estimator_params : dict = None ) -> float :
235
+ def estimate_risk_ratio (self , adjustment_config : dict = None , bootstrap_size : int = 100 ) -> float :
235
236
"""Estimate the ate effect of the treatment on the outcome. That is, the change in outcome caused
236
237
by changing the treatment variable from the control value to the treatment value. Here, we actually
237
238
calculate the expected outcomes under control and treatment and divide one by the other. This
238
239
allows for custom terms to be put in such as squares, inverses, products, etc.
239
240
240
241
:return: The estimated risk ratio and 95% confidence intervals.
241
242
"""
242
- if estimator_params is None :
243
- estimator_params = {}
244
- bootstrap_size = estimator_params .get ("bootstrap_size" , 100 )
245
- adjustment_config = estimator_params .get ("adjustment_config" , None )
243
+ if adjustment_config is None :
244
+ adjustment_config = {}
246
245
(control_outcome , control_bootstraps ), (
247
246
treatment_outcome ,
248
247
treatment_bootstraps ,
@@ -374,7 +373,6 @@ def estimate_control_treatment(self, adjustment_config: dict = None) -> tuple[pd
374
373
"""
375
374
if adjustment_config is None :
376
375
adjustment_config = {}
377
-
378
376
model = self ._run_linear_regression ()
379
377
380
378
x = pd .DataFrame (columns = self .df .columns )
@@ -393,13 +391,15 @@ def estimate_control_treatment(self, adjustment_config: dict = None) -> tuple[pd
393
391
394
392
return y .iloc [1 ], y .iloc [0 ]
395
393
396
- def estimate_risk_ratio (self ) -> tuple [float , list [float , float ]]:
394
+ def estimate_risk_ratio (self , adjustment_config : dict = None ) -> tuple [float , list [float , float ]]:
397
395
"""Estimate the risk_ratio effect of the treatment on the outcome. That is, the change in outcome caused
398
396
by changing the treatment variable from the control value to the treatment value.
399
397
400
398
:return: The average treatment effect and the 95% Wald confidence intervals.
401
399
"""
402
- control_outcome , treatment_outcome = self .estimate_control_treatment ()
400
+ if adjustment_config is None :
401
+ adjustment_config = {}
402
+ control_outcome , treatment_outcome = self .estimate_control_treatment (adjustment_config = adjustment_config )
403
403
ci_low = treatment_outcome ["mean_ci_lower" ] / control_outcome ["mean_ci_upper" ]
404
404
ci_high = treatment_outcome ["mean_ci_upper" ] / control_outcome ["mean_ci_lower" ]
405
405
@@ -413,6 +413,8 @@ def estimate_ate_calculated(self, adjustment_config: dict = None) -> tuple[float
413
413
414
414
:return: The average treatment effect and the 95% Wald confidence intervals.
415
415
"""
416
+ if adjustment_config is None :
417
+ adjustment_config = {}
416
418
control_outcome , treatment_outcome = self .estimate_control_treatment (adjustment_config = adjustment_config )
417
419
ci_low = treatment_outcome ["mean_ci_lower" ] - control_outcome ["mean_ci_upper" ]
418
420
ci_high = treatment_outcome ["mean_ci_upper" ] - control_outcome ["mean_ci_lower" ]
0 commit comments