dowhy.causal_estimators package

Submodules

dowhy.causal_estimators.causalml module

class dowhy.causal_estimators.causalml.Causalml(*args, causalml_methodname, **kwargs)[source]

Bases: CausalEstimator

Wrapper class for estimators from the causalml library.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below. For specific parameters of each estimator, refer to the CausalML docs.

Parameters

causalml_methodname – Fully qualified name of causalml estimator class.

construct_symbolic_estimator(estimand)[source]

dowhy.causal_estimators.distance_matching_estimator module

class dowhy.causal_estimators.distance_matching_estimator.DistanceMatchingEstimator(*args, num_matches_per_unit=1, distance_metric='minkowski', exact_match_cols=None, **kwargs)[source]

Bases: CausalEstimator

Simple matching estimator for binary treatments based on a distance metric.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below.

Parameters
  • num_matches_per_unit – The number of matches per data point. Default=1.

  • distance_metric – Distance metric to use. Default=”minkowski” that corresponds to Euclidean distance metric with p=2.

  • exact_match_cols – List of column names whose values should be

exactly matched. Typically used for columns with discrete values.

Valid_Dist_Metric_Params = ['p', 'V', 'VI', 'w']
construct_symbolic_estimator(estimand)[source]

dowhy.causal_estimators.econml module

class dowhy.causal_estimators.econml.Econml(*args, econml_methodname, **kwargs)[source]

Bases: CausalEstimator

Wrapper class for estimators from the EconML library.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below. For init and fit parameters of each estimator, refer to the EconML docs.

Parameters

econml_methodname – Fully qualified name of econml estimator class. For example, ‘econml.dml.DML’

construct_symbolic_estimator(estimand)[source]
effect(df: DataFrame, *args, **kwargs) ndarray[source]
effect_inference(df: DataFrame, *args, **kwargs) ndarray[source]
shap_values(df: DataFrame, *args, **kwargs)[source]

dowhy.causal_estimators.generalized_linear_model_estimator module

class dowhy.causal_estimators.generalized_linear_model_estimator.GeneralizedLinearModelEstimator(*args, glm_family=None, predict_score=True, **kwargs)[source]

Bases: RegressionEstimator

Compute effect of treatment using a generalized linear model such as logistic regression.

Implementation uses statsmodels.api.GLM. Needs an additional parameter, “glm_family” to be specified in method_params. The value of this parameter can be any valid statsmodels.api families object. For example, to use logistic regression, specify “glm_family” as statsmodels.api.families.Binomial().

For a list of args and kwargs, see documentation for CausalEstimator.

Parameters
  • glm_family – statsmodels family for the generalized linear model. For example, use statsmodels.api.families.Binomial() for logistic regression or statsmodels.api.families.Poisson() for count data.

  • predict_score – For models that have a binary output, whether to output the model’s score or the binary output based on the score.

construct_symbolic_estimator(estimand)[source]
predict_fn(model, features)[source]

dowhy.causal_estimators.instrumental_variable_estimator module

class dowhy.causal_estimators.instrumental_variable_estimator.InstrumentalVariableEstimator(*args, iv_instrument_name=None, **kwargs)[source]

Bases: CausalEstimator

Compute effect of treatment using the instrumental variables method.

This is also a superclass that can be inherited by other specific methods.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below.

Parameters

iv_instrument_name – Name of the specific instrumental variable to be used. Needs to be one of the IVs identified in the identification step. Default is to use all the IV variables from the identification step.

construct_symbolic_estimator(estimand)[source]

dowhy.causal_estimators.linear_regression_estimator module

class dowhy.causal_estimators.linear_regression_estimator.LinearRegressionEstimator(*args, **kwargs)[source]

Bases: RegressionEstimator

Compute effect of treatment using linear regression.

Fits a regression model for estimating the outcome using treatment(s) and confounders. For a univariate treatment, the treatment effect is equivalent to the coefficient of the treatment variable.

Simple method to show the implementation of a causal inference method that can handle multiple treatments and heterogeneity in treatment. Requires a strong assumption that all relationships from (T, W) to Y are linear.

For a list of args and kwargs, see documentation for CausalEstimator.

construct_symbolic_estimator(estimand)[source]
predict_fn(model, features)[source]

dowhy.causal_estimators.propensity_score_estimator module

class dowhy.causal_estimators.propensity_score_estimator.PropensityScoreEstimator(*args, propensity_score_model=None, recalculate_propensity_score=True, propensity_score_column='propensity_score', **kwargs)[source]

Bases: CausalEstimator

Base class for estimators that estimate effects based on propensity of treatment assignment.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below.

Parameters
  • propensity_score_model – Model used to compute propensity score. Can be any classification model that supports fit() and predict_proba() methods. If None, LogisticRegression is used.

  • recalculate_propensity_score – Whether the propensity score should be estimated. To use pre-computed propensity scores, set this value to False. Default=True.

  • propensity_score_column – Column name that stores the propensity score. Default=’propensity_score’

construct_symbolic_estimator(estimand)[source]

A symbolic string that conveys what each estimator does. For instance, linear regression is expressed as y ~ bx + e

dowhy.causal_estimators.propensity_score_matching_estimator module

class dowhy.causal_estimators.propensity_score_matching_estimator.PropensityScoreMatchingEstimator(*args, propensity_score_model=None, recalculate_propensity_score=True, propensity_score_column='propensity_score', **kwargs)[source]

Bases: PropensityScoreEstimator

Estimate effect of treatment by finding matching treated and control units based on propensity score.

Straightforward application of the back-door criterion.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below.

Parameters
  • propensity_score_model – Model used to compute propensity score. Can be any classification model that supports fit() and predict_proba() methods. If None, LogisticRegression is used.

  • recalculate_propensity_score – Whether the propensity score should be estimated. To use pre-computed propensity scores, set this value to False. Default=True.

  • propensity_score_column – Column name that stores the propensity score. Default=’propensity_score’

construct_symbolic_estimator(estimand)[source]

A symbolic string that conveys what each estimator does. For instance, linear regression is expressed as y ~ bx + e

dowhy.causal_estimators.propensity_score_stratification_estimator module

class dowhy.causal_estimators.propensity_score_stratification_estimator.PropensityScoreStratificationEstimator(*args, num_strata='auto', clipping_threshold=10, propensity_score_model=None, recalculate_propensity_score=True, propensity_score_column='propensity_score', **kwargs)[source]

Bases: PropensityScoreEstimator

Estimate effect of treatment by stratifying the data into bins with identical common causes.

Straightforward application of the back-door criterion.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below.

Parameters
  • num_strata – Number of bins by which data will be stratified. Default is automatically determined.

  • clipping_threshold – Mininum number of treated or control units per strata. Default=10

  • propensity_score_model – The model used to compute propensity score. Can be any classification model that supports fit() and predict_proba() methods. If None, use LogisticRegression model as the default.

  • recalculate_propensity_score – If true, force the estimator to estimate the propensity score. To use pre-computed propensity scores, set this value to False. Default=True

  • propensity_score_column – Column name that stores the propensity

score. Default=’propensity_score’

construct_symbolic_estimator(estimand)[source]

A symbolic string that conveys what each estimator does. For instance, linear regression is expressed as y ~ bx + e

dowhy.causal_estimators.propensity_score_weighting_estimator module

class dowhy.causal_estimators.propensity_score_weighting_estimator.PropensityScoreWeightingEstimator(*args, min_ps_score=0.05, max_ps_score=0.95, weighting_scheme='ips_weight', propensity_score_model=None, recalculate_propensity_score=True, propensity_score_column='propensity_score', **kwargs)[source]

Bases: PropensityScoreEstimator

Estimate effect of treatment by weighing the data by inverse probability of occurrence.

Straightforward application of the back-door criterion.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below.

Parameters
  • min_ps_score – Lower bound used to clip the propensity score. Default=0.05

  • max_ps_score – Upper bound used to clip the propensity score. Default=0.95

  • weighting_scheme – Weighting method to use. Can be inverse propensity score (“ips_weight”, default), stabilized IPS score (“ips_stabilized_weight”), or normalized IPS score (“ips_normalized_weight”).

  • propensity_score_model – The model used to compute propensity score. Can be any classification model that supports fit() and predict_proba() methods. If None, use LogisticRegression model as the default. Default=None

  • recalculate_propensity_score – If true, force the estimator to estimate the propensity score. To use pre-computed propensity scores, set this value to false. Default=True

  • propensity_score_column – Column name that stores the propensity score. Default=’propensity_score’

construct_symbolic_estimator(estimand)[source]

A symbolic string that conveys what each estimator does. For instance, linear regression is expressed as y ~ bx + e

dowhy.causal_estimators.regression_discontinuity_estimator module

class dowhy.causal_estimators.regression_discontinuity_estimator.RegressionDiscontinuityEstimator(*args, rd_variable_name=None, rd_threshold_value=None, rd_bandwidth=None, **kwargs)[source]

Bases: CausalEstimator

Compute effect of treatment using the regression discontinuity method.

Estimates effect by transforming the problem to an instrumental variables problem.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below.

Parameters
  • rd_variable_name – Name of the variable on which the discontinuity occurs. This is the instrument.

  • rd_threshold_value – Threshold at which the discontinuity occurs.

  • rd_bandwidth – Distance from the threshold within which confounders can be considered the same between treatment and control. Considered band is (threshold +- bandwidth)

construct_symbolic_estimator(estimand)[source]

dowhy.causal_estimators.regression_estimator module

class dowhy.causal_estimators.regression_estimator.RegressionEstimator(*args, **kwargs)[source]

Bases: CausalEstimator

Compute effect of treatment using some regression function.

Fits a regression model for estimating the outcome using treatment(s) and confounders.

Base class for all regression models, inherited by LinearRegressionEstimator and GeneralizedLinearModelEstimator.

For a list of standard args and kwargs, see documentation for CausalEstimator.

dowhy.causal_estimators.two_stage_regression_estimator module

class dowhy.causal_estimators.two_stage_regression_estimator.TwoStageRegressionEstimator(*args, first_stage_model=None, second_stage_model=None, **kwargs)[source]

Bases: CausalEstimator

Compute treatment effect whenever the effect is fully mediated by another variable (front-door) or when there is an instrument available.

Currently only supports a linear model for the effects.

For a list of standard args and kwargs, see documentation for CausalEstimator.

Supports additional parameters as listed below.

Parameters
  • first_stage_model – First stage estimator to be used. Default is linear regression.

  • second_stage_model – Second stage estimator to be used. Default is linear regression.

DEFAULT_FIRST_STAGE_MODEL

alias of LinearRegressionEstimator

DEFAULT_SECOND_STAGE_MODEL

alias of LinearRegressionEstimator

build_first_stage_features()[source]
construct_symbolic_estimator(first_stage_symbolic, second_stage_symbolic, total_effect_symbolic=None, estimand_type=None)[source]

Module contents

dowhy.causal_estimators.get_class_object(method_name, estimator_name=None, *args, **kwargs)[source]