一、medDML函数
基于Farbmacher等(2022)、张涛和李均超(2023)的研究方法,本文将介绍如何使用R语言进行双重机器学习的中介效应分析,本文示例数据采用的是张涛和李均超(2023)的附件数据。
在双重机器学习中,中介效应的估计方法可以利用R语言的causalweight包中“medDML”函数进行估计,这个函数的解释说明在causalweight包的说明文档中有详细介绍:
medDML(
y,
d,
m,
x,
k = 3,
trim = 0.05,
order = 1,
multmed = TRUE,
fewsplits = FALSE,
normalized = TRUE
)
具体参数的解释如下:
**y** Dependent variable, must not contain missings.
**d** Treatment, must be binary (either 1 or 0), must not contain missings.
**m** Mediator, must not contain missings. May be a scalar or a vector of binary,
categorical, or continuous variables if multmed is TRUE. Must be a binary scalar
if multmed is FALSE.
**x** (Potential) pre-treatment confounders of the treatment, mediator, and/or
outcome, must not contain missings.
**k** Number of folds in k-fold cross-fitting if multmed is FALSE. k-1 folds are
used for estimating the model parameters of the treatment, mediator, and outcome
equations and one fold is used for predicting the efficient score functions. The
roles of the folds are swapped. Default for k is 3. If multmed is TRUE, then
3-fold cross-va