Skip to content

Commit

Permalink
Add docs + fix placebo_refuter
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmor-ms committed Nov 29, 2022
1 parent 972b071 commit cbda5ca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Expand Up @@ -338,7 +338,6 @@
"outputs": [],
"source": [
"import keras\n",
"from econml.deepiv import DeepIVEstimator\n",
"dims_zx = len(model.get_instruments())+len(model.get_effect_modifiers())\n",
"dims_tx = len(model._treatment)+len(model.get_effect_modifiers())\n",
"treatment_model = keras.Sequential([keras.layers.Dense(128, activation='relu', input_shape=(dims_zx,)), # sum of dims of Z and X \n",
Expand All @@ -356,7 +355,7 @@
" keras.layers.Dense(1)])\n",
"\n",
"deepiv_estimate = model.estimate_effect(identified_estimand, \n",
" method_name=\"iv.econml.deepiv.DeepIV\",\n",
" method_name=\"iv.econml.iv.nnet.DeepIV\",\n",
" target_units = lambda df: df[\"X0\"]>-1, \n",
" confidence_intervals=False,\n",
" method_params={\"init_params\":{'n_components': 10, # Number of gaussians in the mixture density networks\n",
Expand Down
8 changes: 8 additions & 0 deletions dowhy/causal_estimators/causalml.py
Expand Up @@ -160,6 +160,14 @@ def _get_causalml_class_object(self, module_method_name, *args, **kwargs):
def estimate_effect(
self, data: pd.DataFrame = None, treatment_value: Any = 1, control_value: Any = 0, target_units=None, **_
):
"""
data: dataframe containing the data on which treatment effect is to be estimated.
treatment_value: value of the treatment variable for which the effect is to be estimated.
control_value: value of the treatment variable that denotes its absence (usually 0)
target_units: The units for which the treatment effect should be estimated.
It can be a DataFrame that contains values of the effect_modifiers and effect will be estimated only for this new data.
It can also be a lambda function that can be used as an index for the data (pandas DataFrame) to select the required rows.
"""
if data is None:
data = self._data

Expand Down
8 changes: 8 additions & 0 deletions dowhy/causal_estimators/econml.py
Expand Up @@ -219,6 +219,14 @@ def _get_econml_class_object(self, module_method_name, *args, **kwargs):
def estimate_effect(
self, data: pd.DataFrame = None, treatment_value: Any = 1, control_value: Any = 0, target_units=None, **_
):
"""
data: dataframe containing the data on which treatment effect is to be estimated.
treatment_value: value of the treatment variable for which the effect is to be estimated.
control_value: value of the treatment variable that denotes its absence (usually 0)
target_units: The units for which the treatment effect should be estimated.
It can be a DataFrame that contains values of the effect_modifiers and effect will be estimated only for this new data.
It can also be a lambda function that can be used as an index for the data (pandas DataFrame) to select the required rows.
"""
if data is None:
data = self._data
self._target_units = target_units
Expand Down
8 changes: 7 additions & 1 deletion dowhy/causal_refuters/placebo_treatment_refuter.py
Expand Up @@ -8,7 +8,7 @@
from joblib import Parallel, delayed
from tqdm.auto import tqdm

from dowhy.causal_estimator import CausalEstimate, CausalEstimator
from dowhy.causal_estimator import CausalEstimate
from dowhy.causal_estimators.econml import Econml
from dowhy.causal_estimators.instrumental_variable_estimator import InstrumentalVariableEstimator
from dowhy.causal_identifier.identified_estimand import IdentifiedEstimand
Expand Down Expand Up @@ -206,6 +206,12 @@ def refute_placebo_treatment(
"Only placebo_type=''permute'' is supported for creating placebo for instrumental variable estimation methods."
)

# For IV methods, the estimating_instrument_names should also be
# changed. Create a copy to avoid modifying original object
if isinstance(estimate, InstrumentalVariableEstimator):
estimate = copy.deepcopy(estimate)
estimate.iv_instrument_name = ["placebo_" + s for s in parse_state(estimate.iv_instrument_name)]

# We need to change the identified estimand
# We make a copy as a safety measure, we don't want to change the
# original DataFrame
Expand Down

0 comments on commit cbda5ca

Please sign in to comment.