Last updated: 2025-02-13

Checks: 2 0

Knit directory: demor2/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version b4f541e. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/mediation.Rmd) and HTML (docs/mediation.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd b4f541e Chun-Hui Lin 2025-02-13 Update mediation page (counterfactual appriach).
html 7081c3f Chun-Hui Lin 2025-02-12 Build site.
Rmd 6cda313 Chun-Hui Lin 2025-02-12 Add mediation-related files.

Some notes on causal mediation analysis from VanderWeele’s materials.

Traditional Approach

Symbols
  • \(A\): exposure of interest
  • \(M\): potential mediator
  • \(Y\): outcome
  • \(C\): baseline covariates

The Difference Method

M1: a regression of the outcome \(Y\) on the exposure \(A\) and covariates \(C\)

\(E[Y|a, c] = \phi_0 + \phi_1a + \phi'_4c\)

\(\phi_1\) is interpreted as the total effect (TE) of the exposure \(A\) on the outcome \(Y\).


M2: similar but add the mediator \(M\) in the regression as well

\(E[Y|a, m, c] = \theta_0 + \theta_1a + \theta_2m + \theta'_4c\)

\(\theta_1\) is interpreted as the direct effect (DE) of \(A\) on \(Y\) when control has been made for the mediator.

The difference of TE and DE is interpreted as the indirect effect (IE), th effect of \(A\) on \(Y\) explained by the mediator.

\(IE = \phi_1 - \theta_1\)

The Product Method

Once again, M2 is employed.

M3: a regression of the mediator \(M\) on the exposure \(A\) and covariates \(C\)

\(E[M|a, c] = \beta_0 + \beta_1a + \beta'_2c\)

Then, substitute M3 in M2 for \(m\).

\(E_M[E[Y|a, m, c]]\)
\(= \theta_0 + \theta_1a + \theta_2(\beta_0 + \beta_1a + \beta'_2c) + \theta'_4c\)
\(= \theta_0 + (\theta_1 + \theta_2\beta_1)a + (\theta_2\beta'_2c + \theta_2\beta_0 + \theta'_4c)\)

\(DE = \theta_1\)
\(IE = \theta_2\beta_1\)

The interpretation of DE is the same as the difference method. The IE, however, is interpreted as the effect of the exposure on the mediator \(\beta_1\) times the effect of the mediator on the outcome \(\theta_2\).

Limitations
  • Two methods differ in the case of binary outcome.
  • Confounders for the mediator-outcome relationship may exist.
  • Interactions of the exposure-mediator relationship may exist.

Counterfactual Approach

Symbols
  • \(Y_a = Y(a)\): Y when setting \(A\) to \(a\)
  • \(Y_{am} = Y(a, m)\): Y when setting \(A\) to \(a\) and \(M\) to \(m\)
  • \(M_a = M(a)\): M when setting \(M\) to \(m\)

\(TE = Y_1 - Y_0 = Y_{1M_1} - Y_{0M_0} = (Y_{1M_1} - Y_{1M_0}) + (Y_{1M_0} - Y_{0M_0}) = NIE + NDE\)

Controlled direct effect (CDE): the outcome change on average when \(a = 1\)\(0\) and \(M = m\).

\(CDE(m) = Y_{1m} - Y_{0m}\)

Natural direct effect (NDE): the outcome change on average when \(a = 1\)\(0\) and the mediator is controlled at the level in the absence of the exposure.

\(NDE = CDE(M_0) = Y_{1M_0} - Y_{0M_0} = Y_{1M(A = 0)} - Y_{0M(A = 0)}\)

Natural indirect effect (NIE): the outcome change on average when \(a = 1\) and the mediator change if \(a = 1\)\(0\).

\(NIE = Y_{1M_1} - Y_{1M_0} = Y_{1M(A = 1)} - Y_{1M(A = 0)}\)

Proportion Mediation (PM): how much of the effect is mediated.

\(PM = \frac{NIE}{TE}\)

Proportion Eliminated (PE): how much of the effect is eliminated when \(M = m\).

\(PE = \frac{TE - CDE(m)}{TE}\)