This example demonstrates how to use cmest
when there are mediator-outcome confounders affected by the exposure. For this purpose, we simulate some data containing a continuous baseline confounder $C_1$, a binary baseline confounder $C_2$, a binary exposure $A$, a continuous mediator-outcome confounder affected by the exposure $L$, a binary mediator $M$ and a binary outcome $Y$. The true regression models for $A$, $L$, $M$ and $Y$ are:
$$logit(E(A|C_1,C_2))=0.2+0.5C_1+0.1C_2$$
$$E(L|A,C_1,C_2)=1+A-C_1-0.5C_2$$
$$logit(E(M|A,L,C_1,C_2))=1+2A-L+1.5C_1+0.8C_2$$
$$logit(E(Y|A,L,M,C_1,C_2)))=-3-0.4A-1.2M+0.5AM-0.5L+0.3C_1-0.6C_2$$
set.seed(1) expit <- function(x) exp(x)/(1+exp(x)) n <- 10000 C1 <- rnorm(n, mean = 1, sd = 0.1) C2 <- rbinom(n, 1, 0.6) A <- rbinom(n, 1, expit(0.2 + 0.5*C1 + 0.1*C2)) L <- rnorm(n, mean = 1 + A - C1 - 0.5*C2, sd = 0.5) M <- rbinom(n, 1, expit(1 + 2*A - L + 1.5*C1 + 0.8*C2)) Y <- rbinom(n, 1, expit(-3 - 0.4*A - 1.2*M + 0.5*A*M - 0.5*L + 0.3*C1 - 0.6*C2)) data <- data.frame(A, M, Y, C1, C2, L)
The DAG for this scientific setting is:
library(CMAverse) cmdag(outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), postc = "L", node = TRUE, text_col = "white")
In this setting, we can use the marginal structural model and the $g$-formula approach. The results are shown below.
res_msm <- cmest(data = data, model = "msm", outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), postc = "L", EMint = TRUE, ereg = "logistic", yreg = "logistic", mreg = list("logistic"), wmnomreg = list("logistic"), wmdenomreg = list("logistic"), astar = 0, a = 1, mval = list(1), estimation = "imputation", inference = "bootstrap", nboot = 2)
summary(res_msm)
res_gformula <- cmest(data = data, model = "gformula", outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), postc = "L", EMint = TRUE, mreg = list("logistic"), yreg = "logistic", postcreg = list("linear"), astar = 0, a = 1, mval = list(1), estimation = "imputation", inference = "bootstrap", nboot = 2)
summary(res_gformula)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.