Relying on a regression-based approach, the exactmed_c()
function calculates standard
causal mediation effects when the outcome is binary and the mediator is continuous. More precisely, exactmed_c()
relies on logistic and linear models for the outcome and mediator, respectively, in order to compute exact
conditional natural direct and indirect effects.
Nested counterfactual probabilities underlying the definition of natural effects are calculated using numerical integration.
The function returns point and interval estimates for the conditional natural effects without making any assumption
regarding the rareness or commonness of the outcome (hence the term exact). For completeness, exactmed_c()
also
calculates the conditional controlled direct effect at a specified value of the mediator. Natural and controlled effects
estimates are reported using three different scales: odds ratio (OR), risk ratio (RR) and risk difference (RD).
The interval estimates can be obtained either by the delta method or the bootstrap.
Usage
exactmed_c(
data,
a,
m,
y,
a1,
a0,
m_cov = NULL,
y_cov = NULL,
m_cov_cond = NULL,
y_cov_cond = NULL,
adjusted = TRUE,
interaction = TRUE,
Firth = FALSE,
boot = FALSE,
nboot = 1000,
bootseed = 1991,
confcoef = 0.95,
hvalue_y = NULL,
yprevalence = NULL,
mf = NULL
)
Arguments
- data
A named data frame that includes the exposure, mediator and outcome variables as well as the covariates to be adjusted for in the models. The exposure can be either binary or continuous. If a covariate is categorical, it has to be included in the data frame as a factor, character or logical variable.
- a
The name of the binary or continuous exposure variable.
- m
The name of the continuous mediator variable.
- y
The name of the binary outcome variable.
- a1
A value corresponding to the high level of the exposure.
- a0
A value corresponding to the low level of the exposure.
- m_cov
A vector containing the names of the adjustment variables (covariates) in the mediator model.
- y_cov
A vector containing the names of the adjustment variables (covariates) in the outcome model.
- m_cov_cond
A named vector (atomic vector or list) containing specific values for some or all of the adjustment covariates
m_cov
in the mediator model. Please consult the package vignette for details.- y_cov_cond
A named vector (atomic vector or list) containing specific values for some or all of the adjustment covariates
y_cov
in the outcome model. Please consult the package vignette for details.- adjusted
A logical variable specifying whether to obtain adjusted or unadjusted estimates. If
adjusted = FALSE
, vectorsm_cov
andy_cov
are ignored by the procedure.- interaction
A logical variable specifying whether there is an exposure-mediator interaction term in the outcome model.
- Firth
A logical variable specifying whether to compute conventional or penalized maximum likelihood estimates for the outcome logistic regression model.
- boot
A logical value specifying whether the confidence intervals are obtained by the delta method or by percentile bootstrap.
- nboot
The number of bootstrap replications used to obtain the confidence intervals if
boot = TRUE
. By defaultnboot = 1000
.- bootseed
The value of the initial seed (positive integer) for random number generation if
boot = TRUE
.- confcoef
A number between 0 and 1 for the confidence coefficient (ex.: 0.95) of the interval estimates.
- hvalue_y
The value corresponding to the high level of the outcome. If the outcome is already coded as a numerical binary variable taking 0 or 1 values, then by default
hvalue_y = 1
.- yprevalence
The prevalence of the outcome in the population (a number between 0 and 1). Option used when case-control data are used. The low level of the outcome is treated as the control level.
- mf
The value of the mediator at which the conditional controlled direct effect is computed. If it is not specified,
mf
is fixed at the sample-specific mean of the mediator (default).
Value
An object of class results_c
is returned:
- ne.or
Natural effects estimates on OR scale.
- ne.rr
Natural effects estimates on RR scale.
- ne.rd
Natural effects estimates on RD scale.
- cde
Controlled direct effect estimates.
- med.reg
Summary of the mediator regression.
- out.reg
Summary of the outcome regression.
If boot==TRUE
, the returned object also contains:
- boot.ne.or
Bootstrap replications of natural effects on OR scale.
- boot.ne.rr
Bootstrap replications of natural effects on RR scale.
- boot.ne.rd
Bootstrap replications of natural effects on RD scale.
- boot.cde.or
Bootstrap replications of controlled direct effect on OR scale.
- boot.cde.rr
Bootstrap replications of controlled direct effect on RR scale.
- boot.cde.rd
Bootstrap replications of controlled direct effect on RD scale.
- boot.ind
Indices of the observations sampled in each bootstrap replication (one replication per column).
Details
By default, exactmed_c()
reports mediation effects evaluated at the sample-specific mean values of the numerical covariates
(including the dummy variables created internally by the function to represent the non-reference levels of the categorical covariates).
In order to estimate mediation effects at specific values of some covariates (that is, stratum-specific effects),
the user needs to provide named vectors m_cov_cond
and/or y_cov_cond
containing those values or levels. The adjustment
covariates appearing in both m_cov
and y_cov
(common adjustment covariates) must have the same values; otherwise,
exactmed_c()
's execution is aborted and an error message is displayed in the R console.
The Firth parameter allows to reduce the bias of the outcome logistic regression coefficients estimators when facing a problem of
separation or quasi-separation. The bias reduction is achieved by the brglmFit
fitting method of the brglm2 package.
More precisely, estimates are obtained via penalized maximum likelihood with a Jeffreys prior penalty, which is equivalent to the mean
bias-reducing adjusted score equation approach in Firth (1993).
When the data come from a case-control study, the yprevalence
parameter should be used and its value ideally correspond to the true outcome prevalence.
exactmed_c()
accounts for the ascertainment in the sample by employing weighted regression techniques that use inverse probability weighting (IPW)
with robust standard errors. These errors are obtained via the vcovHC
function of the R package sandwich.
Specifically, we use the HC3 type covariance matrix estimator (default type of the vcovHC
function).
For the mediation effects expressed on the multiplicative scales (odds ratio, OR; risk ratio, RR), the exactmed_c()
function
returns delta method confidence intervals by exponentiating the lower and upper limits of the normal confidence intervals obtained
for the logarithmic transformations of the effects. The exactmed_c()
function also provides the estimated standard errors of
natural and controlled direct effects estimators that are not log-transformed, where those are derived using a first order Taylor expansion
(e.g., \(\hat{SE}(\hat{OR})=\hat{OR} \times \hat{SE}(\log(\hat{OR}))\)). The function performs Z-tests (null hypothesis: there is no effect)
computing the corresponding two-tailed p-values. Note that for the multiplicative scales, the standard scores (test statistics)
are obtained by dividing the logarithm of an effect estimator by the estimator of the corresponding standard error
(e.g., \(\log(\hat{OR}) / \hat{SE}(\log(\hat{OR}))\)). No log-transformation is applied when working on the risk difference scale.
Note
The exactmed_c()
function only works for complete data. Users can apply multiple imputation techniques (e.g., R package mice)
or remove observations of variables used in mediation analysis that have missing values (NA).
References
Samoilenko M, Blais L, Lefebvre G. Comparing logistic and log-binomial models for causal mediation analyses of binary mediators and rare binary outcomes: evidence to support cross-checking of mediation results in practice. Observational Studies.2018;4(1):193-216.
Samoilenko M, Lefebvre G. Parametric-regression-based causal mediation analysis of binary outcomes and binary mediators: moving beyond the rareness or commonness of the outcome. American Journal of Epidemiology.2021;190(9):1846-1858. doi:10.1093/aje/kwab055 .
Samoilenko M, Lefebvre G. An exact regression-based approach for the estimation of the natural direct and indirect effects with a binary outcome and a continuous mediator. Statistics in Medicine.2023; 42(3): 353–387. doi:10.1002/sim.9621 .
Firth D. Bias reduction of maximum likelihood estimates. Biometrika.1993;80:27-38. doi:10.2307/2336755 .
Examples
exactmed_c(
data = datamed_c, a = "X", m = "M", y = "Y", a1 = 1, a0 = 0,
m_cov = c("C1", "C2"), y_cov = c("C1", "C2")
)
#>
#> Natural effects on OR scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 4.31959 0.72009 3.11561 5.98881 < 2e-16
#> Indirect effect 0.82693 0.06321 0.71187 0.96057 0.012912
#> Total effect 3.57197 0.50942 2.70093 4.72394 < 2e-16
#>
#> Natural effects on RR scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 1.84144 0.12239 1.61653 2.09764 < 2.22e-16
#> Indirect effect 0.94962 0.01865 0.91376 0.98688 0.0084812
#> Total effect 1.74867 0.11184 1.54264 1.98221 < 2.22e-16
#>
#> Natural effects on RD scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 0.34112 0.03466 0.27319 0.40905 < 2.22e-16
#> Indirect effect -0.03761 0.01451 -0.06605 -0.00917 0.0095435
#> Total effect 0.30351 0.03167 0.24144 0.36558 < 2.22e-16
#>
#> Controlled direct effect (m=-0.5107948):
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> OR scale 2.90424 0.46784 2.11794 3.98247 3.6280e-11
#> RR scale 1.51341 0.09691 1.33491 1.71578 9.7243e-11
#> RD scale 0.24778 0.03570 0.17781 0.31774 3.8918e-12
#>
#>
#> Mediator model:
#>
#>
#> Call:
#> lm(formula = Mform, data = data)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -6.1821 -1.4324 0.0568 1.2604 7.1676
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -0.62373 0.10799 -5.776 1.02e-08 ***
#> X 1.53357 0.12476 12.292 < 2e-16 ***
#> C1 -1.22692 0.12473 -9.837 < 2e-16 ***
#> C2 1.61857 0.06236 25.956 < 2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Residual standard error: 1.971 on 996 degrees of freedom
#> Multiple R-squared: 0.4774, Adjusted R-squared: 0.4758
#> F-statistic: 303.3 on 3 and 996 DF, p-value: < 2.2e-16
#>
#>
#> Outcome model:
#>
#>
#> Call:
#> glm(formula = Yform, family = binomial(link = "logit"), data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.51704 0.13059 -3.959 7.52e-05 ***
#> X 0.74814 0.15871 4.714 2.43e-06 ***
#> M 0.49722 0.05253 9.465 < 2e-16 ***
#> X:M -0.62263 0.06358 -9.793 < 2e-16 ***
#> C1 1.39342 0.16191 8.606 < 2e-16 ***
#> C2 -0.53693 0.09816 -5.470 4.50e-08 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 1377.4 on 999 degrees of freedom
#> Residual deviance: 1102.9 on 994 degrees of freedom
#> AIC: 1114.9
#>
#> Number of Fisher Scoring iterations: 4
#>
exactmed_c(
data = datamed_c, a = "X", m = "M", y = "Y", a1 = 1, a0 = 0,
m_cov = c("C1", "C2"), y_cov = c("C1", "C2"), yprevalence = 0.1
)
#>
#> Natural effects on OR scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 4.80409 1.10565 3.05991 7.54246 9.1425e-12
#> Indirect effect 0.74541 0.09330 0.58325 0.95267 0.01891
#> Total effect 3.58104 0.59990 2.57879 4.97281 2.6423e-14
#>
#> Natural effects on RR scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 3.89677 0.73365 2.69431 5.63587 5.0315e-13
#> Indirect effect 0.79360 0.07486 0.65964 0.95477 0.014262
#> Total effect 3.09249 0.45475 2.31813 4.12551 1.6209e-14
#>
#> Natural effects on RD scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 0.17730 0.03531 0.10810 0.24651 5.1324e-07
#> Indirect effect -0.04923 0.02362 -0.09551 -0.00294 0.037107
#> Total effect 0.12808 0.01928 0.09029 0.16586 3.0695e-11
#>
#> Controlled direct effect (m=-0.5107948):
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> OR scale 2.95657 0.51026 2.10806 4.14661 3.3610e-10
#> RR scale 2.55653 0.37550 1.91702 3.40938 1.6519e-10
#> RD scale 0.12448 0.02269 0.08002 0.16895 4.0962e-08
#>
#>
#> Mediator model:
#>
#>
#> t test of coefficients:
#>
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -1.106404 0.130330 -8.4892 < 2.2e-16 ***
#> X 2.192341 0.165643 13.2354 < 2.2e-16 ***
#> C1 -1.367929 0.160453 -8.5254 < 2.2e-16 ***
#> C2 1.551308 0.080512 19.2680 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#>
#> Outcome model:
#>
#>
#> z test of coefficients:
#>
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -2.902901 0.137920 -21.0477 < 2.2e-16 ***
#> X 0.744396 0.169829 4.3832 1.169e-05 ***
#> M 0.529404 0.061280 8.6391 < 2.2e-16 ***
#> X:M -0.664913 0.073693 -9.0228 < 2.2e-16 ***
#> C1 1.444654 0.181671 7.9520 1.835e-15 ***
#> C2 -0.628551 0.116440 -5.3981 6.736e-08 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
m_cov_cond <- c(C1 = 0.1, C2 = 0.4)
y_cov_cond <- c(C1 = 0.1, C2 = 0.4)
exactmed_c(
data = datamed_c, a = "X", m = "M", y = "Y", a1 = 1, a0 = 0,
m_cov = c("C1", "C2"), y_cov = c("C1", "C2"),
m_cov_cond = m_cov_cond, y_cov_cond = y_cov_cond
)
#>
#> Natural effects on OR scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 2.01489 0.32513 1.46858 2.76442 1.415e-05
#> Indirect effect 0.82739 0.06268 0.71322 0.95983 0.01238028
#> Total effect 1.66710 0.25508 1.23515 2.25010 0.00083701
#>
#> Natural effects on RR scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 1.46552 0.12801 1.23494 1.73916 1.2092e-05
#> Indirect effect 0.91266 0.03285 0.85051 0.97937 0.01110766
#> Total effect 1.33753 0.11689 1.12698 1.58742 0.00087533
#>
#> Natural effects on RD scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 0.17195 0.03903 0.09545 0.24844 1.055e-05
#> Indirect effect -0.04728 0.01884 -0.08420 -0.01035 0.0120976
#> Total effect 0.12467 0.03701 0.05214 0.19720 0.0007549
#>
#> Controlled direct effect (m=-0.5107948):
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> OR scale 2.90424 0.46784 2.11794 3.98247 3.6280e-11
#> RR scale 1.84794 0.17187 1.53999 2.21746 4.0481e-11
#> RD scale 0.25453 0.03752 0.18100 0.32807 1.1685e-11
#>
#>
#> Mediator model:
#>
#>
#> Call:
#> lm(formula = Mform, data = data)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -6.1821 -1.4324 0.0568 1.2604 7.1676
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -0.62373 0.10799 -5.776 1.02e-08 ***
#> X 1.53357 0.12476 12.292 < 2e-16 ***
#> C1 -1.22692 0.12473 -9.837 < 2e-16 ***
#> C2 1.61857 0.06236 25.956 < 2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Residual standard error: 1.971 on 996 degrees of freedom
#> Multiple R-squared: 0.4774, Adjusted R-squared: 0.4758
#> F-statistic: 303.3 on 3 and 996 DF, p-value: < 2.2e-16
#>
#>
#> Outcome model:
#>
#>
#> Call:
#> glm(formula = Yform, family = binomial(link = "logit"), data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.51704 0.13059 -3.959 7.52e-05 ***
#> X 0.74814 0.15871 4.714 2.43e-06 ***
#> M 0.49722 0.05253 9.465 < 2e-16 ***
#> X:M -0.62263 0.06358 -9.793 < 2e-16 ***
#> C1 1.39342 0.16191 8.606 < 2e-16 ***
#> C2 -0.53693 0.09816 -5.470 4.50e-08 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 1377.4 on 999 degrees of freedom
#> Residual deviance: 1102.9 on 994 degrees of freedom
#> AIC: 1114.9
#>
#> Number of Fisher Scoring iterations: 4
#>
C1b <- factor(sample(c("a", "b", "c"), nrow(datamed_c), replace = TRUE))
datamed_c$C1 <- C1b
m_cov_cond <- list(C1 = "c", C2 = 0.4)
y_cov_cond <- list(C1 = "c", C2 = 0.4)
exactmed_c(
data = datamed_c, a = "X", m = "M", y = "Y", a1 = 1, a0 = 0,
m_cov = c("C1", "C2"), y_cov = c("C1", "C2"),
m_cov_cond = m_cov_cond, y_cov_cond = y_cov_cond
)
#>
#> Natural effects on OR scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 2.78347 0.44316 2.03736 3.80283 1.2769e-10
#> Indirect effect 0.72742 0.05111 0.63383 0.83482 5.9179e-06
#> Total effect 2.02475 0.29996 1.51450 2.70691 1.9183e-06
#>
#> Natural effects on RR scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 1.63161 0.12679 1.40110 1.90005 2.9795e-10
#> Indirect effect 0.88284 0.02482 0.83551 0.93285 9.3221e-06
#> Total effect 1.44045 0.11194 1.23695 1.67744 2.6481e-06
#>
#> Natural effects on RD scale:
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> Direct effect 0.25002 0.03708 0.17734 0.32269 1.5548e-11
#> Indirect effect -0.07567 0.01647 -0.10794 -0.04339 4.3320e-06
#> Total effect 0.17435 0.03593 0.10393 0.24477 1.2189e-06
#>
#> Controlled direct effect (m=-0.5107948):
#>
#> Estimate Std.error 2.5% 97.5% P.val
#> OR scale 2.95169 0.45525 2.18166 3.99351 2.2540e-12
#> RR scale 1.68259 0.12982 1.44645 1.95729 1.5429e-11
#> RD scale 0.26380 0.03566 0.19391 0.33368 1.3811e-13
#>
#>
#> Mediator model:
#>
#>
#> Call:
#> lm(formula = Mform, data = data)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -6.6561 -1.4269 0.0105 1.3385 7.7929
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -1.21193 0.13604 -8.909 <2e-16 ***
#> X 1.54303 0.13103 11.776 <2e-16 ***
#> C1b -0.04221 0.16006 -0.264 0.792
#> C1c 0.01169 0.16379 0.071 0.943
#> C2 1.62580 0.06544 24.843 <2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Residual standard error: 2.065 on 995 degrees of freedom
#> Multiple R-squared: 0.4267, Adjusted R-squared: 0.4244
#> F-statistic: 185.1 on 4 and 995 DF, p-value: < 2.2e-16
#>
#>
#> Outcome model:
#>
#>
#> Call:
#> glm(formula = Yform, family = binomial(link = "logit"), data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) 0.09017 0.15105 0.597 0.550540
#> X 0.78456 0.15235 5.150 2.61e-07 ***
#> M 0.36745 0.04707 7.807 5.87e-15 ***
#> X:M -0.58305 0.06030 -9.669 < 2e-16 ***
#> C1b 0.11021 0.17204 0.641 0.521780
#> C1c -0.22692 0.17485 -1.298 0.194357
#> C2 -0.34441 0.09142 -3.767 0.000165 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 1377.4 on 999 degrees of freedom
#> Residual deviance: 1180.4 on 993 degrees of freedom
#> AIC: 1194.4
#>
#> Number of Fisher Scoring iterations: 4
#>