Skip to content

Causal Inference What If Chapters 16-20 (因果推断第 16-20 章)

来源: Causal Inference: What If (Hernán & Robins)
编译时间: 2026-06-01
状态: 中英对照编译
基于: 第 16-20 章核心概念
关联: 因果推断第 11-15 章, 因果推断第 1-3 章


📚 目录 (Table of Contents)

  1. 第 16 章:因果暴露反应函数
  2. 第 17 章:因果推断的机器学习方法
  3. 第 18 章:干扰
  4. 第 19 章:纵向数据与 G 公式进阶
  5. 第 20 章:结构嵌套模型进阶

16. 第 16 章 因果暴露反应函数 (Chapter 16 Causal Exposure-Response Functions)

16.1 连续处理 (Continuous Treatments)

英文:

Causal inference for continuous treatments requires extending the potential outcomes framework. Instead of binary treatments A ∈ {0, 1}, we consider continuous treatments A ∈ ℝ.

中文:

连续处理的因果推断需要扩展潜在结果框架。我们考虑连续处理 A ∈ ℝ,而不是二元处理 A ∈ {0, 1}。

连续处理的潜在结果 (Potential Outcomes for Continuous Treatments):

\[ Y^a: \text{如果处理设置为 } a \in \mathbb{R} \text{ 时的结局} \]

因果暴露反应函数 (Causal Exposure-Response Function):

\[ f(a) = E[Y^a] \]

表示如果将处理设置为水平 \(a\) 时的平均结局。

16.2 广义倾向评分 (Generalized Propensity Score)

英文:

The generalized propensity score is the conditional density of receiving a particular treatment level given covariates.

中文:

广义倾向评分是在给定协变量条件下接受特定处理水平的条件密度。

广义倾向评分定义 (Definition):

\[ GPS(a, L) = f_{A|L}(a|L) \]

其中 \(f_{A|L}\) 是给定协变量 \(L\) 时处理 \(A\) 的条件密度。

逆概率加权 (IPW for Continuous Treatments):

\[ E[Y^a] = E\left[ \frac{Y \cdot I(A = a)}{f_{A|L}(a|L)} \right] \]

Python 实现 (Python Implementation):

import numpy as np
from scipy.stats import norm
from sklearn.linear_model import LinearRegression

def continuous_ipw(A, L, Y, a_values):
    """
    连续处理的逆概率加权

    参数:
        A: 连续处理变量
        L: 协变量矩阵
        Y: 结局变量
        a_values: 要估计的处理水平

    返回:
        causal_effect: 每个处理水平的因果效应估计
    """
    # 拟合处理模型 (假设正态分布)
    treatment_model = LinearRegression()
    treatment_model.fit(L, A)

    # 预测均值和方差
    A_pred = treatment_model.predict(L)
    sigma = np.std(A - A_pred)

    # 计算广义倾向评分
    gps = norm.pdf(A, loc=A_pred, scale=sigma)

    # 对每个处理水平估计因果效应
    causal_effects = []
    for a in a_values:
        # 计算权重
        weights = norm.pdf(np.full_like(A, a), loc=A_pred, scale=sigma) / gps

        # 加权平均
        causal_effect = np.sum(weights * Y * (np.abs(A - a) < 0.1)) / np.sum(weights * (np.abs(A - a) < 0.1))
        causal_effects.append(causal_effect)

    return causal_effects

17. 第 17 章 因果推断的机器学习方法 (Chapter 17 Machine Learning Methods for Causal Inference)

17.1 因果森林 (Causal Forests)

英文:

Causal forests extend random forests to estimate heterogeneous treatment effects by modifying the splitting criterion to maximize differences in treatment effects.

中文:

因果森林扩展随机森林来估计异质性处理效应,通过修改分裂准则来最大化处理效应的差异。

因果森林算法 (Causal Forest Algorithm):

For each tree b = 1 to B:
  1. Bootstrap 采样
  2. 生长树:
     - 在每个节点:
       a. 寻找最大化处理效应异质性的分裂
       b. 分裂标准: Δ = |τ_left - τ_right|
       c. τ = E[Y|A=1] - E[Y|A=0]
  3. 返回树 T_b

预测处理效应 τ(x):
  τ̂(x) = (1/B) Σ T_b(x)

17.2 双机器学习 (Double/Debiased Machine Learning)

英文:

Double machine learning uses machine learning to estimate nuisance parameters while maintaining valid inference for the treatment effect through orthogonalization.

中文:

双机器学习使用机器学习估计干扰参数,同时通过正交化保持对处理效应的有效推断。

DML 算法 (DML Algorithm):

1. 随机分割数据为 K 折
2. For each fold k:
   a. 在 K-1 折上拟合结局模型: Ŷ = f_Y(X, A)
   b. 在 K-1 折上拟合处理模型: Â = f_A(X)
   c. 在第 k 折计算残差:
      - 结局残差: R_Y = Y - Ŷ
      - 处理残差: R_A = A - Â
3. 使用所有折的残差估计处理效应:
   θ̂ = (Σ R_A × R_Y) / (Σ R_A²)

Python 实现 (Python Implementation):

from sklearn.model_selection import KFold
from sklearn.ensemble import RandomForestRegressor
import numpy as np

def double_machine_learning(Y, A, X, n_splits=5):
    """
    双机器学习估计处理效应

    参数:
        Y: 结局变量
        A: 处理变量
        X: 协变量
        n_splits: 交叉验证折数

    返回:
        theta: 处理效应估计
    """
    kf = KFold(n_splits=n_splits, shuffle=True)

    # 存储残差
    residuals_Y = np.zeros_like(Y, dtype=float)
    residuals_A = np.zeros_like(A, dtype=float)

    for train_idx, test_idx in kf.split(X):
        X_train, X_test = X[train_idx], X[test_idx]
        Y_train = Y[train_idx]
        A_train = A[train_idx]

        # 拟合结局模型
        model_Y = RandomForestRegressor()
        model_Y.fit(X_train, np.column_stack([A_train, X_train]))
        Y_pred = model_Y.predict(np.column_stack([A[test_idx], X_test]))

        # 拟合处理模型
        model_A = RandomForestRegressor()
        model_A.fit(X_train, A_train)
        A_pred = model_A.predict(X_test)

        # 计算残差
        residuals_Y[test_idx] = Y[test_idx] - Y_pred
        residuals_A[test_idx] = A[test_idx] - A_pred

    # 估计处理效应
    theta = np.sum(residuals_A * residuals_Y) / np.sum(residuals_A ** 2)

    return theta

18. 第 18 章 干扰 (Chapter 18 Interference)

18.1 干扰的定义 (Definition of Interference)

英文:

Interference occurs when one individual's treatment affects another individual's outcome. This violates the SUTVA assumption.

中文:

当一个个体的处理影响另一个个体的结局时,就会发生干扰。这违反了 SUTVA 假设。

SUTVA 假设 (SUTVA Assumption):

稳定处理 - 无干扰值假设 (Stable Unit Treatment Value Assumption):

\[ Y_i(A_1, A_2, \ldots, A_n) = Y_i(A_i) \]

干扰存在时:

\[ Y_i(A_1, A_2, \ldots, A_n) \neq Y_i(A_i) \]

18.2 直接效应与间接效应 (Direct and Indirect Effects)

英文:

In the presence of interference, we can distinguish between direct effects (own treatment) and indirect effects (others' treatment).

中文:

在干扰存在时,我们可以区分直接效应 (自己的处理) 和间接效应 (他人的处理)。

效应分解 (Effect Decomposition):

效应类型 英文 定义
直接效应 Direct Effect 个体自身处理的影响
间接效应 Indirect Effect 他人处理对个体的影响 (溢出效应)
总效应 Total Effect 直接效应 + 间接效应

干扰模型示例 (Interference Model Example):

\[ Y_i = \alpha + \beta_1 A_i + \beta_2 \frac{\sum_{j \in N(i)} A_j}{|N(i)|} + \epsilon_i \]

其中: - \(\beta_1\): 直接效应 - \(\beta_2\): 间接效应 (溢出) - \(N(i)\): 个体 i 的邻居集合

18.3 群体随机化 (Cluster Randomization)

英文:

Cluster randomization is a design where groups (clusters) are randomized to treatment conditions rather than individuals.

中文:

群体随机化是一种设计,其中群体 (簇) 被随机分配到处理条件,而不是个体。

群体随机化设计 (Cluster Randomized Design):

群体水平随机化:

群体 1: [● ● ● ● ●] → 处理组
群体 2: [○ ○ ○ ○ ○] → 对照组
群体 3: [● ● ● ● ●] → 处理组
群体 4: [○ ○ ○ ○ ○] → 对照组

分析考虑群体内相关性

19. 第 19 章 纵向数据与 G 公式进阶 (Chapter 19 Longitudinal Data and Advanced G-Formula)

19.1 动态处理制度 (Dynamic Treatment Regimes)

英文:

A dynamic treatment regime is a sequence of decision rules that specify how treatment should be assigned at each time point based on the individual's history.

中文:

动态处理制度是一系列决策规则,指定在每个时间点如何根据个体的历史分配处理。

动态处理制度 (Dynamic Treatment Regime):

\[ d = (d_0, d_1, \ldots, d_T) \]

其中每个决策规则:

\[ d_t(L_t) \in \{0, 1\} \]

基于历史 \(L_t\) 决定时间 t 的处理。

最优动态制度 (Optimal Dynamic Regime):

\[ d^{opt} = \arg\max_d E[Y^d] \]

19.2 参数 G 公式 (Parametric G-Formula)

英文:

The parametric g-formula estimates the causal effect by modeling the joint distribution of time-varying variables and simulating outcomes under different treatment regimes.

中文:

参数 G 公式通过建模时变变量的联合分布,并在不同处理制度下模拟结局来估计因果效应。

参数 G 公式步骤 (Parametric G-Formula Steps):

1. 拟合条件分布模型:
   - 结局模型: f(Y_t | 历史)
   - 协变量模型: f(L_t | 历史)
   - 处理模型: f(A_t | 历史)

2. 蒙特卡洛模拟:
   For 每个处理制度 d:
     For i = 1 to N_sim:
       a. 初始化 L_0
       b. For t = 0 to T:
          - 根据 d_t 设置 A_t
          - 从 f(L_{t+1}|历史) 抽样 L_{t+1}
       c. 从 f(Y|历史) 抽样 Y^d
     c. 计算 E[Y^d] ≈ (1/N_sim) Σ Y^d_i

3. 比较不同制度的 E[Y^d]

20. 第 20 章 结构嵌套模型进阶 (Chapter 20 Advanced Structural Nested Models)

20.1 结构嵌套均值模型 (Structural Nested Mean Models)

英文:

Structural nested mean models directly model the blip function, which represents the average causal effect of treatment at each time point.

中文:

结构嵌套均值模型直接建模脉冲函数,它表示每个时间点处理的平均因果效应。

脉冲函数 (Blip Function):

\[ \gamma_t(L_t, A_t) = E[Y^{A_t, 0} - Y^{0, 0} | L_t, A_t] \]

表示在时间 t 接受治疗而非不接受的额外效应。

SNMM 模型 (SNMM Model):

\[ E[Y^{\bar{a}} | L] = \mu(L) + \sum_{t=0}^{T} \gamma_t(L_t, a_t) \]

20.2 G 估计 (G-Estimation)

英文:

G-estimation is a method for estimating structural nested models that solves estimating equations derived from the counterfactual framework.

中文:

G 估计是一种估计结构嵌套模型的方法,它求解从反事实框架导出的估计方程。

G 估计方程 (G-Estimation Equation):

\[ \sum_{i=1}^{n} S(L_i, A_i; \psi) \cdot (Y_i - \gamma(A_i; \psi)) = 0 \]

其中: - \(S\): 得分函数 - \(\psi\): 模型参数 - \(\gamma\): 脉冲函数

20.3 方法比较 (Methods Comparison)

方法 优点 缺点 适用场景
G 公式 可估计任意制度 模型依赖性强 复杂动态制度
IPW/MSM 简单,软件支持好 权重不稳定 边际效应
SNMM/G 估计 双重稳健 实现复杂 条件效应
TMLE 半参有效 计算复杂 高效估计

🔑 关键术语对照表 (Glossary)

English 中文 定义
Continuous treatment 连续处理 取值连续的暴露变量
Generalized propensity score 广义倾向评分 连续处理的倾向评分
Causal forest 因果森林 估计异质性处理效应的随机森林
Double machine learning 双机器学习 使用 ML 的因果推断方法
Interference 干扰 个体处理影响他人结局
SUTVA SUTVA 稳定处理 - 无干扰值假设
Direct effect 直接效应 自身处理的影响
Indirect effect 间接效应 他人处理的溢出效应
Cluster randomization 群体随机化 以群体为单位随机化
Dynamic treatment regime 动态处理制度 时变处理决策规则
Parametric g-formula 参数 G 公式 基于模型的 G 公式
Structural nested model 结构嵌套模型 直接建模因果效应的模型
G-estimation G 估计 估计 SNMM 的方法

编译完成时间: 2026-06-01
来源: Causal Inference: What If 第 16-20 章
关联文档: causal-inference-ch11-15-zh-en.md


**因果推断第 16-20 章 | 中英对照版** [返回顶部](#目录-table-of-contents)