@@ -492,7 +492,7 @@ def __init__(
492
492
terms = [treatment ] + sorted (list (adjustment_set )) + sorted (list (effect_modifiers ))
493
493
self .formula = f"{ outcome } ~ cr({ '+' .join (terms )} , df={ basis } )"
494
494
495
- def estimate_ate_calculated (self , adjustment_config : dict = None ) -> float :
495
+ def estimate_ate_calculated (self , adjustment_config : dict = None ) -> pd . Series :
496
496
model = self ._run_linear_regression ()
497
497
498
498
x = {"Intercept" : 1 , self .treatment : self .treatment_value }
@@ -508,7 +508,7 @@ def estimate_ate_calculated(self, adjustment_config: dict = None) -> float:
508
508
x [self .treatment ] = self .control_value
509
509
control = model .predict (x ).iloc [0 ]
510
510
511
- return treatment - control
511
+ return pd . Series ( treatment - control )
512
512
513
513
514
514
class InstrumentalVariableEstimator (Estimator ):
@@ -564,7 +564,7 @@ def add_modelling_assumptions(self):
564
564
"""
565
565
)
566
566
567
- def estimate_iv_coefficient (self , df ):
567
+ def estimate_iv_coefficient (self , df ) -> float :
568
568
"""
569
569
Estimate the linear regression coefficient of the treatment on the
570
570
outcome.
@@ -578,7 +578,7 @@ def estimate_iv_coefficient(self, df):
578
578
# Estimate the coefficient of I on X by cancelling
579
579
return ab / a
580
580
581
- def estimate_coefficient (self , bootstrap_size = 100 ):
581
+ def estimate_coefficient (self , bootstrap_size = 100 ) -> tuple [ pd . Series , list [ pd . Series , pd . Series ]] :
582
582
"""
583
583
Estimate the unit ate (i.e. coefficient) of the treatment on the
584
584
outcome.
@@ -587,10 +587,10 @@ def estimate_coefficient(self, bootstrap_size=100):
587
587
[self .estimate_iv_coefficient (self .df .sample (len (self .df ), replace = True )) for _ in range (bootstrap_size )]
588
588
)
589
589
bound = ceil ((bootstrap_size * self .alpha ) / 2 )
590
- ci_low = bootstraps [bound ]
591
- ci_high = bootstraps [bootstrap_size - bound ]
590
+ ci_low = pd . Series ( bootstraps [bound ])
591
+ ci_high = pd . Series ( bootstraps [bootstrap_size - bound ])
592
592
593
- return self .estimate_iv_coefficient (self .df ), ( ci_low , ci_high )
593
+ return pd . Series ( self .estimate_iv_coefficient (self .df )), [ ci_low , ci_high ]
594
594
595
595
596
596
class CausalForestEstimator (Estimator ):
@@ -607,7 +607,7 @@ def add_modelling_assumptions(self):
607
607
"""
608
608
self .modelling_assumptions .append ("Non-parametric estimator: no restrictions imposed on the data." )
609
609
610
- def estimate_ate (self ) -> float :
610
+ def estimate_ate (self ) -> tuple [ pd . Series , list [ pd . Series , pd . Series ]] :
611
611
"""Estimate the average treatment effect.
612
612
613
613
:return ate, confidence_intervals: The average treatment effect and 95% confidence intervals.
@@ -635,9 +635,9 @@ def estimate_ate(self) -> float:
635
635
model .fit (outcome_df , treatment_df , X = effect_modifier_df , W = confounders_df )
636
636
637
637
# Obtain the ATE and 95% confidence intervals
638
- ate = model .ate (effect_modifier_df , T0 = self .control_value , T1 = self .treatment_value )
638
+ ate = pd . Series ( model .ate (effect_modifier_df , T0 = self .control_value , T1 = self .treatment_value ) )
639
639
ate_interval = model .ate_interval (effect_modifier_df , T0 = self .control_value , T1 = self .treatment_value )
640
- ci_low , ci_high = ate_interval [0 ], ate_interval [1 ]
640
+ ci_low , ci_high = pd . Series ( ate_interval [0 ]), pd . Series ( ate_interval [1 ])
641
641
return ate , [ci_low , ci_high ]
642
642
643
643
def estimate_cates (self ) -> pd .DataFrame :
0 commit comments