boot.med: Statistical Inference on Mediation Analysis with Continuous...

View source: R/mma.r

boot.medR Documentation

Statistical Inference on Mediation Analysis with Continuous or Binary Predictor

Description

To make inferences on the mediation effects when the predictor is continuous or binary.

Usage

boot.med(data,x=data$x, y=data$y,dirx=data$dirx,binm=data$binm,
         contm=data$contm,catm=data$catm,jointm=data$jointm, 
         cova=data$cova, margin=1,n=20,
         nonlinear=FALSE,df1=1,nu=0.001,D=3,distn=NULL,family1=data$family1,
         n2=50,w=rep(1,nrow(x)),refy=NULL,x.new=x,pred.new=dirx,
         cova.new=cova,binpred=data$binpred,type=NULL,
         w.new=NULL,all.model=FALSE,xmod=NULL,custom.function=NULL,para=FALSE,echo=TRUE)

Arguments

data

the list of result from data.org that organize the covariates, mediators, predictor and outcome. If data is FALSE, then need to set x, y, dirx, contm, catm, and jointm.

x

a data frame contains all mediators and covariates. Need to set up only when data is FALSE. All varaibles in x that are not identified as potential mediators (by mediator, contmed, binmed, catmed, or jointm) are forced in mediation analysis as covariates.

y

the vector of outcome variable. Need to set up only when data is FALSE.

dirx

the vector/matrix of predictor(s). Need to set up only when data is FALSE.

binm

the variable names or the column number of x that locates the binary mediators. Need to set up only when data is FALSE.

contm

the variable names or the column numbers of x that locate the potential continuous mediators. Need to set up only when data is FALSE.

catm

categorical mediators should be binarized and be presented as a list, where the first item is the number of categorical variables and the following items are the names or the column numbers of each binarized categorical variable in x. data.org organizes the categorical mediators in this format after they pass the mediator tests. Need to set up only when data is FALSE.

jointm

a list where the first item is the number of groups of joint mediators to be considered, and each of the following items identifies the names or the column numbers of the mediators in x for each group of joint mediators. Need to set up only when data is FALSE.

cova

The data frame of covariates to be used to predict the mediator(s). The covariates in cova cannot be potential mediators. If the covariates are for some specific potential mediators, cova$for.m is the vector of names of potential mediators that use the covariates. Works for continuous predictors (pred) only, also the specified covariates should have no missing if only some mediators uses the covariates. Works mainly for continuous predictors (pred), also the specified covariates should have no missing if only some mediators uses the covariates.

margin

the change in predictor when calculating the mediation effects, see Yu et al. (2014).

n

the time of resampling in calculating the indirect effects, default is n=20, see Yu et al. (2014).

nonlinear

if TURE, Multiple Additive Regression Trees (MART) will be used to fit the final full model in estimating the outcome. The default value of nonlinear is FALSE, in which case, a generalized linear model will be used to fit the final full model.

df1

if nonlinear is TURE, natural cubic spline will be used to fit the relationship between the predictor and each mediator. The df is the degree of freedom in the ns() function, the default is 1.

nu

set the parameter "shrinkage" in gbm function if MART is to be used, by default, nu=0.001. See also help(gbm.fit).

D

set the parameter "interaction.depth" in gbm function if MART is to be used, by default, D=3. See also help(gbm.fit).

distn

the assumed distribution of the outcome if MART is used for final full model. The default value of distn is "gaussian" for coninuous y, and "bernoulli" for binary y.

family1

define the conditional distribution of y given x, and the linkage function that links the mean of y with the system component if generalized linear model is used as the final full model. The default value of family1 is gaussian(link="identity") for continuous y, and binomial(link = "logit") for binary y.

n2

the number of times of bootstrap resampling. The default value is n2=50.

w

the weight for observations.

refy

if y is binary, the reference group of y.

x.new

of the same format as x, with a new set of covariates and mediators on which to calculate the mediation effects.

pred.new

a new set of predictor(s).

cova.new

a new set of covaraite(s).

binpred

if TRUE, the predictor is binary.

type

the type of prediction when y is class Surv. Is "risk" if not specified.

w.new

the weights for new.x.

all.model

save all the fitted model from bootstrap samples if TRUE. This needs to be true to make inferences on moderation effects.

xmod

If there is a moderator, xmod gives the moderator's name in cova and/or x.

custom.function

a string of customer defined final model for predicting the outcome(s). The response variable should be noted as "responseY", the dataset should be noted as "dataset123". The weights for observations should be noted as "weights123". The covariates should be in x or pred. Use "~." for all varaibles in x and pred is allowed. The customer defined model should be able to make prediction by using "predict(object, newdata=...)", where the object is the results of the fitted model. If a specific package needs to be called to fit the model, the user should call the package first. For example, if the gamlss package is used to fit a piecewise polynomial with "age" to be the mediator and "race" be the predictor, we can set custom.function="gamlss(responseV~b(age,df=3)+race,data=dataset123,tace=FALSE)". The length of custom.function should be the same as the dimension of y. If custom.function[j] is NA, the usual method will be used to fit y[j].

para

It is for binary predictors. If it is true, we would like the x-m relationship be fitted parametrically.

echo

If echo is FALSE, there is no counting printed for the number of bootstrap iterations.

Details

The mediators are not tested in this function. data.org should be used for the tests and data organizing, and then the resulting list from data.org can be used directly to define the arguments in this function. boot.med considers all variables in x as mediators or covariates in the final model and all variables identified by contm, binm, catm, or jointm as mediators.

Value

Returns an mma object.

estimation

list the estimation of ie (indirect effect), te (total effect), and de (direct effect from the predictor) separately.

bootsresults

a list where the first item, ie, is a matrix of n2 rows where each column gives the estimated indirect effect from the corresponding mediator (identified by the column name) from the n2 bootstrap samples; the second item, te, is a vector of estimated total effects from the bootstrap sample; and the 3rd item, de, is a vector of estimated direct effect of the predictor from the bootstrap sample.

model

a list where the first item, MART, is TRUE if mart is fitted for the final model; the second item, Survival, is TRUE if a survival model is fitted; the third item, type, is the type of prediction when a survival model is fitted; the fourth item, model, is the fitted final full model where y is the outcome and all predictor, covariates, and mediators are the explanatory variables; and the fourth item, best.iter is the number of best iterations if MART is used to fit the final model.

data

a list that contains all the used data: x=x, y=y, dirx=dirx, binm=binm, contm=contm, catm=catm, jointm=jointm, binpred=FALSE.

boot.detail

a list that contains the mediation effects on each row of new.x: new.x=new.x, te1, de1, ie1.

all_model

a list with all fitted models from bootstrap samples if all.model is TRUE.

all_iter

if all.model is TRUE, a matrix with all fitted best iterations if MART is used. Each row is from one bootstrap sample.

all_boot

if all.model is TRUE, a matrix with all bootstrap samples. Each row is one bootstrap sample.

Author(s)

Qingzhao Yu qyu@lsuhsc.edu

References

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 & Biostatistics,5(2): 189.

Yu, Q., Scribner, R.A., Leonardi, C., Zhang, L., Park, C., Chen, L., and Simonsen, N.R. (2017) <doi:10.1016/j.sste.2017.02.001>. "Exploring racial disparity in obesity: a mediation analysis considering geo-coded environmental factors," Spatial and Spatio-temporal Epidemiology, 21, 13-23.

Yu, Q., and Li, B. (2017) <doi:10.5334/hors.160>. "mma: An r package for multiple mediation analysis," Journal of Open Research Software, 5(1), 11.

Yu, Q., Wu, X., Li, B., and Scribner, R. (2018). <doi:10.1002/sim.7977>. "Multiple Mediation Analysis with Survival Outcomes – With an Application to Explore Racial Disparity in Breast Cancer Survival," Statistics in Medicine.

Yu, Q., Medeiros, KL, Wu, X., and Jensen, R. (2018). <doi:10.1007/s11336-018-9612-2>. "Explore Ethnic Disparities in Anxiety and Depression Among Cancer Survivors Using Nonlinear Mediation Analysis," Psychometrika, 83(4), 991-1006.

See Also

"med" just estimate the mediation effects.

Examples

data("weight_behavior")
##binary x
#binary y
 x=weight_behavior[,c(2,4:14)]
 pred=weight_behavior[,3]
 y=weight_behavior[,15]
 data.bin<-data.org(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10),binref=c(1,1),
                    catmed=5,catref=1,predref="M",alpha=0.4,alpha2=0.4)
 temp1<-boot.med(data=data.bin,n=2,n2=4)
 temp2<-boot.med(data=data.bin,n=2,n2=4,nu=0.05,nonlinear=TRUE)


#continuous y
 x=weight_behavior[,c(2,4:14)]
 pred=weight_behavior[,3]
 y=weight_behavior[,1]
 data.cont<-data.org(x,y,pred=pred,mediator=5:12,jointm=list(n=1,j1=7:9), 
                     predref="M",alpha=0.4,alpha2=0.4)
 temp3<-boot.med(data=data.cont,n=2,n2=4) 
 temp4<-boot.med(data=data.cont,n=2,n2=4,nu=0.05, nonlinear=TRUE)


##Surv class outcome (survival analysis)

data(cgd1)       #a dataset in the survival package
x=cgd1[,c(4:5,7:12)]
pred=cgd1[,6]
status<-ifelse(is.na(cgd1$etime1),0,1)
y=Surv(cgd1$futime,status)          
#for continuous predictor
data.surv.contx<-data.org(x,y,pred=pred,mediator=1:ncol(x),      
                          alpha=0.5,alpha2=0.5)
temp9.contx<-boot.med(data=data.surv.contx,n=1,n2=2, type="lp") 
temp10.contx<-boot.med(data=data.surv.contx,nonlinear=TRUE,n=1,n2=2) 

#for binary predictor

x=cgd1[,c(5:12)]
pred=cgd1[,4]
data.surv.binx<-data.org(x,y,pred=pred,mediator=1:ncol(x),   
                    alpha=0.4,alpha2=0.4)
temp9.binx<-boot.med(data=data.surv.binx,n=1,n2=2, type="lp") 
summary(temp9.binx)
temp10.binx<-boot.med(data=data.surv.binx,nonlinear=TRUE,n=1,n2=2) 



mma documentation built on Aug. 30, 2023, 1:08 a.m.