Learn R Programming

mma (version 3.1-0)

mma: Multiple Mediation Analysis

Description

Test for mediators and do statistical inferences on the identified mediation effects.

Usage

mma(x,y,pred,mediator=NULL, contmed=NULL,binmed=NULL,binref=rep(1,length(binmed)), catmed=NULL,catref=rep(1,length(catmed)),jointm=NULL,refy=NULL, predref=NULL,alpha=0.1,alpha2=0.1, 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)),x.new=NULL)

Arguments

x
a data frame contains the predictor, all potential mediators and covariates.
y
the vector of outcome variable.
pred
the column number that locates the predictor in x.
mediator
the list of mediators (column numbers in x or by variable names). The mediators to be checked can be identified by "contmed", "binmed" and "catmed", or by this argument, "mediator", where binary and categorical mediators in x are identified by factors, the reference group is the first level of the factor.
contmed
a vector of column numbers that locate the potential continuous mediators in x.
binmed
a vector of column numbers that locate the potential binary mediators in x.
binref
the defined reference groups of the binary potential mediators in binmed.
catmed
a vector of column numbers that locate the potential categorical mediators in x.
catref
the defined reference groups of the categorical potential mediators in catmed.
jointm
a list that identifies the mediators that need to be considered jointly, where the first item indicates the number of groups of mediators to be considered jointly, and each of the following items identifies the column numbers of the mediators in x for each group of joint mediators.
refy
if y is binary, the reference group of y.By default, the reference group will be the first level of as.factor(y).
predref
if predictor is binary, identify the reference group of the binary predictor. By default, the reference group will be the first level of the predictor.
alpha
the significance level at which to test if the potential mediators (identified by contmed, binmed, and catmed) can be used as a covariate or mediator in estimating y when all variables in x are included in the model. The default value is alpha=0.1
alpha2
the significant level at which to test if a potential mediator is related with the predictor. The default value is alpha2=0.1.
margin
if binpred is FALSE, define 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 countinuous 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 "bernoulli" for binary y, and "gaussian" for continuous 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 binomial(link = "logit") for binary y, gaussian(link="identity") for continuous y.
n2
the number of times of bootstrap resampling. The default value is n2=50.
weight
the weight for each observation.
x.new
for continuous predictor only. of the same format as x (after data.org), with a new set of predictor and corresponding covariates on which to calculate the mediation effects. If is NULL, the mediation effects will be calculated based on the original data set.

Value

Returns an mma object.

Details

mma first tests if the potential mediators defined by binm, contm, and catm should be treated as mediators or covariates (if none, the variable will be deleted from further analysis). All variables identified by jointm are treated as mediators. All other variables in x that are not tested are treated as covariates. Then mma does the mediation effects estimation and inference on the selected variables.

References

Baron, R.M., and Kenny, D.A. (1986) . "The moderator-mediator variable distinction in social psychological research: conceptual, strategic, and statistical considerations," J. Pers Soc Psychol, 51(6), 1173-1182.

J.H. Friedman, T. Hastie, R. Tibshirani (2000) . "Additive Logistic Regression: a Statistical View of Boosting," Annals of Statistics 28(2):337-374.

J.H. Friedman (2001) . "Greedy Function Approximation: A Gradient Boosting Machine," Annals of Statistics 29(5):1189-1232.

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

"data.org" is for mediator tests, and "med" , and "boot.med" for mediation analysis and inferences.

Examples

Run this code
data("weight_behavior")
 #binary x
 #binary y
 x=weight_behavior[,2:14]
 y=weight_behavior[,15]
 temp.b.b.glm<-mma(x,y,pred=2,mediator=6:13,predref="M",alpha=0.4,alpha2=0.4, 
   n=2,n2=2)
 
 temp.b.b.mart<-mma(x,y,pred=2,mediator=6:13,predref="M",alpha=0.4,alpha2=0.4, 
   nonlinear=TRUE,n=2,n2=5)
 #continuous y
 x=weight_behavior[,2:14]
 y=weight_behavior[,1]
 temp.b.c.glm<-mma(x,y,pred=2,mediator=c(8:10,12:13,7,11,6),jointm=list(n=1,j1=8:10), 
   predref="M",alpha=0.4,alpha2=0.4,n=2,seed=1,n2=20)
 temp.b.c.mart<-mma(x,y,pred=2,mediator=6:13,jointm=list(n=1,j1=8:10, j2=12:13), 
   predref="M",alpha=0.4,alpha2=0.4, n=2,seed=1,nonlinear=TRUE,n2=20)

Run the code above in your browser using DataLab