Title: | Bayesian Mediation Analysis |
---|---|
Description: | We perform general mediation analysis in the Bayesian setting using the methods described in Yu and Li (2022, ISBN:9780367365479). With the package, the mediation analysis can be performed on different types of outcomes (e.g., continuous, binary, categorical, or time-to-event), with default or user-defined priors and predictive models. The Bayesian estimates and credible sets of mediation effects are reported as analytic results. |
Authors: | Qingzhao Yu [aut, cre, cph], Bin Li [aut] |
Maintainer: | Qingzhao Yu <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.1 |
Built: | 2024-11-19 06:31:07 UTC |
Source: | CRAN |
Functions in the package are used for Bayesian mediation analysis. Mediation effect refers to the effect conveyed by intervening variables to an observed relationship between an exposure and a response variable (outcome). In this package, the exposure is called the predictor, the intervening variables are called mediators. The mediation effects include the total effect, direct effect, and indirect effect, which are defined and the statistical inferences described in Yu et al.(2014). We use four different method for the mediation analysis (Yu et al. 2022a, Yu et al. 2022b).
Qingzhao Yu [email protected] and Bin Li [email protected]
Maintainer: Qingzhao Yu [email protected]
Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. General Multiple Mediation Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival, Journal of Biometrics and Biostatistics, 5(2):189.
Yu, Q. and Li, B., 2022. Statistical Methods for Mediation, Confounding and Moderation Analysis Using R and SAS. Chapman and Hall/CRC. ISBN 9780367365479.
Yu, Q., Cao, W., Mercante, D., Wu, X,, and Li, B., 2022. Bayesian Mediation Analysis Methods to Explore Racial/Ethnic Disparities in Anxiety Among Cancer Survivors. Accepted by Behaviormetrika.
The function is to perform the Bayesian mediation anlaysis.
bma.bx.cy(pred, m, y, refy = rep(NA, ncol(data.frame(y))), predref = rep(NA, ncol(data.frame(pred))), fpy = NULL, deltap = rep(0.001, ncol(data.frame(pred))), fmy = NULL, deltam = rep(0.001,ncol(data.frame(m))), fpm = NULL, mref = rep(NA, ncol(data.frame(m))), cova = NULL, mcov = NULL, mclist = NULL, inits = NULL, n.chains = 1, n.iter = 1100, n.burnin = 100, n.thin = 1, mu = NULL,Omega = NULL, Omegac = NULL, muc = NULL, mucv = NULL, Omegacv = NULL, mu0.1 = NULL, Omega0.1 = NULL, mu1.1 = NULL, Omega1.1 = NULL, mu0.a = NULL, Omega0.a = NULL, mu1.a = NULL, Omega1.a = NULL, mu0.b =NULL, Omega0.b = NULL, mu1.b = NULL, Omega1.b = NULL, mu0.c = NULL, Omega0.c = NULL, mu1.c = NULL, Omega1.c = NULL, preci = 1e-06, tmax = Inf, multi = NULL,filename=NULL)
bma.bx.cy(pred, m, y, refy = rep(NA, ncol(data.frame(y))), predref = rep(NA, ncol(data.frame(pred))), fpy = NULL, deltap = rep(0.001, ncol(data.frame(pred))), fmy = NULL, deltam = rep(0.001,ncol(data.frame(m))), fpm = NULL, mref = rep(NA, ncol(data.frame(m))), cova = NULL, mcov = NULL, mclist = NULL, inits = NULL, n.chains = 1, n.iter = 1100, n.burnin = 100, n.thin = 1, mu = NULL,Omega = NULL, Omegac = NULL, muc = NULL, mucv = NULL, Omegacv = NULL, mu0.1 = NULL, Omega0.1 = NULL, mu1.1 = NULL, Omega1.1 = NULL, mu0.a = NULL, Omega0.a = NULL, mu1.a = NULL, Omega1.a = NULL, mu0.b =NULL, Omega0.b = NULL, mu1.b = NULL, Omega1.b = NULL, mu0.c = NULL, Omega0.c = NULL, mu1.c = NULL, Omega1.c = NULL, preci = 1e-06, tmax = Inf, multi = NULL,filename=NULL)
pred |
a vector or matrix of exposure variable(s). |
m |
a data frame with all mediators. |
y |
the response variable. |
refy |
the reference group of the response variable if y is binary or categorical. |
predref |
the reference group(s) of the exposure variable(s) by the column of pred. |
fpy |
the transformation function expressions on pred in explaining y (eg, list(1,c("x^2","log(x)"))). The first item lists column numbers/variable names of the exposure variable in pred, which needs to be transformed. By that order, each of the rest items of fpy list the transformation functional expressions for each exposure. The exposures not specified in the list will not be transformed in any way in explaining y. For example, list(1,c("x^2","log(x)")) means that the first column of the pred will be transformed to square and log forms in the function to explain y. |
deltap |
the vector of differences in the exposure variable when calculating the partial differences in methods 2 and 3. The vector is in the order of columns of pred. By default, 0.001 for continuous variables and 1 for binary or categorical exposures. |
fmy |
the transformation function expressions on m in explaining y. The first item lists column numbers/variable names of the mediator in m, which needs to be transformed. By that order, each of the rest items of fmy list the transformation functional expressions for each mediator. The mediators not specified in the list will keep the original formats in explaining y. |
deltam |
the vector of differences in the mediators in calculating the partial difference in y for method 2. The vector is in the order of columns of m. By default, 0.001 for continuous variables and 1 for binary or categorical mediators. |
fpm |
the transformation-function-expression list on exposure variable(s) (pred) in explaining mediators (m). The first item is a matrix with two columns: the first column is the column numbers of the mediators in m, which should be explained by the transformed predictor(s). The second column indicates the column number of the exposure in pred that will be transformed to explain the mediator identified by the 1st column of the same row. By the order of the rows of the first item, each of the rest items of fpm lists the transformation functional expressions for the exposure (identified by column 2) in explaining each mediator (identified by column 1). The mediators not specified in the list will be explained by the original format of the exposures in pred. For example, fpm=list(matrix(c(1,2,1,1),2,2), "x^2",c("x","x^2")) means that pred[,1]^2 is used to explain m[,1], and both pred and pred[,1]^2 are used to explain m[,2]. |
mref |
the reference group of the mediators in the order of the columns of m. |
cova |
the covariates that are used to explain y in addition to pred, m and/or their transformations. |
mcov |
the covariates that are used to explain mediators in additon to pred and/or their tranformations. |
mclist |
If mclist is NULL (by default), all covariates in mcov are used for all mediators in m. Otherwise, the first item of mclist lists all column numbers/names of mediators in m that are to be explained by covariates in mcov, the following items give the covariates in mcov for the mediators in the order of the first item. Use NA if no mcov is to be used. |
inits |
the initial values for parameters in models. For example, inits<-function()list(alpha=0,beta=0,c=0,var1=0.5,r=1,lamda=0.01). |
n.chains |
number of Markov chains. By fault, the number is 1. |
n.iter |
number of total iterations per chain. The default number is 1100. |
n.burnin |
length of burn in, i.e. number of iterations to discard at the beginning. Default is 100. |
n.thin |
thinning rate. Must be a positive integer. Set n.thin > 1 to save memory and computation time if n.iter is large. Default is max(1, floor(n.chains * (n.iter-n.burnin) / 1000)) which will only thin if there are at least 2000 simulations. |
mu |
the prior mean vector (of length P, where P is number of mediators) for coefficients of mediators in the final model for y. By default, all prior mean is 0. |
Omega |
the prior variance-covariance matrix for the coefficients of mediators in the final model for y. The dimension is P*P. By default, all variance-covariance matrix is diagnal with precision term defined by preci. |
Omegac |
the prior variance-covariance matrix for the coefficients of exposure(s) in the final model for y. The dimention is c2*c2. c2 is number of expsoure(s) to predict y. |
muc |
the prior mean vector (of length p2) for coefficients of exposure(s) in the final model for y. |
mucv |
the prior mean vector for coefficients of covariate(s) in the final model for y. |
Omegacv |
the prior variance-covariance matrix for the coefficients of covariate(s) in the final model for y. |
mu0.1 |
the prior mean matrix for coefficients of intercept and covariate(s) in the model for predicting mediators. The dimension is P*nmc, where P is the total number of mediators, and nmc is the total number of covariates (1 is a covarite when intercept is fitted). Note that if there are different numbers of covariates for different mediators, the priors need to specified in the bug model defined in filename. |
Omega0.1 |
the prior variance-covariance matrix for coefficients of intercept and covariate(s) in the model for predicting mediators. The dimension is nmc*nmc. Note that if there are different numbers of covariates for different mediators, the priors need to specified in the bug model defined in filename. |
mu1.1 |
the prior mean matrix for coefficients of exposure(s) in the model for predicting mediators. The dimension is P*c1, where P is the total number of mediators, and c1 is the total number of original exposure(s). Note that if there are different numbers or transformation of exposure(s) for different mediators, the priors need to specified in the bug model defined in filename. |
Omega1.1 |
the prior variance-covariance matrix for coefficients of exposure(s) in the model for predicting mediators. The dimension is c1*c1. Note that if there are different numbers of exposure(s) for coefficients, the priors need to be specified in the bug model defined in filename. |
mu0.a |
the prior mean matrix for coefficients of intercept and covariate(s) in the model for predicting continuous mediators. The dimension is p1*nmc, where p1 is the total number of continuous mediators, and nmc is the total number of covariates (1 is a covarite when intercept is fitted). Note that if there are different numbers of covariates for different mediators, the priors need to specified in the bug model defined in filename. |
Omega0.a |
the prior variance-covariance matrix for coefficients of intercept and covariate(s) in the model for predicting continuous mediators. The dimension is nmc*nmc. Note that if there are different number of covariate(s) for different mediators, the priors need to be specified in the bug model defined in filename. |
mu1.a |
the prior mean matrix for coefficients of exposure(s) in the model for predicting continuous mediators. The dimension is p1*c1, where p1 is the total number of continuous mediators, and c1 is the total number of original exposure(s). Note that if there are different numbers or transformation of exposure(s) for different mediators, the priors need to specified in the bug model defined in filename. |
Omega1.a |
the prior variance-covariance matrix for coefficients of exposure(s) in the model for predicting continuous mediators. The dimension is c1*c1. Note that if there are different numbers of exposure(s) for each mediator, the priors need to be specified in the bug model defined in filename. |
mu0.b |
the prior mean matrix for coefficients of intercept and covariate(s) in the model for predicting binary mediators. The dimension is p2*nmc, where p2 is the total number of binary mediators, and nmc is the total number of covariates (1 is a covarite when intercept is fitted). Note that if there are different numbers of covariates for different mediators, the priors need to specified in the bug model defined in filename. |
Omega0.b |
the prior variance-covariance matrix for coefficients of intercept and covariate(s) in the model for predicting binary mediators. The dimension is nmc*nmc. Note that if there are different number of covariate(s) for different mediators, the priors need to be specified in the bug model defined in filename. |
mu1.b |
the prior mean matrix for coefficients of exposure(s) in the model for predicting binary mediators. The dimension is p2*c1, where p2 is the total number of binary mediators, and c1 is the total number of original exposure(s). Note that if there are different numbers or transformation of exposure(s) for different mediators, the priors need to specified in the bug model defined in filename. |
Omega1.b |
the prior variance-covariance matrix for coefficients of exposure(s) in the model for predicting binary mediators. The dimension is c1*c1. Note that if there are different numbers of exposure(s) for each mediator, the priors need to be specified in the bug model defined in filename. |
mu0.c |
the prior mean matrix for coefficients of intercept and covariate(s) in the model for predicting categorical mediators. The dimension is p3*cat1*nmc, where p3 is the total number of categorical mediators, cat1 is the biggest number of categories for all categorical mediators, and nmc is the total number of covariates (1 is a covarite when intercept is fitted). Note that if there are different numbers of covariates for different mediators, the priors need to specified in the bug model defined in filename. |
Omega0.c |
the prior variance-covariance matrix for coefficients of intercept and covariate(s) in the model for predicting categorical mediators. The dimension is nmc*nmc. Note that if there are different number of covariate(s) for different mediators, the priors need to be specified in the bug model defined in filename. |
mu1.c |
the prior mean matrix for coefficients of exposure(s) in the model for predicting categorical mediators. The dimension is p3*c1, where p3 is the total number of categorical mediators, and c1 is the total number of original exposure(s). Note that if there are different numbers or transformation of exposure(s) for different mediators, the priors need to specified in the bug model defined in filename. |
Omega1.c |
the prior variance-covariance matrix for coefficients of exposure(s) in the model for predicting categorical mediators. The dimension is c1*c1. Note that if there are different numbers of exposure(s) for each mediator, the priors need to be specified in the bug model defined in filename. |
preci |
define the precision term in the diagnoal variance-covariance matrix. |
tmax |
the maximum suvival time if the outcome is time-to-event. |
multi |
if true, report the productive effect. |
filename |
If specified, filename gives the bugs model with folder direction, e.g., "C:/bugs.txt". If not specified, a bugs model will be generated automatically. |
In this function, data_org is called first and then jags is called for a Bayesian model fitting. Finally, three different Bayesian mediation analysis methods are used to make inferences on mediation effects.
aie1 |
The average indiect effect from method 1. The dimension is (n.iter-n.burnin)*(# of mediators)*(# of exposures). |
ade1 |
The average diect effect from method 1. The dimension is (n.iter-n.burnin)*(# of exposures). |
ate1 |
The average total effect from method 1. The dimension is (n.iter-n.burnin)*(# of exposures). |
aie2 |
The average indiect effect from method 2. The dimension is (n.iter-n.burnin)*(# of mediators)*(# of exposures). |
ade2 |
The average diect effect from method 2. The dimension is (n.iter-n.burnin)*(# of exposures). |
ate2 |
The average total effect from method 2. The dimension is (n.iter-n.burnin)*(# of exposures). |
aie3 |
The average indiect effect from method 3. The dimension is (n.iter-n.burnin)*(# of mediators)*(# of exposures). |
ade3 |
The average diect effect from method 3. The dimension is (n.iter-n.burnin)*(# of exposures). |
ate3 |
The average total effect from method 3. The dimension is (n.iter-n.burnin)*(# of exposures). |
aie4 |
The average indiect effect from method 4. The dimension is (n.iter-n.burnin)*(# of mediators)*(# of exposures). |
ade4 |
The average diect effect from method 4. The dimension is (n.iter-n.burnin)*(# of exposures). |
ate4 |
The average total effect from method 4. The dimension is (n.iter-n.burnin)*(# of exposures). |
sims.list |
The Bayesian model fitting results from japs. |
data0 |
The fitting results from data_org. |
omu3 |
When the outcome is time-to-event, omu3 gives the mean survival at the original data for method 3. |
omu4 |
When the outcome is time-to-event, omu4 gives the mean survival at the original data for method 4. |
Qingzhao Yu and Bin Li
data("weight_behavior") #n.iter and n.burnin are set to be very small, should be adjusted #binary predictor test.b.c<- bma.bx.cy(pred=weight_behavior[,3], m=weight_behavior[,c(14,12,13)], y=weight_behavior[,1],n.iter=5,n.burnin = 1) summary(test.b.c) #categorical predictor test.ca.c<- bma.bx.cy(pred=weight_behavior[,4], m=weight_behavior[,12:14], y=weight_behavior[,1],n.iter=5,n.burnin = 1) summary(test.ca.c) #use covariate for y test.b.c.2<- bma.bx.cy(pred=weight_behavior[,3], m=weight_behavior[,12:14], y=weight_behavior[,1],cova=weight_behavior[,2],n.iter=10,n.burnin = 1) summary(test.b.c.2) #use covariate for mediators test.b.c.3<- bma.bx.cy(pred=weight_behavior[,3], m=weight_behavior[,c(9,12:14)], y=weight_behavior[,1],mcov=weight_behavior[,c(2,5)], mclist = list(1,2),n.iter=5,n.burnin = 1) summary(test.b.c.3) #use continuous predictor test.c.c<- bma.bx.cy(pred=weight_behavior[,2], m=weight_behavior[,12:14], y=weight_behavior[,1],n.iter=5,n.burnin = 1) summary(test.c.c,method=3) #use transfered continuous predictor for y test.c.c.2<- bma.bx.cy(pred=weight_behavior[,2], m=weight_behavior[,12:14], y=weight_behavior[,1],fpy=list(1,c("x","x^2")),n.iter=5,n.burnin = 1) summary(test.c.c.2,method=1) #multiple predictors test.m.c<- bma.bx.cy(pred=weight_behavior[,2:4], m=weight_behavior[,12:14], y=weight_behavior[,1],n.iter=10,n.burnin = 1) summary(test.m.c,method=3) ##binary outcome test.m.b<- bma.bx.cy(pred=weight_behavior[,2:4], m=weight_behavior[,12:14], y=weight_behavior[,15],cova=weight_behavior[,5],n.iter=5,n.burnin = 1) summary(test.m.b,method=2) ##time-to-event outcome #use a simulation set.seed(1) N=100 alpha=0.5 x=rnorm(N,0,1) x=ifelse(x>0,1,0) e1=rnorm(N,0,1) M=alpha*x+e1 lambda=0.01 rho=1 beta=1.2 c=-1 rateC=0.001 v=runif(n=N) Tlat =(- log(v) / (lambda * exp(c*x+M*beta)))^(1 / rho) C=rexp(n=N, rate=rateC) time=pmin(Tlat, C) status <- as.numeric(Tlat <= C) test.m.t.1<- bma.bx.cy(pred=x, m=M,y=Surv(time,status),inits=function(){ list(r=1,lambda=0.01)},n.iter=10,n.burnin = 1) temp1=summary(test.m.t.1) print(temp1,method=1,RE=FALSE) ##categorical outcome test.m.c<- bma.bx.cy(pred=weight_behavior[,2:4], m=weight_behavior[,12:13], y=weight_behavior[,14],cova=weight_behavior[,5],n.iter=5,n.burnin = 1) summary(test.m.c,method=3)
data("weight_behavior") #n.iter and n.burnin are set to be very small, should be adjusted #binary predictor test.b.c<- bma.bx.cy(pred=weight_behavior[,3], m=weight_behavior[,c(14,12,13)], y=weight_behavior[,1],n.iter=5,n.burnin = 1) summary(test.b.c) #categorical predictor test.ca.c<- bma.bx.cy(pred=weight_behavior[,4], m=weight_behavior[,12:14], y=weight_behavior[,1],n.iter=5,n.burnin = 1) summary(test.ca.c) #use covariate for y test.b.c.2<- bma.bx.cy(pred=weight_behavior[,3], m=weight_behavior[,12:14], y=weight_behavior[,1],cova=weight_behavior[,2],n.iter=10,n.burnin = 1) summary(test.b.c.2) #use covariate for mediators test.b.c.3<- bma.bx.cy(pred=weight_behavior[,3], m=weight_behavior[,c(9,12:14)], y=weight_behavior[,1],mcov=weight_behavior[,c(2,5)], mclist = list(1,2),n.iter=5,n.burnin = 1) summary(test.b.c.3) #use continuous predictor test.c.c<- bma.bx.cy(pred=weight_behavior[,2], m=weight_behavior[,12:14], y=weight_behavior[,1],n.iter=5,n.burnin = 1) summary(test.c.c,method=3) #use transfered continuous predictor for y test.c.c.2<- bma.bx.cy(pred=weight_behavior[,2], m=weight_behavior[,12:14], y=weight_behavior[,1],fpy=list(1,c("x","x^2")),n.iter=5,n.burnin = 1) summary(test.c.c.2,method=1) #multiple predictors test.m.c<- bma.bx.cy(pred=weight_behavior[,2:4], m=weight_behavior[,12:14], y=weight_behavior[,1],n.iter=10,n.burnin = 1) summary(test.m.c,method=3) ##binary outcome test.m.b<- bma.bx.cy(pred=weight_behavior[,2:4], m=weight_behavior[,12:14], y=weight_behavior[,15],cova=weight_behavior[,5],n.iter=5,n.burnin = 1) summary(test.m.b,method=2) ##time-to-event outcome #use a simulation set.seed(1) N=100 alpha=0.5 x=rnorm(N,0,1) x=ifelse(x>0,1,0) e1=rnorm(N,0,1) M=alpha*x+e1 lambda=0.01 rho=1 beta=1.2 c=-1 rateC=0.001 v=runif(n=N) Tlat =(- log(v) / (lambda * exp(c*x+M*beta)))^(1 / rho) C=rexp(n=N, rate=rateC) time=pmin(Tlat, C) status <- as.numeric(Tlat <= C) test.m.t.1<- bma.bx.cy(pred=x, m=M,y=Surv(time,status),inits=function(){ list(r=1,lambda=0.01)},n.iter=10,n.burnin = 1) temp1=summary(test.m.t.1) print(temp1,method=1,RE=FALSE) ##categorical outcome test.m.c<- bma.bx.cy(pred=weight_behavior[,2:4], m=weight_behavior[,12:13], y=weight_behavior[,14],cova=weight_behavior[,5],n.iter=5,n.burnin = 1) summary(test.m.c,method=3)
The function is used to identify exposure, mediator, covariate, and outcome variables and organize the data into formats usable for the mediaiton analysis. The function is called by bma.bx.cy function before doing the Bayesian mediation analysis.
data_org(pred, m, y, refy = rep(NA, ncol(data.frame(y))), predref = rep(NA, ncol(data.frame(pred))),fpy = NULL, deltap = rep(0.001, ncol(data.frame(pred))), fmy = NULL, deltam = rep(0.001,ncol(data.frame(m))), fpm = NULL, mref = rep(NA, ncol(data.frame(m))), cova = NULL, mcov = NULL, mclist = NULL)
data_org(pred, m, y, refy = rep(NA, ncol(data.frame(y))), predref = rep(NA, ncol(data.frame(pred))),fpy = NULL, deltap = rep(0.001, ncol(data.frame(pred))), fmy = NULL, deltam = rep(0.001,ncol(data.frame(m))), fpm = NULL, mref = rep(NA, ncol(data.frame(m))), cova = NULL, mcov = NULL, mclist = NULL)
pred |
a vector or matrix of exposure variable(s). |
m |
a data frame with all mediators. |
y |
the response variable. |
refy |
the reference group of the response variable if y is binary or categorical. |
predref |
the reference group(s) of the exposure variable(s) by the column of pred. |
fpy |
the transformation function expressions on pred in explaining y (eg, list(1,c("x^2","log(x)"))). The first item lists column numbers/variable names of the exposure variable in pred, which needs to be transformed. By that order, each of the rest items of fpy list the transformation functional expressions for each exposure. The exposures not specified in the list will not be transformed in any way in explaining y. For example, list(1,c("x^2","log(x)")) means that the first column of the pred will be transformed to square and log forms in the function to explain y. |
deltap |
the vector of differences in the exposure variable when calculating the partial differences in methods 2 and 3. The vector is in the order of columns of pred. By default, 0.001 for continuous variables and 1 for binary or categorical exposures. |
fmy |
the transformation function expressions on m in explaining y. The first item lists column numbers/variable names of the mediator in m, which needs to be transformed. By that order, each of the rest items of fmy list the transformation functional expressions for each mediator. The mediators not specified in the list will keep the original formats in explaining y. |
deltam |
the vector of differences in the mediators in calculating the partial difference in y for method 2. The vector is in the order of columns of m. By default, 0.001 for continuous variables and 1 for binary or categorical mediators. |
fpm |
the transformation-function-expression list on exposure variable(s) (pred) in explaining mediators (m). The first item is a matrix with two columns: the first column is the column numbers of the mediators in m, which should be explained by the transformed predictor(s). The second column indicates the column number of the exposure in pred that will be transformed to explain the mediator identified by the 1st column of the same row. By the order of the rows of the first item, each of the rest items of fpm lists the transformation functional expressions for the exposure (identified by column 2) in explaining each mediator (identified by column 1). The mediators not specified in the list will be explained by the original format of the exposures in pred. For example, fpm=list(matrix(c(1,2,1,1),2,2), "x^2",c("x","x^2")) means that pred[,1]^2 is used to explain m[,1], and both pred[,1] and pred[,1]^2 are used to explain m[,2]. |
mref |
the reference group of the mediators in the order of the columns of m. |
cova |
the covariates that are used to explain y in addition to pred, m and/or their transformations. |
mcov |
the covariates that are used to explain mediators in additon to pred and/or their transformations. |
mclist |
If mclist is NULL (by default), all covariates in mcov are used for all mediators in m. Otherwise, the first item of mclist lists all column numbers/names of mediators in m that are to be explained by covariates in mcov, the following items give the covariates in mcov for the mediators in the order of the first item. Use NA if no mcov is to be used. |
The function returns a list with transformed and organized data with the following items:
N |
total number of obserations. |
y_type |
the data type of y: 1 for continuous, 2 is binary, 3 for categorical, and 4 is time-to-event outcome. |
y |
the response variable. |
pred1 |
exposure variable(s) in original formats, pred. |
pred1.0 |
exposure variable(s) in original formats if continuous, binarized if binary or categorical. |
pred2 |
all the exposure variables with transformations for y. |
pred3 |
all the exposure variables with transformations for y and continuous variable be pred+deltap. |
cova |
the covariance data frame for explaining y. |
pred.cont.der |
the derivative functions of the continuous exposure variables to explain y. |
binpred2 |
the column numbers of binary exposures in pred2. |
catpred2 |
the column numbers of categorical exposures in pred2. Each row is for one categorical exposure variable: column 1 is the starting column and column 2 is the ending column in pred2. |
contpred2 |
the column numbers of continuous exposures in pred2. Each row is for one continuous exposure variable: column 1 is the starting column and column 2 is the ending column in pred2. |
binpred1 |
the column numbers of binary exposures in pred1. |
catpred1 |
the column numbers of categorical exposures in pred1. |
contpred1 |
the column numbers of continuous exposures in pred1. |
binpred1.0 |
the column numbers of binary exposures in pred1.0. |
catpred1.0 |
the column numbers of categorical exposures in pred1.0. Each row is for one categorical exposure variable: column 1 is the starting column and column 2 is the ending column in pred2. |
contpred1.0 |
the column numbers of continuous exposures in pred1.0. |
contpred3 |
the column numbers of continuous exposures in pred3 and in pred.cont.der. Each row is for one continuous exposure variable: column 1 is the starting column and column 2 is the ending column in pred3. |
npred |
the number of exposure variables. |
m1 |
the mediators in their original format. |
m2 |
the mediators all transformed to formats in explaining y. |
m3 |
transformed continuous mediators at the value of mediator+deltam. |
m.cont.der |
derivative of the transformation functions for continuous mediators. |
binm2 |
the column number of binary mediators in m2. |
catm2 |
the column number of categorical mediators in m2. Each row is for one categorical mediator: column 1 is the starting column and column 2 is the ending column in m2. |
contm2 |
the column number of continuous mediators in m2. Each row is for one continuous mediator: column 1 is the starting column and column 2 is the ending column in m2. |
binm1 |
the column number of binary mediators in m1. |
catm1 |
the column number of categorical mediators in m1. |
contm1 |
the column number of continuous mediators in m1. |
contm3 |
the column numbers of continuous mediators in m3 and in m.cont.der. Each row is for one continuous mediator: column 1 is the starting column and column 2 is the ending column in m3 and m.cont.der. |
nm |
total number of mediators. |
pm |
the matrix of exposures with transformations that are used to explain mediators. The first column is all 0s. |
pm.der |
the derivative matrix of exposures and transformed exposures that are used to explain mediators. |
pm.idx |
a list, with the ith item gives the column numbers in pm that are used to explain the ith mediator. |
pm.ind |
a matrix, with the ith row gives the column numbers in pm that are used to explain the ith mediator. |
fpm.2 |
a list similar to fpm. |
binp |
the column number of binary exposures in pm. |
catp |
the column number of categorical exposures in pm. Each row is for one categorical exposure: column 1 is the starting column and column 2 is the ending column in pm. |
contp |
the column number of continuous exposures in pm. Each row is for one continuous exposure: column 1 is the starting column and column 2 is the ending column in pm. |
p1 |
the number of continuous mediators. |
p2 |
the number of binary mediators. |
p3 |
the number of categorical mediators. |
mcov |
the matrix of all covariates for explaining mediators. |
mind |
a matrix with the ith row indicate the columns of covariates in mcov that should be used to explain the ith mediator. |
Qingzhao Yu and Bin Li
Print the summary results from summary.bma.bx.cy.
## S3 method for class 'summary.bma' print(x, ..., digit = x$digit, method = x$method, RE = x$RE)
## S3 method for class 'summary.bma' print(x, ..., digit = x$digit, method = x$method, RE = x$RE)
x |
the oject from summary.bma.bx.cy. |
... |
other arguments. |
digit |
the nubmer of digits to be printed. |
method |
the method to be used. |
RE |
if ture, print the relative effect |
Print and plot from the summary of bma.bx.cy.
Qingzhao Yu and Bin Li
# see example at bma.bx.cy.
# see example at bma.bx.cy.
Calculate the Bayesian estimates, standard deviations and credible sets for the mediation effects.
## S3 method for class 'bma.bx.cy' summary(object, ..., plot = TRUE, RE = TRUE, quant = c(0.025, 0.25, 0.5, 0.75, 0.975), digit = 4, method = 3)
## S3 method for class 'bma.bx.cy' summary(object, ..., plot = TRUE, RE = TRUE, quant = c(0.025, 0.25, 0.5, 0.75, 0.975), digit = 4, method = 3)
object |
The bma.bx.cy object which is the outcome of the function bam.bx.cy. |
... |
arguments to be passed to methods. |
plot |
If plot is True (default), plot the estimated (relative) effects with the predicted credit sets, using method specified by method. |
RE |
If RE is true, the relative effect plot is drawn. |
quant |
The quantiles of the estimates to be reported. By default, the quantiles are c(0.025, 0.25, 0.5, 0.75, 0.975). |
digit |
The number of digit to print in the result. |
method |
The method is printing to be used for estimation. |
This function returns an object that has the following items:
result1 |
The result of (in)direct estimates from method 1. |
result1.re |
The result of relative (in)direct estimates from method 1. |
result2 |
The result of (in)direct estimates from method 2. |
result2.re |
The result of relative (in)direct estimates from method 2. |
result3 |
The result of (in)direct estimates from method 3. |
result3.re |
The result of relative (in)direct estimates from method 3. |
result4 |
The result of (in)direct estimates from method 4. |
result4.re |
The result of relative (in)direct estimates from method 4. |
Qingzhao Yu and Ari Li.
# See examples at bma.bx.cy.
# See examples at bma.bx.cy.
This database was obtained from the Louisiana State University Health Sciences Center, New Orleans, by Dr. Richard Scribner. He explored the relationship between BMI and kids behavior through a survey at children, teachers and parents in Grenada in 2014. This data set includes 691 observations and 15 variables.
data(weight_behavior)
data(weight_behavior)
The data set contains the following variables:
bmi - body mass index, calculated by weight(kg)/height(cm)^2, numeric
age - children's age in years at the time of survey, numeric
sex - sex of the children, factor
race - race of the children, factor
numpeople - number of people in family, numeric
car - the number of cars in family, numeric
gotosch - the method used to go to school, factor
snack - eat snack or not in a day, binary
tvhours - number of hours watching TV per week, numeric
cmpthours - number of hours using computer per week, numeric
cellhours - number of hours playing with cell phones per week, numeric
sports - join in a sport team or not, 1: yes; and 2: no
exercises - number of hours of exercises per week, numeric
sweat - number of hours of sweating activities per week, numeric
overweigh - the child is overweighed or not, binary
data(weight_behavior) names(weight_behavior)
data(weight_behavior) names(weight_behavior)