Skip to content

Commit ea8c273

Browse files
refactor all estimate_* return types to be pd.Series for LinearRegressionEstimator
1 parent da87421 commit ea8c273

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

causal_testing/testing/estimators.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,9 @@ def estimate_ate(self) -> tuple[float, list[float, float], float]:
382382

383383
# Perform a t-test to compare the predicted outcome of the control and treated individual (ATE)
384384
t_test_results = model.t_test(individuals.loc["treated"] - individuals.loc["control"])
385-
ate = t_test_results.effect[0]
385+
ate = pd.Series(t_test_results.effect[0])
386386
confidence_intervals = list(t_test_results.conf_int(alpha=self.alpha).flatten())
387+
confidence_intervals = (pd.Series(interval) for interval in confidence_intervals)
387388
return ate, confidence_intervals
388389

389390
def estimate_control_treatment(self, adjustment_config: dict = None) -> tuple[pd.Series, pd.Series]:
@@ -421,8 +422,9 @@ def estimate_risk_ratio(self, adjustment_config: dict = None) -> tuple[float, li
421422
if adjustment_config is None:
422423
adjustment_config = {}
423424
control_outcome, treatment_outcome = self.estimate_control_treatment(adjustment_config=adjustment_config)
424-
ci_low = treatment_outcome["mean_ci_lower"] / control_outcome["mean_ci_upper"]
425-
ci_high = treatment_outcome["mean_ci_upper"] / control_outcome["mean_ci_lower"]
425+
ci_low = pd.Series(treatment_outcome["mean_ci_lower"] / control_outcome["mean_ci_upper"])
426+
ci_high = pd.Series(treatment_outcome["mean_ci_upper"] / control_outcome["mean_ci_lower"])
427+
return pd.Series(treatment_outcome["mean"] / control_outcome["mean"]), [ci_low, ci_high]
426428

427429
return (treatment_outcome["mean"] / control_outcome["mean"]), [ci_low, ci_high]
428430

@@ -437,10 +439,9 @@ def estimate_ate_calculated(self, adjustment_config: dict = None) -> tuple[float
437439
if adjustment_config is None:
438440
adjustment_config = {}
439441
control_outcome, treatment_outcome = self.estimate_control_treatment(adjustment_config=adjustment_config)
440-
ci_low = treatment_outcome["mean_ci_lower"] - control_outcome["mean_ci_upper"]
441-
ci_high = treatment_outcome["mean_ci_upper"] - control_outcome["mean_ci_lower"]
442-
443-
return (treatment_outcome["mean"] - control_outcome["mean"]), [ci_low, ci_high]
442+
ci_low = pd.Series(treatment_outcome["mean_ci_lower"] - control_outcome["mean_ci_upper"])
443+
ci_high = pd.Series(treatment_outcome["mean_ci_upper"] - control_outcome["mean_ci_lower"])
444+
return pd.Series(treatment_outcome["mean"] - control_outcome["mean"]), [ci_low, ci_high]
444445

445446
def _run_linear_regression(self) -> RegressionResultsWrapper:
446447
"""Run linear regression of the treatment and adjustment set against the outcome and return the model.

0 commit comments

Comments
 (0)