Title: | Mediation Analysis Based on the Product Method |
---|---|
Description: | Functions for calculating the point and interval estimates of the natural indirect effect (NIE), total effect (TE), and mediation proportion (MP), based on the product approach. We perform the methods considered in Cheng, Spiegelman, and Li (2021) Estimating the natural indirect effect and the mediation proportion via the product method. |
Authors: | Chao Cheng; Donna Spiegelman; Fan Li |
Maintainer: | Chao Cheng <[email protected]> |
License: | GPL |
Version: | 0.2.0 |
Built: | 2025-02-14 05:26:11 UTC |
Source: | https://github.com/cran/mediateP |
Function for calculating the point and interval estimates for the NIE, TE and MP, based on the product method.
mediate(data, outcome, mediator, exposure, binary.outcome, binary.mediator, covariate.outcome, covariate.mediator, x0, x1, c.outcome, c.mediator, boot, R)
mediate(data, outcome, mediator, exposure, binary.outcome, binary.mediator, covariate.outcome, covariate.mediator, x0, x1, c.outcome, c.mediator, boot, R)
data |
(Required) The name of the dataset. |
outcome |
(Required) Name of the outcome variable, which should be either a continuous or binary datatype. |
mediator |
(Required) Name of the mediator variable, which should be either a continuous or binary datatype. |
exposure |
(Required) Name of the exposure variable, which should be either a continuous or binary datatype. |
binary.outcome |
(Required) If the outcome is binary, set to 1. If the outcome is continuous, set to 0. |
binary.mediator |
(Required) If the mediator is binary, set to 1. If the mediator is continuous, set to 0. |
covariate.outcome |
A vector of names showing the confounding variables used in the outcome model. The default value is NULL, which represents no confounding variables. We only accepted continuous and binary confounding variables, if one confounding variable is categorical, please set it to a series of binary variables in advance. |
covariate.mediator |
A vector of names showing the confounding variables used in the mediator model. The default value is NULL, which represents no confounding variables. We only accepted continuous and binary confounding variables, if one confounding variable is categorical, please set it to a series of binary variables in advance. |
x0 |
The baseline exposure level (i.e., $x^*$). The default value is 0. |
x1 |
The new exposure level (i.e., $x$). The default value is 1. |
c.outcome |
A vector of numbers representing the conditional level of the confounding variables in the outcome model. The default value is a vector of 0. |
c.mediator |
A vector of numbers representing the conditional level of the confounding variables in the mediator model. The default value is a vector of 0. |
boot |
If a percentile bootstrap confidence interval needed to be added, set to 1. Otherwise, set to 0. The default value is 0. |
R |
(Required if using bootstrap approach) The number of replications when apply the percentile bootstrap method to calculate the confidence interval. The default value is 2,000. |
A list presents the mediation analysis results, which includes two components. The first component ‘res’ presents the point estimator, standard error, and the 95% confidence interval for the NIE, TE, and MP; the second component ‘class’ clarifies this is a ‘mediate’ object.
Chao Cheng ([email protected]), Donna Spiegelman, Fan Li
Cheng C, Spiegelman D, Li F. Estimating the natural indirect effect and the mediation proportion via the product method. BMC medical research methodology. 2021 Dec;21(1):1-20.
## Generate a data set including two confounders (C1 and C2), one binary ## mediator (M), one binary exposure (X), one binary outcome (Y1), and ## one continuous outcome (Y2) C1=rnorm(2000)>0 C2=rnorm(2000) X = rnorm(2000) M= as.numeric(runif(2000)< 1/(1+exp(0-0.9*X+0.1*C1))) Y1= as.numeric(runif(2000)< 1/(1+exp(-(-2+0.5*X+0.5*M+0.2*C1+0.2*C2)))) Y2= -2+0.9*X-0.6*M+0.2*C1+0.2*C2+rnorm(2000,mean=0,sd=1) mydata=as.data.frame(cbind(Y1,Y2,M,X,C1,C2)) ## Example 1: Mediation analysis for X in change from 0 to 1 on Outcome Y1. ## In the outcome model, we adjusted for C1 and C2. In the mediator model, ## we only adjusted for C1. We calculated the NIE, TE and MP for exposure in ## change from 0 to 1, conditional on C1=0 and C2=1. result=mediate(data=mydata, outcome="Y1", mediator="M", exposure="X", binary.outcome=1, binary.mediator=1, covariate.outcome=c("C1","C2"), covariate.mediator=c("C1"), x0=0, x1=1, c.outcome=c(0,1), c.mediator=c(0), boot=0) print(result) ## Example 2: Mediation analysis for X in change from 0 to 1 on Outcome Y2. ## In the outcome model, we adjusted for C1 and C2. In the mediator model, ## we did not adjust for any confounders. We calculated the NIE, TE and MP ## for exposure in change from 0 to 1, conditional on C1=0 and C2=1. result=mediate(data=mydata, outcome="Y2", mediator="M", exposure="X", binary.outcome=0, binary.mediator=1, covariate.outcome=c("C1","C2"), covariate.mediator=NULL, x0=0, x1=1, c.outcome=c(0,1), c.mediator=NULL, boot=0) print(result) ## Example 3: Mediation analysis without any confounding adjustment ## We conduct mediation analysis for X in change from 0 to 1 on Outcome ## Y1, but here no confounders in the outcome and mediator models were ## considered. result=mediate(data=mydata, outcome="Y1", mediator="M", exposure="X", binary.outcome=1, binary.mediator=1, covariate.outcome=NULL, covariate.mediator=NULL, x0=0, x1=1, c.outcome=NULL, c.mediator=NULL, boot=0) print(result)
## Generate a data set including two confounders (C1 and C2), one binary ## mediator (M), one binary exposure (X), one binary outcome (Y1), and ## one continuous outcome (Y2) C1=rnorm(2000)>0 C2=rnorm(2000) X = rnorm(2000) M= as.numeric(runif(2000)< 1/(1+exp(0-0.9*X+0.1*C1))) Y1= as.numeric(runif(2000)< 1/(1+exp(-(-2+0.5*X+0.5*M+0.2*C1+0.2*C2)))) Y2= -2+0.9*X-0.6*M+0.2*C1+0.2*C2+rnorm(2000,mean=0,sd=1) mydata=as.data.frame(cbind(Y1,Y2,M,X,C1,C2)) ## Example 1: Mediation analysis for X in change from 0 to 1 on Outcome Y1. ## In the outcome model, we adjusted for C1 and C2. In the mediator model, ## we only adjusted for C1. We calculated the NIE, TE and MP for exposure in ## change from 0 to 1, conditional on C1=0 and C2=1. result=mediate(data=mydata, outcome="Y1", mediator="M", exposure="X", binary.outcome=1, binary.mediator=1, covariate.outcome=c("C1","C2"), covariate.mediator=c("C1"), x0=0, x1=1, c.outcome=c(0,1), c.mediator=c(0), boot=0) print(result) ## Example 2: Mediation analysis for X in change from 0 to 1 on Outcome Y2. ## In the outcome model, we adjusted for C1 and C2. In the mediator model, ## we did not adjust for any confounders. We calculated the NIE, TE and MP ## for exposure in change from 0 to 1, conditional on C1=0 and C2=1. result=mediate(data=mydata, outcome="Y2", mediator="M", exposure="X", binary.outcome=0, binary.mediator=1, covariate.outcome=c("C1","C2"), covariate.mediator=NULL, x0=0, x1=1, c.outcome=c(0,1), c.mediator=NULL, boot=0) print(result) ## Example 3: Mediation analysis without any confounding adjustment ## We conduct mediation analysis for X in change from 0 to 1 on Outcome ## Y1, but here no confounders in the outcome and mediator models were ## considered. result=mediate(data=mydata, outcome="Y1", mediator="M", exposure="X", binary.outcome=1, binary.mediator=1, covariate.outcome=NULL, covariate.mediator=NULL, x0=0, x1=1, c.outcome=NULL, c.mediator=NULL, boot=0) print(result)
Mediation analysis function for binary outcome and binary mediator.
mediate_binaY_binaM( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0) )
mediate_binaY_binaM( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0) )
data |
A dataset. |
outcome |
The outcome variable. |
mediator |
The mediator variable. |
exposure |
The exposure variable. |
covariateY |
A vector of confounders in the outcome regression. |
covariateM |
A vector of confounders in the mediator regression. |
x0 |
The baseline exposure level. |
x1 |
The new exposure level. |
cY |
conditional levels of covariateY |
cM |
conditional levels of covariateM |
A list containing NIE, NDE and MP point and interval estimates.
Using bootstrap to calculate the confidence intervals in the scenario of binary outcome and binary mediator.
Mediate_binaY_binaM_bootci( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0), R = 1000 )
Mediate_binaY_binaM_bootci( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0), R = 1000 )
data |
A dataset. |
outcome |
The outcome variable. |
mediator |
The mediator variable. |
exposure |
The exposure variable. |
covariateY |
A vector of confounders in the outcome regression. |
covariateM |
A vector of confounders in the mediator regression. |
x0 |
The baseline exposure level. |
x1 |
The new exposure level. |
cY |
conditional levels of covariateY |
cM |
conditional levels of covariateM |
R |
The number of replications. |
The 95
Mediation analysis function for binary outcome and continuous mediator
mediate_binaY_contM( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0) )
mediate_binaY_contM( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0) )
data |
A dataset. |
outcome |
The outcome variable. |
mediator |
The mediator variable. |
exposure |
The exposure variable. |
covariateY |
A vector of confounders in the outcome regression. |
covariateM |
A vector of confounders in the mediator regression. |
x0 |
The baseline exposure level. |
x1 |
The new exposure level. |
cY |
conditional levels of covariateY |
cM |
conditional levels of covariateM |
A list containing NIE, NDE and MP point and interval estimates.
Using bootstrap to calculate the confidence intervals in the scenario of binary outcome and continuous mediator.
Mediate_binaY_contM_bootci( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0), R = 1000 )
Mediate_binaY_contM_bootci( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0), R = 1000 )
data |
A dataset. |
outcome |
The outcome variable. |
mediator |
The mediator variable. |
exposure |
The exposure variable. |
covariateY |
A vector of confounders in the outcome regression. |
covariateM |
A vector of confounders in the mediator regression. |
x0 |
The baseline exposure level. |
x1 |
The new exposure level. |
cY |
conditional levels of covariateY |
cM |
conditional levels of covariateM |
R |
The number of replications. |
The 95
Mediation analysis function for continuous outcome and binary mediator
mediate_contY_binaM( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0) )
mediate_contY_binaM( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0) )
data |
A dataset. |
outcome |
The outcome variable. |
mediator |
The mediator variable. |
exposure |
The exposure variable. |
covariateY |
A vector of confounders in the outcome regression. |
covariateM |
A vector of confounders in the mediator regression. |
x0 |
The baseline exposure level. |
x1 |
The new exposure level. |
cY |
conditional levels of covariateY |
cM |
conditional levels of covariateM |
A list containing NIE, NDE and MP point and interval estimates.
Using bootstrap to calculate the confidence intervals in the scenario of continuous outcome and binary mediator.
Mediate_contY_binaM_bootci( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0), R = 1000 )
Mediate_contY_binaM_bootci( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, cY = c(0, 0), cM = c(0, 0), R = 1000 )
data |
A dataset. |
outcome |
The outcome variable. |
mediator |
The mediator variable. |
exposure |
The exposure variable. |
covariateY |
A vector of confounders in the outcome regression. |
covariateM |
A vector of confounders in the mediator regression. |
x0 |
The baseline exposure level. |
x1 |
The new exposure level. |
cY |
conditional levels of covariateY |
cM |
conditional levels of covariateM |
R |
The number of replications. |
The 95
Mediation analysis function for continuous outcome and mediator
mediate_contY_contM( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1 )
mediate_contY_contM( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1 )
data |
A dataset. |
outcome |
The outcome variable. |
mediator |
The mediator variable. |
exposure |
The exposure variable. |
covariateY |
A vector of confounders in the outcome regression. |
covariateM |
A vector of confounders in the mediator regression. |
x0 |
The baseline exposure level. |
x1 |
The new exposure level. |
A list containing NIE, NDE and MP point and interval estimates.
Using bootstrap to calculate the confidence intervals in the scenario of continuous outcome and continuous mediator.
Mediate_contY_contM_bootci( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, R = 1000 )
Mediate_contY_contM_bootci( data, outcome = "Y", mediator = "M", exposure = "X", covariateY = c("X1", "X2"), covariateM = c("X1", "X2"), x0 = 0, x1 = 1, R = 1000 )
data |
A dataset. |
outcome |
The outcome variable. |
mediator |
The mediator variable. |
exposure |
The exposure variable. |
covariateY |
A vector of confounders in the outcome regression. |
covariateM |
A vector of confounders in the mediator regression. |
x0 |
The baseline exposure level. |
x1 |
The new exposure level. |
R |
The number of replications. |
The 95
Function to print mediation results.
## S3 method for class 'mediate' print(x, ...)
## S3 method for class 'mediate' print(x, ...)
x |
An object of class 'mediate'. |
... |
other parameters in 'print'. |
Print the mediation analysis results, including the point estimation, standard errors, and the 95% confidence interval.