Skip to contents

Weighting rather than conditioning lets the mediator model stay marginal. Conditioning on a mediator-outcome confounder would also condition on anything the exposure caused; the weights remove the confounding while leaving the exposure effect on the mediator intact.

Usage

Medmsm(y, A, M, H)

Arguments

y

Outcome.

A

Binary exposure.

M

Mediator.

H

Confounder history used for the weights.

Value

List with estimate, nie, total, theta, beta, w_mean, n.

Details

Formula: weights 1/P(A|H), then weighted Y = th0 + th1 a + th2 m + th3 a m and M = b0 + b1 a, giving NDE = th1 + th3(b0 + b1 a*) and NIE = b1(th2 + th3 a).

References

VanderWeele & Vansteelandt (2010) Am J Epidemiol 172:1339-1348; Robins, Hernan & Brumback (2000) Epidemiology 11:550-560.

Examples

set.seed(4)
n <- 500
H <- rnorm(n)
A <- rbinom(n, 1, plogis(H))
M <- 0.5 * A + 0.3 * H + rnorm(n)
y <- 0.4 * A + 0.6 * M + H + rnorm(n)
Medmsm(y, A, M, matrix(H))[c("nie", "total")]
#> $nie
#> [1] 0.2509118
#> 
#> $total
#> [1] 0.5353635
#>