中介分析:估计自然直接效应和自然间接效应#

中介分析可用于量化因果影响通过特定路径发挥作用的程度。DoWhy 支持估计自然直接效应自然间接效应

自然直接效应:由路径 v0->y 引起的效应 自然间接效应:由路径 v0->FD0->y 引起的效应(由 FD0 中介)。

更多详细信息,请参阅 Judea Pearl 的《因果中介的解释与识别》。

使用 DoWhy 的效应估计框架,我们可以通过相应调整 estimand_type 参数来执行中介分析

识别#

>>> # Natural direct effect (nde)
>>> identified_estimand_nde = model.identify_effect(estimand_type="nonparametric-nde",
>>>                                                 proceed_when_unidentifiable=True)
>>> print(identified_estimand_nde)
>>> # Natural indirect effect (nie)
>>> identified_estimand_nie = model.identify_effect(estimand_type="nonparametric-nie",
>>>                                                 proceed_when_unidentifiable=True)
>>> print(identified_estimand_nie)

估计#

>>> import dowhy.causal_estimators.linear_regression_estimator
>>> causal_estimate_nie = model.estimate_effect(identified_estimand_nie,
>>>                                             method_name="mediation.two_stage_regression",
>>>                                             confidence_intervals=False,
>>>                                             test_significance=False,
>>>                                             method_params = {
>>>                                                 'first_stage_model': dowhy.causal_estimators.linear_regression_estimator.LinearRegressionEstimator,
>>>                                                 'second_stage_model': dowhy.causal_estimators.linear_regression_estimator.LinearRegressionEstimator
>>>                                             })
>>> print(causal_estimate_nie)
>>> causal_estimate_nde = model.estimate_effect(identified_estimand_nde,
>>>                                             method_name="mediation.two_stage_regression",
>>>                                             confidence_intervals=False,
>>>                                             test_significance=False,
>>>                                             method_params = {
>>>                                               'first_stage_model': dowhy.causal_estimators.linear_regression_estimator.LinearRegressionEstimator,
>>>                                               'second_stage_model': dowhy.causal_estimators.linear_regression_estimator.LinearRegressionEstimator
>>>                                             })
>>> print(causal_estimate_nde)