can now optionally specify treatment and control values for estimate effect--useful for continuous tratments

This commit is contained in:
Amit Sharma 2019-12-12 16:07:28 +05:30
Родитель 2c45912bbe
Коммит ef31b5ad47
5 изменённых файлов: 120 добавлений и 2295 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -10,7 +10,8 @@ class CausalEstimator:
"""
def __init__(self, data, identified_estimand, treatment, outcome,
test_significance, evaluate_effect_strength=False,
control_value=0, treatment_value=1,
test_significance=False, evaluate_effect_strength=False,
confidence_intervals = False,
target_units=None, effect_modifiers=None,
params=None):
@ -36,6 +37,8 @@ class CausalEstimator:
# Currently estimation methods only support univariate treatment and outcome
self._treatment_name = treatment[0]
self._outcome_name = outcome[0]
self._control_value = control_value
self._treatment_value = treatment_value
self._significance_test = test_significance
self._effect_strength_eval = evaluate_effect_strength
self._target_units = target_units

Просмотреть файл

@ -76,8 +76,8 @@ class EconmlCateEstimator(CausalEstimator):
boolean_criterion = np.array(filtered_rows.notnull().iloc[:,0])
X_test = X[boolean_criterion]
n_target_units = X_test.shape[0]
T0_test = np.zeros((n_target_units, 1)) # single-dimensional treatment
T1_test = np.ones((n_target_units, 1))
T0_test = np.repeat([[self._control_value]], n_target_units, axis=0)
T1_test = np.repeat([[self._treatment_value]], n_target_units, axis=0)
est = self.estimator.effect(X_test, T0 = T0_test, T1 = T1_test)
ate = np.mean(est)

Просмотреть файл

@ -35,7 +35,7 @@ class LinearRegressionEstimator(CausalEstimator):
coefficients = self._linear_model.coef_
self.logger.debug("Coefficients of the fitted linear model: " +
",".join(map(str, coefficients)))
effect_estimate = self._do(1) - self._do(0)
effect_estimate = self._do(self._treatment_value) - self._do(self._control_value)
estimate = CausalEstimate(estimate=effect_estimate,
target_estimand=self._target_estimand,
realized_estimand_expr=self.symbolic_estimator,

Просмотреть файл

@ -135,6 +135,8 @@ class CausalModel:
return identified_estimand
def estimate_effect(self, identified_estimand, method_name=None,
control_value = 0,
treatment_value = 1,
test_significance=None, evaluate_effect_strength=False,
confidence_intervals=False,
target_units="ate", effect_modifiers=None,
@ -180,6 +182,8 @@ class CausalModel:
self._data,
identified_estimand,
self._treatment, self._outcome, #names of treatment and outcome
control_value = control_value,
treatment_value = treatment_value,
test_significance=test_significance,
evaluate_effect_strength=evaluate_effect_strength,
confidence_intervals = confidence_intervals,