This example demonstrates how to use cmest
when there is a single mediator. 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 binary mediator $M$ and a binary outcome $Y$. The true regression models for $A$, $M$ and $Y$ are:
$$logit(E(A|C_1,C_2))=0.2+0.5C_1+0.1C_2$$
$$logit(E(M|A,C_1,C_2))=1+2A+1.5C_1+0.8C_2$$
$$logit(E(Y|A,M,C_1,C_2)))=-3-0.4A-1.2M+0.5AM+0.3C_1-0.6C_2$$
library(CMAverse) 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)) M <- rbinom(n, 1, expit(1 + 2*A + 1.5*C1 + 0.8*C2)) Y <- rbinom(n, 1, expit(-3 - 0.4*A - 1.2*M + 0.5*A*M + 0.3*C1 - 0.6*C2)) data <- data.frame(A, M, Y, C1, C2)
The DAG for this scientific setting is:
cmdag(outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), postc = NULL, node = TRUE, text_col = "white")
In this setting, we can use all of the six statistical modeling approaches. The results are shown below:
res_rb_param_delta <- cmest(data = data, model = "rb", outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), EMint = TRUE, mreg = list("logistic"), yreg = "logistic", astar = 0, a = 1, mval = list(1), estimation = "paramfunc", inference = "delta")
summary(res_rb_param_delta)
res_rb_param_bootstrap <- cmest(data = data, model = "rb", outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), EMint = TRUE, mreg = list("logistic"), yreg = "logistic", astar = 0, a = 1, mval = list(1), estimation = "paramfunc", inference = "bootstrap", nboot = 2)
summary(res_rb_param_bootstrap)
res_rb_impu_bootstrap <- cmest(data = data, model = "rb", outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), EMint = TRUE, mreg = list("logistic"), yreg = "logistic", astar = 0, a = 1, mval = list(1), estimation = "imputation", inference = "bootstrap", nboot = 2)
summary(res_rb_impu_bootstrap)
res_wb <- cmest(data = data, model = "wb", outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), EMint = TRUE, ereg = "logistic", yreg = "logistic", astar = 0, a = 1, mval = list(1), estimation = "imputation", inference = "bootstrap", nboot = 2)
summary(res_wb)
res_iorw <- cmest(data = data, model = "iorw", outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), ereg = "logistic", yreg = "logistic", astar = 0, a = 1, mval = list(1), estimation = "imputation", inference = "bootstrap", nboot = 2)
summary(res_iorw)
res_msm <- cmest(data = data, model = "msm", outcome = "Y", exposure = "A", mediator = "M", basec = c("C1", "C2"), 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"), EMint = TRUE, mreg = list("logistic"), yreg = "logistic", 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.