23  Causal Mediation Analysis

Code
using CairoMakie
CairoMakie.activate!(type = "png")
using GraphMakie
using Graphs
using GLM
using DataFrames
using StatsModels
using DataFramesMeta
using Random
using Distributions
using StatsFuns
using Statistics
using Lavaan
using Crumble
using Printf

Mediation asks how a treatment works, not only whether it works. The graph below is the setting: \(w\) is the treatment, \(m\) a mediator that \(w\) affects and that in turn affects the outcome \(y\), and \(c\) a set of covariates confounding both the \(w \to y\) and the \(m \to y\) relationships. The effect of \(w\) on \(y\) splits into a path through \(m\) and a path around it.

23.1 Classical Mediation

Traditionally mediation model can be represented in the following equations:

\[ Y = a W + b M + \epsilon_1 \tag{23.1}\] \[ M = c W + \epsilon_2 \tag{23.2}\]

That is, we’d like to study the effect of \(W\) on \(Y\), and we see the effect can be a direct effect, and an indirect effect, through \(M\).

Baron and Kenny’s (http://davidakenny.net/cm/mediate.htm) method is done in four steps. Modern approach tends to use SEM (structural equation modeling) to model these two equations directly.

We simulate \(n = 10{,}000\) observations from exactly this structure: \(X \sim N(0,1)\), \(M = 0.5X + \varepsilon_2\), and \(Y = 0.7M + 0.3X + \varepsilon_1\), with both errors standard normal. So the true direct effect is \(a = 0.3\), the mediator coefficient is \(b = 0.7\), the treatment-to-mediator coefficient is \(c = 0.5\), the indirect effect is \(bc = 0.35\), and the total effect is \(0.3 + 0.35 = 0.65\). There is no confounding of any kind, which is what makes this the easy case.

Code
using Random
using DataFrames
using StatsModels
using Lavaan

Random.seed!(1234)
n = 10000
X = randn(n)
M = 0.5 .* X .+ randn(n)
Y = 0.7 .* M .+ 0.3 .* X .+ randn(n)
Data = DataFrame(X = X, M = M, Y = Y)

model = """
   Y ~ a*X + b*M
   M ~ c*X
   # direct effect (a)
   # indirect effect (b*c)
   bc := b*c
   # total effect
   total := a + (b*c)
"""
"   Y ~ a*X + b*M\n   M ~ c*X\n   # direct effect (a)\n   # indirect effect (b*c)\n   bc := b*c\n   # total effect\n   total := a + (b*c)\n"
Code
fit = sem(model, Data)
println(fit)
parameterEstimates(fit)
lavaan 0.1.0-dev fit object
  Estimator:   ML
  Converged:   Yes
  χ²(0) = 0.000  [p = NaN]
  Call summary() for full output.
8×11 DataFrame
Row lhs op rhs est se z pvalue ci_lower ci_upper label free
String String String Float64 Float64 Float64 Float64 Float64 Float64 String Int64
1 Y ~ X 0.295669 0.0111736 26.4614 0.0 0.273769 0.317569 a 1
2 Y ~ M 0.70038 0.0099825 70.1608 0.0 0.680814 0.719946 b 2
3 M ~ X 0.512129 0.00995286 51.4554 0.0 0.492621 0.531637 c 3
4 bc := b*c 0.358685 0.00864452 41.4927 0.0 0.341742 0.375628 0
5 total := a + (b*c) 0.654354 0.0121369 53.9143 0.0 0.630565 0.678142 0
6 M ~~ M 1.00917 0.0142719 70.7107 0.0 0.981199 1.03715 4
7 Y ~~ Y 1.00564 0.014222 70.7107 0.0 0.977769 1.03352 5
8 X ~~ X 1.01875 NaN NaN NaN NaN NaN 0

The estimates are \(a = 0.296\), \(b = 0.700\) and \(c = 0.512\), against true values of 0.3, 0.7 and 0.5. The derived quantities are \(bc = 0.359\) against a true 0.35 and a total of 0.654 against 0.65. Everything is recovered, and the model test statistic is 0 on 0 degrees of freedom because the model is saturated — it has as many parameters as moments, so it cannot fail to fit and the fit statistic carries no information.

23.1.1 Problems with Classical Mediation

  • Lack of causal claim. We have to assume that there is no unmeasured confounder between \(M\) and \(Y\). This is a strong assumption.
  • Assumption of homogeneous effect.

23.2 Causal Mediation

23.2.1 CDE

Suppose we can set \(W\) and \(M\) at will to any \((w, m)\), then we have the potential outcome \(Y(w,m)\).

Controlled direct effect (CDE) is defined as \[ CDE(m) = E[Y(1,m)-Y(0,m)] \tag{23.3}\] That is, setting \(M\) to \(m\), what is the effect of \(W\) on \(Y\)?

23.2.2 Assumptions

  • Conditional treatment randomization. Suppose we observe confounders X, which can be a joint set of confounders for the W to Y pathway, or the M to Y pathway.

\[ Y(w,m) \perp W|X \tag{23.4}\]

This is the usual conditional independence (unconfoundedness, ignorability, etc.) assumption. This is saying the assignment of treatment, given covariates \(X\), has nothing to do with potential outcomes.

  • Conditional mediator randomization.

\[ Y(w,m) \perp M|X, W=w \tag{23.5}\]

This is to say, within each strata of X, given treatment status, the assignment of mediator gives no information about potential outcome. This randomization is usually not implemented during many experiments (random trials). This is the assumption that makes a lot of mediation hard to make a causal claim.

  • Positivity (overlap). There are two positivity assumptions:

\[ P(W=w | X=x) > 0 \tag{23.6}\] for all \(x\). This is the usual positivity assumption.

\[ P(M=m | X=x, W=w) > 0 \tag{23.7}\] for all \(x\), \(w\), and \(m\). This is the mediator positivity.

23.2.3 Estimation

CDE can be estimated using G-computation method, or IPW, or the doubly-robust methods, one of them is AIPW (augmented IPW).

23.2.4 G-computation

G-computation is to model the outcome equation: \[ \begin{aligned} CDE_G(m) &= \sum_x [ E[Y \mid W=1, M=m, X=x] \\ &\quad - E[Y \mid W=0, M=m, X=x]]\, P(X=x) \end{aligned} \tag{23.8}\]

23.2.5 IPW

IPW is to model the treatment assignment equation and the mediator assignment equation. The joint denominator factorizes sequentially – treatment given covariates, then mediator given treatment and covariates – which is the structure the estimator below relies on:

\[ \small E[Y(w,m)] = E\!\left[{\frac{I(W=w)\,I(M=m)}{g_W(w|X)\,g_M(m|w,X)}}\, Y\right] \tag{23.9}\]

Therefore,

\[ \small CDE_{ipw}(m) = E\left[\frac{I(W=1,M=m)}{g_M(m|1,X)\,g_W(1|X)}\, Y - \frac{I(W=0,M=m)}{g_M(m|0,X)\,g_W(0|X)}\, Y\right] \tag{23.10}\]

where \(g_M\) is the probability of the mediator and \(g_W\) the probability of treatment. This indicator-based form is for a discrete (here binary) mediator. For a continuous mediator the indicator \(I(M=m)\) and the probability \(g_M\) must be replaced by a conditional density (or a kernel/stochastic-intervention formulation); the estimator above does not apply as written.

23.2.6 AIPW

\[ CDE_{AIPW} = CDE_G(m) + B(\bar Q, g_M, g_W) \tag{23.11}\] where \(\bar Q\) is the mean outcome function.

\[ \begin{aligned} B(\bar Q, g_M, g_W) &= \frac{1}{n} \sum_{i=1}^{n} {\frac{I(M_i=m, W_i=1)}{g_M(m|1, X_i) g_W(1|X_i)}[Y_i-\bar Q(m,1,X_i)]} \\ &\quad - \frac{1}{n} \sum_{i=1}^{n} {\frac{I(M_i=m, W_i=0)}{g_M(m|0, X_i) g_W(0|X_i)}[Y_i-\bar Q(m,0,X_i)]} \end{aligned} \tag{23.12}\]

23.2.7 Example: G-computation

The three estimators below run on one simulated data set of \(n = 5000\). There are two independent standard normal covariates, \(W_1\) confounding the treatment-outcome relationship and \(W_2\) confounding the mediator-outcome relationship. Treatment is \(A \sim \text{Bernoulli}(\Lambda(-1 + W_1/2))\), the mediator is \(M \sim \text{Bernoulli}(\Lambda(-2 + A/2 + W_2/3))\), and the outcome is \(Y \sim \text{Bernoulli}(\Lambda(-1 + A - M/2 + W_1/3 + W_2/3))\). All three are binary.

The target is \(CDE(0)\), the effect of treatment with the mediator held at 0 for everyone. Since the DGP is fully specified we can integrate it out: \(CDE(0) = E_W[\Lambda(W_1/3 + W_2/3) - \Lambda(-1 + W_1/3 + W_2/3)] = 0.222\). For comparison, \(CDE(1) = 0.191\) — the effect is smaller when the mediator is held at 1, because the logistic link is flatter away from its centre.

Code
using GLM
using Distributions
using StatsFuns
using Statistics

Random.seed!(1234)
n = 5000
# confounder of A/Y
W1 = randn(n)
# confounder of M/Y
W2 = randn(n)
# treatment
A = rand.(Bernoulli.(logistic.(-1 .+ W1 ./ 2)))
# binary mediator
M = rand.(Bernoulli.(logistic.(-2 .+ A ./ 2 .+ W2 ./ 3)))
# binary outcome
Y = rand.(Bernoulli.(logistic.(-1 .+ A .- M ./ 2 .+ W1 ./ 3 .+ W2 ./ 3)))
full_data = DataFrame(W1 = W1, W2 = W2, A = A, M = M, Y = Y)

# fit outcome regression
or_fit = glm(@formula(Y ~ A + M + W1 + W2), full_data, Binomial(), LogitLink())

# new data setting A and M
data_A1_M0 = copy(full_data)
data_A0_M0 = copy(full_data)
data_A1_M0.A .= 1; data_A1_M0.M .= 0
data_A0_M0.A .= 0; data_A0_M0.M .= 0

# predict on new data
Qbar_A1_M0 = predict(or_fit, data_A1_M0)
Qbar_A0_M0 = predict(or_fit, data_A0_M0)

# gcomp estimate of CDE(0)
cde_gcomp = mean(Qbar_A1_M0 .- Qbar_A0_M0)
@printf "CDE(0) G-computation = %.4g\n" cde_gcomp
CDE(0) G-computation = 0.2113

G-computation gives 0.2113.

23.2.8 Example: IPW

The same target through the treatment and mediator models instead of the outcome model.

Code
# model for P(A = 1 | W)
ps_fit1 = glm(@formula(A ~ W1 + W2), full_data, Binomial(), LogitLink())
P_A1_W = predict(ps_fit1)
P_A0_W = 1 .- P_A1_W

# model for P(M = 0 | A, W)
ps_fit2 = glm(@formula(M ~ A + W1 + W2), full_data, Binomial(), LogitLink())

# P(M = 0 | A = 1, W)
data_A1 = copy(full_data); data_A1.A .= 1
P_M0_A1_W = 1 .- predict(ps_fit2, data_A1)

# P(M = 0 | A = 0, W)
data_A0 = copy(full_data); data_A0.A .= 0
P_M0_A0_W = 1 .- predict(ps_fit2, data_A0)

# ipw estimate of CDE(0)
cde_ipw = mean( (A .== 1) ./ P_A1_W .* (M .== 0) ./ P_M0_A1_W .* Y ) -
          mean( (A .== 0) ./ P_A0_W .* (M .== 0) ./ P_M0_A0_W .* Y )
@printf "CDE(0) IPW = %.4g\n" cde_ipw
CDE(0) IPW = 0.226

IPW gives 0.2260.

23.2.9 Example: AIPW

Combining both, so that either the outcome model or the two treatment models may be wrong.

Code
# aipw estimate of E[Y(1,0)]
aiptw_EY_A1_M0 = mean(Qbar_A1_M0) +
mean( (A .== 1) ./ P_A1_W .* (M .== 0) ./ P_M0_A1_W .* (Y .- Qbar_A1_M0) )

# aipw estimate of E[Y(0,0)]
aiptw_EY_A0_M0 = mean(Qbar_A0_M0) +
mean( (A .== 0) ./ P_A0_W .* (M .== 0) ./ P_M0_A0_W .* (Y .- Qbar_A0_M0) )

# aipw estimate of CDE(0)
cde_aipw = aiptw_EY_A1_M0 - aiptw_EY_A0_M0
@printf "CDE(0) AIPW = %.4g\n" cde_aipw
CDE(0) AIPW = 0.2245

AIPW gives 0.2245.

The three estimates are 0.2113, 0.2260 and 0.2245 against a true \(CDE(0)\) of 0.222. Every model here is correctly specified, and over 400 replications of this design the g-computation estimator averages 0.2216 with a sampling standard deviation of 0.0154, so this seed’s 0.2113 is 0.7 standard deviations low. The three estimators share the same data and the same fitted nuisance models, so their agreement with each other is a check on implementation, not on sampling error.

23.3 NIE and NDE: Natural Direct and Indirect Effects

CDE is to study the effect of treatment, given the level of mediator. Instead, Natural Effect is to set mediator to its natural value with the value of treatment, that is, \(M=M(w)\).

\[ \begin{aligned} ATE &= NIE + NDE \\ &= (E[Y(1,M(1))] - E[Y(1,M(0))]) \\ &\quad + (E[Y(1, M(0))] - E[Y(0,M(0))]) \end{aligned} \tag{23.13}\]

The advantage of NDE and NIE comparing to CDE is that it’s more “natural”; that is, you don’t set the level of mediator deterministically. And it can decompose the ATE into direct and indirect effects.

However, there is an additional assumption needed to identify NDE and NIE.

23.3.1 Additional Assumption

\[ Y(w, m) \perp M(w^*) | X \tag{23.14}\]

This is the “cross-world” condition: the outcome under \((w,m)\) is independent of \(M\) under \(w^*\). These two situations cannot happen in the same world; you cannot set \(W\) to both \(w\) and \(w^*\). No experiment can implement it.

This cross-world independence is additional to, not a replacement for, the usual identifying assumptions. The standard mediation formula for natural effects also requires:

  • treatment ignorability for the outcome (no unmeasured treatment-outcome confounding) given \(X\);
  • treatment ignorability for the mediator (no unmeasured treatment-mediator confounding), \(M(w) \perp W \mid X\);
  • mediator ignorability (no unmeasured mediator-outcome confounding) given \(W\) and \(X\);
  • positivity for both the treatment and the mediator; and
  • no treatment-induced confounding of the mediator-outcome relationship – there must be no variable affected by \(W\) that confounds \(M\) and \(Y\). (When such a confounder exists, natural effects are not identified by this formula and interventional direct/indirect effects are used instead.)

The cross-world condition by itself is not sufficient.

23.3.2 Estimation

We use the same simulated data. The outcome model now adds \(A \times M\) and \(M \times W_1\) interactions and the mediator model adds \(A \times W_1\) and \(W_1 \times W_2\) — both are richer than the DGP requires, which costs a little precision and no consistency. We then average \(E[Y \mid A=a, M, W]\) over the distribution of \(M\) under \(A = a'\), for each of the four \((a, a')\) combinations.

The truths again follow from the DGP by integration: \(E[Y(1,M(1))] = 0.478\), \(E[Y(1,M(0))] = 0.486\) and \(E[Y(0,M(0))] = 0.267\), so the true \(NDE = 0.218\), \(NIE = -0.008\) and \(ATE = 0.211\). The indirect effect is slightly negative because treatment raises the chance of the mediator (from 0.124 to 0.188) while the mediator lowers the outcome — the \(-M/2\) term. So this treatment helps directly and hurts a little through its mediator.

Code
# fit outcome regression (include interaction because we can)
or_fit = glm(@formula(Y ~ A + M + W1 + W2 + A&M + M&W1), full_data, Binomial(), LogitLink())

# need E(Y | A = 0/1, M = 0/1, W1 = W1i, W2 = W2i)
function get_EY_a_m_Wi(full_data, or_fit, a, m)
    data_Aa_Mm_Wi = copy(full_data)
    data_Aa_Mm_Wi.A .= a
    data_Aa_Mm_Wi.M .= m
    predict(or_fit, data_Aa_Mm_Wi)
end

EY_A0_M0_Wi = get_EY_a_m_Wi(full_data, or_fit, 0, 0)
EY_A0_M1_Wi = get_EY_a_m_Wi(full_data, or_fit, 0, 1)
EY_A1_M0_Wi = get_EY_a_m_Wi(full_data, or_fit, 1, 0)
EY_A1_M1_Wi = get_EY_a_m_Wi(full_data, or_fit, 1, 1)

# include interactions -- why not? (NOTE: A*W1 expands to A + W1 + A&W1, so
# the MAIN effects are included. Writing only A&W1 would omit the main effect
# of A and force the estimated NIE to be essentially zero by construction.)
med_fit = glm(@formula(M ~ A*W1 + W1*W2), full_data, Binomial(), LogitLink())

# estimates of P(M = m | A = a, W = W_i)
function get_Pm_a_Wi(full_data, med_fit, a, m)
    data_Aa_Wi = copy(full_data)
    data_Aa_Wi.A .= a
    p = predict(med_fit, data_Aa_Wi)
    if m == 1
        return p
    else
        return 1 .- p
    end
end

PM0_A0_Wi = get_Pm_a_Wi(full_data, med_fit, 0, 0)
PM1_A0_Wi = get_Pm_a_Wi(full_data, med_fit, 0, 1)
PM0_A1_Wi = get_Pm_a_Wi(full_data, med_fit, 1, 0)
PM1_A1_Wi = get_Pm_a_Wi(full_data, med_fit, 1, 1)

# E(E(Y | A = 1, M, W) | A = 1, W)
EY1M1_Wi = EY_A1_M1_Wi .* PM1_A1_Wi .+ EY_A1_M0_Wi .* PM0_A1_Wi
# E(E(Y | A = 0, M, W) | A = 1, W)
EY0M1_Wi = EY_A0_M1_Wi .* PM1_A1_Wi .+ EY_A0_M0_Wi .* PM0_A1_Wi
# E(E(Y | A = 1, M, W) | A = 0, W)
EY1M0_Wi = EY_A1_M1_Wi .* PM1_A0_Wi .+ EY_A1_M0_Wi .* PM0_A0_Wi
# E(E(Y | A = 0, M, W) | A = 0, W)
EY0M0_Wi = EY_A0_M1_Wi .* PM1_A0_Wi .+ EY_A0_M0_Wi .* PM0_A0_Wi

# estimate of E[Y(1, M(1))]
E_Y1M1 = mean(EY1M1_Wi)
# estimate of E[Y(0, M(1))]
E_Y0M1 = mean(EY0M1_Wi)
# estimate of E[Y(1, M(0))]
E_Y1M0 = mean(EY1M0_Wi)
# estimate of E[Y(0, M(0))]
E_Y0M0 = mean(EY0M0_Wi)

# NDE = E[Y(1,M(0))] - E[Y(0,M(0))], NIE = E[Y(1,M(1))] - E[Y(1,M(0))]
@printf "NDE = %.4g\n" (E_Y1M0 - E_Y0M0)
@printf "NIE = %.4g\n" (E_Y1M1 - E_Y1M0)
@printf "ATE = %.4g\n" (E_Y1M1 - E_Y0M0)
NDE = 0.2093
NIE = -0.01266
ATE = 0.1966

The estimates are \(NDE = 0.209\), \(NIE = -0.013\) and \(ATE = 0.197\), against truths of 0.218, \(-0.008\) and 0.211. The decomposition holds exactly by construction, \(0.2093 + (-0.0127) = 0.1966\), and the sign of the indirect effect is recovered. The direct and total effects sit about 0.01 below their truths, as the g-computation estimate of \(CDE(0)\) did, for the same reason: it is one draw of the data, and every quantity in this section is computed from it.

Note how much smaller the indirect effect is than the direct one, \(-0.013\) against 0.209. Reporting only the total effect of 0.197 would hide that the mediator works against the treatment.

23.4 IIE and IDE: Interventional Direct and Indirect Effects

People are not happy with the cross-world assumption in general. Interventional direct and indirect effects avoid it. The device is a random draw: let \(M^*_w\) denote a draw from the distribution of \(M(w)\) given \(X=x\), rather than the unit’s own \(M(w)\). The standard definitions (Vansteelandt and Daniel 2017; Díaz et al. 2021) use such a draw in every term:

\[ \begin{aligned} IDE &= E[Y(1,M^*_0)] - E[Y(0,M^*_0)] \\ IIE &= E[Y(1,M^*_1)] - E[Y(1,M^*_0)] \end{aligned} \tag{23.15}\]

The direct effect holds the mediator draw fixed at its untreated distribution; the indirect effect moves only that distribution. The two add up to

\[ IDE + IIE = E[Y(1,M^*_1)] - E[Y(0,M^*_0)], \tag{23.16}\]

the overall interventional effect. It need not equal the \(ATE\): replacing the unit’s own \(M(w)\) by a random draw breaks the within-unit dependence between \(M(w)\) and \(Y(w,\cdot)\), and that dependence matters exactly when a treatment-induced confounder \(Z\) sits between the treatment and the mediator — the situation in the example below. The payoff is identification without the cross-world assumption, even in the presence of such a \(Z\). These interventional effects are the estimands Crumble.jl estimates with effect = "RI".

23.4.1 Example

This example uses the medoutcon vignette’s own DGP, which is built to contain exactly the treatment-induced confounder that defeats natural effects. We draw \(n = 1000\) observations. Three binary baseline covariates: \(W_1 \sim \text{Bernoulli}(0.6)\), \(W_2 \sim \text{Bernoulli}(0.3)\), and \(W_3 \sim \text{Bernoulli}(\min(0.2 + (W_1+W_2)/3,\, 1))\). Treatment is \(A \sim \text{Bernoulli}(\Lambda(\sum_j W_j - 2))\).

Then the key variable: \(Z \sim \text{Bernoulli}(\Lambda(-\log 2 + (W_1+W_2+W_3)/3 - A + 0.2))\) is a mediator-outcome confounder that depends on \(A\). The mediator is \(M \sim \text{Bernoulli}(\Lambda(\log 3 (W_1 + W_2) + 2A - 2Z))\) and the outcome is \(Y \sim \text{Bernoulli}(\Lambda(1/(\sum_j W_j - Z + A + M)))\).

Because \(Z\) is affected by \(A\) and confounds \(M\) and \(Y\), natural direct and indirect effects are not identified here by the formula of the previous section. Interventional effects are, which is the reason for this example. Every variable is binary, so the truth follows by summing over the DGP: \(IDE = -0.074\) and \(IIE = -0.025\). Their sum, the overall interventional effect, is \(-0.099\), while the \(ATE\) is \(-0.083\). That is the gap Equation 23.16 warns about: with \(Z\) present, the two interventional effects do not add up to the total effect.

Code
using DataFrames
using StatsModels
using Random
using StatsFuns
using Distributions
using Crumble

Random.seed!(1584)

# produces a simple data set based on a causal model with mediation
function make_example_data(n_obs = 1000)
    # baseline covariates
    w_1 = rand.(Bernoulli(0.6), n_obs)
    w_2 = rand.(Bernoulli(0.3), n_obs)
    w_3_prob = min.(0.2 .+ (w_1 .+ w_2) ./ 3, 1.0)
    w_3 = rand.(Bernoulli.(w_3_prob))

    # exposure
    a_prob = logistic.(w_1 .+ w_2 .+ w_3 .- 2)
    a = rand.(Bernoulli.(a_prob))

    # mediator-outcome confounder affected by treatment
    z_prob = logistic.(-log(2) .- a .+ (w_1 .+ w_2 .+ w_3) ./ 3 .+ 0.2)
    z = rand.(Bernoulli.(z_prob))

    # mediator -- could be multivariate
    m_prob = logistic.(log(3) .* (w_1 .+ w_2) .+ 2 .* a .- 2 .* z)
    m = rand.(Bernoulli.(m_prob))

    # outcome
    y_prob = logistic.(1 ./ (w_1 .+ w_2 .+ w_3 .- z .+ a .+ m))
    y = rand.(Bernoulli.(y_prob))

    # construct output
    dat = DataFrame(W_1 = w_1, W_2 = w_2, W_3 = w_3, A = a, Z = z, M = m, Y = y)
    return dat
end
make_example_data (generic function with 2 methods)
Code
# set seed and simulate example data
example_data = make_example_data()
w_names = ["W_1", "W_2", "W_3"]
m_names = ["M"]

# quick look at the data
first(example_data, 6)
6×7 DataFrame
Row W_1 W_2 W_3 A Z M Y
Bool Bool Bool Bool Bool Bool Bool
1 false true false false false true true
2 false false false false false true true
3 false false false false false true true
4 false false false false false true true
5 true false false false false false true
6 true true true true true true false
Code
# one-step estimates of the interventional direct and indirect effects
# (effect = "RI"); the Riesz representers are bounded at 100, see below
result = crumble(example_data, ["A"];
                 outcome   = "Y",
                 mediators = m_names,
                 moc       = ["Z"],       # mediator-outcome confounder affected by A
                 covar     = w_names,
                 effect    = "RI",
                 learners  = ["glm"],
                 control   = crumble_control(alpha_cap = 100.0))
Crumble.tidy(result)
2×6 DataFrame
Row estimand estimate std_error conf_low conf_high p_value
String Float64 Float64 Float64 Float64 Float64
1 ride 0.0165558 0.124993 -0.22843 0.261541 0.894625
2 riie -9.7107e-6 0.0967316 -0.189604 0.189584 0.99992

The one-step estimator gives an interventional direct effect of \(0.017\) with a 95% interval of \([-0.228, 0.262]\), against a true \(-0.074\), and an indirect effect of \(0.000\) with an interval of \([-0.190, 0.190]\), against a true \(-0.025\). Both intervals include zero and both truths.

Crumble.jl fits the Riesz representers — the weights in the one-step correction — with a neural network, and this design is hard on them. The true weight for the direct-effect functional reaches 45 in a covariate cell that holds about two observations per cross-fitting fold. When a fold misses that cell, the Riesz loss has no minimiser there and an unbounded fit can drift into the thousands. The call above bounds the weights at 100, well above the true maximum.

The flexible weights cost precision. The interval here is more than twice as wide as the one from medoutcon in the R companion chapter, which also compares the one-step estimator with TMLE; Crumble.jl implements only the one-step estimator.

23.5 Summary

Mediation splits the effect of a treatment into a part through a mediator and a part around it. The classical regression decomposition is causal only if nothing unmeasured confounds the mediator and the outcome. The controlled direct effect fixes the mediator at a level. It needs treatment and mediator randomization given covariates, and it can be estimated by g-computation, IPW or AIPW. Natural direct and indirect effects add up to the ATE. They need a cross-world independence that no experiment can implement, and no confounder of the mediator and outcome that is itself affected by treatment. Interventional effects drop the cross-world condition by using a random draw from the mediator’s distribution. Their sum then need not equal the ATE.

In the simulated binary example, the three CDE estimators give 0.2113, 0.2260 and 0.2245 against a true 0.222. The natural effects show a small negative indirect effect beside a direct effect of 0.209. With a treatment-induced confounder, the one-step interventional direct effect is 0.017, with an interval from \(-0.228\) to 0.262 that covers the true \(-0.074\). The flexible Riesz-representer weights make it too imprecise at \(n = 1000\) to be told apart from zero.