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:

The Regression-based Approach

Closed-form Parameter Function Estimation and Delta Method Inference

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)

Closed-form Parameter Function Estimation and Bootstrap Inference

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)

Direct Counterfactual Imputation Estimation and Bootstrap Inference

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)

The Weighting-based Approach

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)

The Inverse Odds-ratio Weighting Approach

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)

The Natural Effect Model

```r

res_ne <- cmest(data = data, model = "ne", outcome = "Y", exposure = "A",

mediator = "M", basec = c("C1", "C2"), EMint = TRUE,

yreg = "logistic",

astar = 0, a = 1, mval = list(1),

estimation = "imputation", inference = "bootstrap", nboot = 2)

```

```r

summary(res_ne)

```

The Marginal Structural Model

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)

The g-formula Approach

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)


LindaValeri/CMAverse documentation built on July 16, 2024, 11:58 p.m.