Learn R Programming

mma (version 3.1-0)

boot.med: 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,margin=1,n=20,seed=sample(1:1000,1), nonlinear=F,df=1,nu=0.001,D=3,distn=NULL,family1=NULL,n2=50, weight=rep(1,length(y)),refy=NULL,x.new=x,binpred=data$binpred)

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 the predictor, all mediators and covariates. Need to set up only when data is FALSE.
y
the vector of outcome variable. Need to set up only when data is FALSE.
dirx
the predictor name or the column number of x that locates the predictor. 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.
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).
seed
set seed to make the calculation repeatable. The default value of seed is from sample(1:1000,1).
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.
df
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 "interaction.depth" in gbm function if MART is to be used, by default, nu=0.001. See also help(gbm.fit).
D
set the parameter "shrinkage" 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.
weight
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 predictor and corresponding covariates on which to calculate the mediation effects.
binpred
if TRUE, the predictor is binary.

Value

Returns an mma object.

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.

References

Yu, Q., Fan, Y., and Wu, X. (2014) . "General Multiple Mediation Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journal of Biometrics & Biostatistics,5(2): 189.

See Also

"med" just estimate the mediation effects.

Examples

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

#continuous y
x=weight_behavior[,2:14]
y=weight_behavior[,1]
data.cont<-data.org(x,y,pred=2,contmed=c(8:10,12:13),binmed=c(7,11),
                    binref=c(1,1),catmed=6,catref=1, 
                    family1=gaussian(link="identity"),predref="M",alpha=0.4,alpha2=0.4)

temp3<-boot.med(data=data.cont,n=2,n2=4,seed=1) 
temp4<-boot.med(data=data.cont,n=2,n2=4,nu=0.05,seed=1, nonlinear=TRUE) 

##continuous x
#binary y
x=weight_behavior[,2:14]
y=weight_behavior[,15]
data.contx<-data.org(x,y,pred=1,contmed=c(8:10,12:13),binmed=c(7,11),
                     binref=c(1,1),catmed=6,catref=1,alpha=0.4,alpha2=0.4)

temp5<-boot.med(data=data.contx,seed=1,n=1,n2=2)
plot(temp5,vari="exercises",xlim=c(0,30))
temp6<-boot.med(data=data.contx,seed=1,n=1,refy=0,nonlinear=T,n2=2)

#continuous y
x=weight_behavior[,2:14]
y=weight_behavior[,1]
data.contx<-data.org(x,y,pred=1,contmed=c(8:10,12:13),binmed=c(7,11),
                     binref=c(1,1),catmed=6,catref=1,alpha=0.4,alpha2=0.4)

temp7<-boot.med(data=data.contx,seed=1,n=1,n2=2) 
temp8<-boot.med(data=data.contx,nonlinear=T,seed=1,n=1,n2=2) 

Run the code above in your browser using DataLab