dowhy.causal_estimators 包#
子模块#
dowhy.causal_estimators.causalml 模块#
- 类 dowhy.causal_estimators.causalml.Causalml(identified_estimand: IdentifiedEstimand, causalml_estimator: _CausalmlEstimator | str, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, **kwargs)#
基类:
CausalEstimatorcausalml 库中估计器的包装类。
支持如下列出的额外参数。有关每个估计器的具体参数,请参阅 CausalML 文档。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
causalml_methodname – causalml 估计器类的完全限定名。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
kwargs – (可选) 额外的估计器特定参数
- construct_symbolic_estimator(estimand)#
- estimate_effect(data: DataFrame, treatment_value: Any = 1, control_value: Any = 0, target_units=None, **_)#
data: 包含用于估计处理效应的数据的数据框。 treatment_value: 用于估计效应的处理变量的值。 control_value: 表示处理变量缺失的值(通常为 0)。 target_units: 应估计处理效应的单位。
它可以是一个包含 effect_modifiers 值的 DataFrame,效应将仅针对这些新数据进行估计。它也可以是一个 lambda 函数,可用作数据的索引(pandas DataFrame)来选择所需的行。
- fit(data: DataFrame, effect_modifier_names: List[str] | None = None)#
使用数据拟合估计器以进行效应估计 :param data: 包含数据的数据框 :param treatment: 处理变量的名称 :param outcome: 结果变量的名称 :param effect_modifiers: 计算单独效应所基于的变量
的变量,或返回一个异质效应函数。并非所有方法目前都支持此功能。
dowhy.causal_estimators.distance_matching_estimator 模块#
- 类 dowhy.causal_estimators.distance_matching_estimator.DistanceMatchingEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, num_matches_per_unit: int = 1, distance_metric: str = 'minkowski', **kwargs)#
基类:
CausalEstimator基于距离度量的二元处理的简单匹配估计器。
支持如下列出的额外参数。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
num_matches_per_unit – 每个数据点的匹配数量。默认值=1。
distance_metric – 要使用的距离度量。默认值为“minkowski”,对应于 p=2 的欧几里得距离度量。
kwargs – (可选) 额外的估计器特定参数
- Valid_Dist_Metric_Params = ['p', 'V', 'VI', 'w']#
- construct_symbolic_estimator(estimand)#
- estimate_effect(data: DataFrame, treatment_value: Any = 1, control_value: Any = 0, target_units=None, **_)#
- fit(data: DataFrame, effect_modifier_names: List[str] | None = None, exact_match_cols=None)#
使用数据拟合估计器以进行效应估计 :param data: 包含数据的数据框 :param treatment: 处理变量的名称 :param outcome: 结果变量的名称 :param exact_match_cols: 需要精确匹配值的列名列表。通常用于离散值列。 :param effect_modifiers: 计算单独效应所基于的变量
的变量,或返回一个异质效应函数。并非所有方法目前都支持此功能。
dowhy.causal_estimators.econml 模块#
- class dowhy.causal_estimators.econml.Econml(identified_estimand: IdentifiedEstimand, econml_estimator: _EconmlEstimator | str, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, **kwargs)[source]#
基类:
CausalEstimatorEconML 库估计器的包装类。
支持如下所列的额外参数。每个估计器的初始化和拟合参数请参阅 EconML 文档。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
econml_estimator – EconML 估计器类实例。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
kwargs – (可选) 额外的估计器特定参数
- effect(df: DataFrame, *args, **kwargs) ndarray[source]#
逐点估计的处理效应,输出形状为 n_units x n_treatment_values (不计对照组)
:param df: 用于评估的单元特征
:param args: 传递给底层估计器
:param kwargs: 传递给底层估计器
- effect_inference(df: DataFrame, *args, **kwargs)[source]#
底层 EconML 估计器产生的推断(不确定性)结果
:param df: 用于评估的单元特征
:param args: 传递给底层估计器
:param kwargs: 传递给底层估计器
- effect_interval(df: DataFrame, *args, **kwargs) ndarray[source]#
估计的处理效应的逐点置信区间
:param df: 用于评估的单元特征
:param args: 传递给底层估计器
:param kwargs: 传递给底层估计器
- effect_tt(df: DataFrame, treatment_value, *args, **kwargs)[source]#
应用于每个单元的实际处理的效果(“处理对接受处理者的效果”)
:param df: 用于评估的单元特征
:param args: 传递给 estimator.effect()
:param kwargs: 传递给 estimator.effect()
- estimate_effect(data: DataFrame, treatment_value: Any = 1, control_value: Any = 0, target_units=None, **_)[source]#
data: 包含用于估计处理效应的数据的数据帧。
treatment_value: 用于估计效应的处理变量值。它可以是(可选)一个序列,用于表示处理变量的不同值。
control_value: 表示处理变量不存在的值(通常为 0)
target_units: 应估计处理效应的单元。它可以是一个包含 effect_modifiers 值的 DataFrame,效应将仅针对这些新数据进行估计。它也可以是一个 lambda 函数,可用作数据的索引(pandas DataFrame)来选择所需的行。
dowhy.causal_estimators.generalized_linear_model_estimator 模块#
- class dowhy.causal_estimators.generalized_linear_model_estimator.GeneralizedLinearModelEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, glm_family: Any | None = None, predict_score: bool = True, **kwargs)[source]#
-
使用广义线性模型(例如逻辑回归)计算处理效应。
实现使用 statsmodels.api.GLM。需要在 method_params 中指定一个额外的参数“glm_family”。此参数的值可以是任何有效的 statsmodels.api families 对象。例如,要使用逻辑回归,将“glm_family”指定为 statsmodels.api.families.Binomial()。
有关 args 和 kwargs 的列表,请参阅
CausalEstimator的文档。- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
glm_family – 广义线性模型的 statsmodels families。例如,对逻辑回归使用 statsmodels.api.families.Binomial(),对计数数据使用 statsmodels.api.families.Poisson()。
predict_score – 对于具有二元输出的模型,是否输出模型的得分或基于得分的二元输出。
kwargs – (可选) 额外的估计器特定参数
dowhy.causal_estimators.instrumental_variable_estimator 模块#
- class dowhy.causal_estimators.instrumental_variable_estimator.InstrumentalVariableEstimator(identified_estimand: IdentifiedEstimand, iv_instrument_name: List | Dict | str | None = None, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, **kwargs)[source]#
基类:
CausalEstimator使用工具变量方法计算处理效应。
这也是可以被其他特定方法继承的超类。
支持如下列出的额外参数。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
iv_instrument_name – 要使用的特定工具变量的名称。需要是识别步骤中标识的 IV 之一。默认是使用识别步骤中的所有 IV 变量。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
kwargs – (可选) 额外的估计器特定参数
- estimate_effect(data: DataFrame, treatment_value: Any = 1, control_value: Any = 0, target_units=None, **_)[source]#
data: 包含用于估计处理效应的数据的数据框。 treatment_value: 用于估计效应的处理变量的值。 control_value: 表示处理变量缺失的值(通常为 0)。 target_units: 应估计处理效应的单位。
它可以是一个包含 effect_modifiers 值的 DataFrame,效应将仅针对这些新数据进行估计。它也可以是一个 lambda 函数,可用作数据的索引(pandas DataFrame)来选择所需的行。
dowhy.causal_estimators.linear_regression_estimator 模块#
- class dowhy.causal_estimators.linear_regression_estimator.LinearRegressionEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, **kwargs)[source]#
-
使用线性回归计算处理效应。
拟合一个回归模型,使用处理和混淆变量估计结果。对于单变量处理,处理效应等同于处理变量的系数。
一个简单的方法,用于展示如何实现一个可以处理多处理和处理异质性的因果推断方法。需要一个强假设,即所有从 (T, W) 到 Y 的关系都是线性的。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
kwargs – (可选) 额外的估计器特定参数
dowhy.causal_estimators.propensity_score_estimator 模块#
- class dowhy.causal_estimators.propensity_score_estimator.PropensityScoreEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, propensity_score_model: Any | None = None, propensity_score_column: str = 'propensity_score', **kwargs)[source]#
基类:
CausalEstimator基于处理分配倾向性估计效应的估计器的基类。
支持如下列出的额外参数。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
propensity_score_model – 用于计算倾向性得分的模型。可以是任何支持 fit() 和 predict_proba() 方法的分类模型。如果为 None,则使用 LogisticRegression。
propensity_score_column – 存储倾向性得分的列名。默认为 ‘propensity_score’
kwargs – (可选) 额外的估计器特定参数
dowhy.causal_estimators.propensity_score_matching_estimator 模块#
- class dowhy.causal_estimators.propensity_score_matching_estimator.PropensityScoreMatchingEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, propensity_score_model: Any | None = None, propensity_score_column: str = 'propensity_score', **kwargs)[source]#
-
通过基于倾向性得分找到匹配的处理组和对照组单元来估计处理效应。
后门准则的直接应用。
支持如下列出的额外参数。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
propensity_score_model – 用于计算倾向性得分的模型。可以是任何支持 fit() 和 predict_proba() 方法的分类模型。如果为 None,则使用 LogisticRegression。
propensity_score_column – 存储倾向性得分的列名。默认为 ‘propensity_score’
kwargs – (可选) 额外的估计器特定参数
dowhy.causal_estimators.propensity_score_stratification_estimator 模块#
- class dowhy.causal_estimators.propensity_score_stratification_estimator.PropensityScoreStratificationEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, num_strata: str | int = 'auto', clipping_threshold: int = 10, propensity_score_model: Any | None = None, propensity_score_column: str = 'propensity_score', **kwargs)[source]#
-
通过将数据分层到具有相同共同原因的箱中来估计处理效应。
后门准则的直接应用。
支持如下列出的额外参数。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
num_strata – 用于分层数据的箱数。默认为自动确定。
clipping_threshold – 每层中处理组或对照组单元的最小数量。默认值=10
propensity_score_model – 用于计算倾向性得分的模型。可以是任何支持 fit() 和 predict_proba() 方法的分类模型。如果为 None,则默认使用 LogisticRegression 模型。
propensity_score_column – 存储倾向性得分的列名。默认为 'propensity_score'
:param kwargs: (可选) 额外的估计器特定参数
dowhy.causal_estimators.propensity_score_weighting_estimator 模块#
- class dowhy.causal_estimators.propensity_score_weighting_estimator.PropensityScoreWeightingEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, min_ps_score: float = 0.05, max_ps_score: float = 0.95, weighting_scheme: str = 'ips_weight', propensity_score_model: Any | None = None, propensity_score_column: str = 'propensity_score', **kwargs)[source]#
-
通过根据发生的逆概率对数据进行加权来估计处理效应。
后门准则的直接应用。
支持如下列出的额外参数。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
min_ps_score – 用于裁剪倾向性得分的下界。默认值=0.05
max_ps_score – 用于裁剪倾向性得分的上界。默认值=0.95
weighting_scheme – 要使用的加权方法。可以是逆倾向性得分(“ips_weight”,默认)、稳定 IPS 得分(“ips_stabilized_weight”)或归一化 IPS 得分(“ips_normalized_weight”)。
propensity_score_model – 用于计算倾向性得分的模型。可以是任何支持 fit() 和 predict_proba() 方法的分类模型。如果为 None,则默认使用 LogisticRegression 模型。默认值=None
propensity_score_column – 存储倾向性得分的列名。默认为 ‘propensity_score’
kwargs – (可选) 额外的估计器特定参数
dowhy.causal_estimators.regression_discontinuity_estimator 模块#
- class dowhy.causal_estimators.regression_discontinuity_estimator.RegressionDiscontinuityEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, rd_variable_name: str | None = None, rd_threshold_value: float | None = None, rd_bandwidth: float | None = None, **kwargs)[source]#
基类:
CausalEstimator使用回归不连续方法计算处理效应。
通过将问题转换为工具变量问题来估计效应。
支持如下列出的额外参数。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
rd_variable_name – 发生不连续的变量的名称。这是工具变量。
rd_threshold_value – 发生不连续的阈值。
rd_bandwidth – 距离阈值的距离,在此范围内混淆变量在处理组和对照组之间可被视为相同。考虑的带宽为 (阈值 +- 带宽)
kwargs – (可选) 额外的估计器特定参数
dowhy.causal_estimators.regression_estimator 模块#
- class dowhy.causal_estimators.regression_estimator.RegressionEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, **kwargs)[source]#
基类:
CausalEstimator使用某种回归函数计算处理效果。
拟合一个回归模型,以使用处理和混杂因素来估计结果。
所有回归模型的基类,由 LinearRegressionEstimator 和 GeneralizedLinearModelEstimator 继承。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
kwargs – (可选) 额外的估计器特定参数
- estimate_effect(data: DataFrame, treatment_value: Any = 1, control_value: Any = 0, target_units=None, need_conditional_estimates=None, **_)[source]#
- fit(data: DataFrame, effect_modifier_names: List[str] | None = None)[source]#
使用数据拟合估计器以进行效应估计 :param data: 包含数据的数据框 :param treatment: 处理变量的名称 :param outcome: 结果变量的名称 :param effect_modifiers: 计算单独效应所基于的变量
的变量,或返回一个异质效应函数。并非所有方法目前都支持此功能。
dowhy.causal_estimators.two_stage_regression_estimator 模块#
- class dowhy.causal_estimators.two_stage_regression_estimator.TwoStageRegressionEstimator(identified_estimand: IdentifiedEstimand, test_significance: bool | str = False, evaluate_effect_strength: bool = False, confidence_intervals: bool = False, num_null_simulations: int = 1000, num_simulations: int = 399, sample_size_fraction: int = 1, confidence_level: float = 0.95, need_conditional_estimates: bool | str = 'auto', num_quantiles_to_discretize_cont_cols: int = 5, first_stage_model: CausalEstimator | Type[CausalEstimator] | None = None, second_stage_model: CausalEstimator | Type[CausalEstimator] | None = None, **kwargs)[source]#
基类:
CausalEstimator当效果完全由另一个变量中介(前门)或存在工具变量时,计算处理效果。
目前仅支持线性模型来估计效果。
支持如下列出的额外参数。
- 参数:
identified_estimand – 表示要估计的目标已识别估计量的概率表达式。
test_significance – 二进制标志或字符串,指示是否以及使用哪种方法进行显著性检验。所有估计器都支持 test_significance=”bootstrap”,它使用 bootstrap 方法估计所得估计量的 p 值。单个估计器可以覆盖此设置以支持自定义检验方法。bootstrap 方法支持一个可选参数 num_null_simulations。如果为 False,则不执行检验。如果为 True,则使用可用自定义方法对估计量的显著性进行检验,否则使用 bootstrap 方法。
evaluate_effect_strength – (实验性) 是否评估效应强度
confidence_intervals – 二进制标志或字符串,指示是否计算置信区间以及使用哪种方法。所有方法都支持使用参数 confidence_intervals=”bootstrap” 通过 bootstrap 方法估计置信区间。bootstrap 方法接受两个参数(num_simulations 和 sample_size_fraction),这两个参数可以在 params 字典中可选地指定。估计器也可以覆盖此设置以实现自己的置信区间方法。如果此参数为 False,则不计算置信区间。如果为 True,则使用估计器的特定方法(如果可用)计算置信区间,否则通过 bootstrap 计算。
num_null_simulations – 用于检验估计量统计显著性的模拟次数
num_simulations – 用于查找估计量置信区间(和/或标准误)的模拟次数
sample_size_fraction – 用于 bootstrap 估计量的样本大小
confidence_level – 置信区间估计的置信水平
need_conditional_estimates – 布尔标志,指示是否应计算条件估计量。如果图中存在效应修饰因子,则默认为 True
num_quantiles_to_discretize_cont_cols – 将数值效应修饰因子分割成的分位数数量,以实现对其条件处理效应的估计。
first_stage_model – 用于第一阶段的估计器。默认是线性回归。
second_stage_model – 用于第二阶段的估计器。默认是线性回归。
kwargs – (可选) 额外的估计器特定参数
- DEFAULT_FIRST_STAGE_MODEL#
- DEFAULT_SECOND_STAGE_MODEL#
- construct_symbolic_estimator(first_stage_symbolic, second_stage_symbolic, total_effect_symbolic=None, estimand_type=None)[source]#
- estimate_effect(data: DataFrame, treatment_value: Any = 1, control_value: Any = 0, target_units=None, **_)[source]#
- fit(data: DataFrame, effect_modifier_names: List[str] | None = None, **_)[source]#
使用数据拟合估计器以进行效果估计 :param data: 包含数据的数据帧 :param treatment: 处理变量的名称 :param outcome: 结果变量的名称 :param iv_instrument_name: 要使用的特定工具变量的名称。
需要是识别步骤中确定的工具变量之一。默认为使用识别步骤中的所有工具变量。
- 参数:
effect_modifiers – 要计算单独效果或返回异质效果函数的变量。目前并非所有方法都支持此功能。