package ‘mma’ - r · 2020-03-23 · package ‘mma’ march 23, 2020 type package title...

45
Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li Maintainer Qingzhao Yu <[email protected]> Depends R (>= 2.14.1), gbm, splines, survival, car, gplots Imports plotrix,lattice Suggests knitr, rmarkdown VignetteBuilder knitr Encoding UTF-8 Description Used for general multiple mediation analysis. The analysis method is described in Yu et al. (2014) <doi:10.4172/2155-6180.1000189> ``Gen- eral Multiple Mediation Analysis With an Application to Explore Racial Disparity in Breast Can- cer Survival'', published on Journal of Biometrics & Biostatis- tics, 5(2):189; and Yu et al.(2017) <DOI:10.1016/j.sste.2017.02.001> ``Exploring racial dispar- ity in obesity: a mediation analysis considering geo-coded environmental factors'', pub- lished on Spatial and Spatio-temporal Epidemiology, 21, 13-23. License GPL (>= 2) URL https://www.r-project.org, https://publichealth.lsuhsc.edu/Faculty_pages/qyu/index.html RoxygenNote 6.1.1 NeedsCompilation no Repository CRAN Date/Publication 2020-03-23 16:40:06 UTC 1

Upload: others

Post on 18-Apr-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

Package ‘mma’March 23, 2020

Type Package

Title Multiple Mediation Analysis

Version 10.2-2

Date 2020-02-27

Author Qingzhao Yu and Bin Li

Maintainer Qingzhao Yu <[email protected]>

Depends R (>= 2.14.1), gbm, splines, survival, car, gplots

Imports plotrix,lattice

Suggests knitr, rmarkdown

VignetteBuilder knitr

Encoding UTF-8

Description Used for general multiple mediation analysis.The analysis method is described in Yu et al. (2014) <doi:10.4172/2155-6180.1000189> ``Gen-eral Multiple Mediation Analysis With an Application to Explore Racial Disparity in Breast Can-cer Survival'', published on Journal of Biometrics & Biostatis-tics, 5(2):189; and Yu et al.(2017) <DOI:10.1016/j.sste.2017.02.001> ``Exploring racial dispar-ity in obesity: a mediation analysis considering geo-coded environmental factors'', pub-lished on Spatial and Spatio-temporal Epidemiology, 21, 13-23.

License GPL (>= 2)

URL https://www.r-project.org,

https://publichealth.lsuhsc.edu/Faculty_pages/qyu/index.html

RoxygenNote 6.1.1

NeedsCompilation no

Repository CRAN

Date/Publication 2020-03-23 16:40:06 UTC

1

Page 2: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

2 mma-package

R topics documented:mma-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2boot.med . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4boot.mod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9cgd1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13data.org . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13form.interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18med . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19mma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25moderate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30plot.med . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31plot.mma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32plot2.mma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34print.med . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35print.mma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36summary.med_iden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38summary.mma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39test.moderation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41weight_behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Index 45

mma-package Mediation Analysis Package

Description

This package is used to identify mediators and for general mediation analysis. Mediation effectrefers to the effect conveyed by intervening variables to an observed relationship between an ex-posure 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, di-rect effect, and indirect effect, which are defined and the statistical inferences described in Yu etal.(2014).

Details

Package: mmaType: PackageVersion: 10Date: 2020-03-18License: GPL (>= 2)

"data.org" is used to identify potential mediators. "med" , and "boot.med" are used for statisticalinferences on the mediation effects when the predictor is binary or continuous. "mma" is a com-bined function that automatically identify potential mediators, based on which to make statistical

Page 3: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

mma-package 3

inference on the mediation effects.

Author(s)

Qingzhao Yu <[email protected]> and Bin Li <[email protected]>

Maintainer: Qingzhao Yu <[email protected]>

References

Baron, R.M., and Kenny, D.A. (1986) <doi:10.1037/0022-3514.51.6.1173>. "The moderator-mediatorvariable distinction in social psychological research: conceptual, strategic, and statistical consider-ations," J. Pers Soc Psychol, 51(6), 1173-1182.

J.H. Friedman, T. Hastie, R. Tibshirani (2000) <doi:10.1214/aos/1016120463>. "Additive LogisticRegression: a Statistical View of Boosting," Annals of Statistics 28(2):337-374.

J.H. Friedman (2001) <doi:10.1214/aos/1013203451>. "Greedy Function Approximation: A Gra-dient Boosting Machine," Annals of Statistics 29(5):1189-1232.

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

Examples

data("weight_behavior")#binary predictor#binary yx=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,15]temp.b.b.glm<-mma(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,n=2,n2=2)

temp.b.b.mart<-mma(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,nonlinear=TRUE,n=2,n2=5)

#continuous yx=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,1]

Page 4: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

4 boot.med

temp.b.c.glm<-mma(x,y,pred=pred,mediator=5:12,jointm=list(n=1,j1=7:9),predref="M",alpha=0.4,alpha2=0.4,n2=20)

temp.b.c.mart<-mma(x,y,pred=pred,mediator=5:12,jointm=list(n=1,j1=7:9),predref="M",alpha=0.4,alpha2=0.4,n=2,nonlinear=TRUE,n2=20)

boot.med Statistical Inference on Mediation Analysis with Continuous or BinaryPredictor

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=F,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)

Arguments

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

x a data frame contains all mediators and covariates. Need to set up only whendata is FALSE. All varaibles in x that are not identified as potential mediators (bymediator, contmed, binmed, catmed, or jointm) are forced in mediation analysisas 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 contin-uous mediators. Need to set up only when data is FALSE.

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

Page 5: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

boot.med 5

jointm a list where the first item is the number of groups of joint mediators to be con-sidered, and each of the following items identifies the names or the columnnumbers of the mediators in x for each group of joint mediators. Need to set uponly when data is FALSE.

cova The data frame of covariates to be used to predict the mediator(s). The covariatesin cova cannot be potential mediators. If the covariates are for some specificpotential mediators, cova$for.m is the vector of names of potential mediatorsthat use the covariates. Works for continuous predictors (pred) only, also thespecified covariates should have no missing if only some mediators uses thecovariates. Works mainly for continuous predictors (pred), also the specifiedcovariates 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 Yuet al. (2014).

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

df1 if nonlinear is TURE, natural cubic spline will be used to fit the relationshipbetween the predictor and each mediator. The df is the degree of freedom in thens() 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, bydefault, 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" forbinary y.

family1 define the conditional distribution of y given x, and the linkage function thatlinks the mean of y with the system component if generalized linear model isused 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 tocalculate 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.

Page 6: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

6 boot.med

all.model save all the fitted model from bootstrap samples if TRUE. This needs to be trueto 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 re-sponse 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 predis allowed. The customer defined model should be able to make prediction byusing "predict(object, newdata=...)", where the object is the results of the fittedmodel. If a specific package needs to be called to fit the model, the user shouldcall the package first. For example, if the gamlss package is used to fit a piece-wise polynomial with "age" to be the mediator and "race" be the predictor, wecan 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 cus-tom.function[j] is NA, the usual method will be used to fit y[j].

Details

The mediators are not tested in this function. data.org should be used for the tests and data orga-nizing, and then the resulting list from data.org can be used directly to define the arguments in thisfunction. boot.med considers all variables in x as mediators or covariates in the final model and allvariables 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 effectfrom the predictor) separately.

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

model a list where the first item, MART, is T if mart is fitted for the final model; thesecond item, Survival, is T if a survival model is fitted; the third item, type, isthe type of prediction when a survival model is fitted; the fourth item, model, isthe 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 thenumber 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=F.

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.

Page 7: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

boot.med 7

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 onebootstrap sample.

Author(s)

Qingzhao Yu <[email protected]>

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"med" just estimate the mediation effects.

Examples

data("weight_behavior")##binary x#binary yx=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)

#multivariate predictorx=weight_behavior[,c(2:3,5:14)]pred=weight_behavior[,4]y=weight_behavior[,15]data.b.b.2.3<-data.org(x,y,mediator=5:12,jointm=list(n=1,j1=c(5,7,9)),

Page 8: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

8 boot.med

pred=pred,predref="OTHER", alpha=0.4,alpha2=0.4)# temp1.2<-boot.med(data.b.b.2.3,n=2,n2=4)# temp2.2<-boot.med(data.b.b.2.3,n=2,n2=4,nu=0.05,nonlinear=TRUE)

#multivariate responsesx=weight_behavior[,c(2:3,5:14)]pred=weight_behavior[,4]y=weight_behavior[,c(1,15)]data.b.b.2.4<-data.org(x,y,mediator=5:12,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="OTHER", alpha=0.4,alpha2=0.4)# temp1.3<-boot.med(data.b.b.2.4,n=2,n2=4)# temp2.3<-boot.med(data.b.b.2.4,n=2,n2=4,nonlinear=TRUE)

#continuous yx=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)

##continuous x#binary yx=weight_behavior[,3:14]pred=weight_behavior[,2]y=weight_behavior[,15]data.contx<-data.org(x,y,pred=pred,mediator=4:10,alpha=0.4,alpha2=0.4)temp5<-boot.med(data=data.contx,n=1,n2=2)#plot(temp5,vari="exercises",xlim=c(0,30))temp6<-boot.med(data=data.contx,n=1,refy=0,nonlinear=TRUE,n2=2)

#continuous yx=weight_behavior[,3:14]y=weight_behavior[,1]pred=weight_behavior[,2]data.contx<-data.org(x,y,pred=pred,contmed=c(11:12),binmed=c(6,10),

binref=c(1,1),catmed=5,catref=1,alpha=0.4,alpha2=0.4)

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

##Surv class outcome (survival analysis)

data(cgd1) #a dataset in the survival packagex=cgd1[,c(4:5,7:12)]pred=cgd1[,6]status<-ifelse(is.na(cgd1$etime1),0,1)y=Surv(cgd1$futime,status)#for continuous predictordata.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")

Page 9: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

boot.mod 9

#summary(temp9.contx)temp10.contx<-boot.med(data=data.surv.contx,nonlinear=TRUE,n=1,n2=2)#summary(temp10.contx)

#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)#summary(temp10.binx)

#multiple predictors (categorical and continuous predictors)x=weight_behavior[,c(3,5:14)]pred=weight_behavior[,c(2,4)]y=weight_behavior[,15]data.b.b.2.3<-data.org(x,y,mediator=4:11,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="OTHER", alpha=0.4,alpha2=0.4)# temp1.4<-boot.med(data=data.b.b.2.3,n=2,n2=2)# temp2.4<-boot.med(data.b.b.2.3,n=2,n2=2,nonlinear=TRUE)

boot.mod Statistical Inference on Mediation Analysis with Continuous or BinaryPredictor at different level of the moderator

Description

To make inferences on the mediation effects when the predictor is continuous or binary at differentlevel of the moderator.

Usage

boot.mod(mma1,vari,continuous.resolution=10,w=NULL,n=20,x.new=NULL,w.new=NULL,pred.new=NULL,cova.new=NULL,xj=1,margin=1,xmod=vari,df1=1)

Arguments

mma1 the mma project generated from the function mma or boot.med.

vari The name of the moderator. The moderator should be included in the originaldata as a covariate for the response(in x) and/or for mediators (in cova).

Page 10: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

10 boot.mod

continuous.resolution

The number of equally space points (for continuous moderator) or levels (forcategorical moderator) at which to evaluate mediation effects separately.

w the weight for observations.

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

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

w.new the weights for new.x.

pred.new a new set of predictor(s).

cova.new a new set of covariate for mediator(s).

xj the inference of mediation effects at different levels of moderator is made on thexjth predictor.

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

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

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

Details

calculate the mediation effects from the xjth predictor to the response variable(s) at each level ofthe mediator.

Value

Returns an mma.mod object, which is similar to the mma object. Instead of calculating mediationeffects for each predictor, the function returns the mediation effects of the xjth predictor at eachlevel of the moderator.

Author(s)

Qingzhao Yu <[email protected]>

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

Page 11: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

boot.mod 11

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

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

See Also

"med" just estimate the mediation effects.

Examples

#binary x and categorical moderator#linear modeldata("weight_behavior")pred=weight_behavior[,3]x=weight_behavior[,c(2,4:14)]inter=form.interaction(x,pred,inter.cov=c("race"),predref="M")x=cbind(x,inter)y=weight_behavior[,15]head(x)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,all.model=TRUE)temp1.mode=boot.mod(temp1,vari="race",continuous.resolution=100)#summary(temp1.mode,ball.use = F)plot2.mma(temp1.mode,vari="exercises",moderator="race")plot2.mma(temp1.mode,vari="sports",moderator="race")

#nonlinear modelx=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)temp2<-boot.med(data=data.bin,n=2,n2=4,nu=0.05,nonlinear=TRUE,all.model=TRUE)temp2.mode=boot.mod(temp2,vari="race",continuous.resolution=100)#summary(temp2.mode,ball.use = F)plot2.mma(temp2.mode,vari="exercises",moderator="race")plot2.mma(temp2.mode,vari="sports",moderator="race")

#binary x and continuou moderatorx=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,1]inter=form.interaction(x,pred,inter.cov=c("age"),predref="M")x=cbind(x,inter)head(x)data.cont<-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)

Page 12: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

12 boot.mod

temp3<-boot.med(data=data.cont,n=2,n2=4,all.model=TRUE)temp3.mode=boot.mod(temp3,vari="age",continuous.resolution=2)summary(temp3.mode)

plot2.mma(temp3.mode,vari="exercises",moderator="age")plot2.mma(temp3.mode,vari="sports",moderator="age")

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)temp4<-boot.med(data=data.cont,n=2,n2=4,nu=0.05, nonlinear=TRUE,all.model=TRUE)temp4.mode=boot.mod(temp4,vari="age",continuous.resolution=2,n=20)summary(temp4.mode)summary(temp4.mode,bymed=TRUE)

#categorical m and continuous xx=weight_behavior[,3:14]pred=weight_behavior[,2]inter=form.interaction(x,pred,inter.cov=c("race"))cova=data.frame(inter)x=cbind(x,cova)head(x)y=weight_behavior[,15]data.contx<-data.org(x,y,pred=pred,mediator=4:10,alpha=0.4,alpha2=0.4,cova=cova)#temp5<-boot.med(data=data.contx,n=1,n2=2,cova=cova,all.model=TRUE)#temp5.mode=boot.mod(temp5,vari="race",continuous.resolution=10)#summary(temp5.mode)

x=weight_behavior[,3:14]pred=weight_behavior[,2]y=weight_behavior[,15]data.contx<-data.org(x,y,pred=pred,mediator=4:10,alpha=0.4,alpha2=0.4,cova=cova)temp6<-boot.med(data=data.contx,n=1,refy=0,nonlinear=TRUE,n2=3,

cova=data.frame(race=x$race),all.model = TRUE)temp6.mode=boot.mod(temp6,vari="race",continuous.resolution=10)summary(temp6.mode)

#plot2.mma(temp5.mode,vari="car",moderator="race")#plot2.mma(temp6.mode,vari="car",moderator="race")

#continuous m and xx=weight_behavior[,3:14]pred=weight_behavior[,2]inter=form.interaction(x,pred,inter.cov=c("numpeople"))x=cbind(x,inter)head(x)y=weight_behavior[,15]data.contx<-data.org(x,y,pred=pred,mediator=4:10,alpha=0.4,alpha2=0.4)#temp5.1<-boot.med(data=data.contx,n=1,n2=2,all.model=TRUE)#temp5.mode1=boot.mod(temp5.1,vari="numpeople",continuous.resolution=2)#summary(temp5.mode1)

Page 13: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

cgd1 13

cgd1 cgd1 Data Set

Description

This database was obtained from the survival package containing a time-to-event data.

Usage

data(weight_behavior)

Format

The data set contains many variables.

Examples

data(cgd1)names(cgd1)

data.org Data Organization and Identify Potential Mediators

Description

Do a preliminary data analysis to identify potential mediators and covariates. Each variable listedin jointm is forced in the final estimation model as a mediator. Also organize the data into a formatthat can be directly used for the mediation analysis functions.

Usage

data.org(x,y,pred,mediator=NULL,contmed=NULL,binmed=NULL,binref=NULL,catmed=NULL,catref=NULL,jointm=NULL,refy=rep(NA,ncol(data.frame(y))),family1=as.list(rep(NA,ncol(data.frame(y)))),predref=rep(NA,ncol(data.frame(pred))),alpha=0.1,alpha2=0.1,testtype=1, w=NULL,cova=NULL)

Page 14: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

14 data.org

Arguments

x a data frame contains the predictor, all potential mediators and covariates. Notethat x has to be a data frame. All varaibles in x that are not identified as poten-tial mediators (by mediator, contmed, binmed, catmed, or jointm) are forced inmediation analysis as covariates.

y the vector of outcome variable.The outcome can be binary, continuous, or of"Surv" class (see survival package for help).

pred the column or matrix of predictor(s): the predictor is the exposure variable, itcan be a binary or multi-categorical factor or one/a few contiuous variable(s).

mediator the list of mediators (column numbers in x or by variable names). The mediatorsto be checked can be identified by "contmed", "binmed" and "catmed", or by thisargument, "mediator", where binary and categorical mediators in x are identifiedas factors or characters, the reference group is the first level of the factor orfactorized character. if a mediator has only two unique values, the mediator isidentified as binary. If the reference groups need to be changed, the binary orcategorical mediators can be listed in binmed or catmed, and the correspondingreference group in binref or catref.

contmed a vector of variable names or column numbers that locate the potential continu-ous 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. Thefirst levels of the mediators if is null.

catmed a vector of variable names or column numbers that locate the potential categor-ical mediators in x. The first levels of the mediators if is null.

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 thefirst item indicates the number of groups of mediators to be considered jointly,and each of the following items identifies the variable names or column numbersof the mediators in x for each group of joint mediators.

refy if y is binary, the reference group of y. The default is the first level of as.factor(y).y for the reference group is assigned as 0.

family1 define the conditional distribution of y given x, and the linkage function thatlinks the mean of y with the system component in generalized linear model.The default value of family1 is binomial(link = "logit") for binary y, and gaus-sian(link="identity") for continuous y.

predref if the predictor is categorical, identify the reference group of the predictor. Thedefault is the first level of the predictor. The value of the predictor is 0 for thereference group.

alpha the significance level at which to test if the potential mediators (identified bycontmed, binmed, and catmed) can be used as a covariate or mediator in esti-mating y when all variables in x are included in the model. The default value isalpha=0.1

alpha2 the significant level at which to test if a potential mediator is related with thepredictor. The default value is alpha2=0.1.

Page 15: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

data.org 15

testtype if the testtype is 1 (by default), covariates/mediators are identified using fullmodel; if the testtype is 2, covariates/mediators are tested one by one in modelswith the predictor only.

w the weight for data analysis, by default is rep(1,length(y)).

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

Value

data.org returns a list with the organized data and identifiers of the potential mediators in the orga-nized data set. The list has two components, bin.results if there is binary or categorical exposure(s),cont.results if there is continuous exposures.

x the organized data frame that include all potential mediators and covariates thatshould be used to estimate the outcome.

dirx the vector/matrix of predictor(s)/exposure variable(s).

contm the column numbers of x that locate the potential continuous mediators.

binm when the predictor is continuous, binm gives the column numbers of x that lo-cate the potential binary mediators.

catm when the predictor is binary, catm gives the column numbers of x that locate thepotential binary or categorical mediators; when the predictor is continuous, catmgives a list where the first item is the number of potential categorical mediators,and the following items give the column numbers of each binarized categoricalmediator in x.

jointm a list where the first item is the number of groups of joint mediators, and each ofthe following items identifies the column numbers of the mediators in the newlyorganized x for each group of joint mediators.

y the vector/matrix of outcome(s).

y_type the variable type of outcome(s): 1 is continuous, 2 is binary, 3 is reserved formulti-categorical (no 3 would show in y_type, since all categorical responsesare binarized), and 4 is survival.

fullmodel a list with each item the full linear model fitted with all potential mediators andcovariates for each response.

rela p-values of tests on the realtionship between the predictor(s) and each potientialmediator.

P1 If testtype=2, P1 gives the p-value of the corresponding variables in predictingthe outcome(s) when only the variable and predictor are covariates in the model.

binpred The columne numbers of binary predictors in pred.

contpred The columne numbers of continuous predictors in pred.

catpred A list with each item includes the columne numbers of a categorical predictor inpred.

Page 16: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

16 data.org

Note

All other variables in x but not identified by mediator, contmed, binmed, or catmed are forced in thefinal model as covariates. Compared with data.org, joint mediators are considered in this function.Every variable in the jointm should be listed in contmed, binmed, or catmed, and these variablesare forced to be included as mediators for further mediation analysis. A variables can be includedin more than one groups of joint mediators in jointm.

Author(s)

Qingzhao Yu <[email protected]>

References

Baron, R.M., and Kenny, D.A. (1986) <doi:10.1037/0022-3514.51.6.1173>. The moderator-mediatorvariable distinction in social psychological research: conceptual, strategic, and statistical consider-ations. J. Pers Soc Psychol, 51(6), 1173-1182.

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"data.org" that does not consider joint mediators, which can be added freely in the mediationanalysis functions later.

Examples

data("weight_behavior")#binary predictor#binary yx=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,15]data.b.b.2.1<-data.org(x,y,mediator=5:12,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="M", alpha=0.4,alpha2=0.4)summary(data.b.b.2.1)#Or you can specify the potential mediators and change the reference

Page 17: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

data.org 17

#group for binary or categorical mediators. In the following code,#potential continuous mediators are columns 8,9,10,12, and 13 of x,#binary mediators are columns 7 and 11, and categorical mediator is#column 6 of x with 1 to be the reference group for all categorical#and binary mediators.data.b.b.2<-data.org(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10),binref=c(1,1),catmed=5,catref=1,jointm=list(n=1,j1=c(5,7,9)),predref="M",alpha=0.4,alpha2=0.4)summary(data.b.b.2)#use the mediator argument instead of contmet, binmed and catmed

#multivariate predictor

x=weight_behavior[,c(2:3,5:14)]pred=weight_behavior[,4]y=weight_behavior[,15]data.b.b.2.3<-data.org(x,y,mediator=5:12,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="OTHER", alpha=0.4,alpha2=0.4)summary(data.b.b.2.3)

#multivariate responsesx=weight_behavior[,c(2:3,5:14)]pred=weight_behavior[,4]y=weight_behavior[,c(1,15)]data.b.b.2.4<-data.org(x,y,mediator=5:12,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="OTHER", alpha=0.4,alpha2=0.4)summary(data.b.b.2.4)

#continuous yx=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,1]data.b.c.2<-data.org(x,y,pred=pred,mediator=5:12,jointm=list(n=1,j1=7:9),predref="M",alpha=0.4,alpha2=0.4)

summary(data.b.c.2)

#continuous predictor#binary yx=weight_behavior[,3:14]pred=weight_behavior[,2]y=weight_behavior[,15]data.c.b.2<-data.org(x,y,pred=pred,mediator=5:12,catref=1,

jointm=list(n=2,j1=7:9,j2=c(5,7)),alpha=0.4,alpha2=0.4)summary(data.c.b.2)

#multivariate predictorsx=weight_behavior[,c(3:12,14)]pred=weight_behavior[,c(2,13)]y=weight_behavior[,15]data.c.b.2.2<-data.org(x,y,pred=pred,mediator=5:11,catref=1,

jointm=list(n=2,j1=7:9,j2=c(5,7)),alpha=0.4,alpha2=0.4)summary(data.c.b.2.2)

Page 18: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

18 form.interaction

#continuous yx=weight_behavior[,3:14]pred=weight_behavior[,2]y=weight_behavior[,1]data.c.c.2<-data.org(x,y,pred=pred,contmed=c(7:9,11:12),binmed=c(6,10),

binref=c(1,1),catmed=5,catref=1,jointm=list(n=2,j1=7:9,j2=c(5,7)),alpha=0.4,alpha2=0.4)

summary(data.c.c.2)

#multivariate responsesx=weight_behavior[,c(2:3,5:14)]pred=weight_behavior[,4]y=weight_behavior[,c(1,15)]data.b.c.2.4<-data.org(x,y,mediator=5:12,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="OTHER", alpha=0.4,alpha2=0.4)summary(data.b.c.2.4)

#x=weight_behavior[,c(3:12,14)]pred=weight_behavior[,c(2,13)]y=weight_behavior[,c(1,15)]data.c.c.2.2<-data.org(x,y,pred=pred,mediator=5:11,catref=1,

jointm=list(n=2,j1=7:9,j2=c(5,7)),alpha=0.4,alpha2=0.4)summary(data.c.c.2.2)

#Surv class outcome (survival analysis)data(cgd1) #a dataset in the survival packagex=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#all other variables are considered as potential mediatordata.surv.contx<-data.org(x,y,pred=pred,mediator=(1:ncol(x)),

alpha=0.5,alpha2=0.5)summary(data.surv.contx)

#for binary predictorx=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)summary(data.surv.binx)

form.interaction Create interaction terms of predictor(s) and potential moderator(s).

Description

Create interaction terms of predictor(S) and potential moderator(s). Mainly for linear models.

Page 19: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

med 19

Usage

form.interaction(x,pred,inter.cov,predref=NULL,kx=NULL)

Arguments

x As the x in data.org.

pred The predictor(s) that might have interaction effect with the potential moderators.

inter.cov The vector of names of potential moderators, which are included in x as covari-ates.

predref The reference group of the predictor if the predictor is categorical.

kx The interaction is with the kx-th predictor(s). kx can be a vector. If kx is null,the interaction is with each predictor.

Details

form.interaction is used to create interaction terms between predictor(s) and potential moderator(s).The created interaction terms should be used as covariates in linear mediation analysis. The functionis not needed for nonlinear mediation method.

Author(s)

Qingzhao Yu <[email protected]>

See Also

"test.moderation", "moderate"

Examples

data("weight_behavior")pred=data.frame(weight_behavior[,3])names(pred)="pred"x=weight_behavior[,c(2,4:14)]inter=form.interaction(x,pred,inter.cov=c("sports","sweat"),predref=NULL)x=cbind(x,inter)head(x)

med Mediation Analysis with Binary or Continuous Predictor

Description

To estimate the mediation effects when the predictor is binary or continuous.

Page 20: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

20 med

Usage

med(data, x=data$bin.results$x, y=data$bin.results$y, dirx=data$bin.results$dirx,binm=data$bin.results$binm,contm = data$bin.results$contm,catm = data$bin.results$catm, jointm = data$bin.results$jointm,cova=data$bin.results$cova, allm = c(contm, catm),margin=1, n=20, nonlinear=F, df1=1, nu=0.001,D=3,distn=NULL,family1=data$bin.results$family1,refy=rep(0,ncol(y)),binpred=data$bin.results$binpred,x.new=x,pred.new=dirx,

cova.new=cova,type=NULL, w=NULL, w.new=NULL,xmod=NULL,custom.function=NULL)

Arguments

data the list of result from data.org that organize the covariates, mediators, predictorand outcome. If data is FALSE, then need to set x1, y1, dirx, contm, catm, andjointm.

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

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

dirx the vector or matrix of predictor(s). The reference group is set to be 0. Need toset 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 contin-uous mediators. Need to set up only when data is FALSE.

catm categorical mediators should be binarized and be presented as a list, where thefirst item is the number of categorical variables and the following items arethe names or the column numbers of each binarized categorical variable in x.data.org organizes the categorical mediators in this format after they pass themediator 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 con-sidered, and each of the following items identifies the names or the columnnumbers of the mediators in x for each group of joint mediators. Need to set uponly when data is FALSE.

cova The data frame of covariates to be used to predict the mediator(s). The covariatesin cova cannot be potential mediators. If the covariates are for some specificpotential mediators, cova$for.m is the vector of names of potential mediatorsthat use the covariates. Works for continuous predictors (pred) only, also thespecified covariates should have no missing if only some mediators uses thecovariates. Need to set up only when data is FALSE.

allm the column numbers of all mediators. Need to set up only when data is FALSE.The default value of allm is c(contm,catm).

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

Page 21: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

med 21

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

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

df1 if nonlinear is TURE, natural cubic spline will be used to fit the relationshipbetween the predictor and each mediator. The df is the degree of freedom in thens() 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, bydefault, D=3. See also help(gbm.fit).

distn the assumed distribution(s) of the outcome(s) if MART is used for final fullmodel. The default value of distn is "gaussian" for continuous y, "bernoulli" forbinary y and coxph for "Surv" class outcome.

family1 a list with the ith item define the conditional distribution of y[,i] given x, and thelinkage function that links the mean of y with the system component if gener-alized linear model is used as the final full model. The default value of family1is gaussian(link="identity") for contiuous y[,i], and binomial(link = "logit") forbinary y[,i].

refy if y is binary, the reference group of y.binpred if TRUE, the predict variable is binary.x.new A new set of covariates, of the same format as x (after data.org), on which to

calculate the mediation effects. For continuous predictor only. If is NULL, themediation effects will be calculated based on the original data set.

pred.new A new set of predictor(s), of the same format as pred (after data.org), on whichto calculate the mediation effects. For continuous predictor only.

cova.new A new set of covariate(s) to estimate mediators, of the same format as cova.type the type of prediction when y is class Surv. By default, type is "risk".w the weight for each case in x.w.new the weight for each case in x.new.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 re-sponse 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 predis allowed. The customer defined model should be able to make prediction byusing "predict(object, newdata=...)", where the object is the results of the fittedmodel. If a specific package needs to be called to fit the model, the user shouldcall the package first. For example, if the gamlss package is used to fit a piece-wise polynomial with "age" to be the mediator and "race" be the predictor, wecan 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 cus-tom.function[j] is NA, the usual method will be used to fit y[j].

Page 22: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

22 med

Details

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

Value

The result is an med object with the item a.binx for results of binary or categorical exposure(s) andthe item a.contx for continuous exposure(s):

denm a matrix where each column gives the estimated direct effect not from the cor-responding mediator (identified by the column name), see Yu et al. (2014) forthe definition, and each row corresponding to the results from one resamplingfor binary predictor or the results on a row of x.new for continuous predictor.

ie a matrix where each column gives the estimated indirect effect from the corre-sponding mediator (identified by the column name) and each row correspondingto the results from one resampling for binary predictor or the results on a row ofx.new for continuous predictor.

te a vector of the estimated total effect on x.new.

model a list, where the first item, MART, is TRUE if a mart is fitted as the final model;the second item, Survial is T if a survival model is fit; the third item, type, is thetype of prediction when a survival model is fitted; the fourth item, full.model, isthe fitted final full model where y is the outcome and all predictor, covariates,and mediators are the explanatory variables; and the fifth item, best.iter, is thenumber of best iterations if MART is used to fit the final model, is NULL if thefinal model is a generalized linear model.

Author(s)

Qingzhao Yu <[email protected]>

References

J.H. Friedman, T. Hastie, R. Tibshirani (2000) <doi:10.1214/aos/1016120463>. "Additive LogisticRegression: a Statistical View of Boosting," Annals of Statistics 28(2):337-374.

J.H. Friedman (2001) <doi:10.1214/aos/1013203451>. "Greedy Function Approximation: A Gra-dient Boosting Machine," Annals of Statistics 29(5):1189-1232.

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

Page 23: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

med 23

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

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

See Also

"boot.med" to make inferences on the estimated mediation effects using bootstrap method.

Examples

data("weight_behavior")##binary x#binary yx=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<-med(data=data.bin,n=2)#or use self-defined final functiontemp1<-med(data=data.bin,n=2,custom.function =

'glm(responseY~.,data=dataset123,family="quasibinomial",weights=weights123)')

temp2<-med(data=data.bin,n=2,nonlinear=TRUE)

#multiple predictors (categorical and continuous predictors)x=weight_behavior[,c(3,5:14)]pred=weight_behavior[,c(2,4)]y=weight_behavior[,15]data.b.b.2.3<-data.org(x,y,mediator=4:11,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="OTHER", alpha=0.4,alpha2=0.4)temp1.2<-med(data.b.b.2.3,n=2)temp2.2<-med(data.b.b.2.3,n=2,nonlinear=TRUE)

#multivariate responsesx=weight_behavior[,c(2:3,5:14)]pred=weight_behavior[,4]y=weight_behavior[,c(1,15)]data.b.b.2.4<-data.org(x,y,mediator=5:12,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="OTHER", alpha=0.4,alpha2=0.4)temp1.3<-med(data.b.b.2.4,n=2)

#or use the self defined functiontemp1.3<-med(data.b.b.2.4,n=2,custom.function =c('glm(responseY~.,

data=dataset123,family="gaussian",weights=weights123)','glm(responseY~.,data=dataset123,family="quasibinomial",weights=weights123)'))

temp2.3<-med(data.b.b.2.4,n=2,nonlinear=TRUE)

Page 24: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

24 med

#continuous yx=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<-med(data=data.cont,n=2)temp4<-med(data=data.cont,n=2,nonlinear=TRUE)

##continuous x#binary yx=weight_behavior[,3:14]pred=weight_behavior[,2]y=weight_behavior[,15]data.contx<-data.org(x,y,pred=pred,mediator=4:10,alpha=0.4,alpha2=0.4)temp5<-med(data=data.contx,n=2)

#or use the self defined functiontemp5<-med(data=data.contx,n=2,custom.function ='glm(responseY~.,

data=dataset123,family="quasibinomial",weights=weights123)')temp6<-med(data=data.contx,n=2,nonlinear=TRUE,nu=0.05)

#continuous yx=weight_behavior[,3:14]y=weight_behavior[,1]pred=weight_behavior[,2]data.contx<-data.org(x,y,pred=pred,contmed=c(11:12),binmed=c(6,10),

binref=c(1,1),catmed=5,catref=1,alpha=0.4,alpha2=0.4)

temp7<-med(data=data.contx,n=2)temp8<-med(data=data.contx,n=2,nonlinear=TRUE,nu=0.05)

##Surv class outcome (survival analysis)data(cgd1) #a dataset in the survival packagex=cgd1[,c(4:5,7:12)]pred=cgd1[,6]status<-ifelse(is.na(cgd1$etime1),0,1)y=Surv(cgd1$futime,status)#for continuous predictordata.surv.contx<-data.org(x,y,pred=pred,mediator=1:ncol(x),

alpha=0.5,alpha2=0.5)temp9.contx<-med(data=data.surv.contx,n=2,type="lp")

#close to mart results when use type="lp"temp9.contxtemp10.contx<-med(data=data.surv.contx,n=2,nonlinear=TRUE)#results in the linear part unittemp10.contx

#for binary predictorx=cgd1[,c(5:12)]pred=cgd1[,4]data.surv.binx<-data.org(x,y,pred=pred,mediator=1:ncol(x),

Page 25: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

mma 25

alpha=0.4,alpha2=0.4)temp9.binx<-med(data=data.surv.binx,n=2,type="lp")temp9.binxtemp10.binx<-med(data=data.surv.binx,n=2,nonlinear=TRUE)temp10.binx

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=NULL,catmed=NULL,catref=NULL,jointm=NULL,cova=NULL, refy=rep(NA,ncol(data.frame(y))),predref=rep(NA,ncol(data.frame(pred))),alpha=0.1,alpha2=0.1, margin=1, n=20,nonlinear=F,df1=1,nu=0.001,D=3,distn=NULL,family1=as.list(rep(NA,ncol(data.frame(y)))),n2=50,w=rep(1,nrow(x)),testtype=1, x.new=NULL, pred.new=NULL, cova.new=NULL, type=NULL,w.new=NULL,all.model=FALSE,xmod=NULL,custom.function = NULL)

Arguments

x a data frame contains the predictor, all potential mediators and covariates. Allvaraibles in x that are not identified as potential mediators (by mediator, con-tmed, binmed, catmed, or jointm) are forced in mediation analysis as covariates.

y the vector of outcome variable.

pred the vector/matrix of the predictor(s).

mediator the list of mediators (column numbers in x or by variable names). The mediatorsto be checked can be identified by "contmed", "binmed" and "catmed", or by thisargument, "mediator", where binary and categorical mediators in x are identifiedby 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 thefirst item indicates the number of groups of mediators to be considered jointly,and each of the following items identifies the column numbers of the mediatorsin x for each group of joint mediators.

Page 26: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

26 mma

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

refy if y is binary, the reference group of y.By default, the reference group will bethe first level of as.factor(y).

predref if predictor is binary, identify the reference group of the binary predictor. Bydefault, the reference group will be the first level of the predictor.

alpha the significance level at which to test if the potential mediators (identified bycontmed, binmed, and catmed) can be used as a covariate or mediator in esti-mating y when all variables in x are included in the model. The default value isalpha=0.1

alpha2 the significant level at which to test if a potential mediator is related with thepredictor. The default value is alpha2=0.1.

margin if binpred is FALSE, define the change in predictor when calculating the medi-ation effects, see Yu et al. (2014).

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

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

df1 if nonlinear is TURE, natural cubic spline will be used to fit the relationshipbetween the countinuous predictor and each mediator. The df is the degree offreedom in the ns() function, the default is 1.

nu set the parameter "interaction.depth" in gbm function if MART is to be used, bydefault, 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 contin-uous y.

family1 define the conditional distribution of y given x, and the linkage function thatlinks the mean of y with the system component if generalized linear model isused 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.

w the weight for each observation.

testtype if the testtype is 1 (by default), covariates/mediators are identified using fullmodel; if the testtype is 2, covariates/mediators are tested one by one in modelswith the predictor only.

Page 27: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

mma 27

x.new A new set of predictor and corresponding covariates, of the same format as x(after data.org), on which to calculate the mediation effects. For continuouspredictor only. If is NULL, the mediation effects will be calculated based on theoriginal data set.

pred.new A new set of predictor(s), of the same format as x (after data.org), on which tocalculate the mediation effects. For continuous predictor only.

cova.new a new set of covaraite(s).

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 trueto 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 re-sponse 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 predis allowed. The customer defined model should be able to make prediction byusing "predict(object, newdata=...)", where the object is the results of the fittedmodel. If a specific package needs to be called to fit the model, the user shouldcall the package first. For example, if the gamlss package is used to fit a piece-wise polynomial with "age" to be the mediator and "race" be the predictor, wecan 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 cus-tom.function[j] is NA, the usual method will be used to fit y[j].

Details

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

Value

Returns an mma object.

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

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

model a list where the first item, MART, is T if mart is fitted for the final model; thesecond item, Survival, is T if a survival model is fitted; the third item, type, isthe type of prediction when a survival model is fitted; the fourth item, model, is

Page 28: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

28 mma

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 thenumber 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=F.

boot.detail for continuous predictor only: a list that contains the mediation effects on eachrow of new.pred: new.pred=new.pred, 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 onebootstrap sample.

Author(s)

Qingzhao Yu <[email protected]>

References

Baron, R.M., and Kenny, D.A. (1986) <doi:10.1037/0022-3514.51.6.1173>. "The moderator-mediatorvariable distinction in social psychological research: conceptual, strategic, and statistical consider-ations," J. Pers Soc Psychol, 51(6), 1173-1182.

J.H. Friedman, T. Hastie, R. Tibshirani (2000) <doi:10.1214/aos/1016120463>. "Additive LogisticRegression: a Statistical View of Boosting," Annals of Statistics 28(2):337-374.

J.H. Friedman (2001) <doi:10.1214/aos/1013203451>. "Greedy Function Approximation: A Gra-dient Boosting Machine," Annals of Statistics 29(5):1189-1232.

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"data.org" is for mediator tests, and "med" , and "boot.med" for mediation analysis and infer-ences.

Page 29: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

mma 29

Examples

data("weight_behavior")#binary predictor#binary yx=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,15]temp.b.b.glm<-mma(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,n=2,n2=2)

temp.b.b.mart<-mma(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,nonlinear=TRUE,n=2,n2=5)

#continuous yx=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=data.frame(weight_behavior[,1])colnames(y)="bmi"temp.b.c.glm<-mma(x,y,pred=pred,mediator=5:12,jointm=list(n=1,j1=7:9),

predref="M",alpha=0.4,alpha2=0.4,n2=20)temp.b.c.mart<-mma(x,y,pred=pred,mediator=5:12,jointm=list(n=1,j1=7:9),

predref="M",alpha=0.4,alpha2=0.4,n=2,nonlinear=TRUE,n2=20)

##Surv class outcome (survival analysis)data(cgd1) #a dataset in the survival packagex=cgd1[,c(4:5,7:12)]pred=cgd1[,6]status<-ifelse(is.na(cgd1$etime1),0,1)y=Surv(cgd1$futime,status)#for continuous predictortemp.cox.contx<-mma(x,y,pred=pred,mediator=1:ncol(x),

alpha=0.5,alpha2=0.5,n=1,n2=2,type="lp")summary(temp.cox.contx)temp.surv.mart.contx<-mma(x,y,pred=pred,mediator=1:ncol(x),

alpha=0.5,alpha2=0.5,nonlinear=TRUE,n2=2)#summary(temp.surv.mart.contx,ball.use=F)#plot(temp.surv.mart.contx,vari="steroids")#plot(temp.cox.contx,vari="steroids")

#for binary predictorx=cgd1[,c(5:12)]pred=cgd1[,4]temp.cox.binx<-mma(x,y,pred=pred,mediator=1:ncol(x),

alpha=0.4,alpha2=0.4,n=1,n2=2,type="lp")summary(temp.cox.binx)#temp.surv.mart.binx<-mma(x,y,pred=pred,mediator=1:ncol(x),# alpha=0.4,alpha2=0.4,nonlinear=TRUE,n=1,n2=2)#summary(temp.surv.mart.binx, RE=T,ball.use=F)#plot(temp.surv.mart.binx,vari="hos.cat")#plot(temp.cox.binx,vari="hos.cat")

Page 30: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

30 moderate

moderate Calculate and plot the direct effect of the selected exposure variableat each level of the moderator.

Description

Calculate and plot the direct effect of the selected exposure variable at each level of the moderator.

Usage

moderate(med1,vari,j=1,kx=1,continuous.resolution=100,plot=T)

Arguments

med1 The med object from the med function.

vari The name of the moderator.

j The jth response if the response is multiple.

kx The moderate effect is with the kx-th predictor(s).continuous.resolution

The number of equally space points at which to evaluate continuous predictors.

plot Plot the direct effect at each level of the moderator if ture.

Details

Calculate and plot the direct effect of the selected exposure variable at each level of the moderatorbase on the result from the med function.

Value

The moderate returns a list where the item result is a data frame with two or three elements

moderator the moderator levels.

x the level of the exposure variable – available only for continuous exposure andmoderate with nonlinear method.

de the direct effect at the corresonding moderator (and exposure) level(s).

Author(s)

Qingzhao Yu <[email protected]>

See Also

"form.interaction", "test.moderation"

Page 31: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

plot.med 31

Examples

#nonlinear modeldata("weight_behavior")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)temp2<-med(data=data.bin,n=2,nonlinear=TRUE)result1=moderate(temp2,vari="race")result2=moderate(temp2,vari="age")

#linear modeldata("weight_behavior")pred=weight_behavior[,3]x=weight_behavior[,c(2,4:14)]inter=form.interaction(x,pred,inter.cov=c("race","age"),predref="M")x=cbind(x,inter)head(x)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<-med(data=data.bin,n=2)result3=moderate(temp1,vari="race")result4=moderate(temp1,vari="age")

##with a transformation of continuous moderatorx=weight_behavior[,c(2,4:14)]x=cbind(x,age2=x[,"age"]^2)inter=form.interaction(x,pred,inter.cov=c("age","age2"),predref="M")x=cbind(x,inter)head(x)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<-med(data=data.bin,n=2)result5=moderate(temp1,vari="age")

plot.med Plot the mediation effect on the fitted med object

Description

Plot the marginal effect of the selected variable on the outcome, and the marginal effect of thepredictor on the selected variable.

Usage

## S3 method for class 'med'plot(x,...,vari,xlim=NULL)

Page 32: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

32 plot.mma

Arguments

x a med object created initially call to med, med.binx, or med.contx.

vari an indices or the name of the variable to plot.

xlim the range of the variable to be plotted.

... other arguments passed to the plot function.

Details

plot.med plots the marginal effect of the selected variable on the outcome, and the marginal effectof the predictor on the selected variable. If the predictor is binary, draw a histogram or boxplot ofthe marginal density of the variable at each different value of the predictor.

Author(s)

Qingzhao Yu <[email protected]>

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof Biometrics & Biostatistics,5(2): 189.

See Also

"med"

Examples

data("weight_behavior")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<-med(data=data.bin,n=2)temp2<-med(data=data.bin,n=2,nonlinear=TRUE)plot(temp1,data.bin,vari="exercises",xlim=c(0,50))plot(temp2,data.bin,vari="sports")

plot.mma Relative effects plot of the fitted mma object

Description

Plot the marginal effect of the selected variable on the outcome, and the marginal effect of thepredictor on the selected variable.

Page 33: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

plot.mma 33

Usage

## S3 method for class 'mma'plot(x,...,vari,xlim=NULL,alpha=0.95,quantile=F)

Arguments

x a mma object created initially call to mma, boot.met.binx, or boot.met.contx.

vari an indices or the name of the variable to plot.

xlim the range of the variable to be plotted.

alpha for continuous predictor only, to draw the alpha confidence interval of the indi-rect effect.

quantile for continuous predictor only, if true to draw the alpha confidence interval of theindirect effect based on quantile, otherwise, based on the normal approximation.

... other arguments passed to the plot function.

Details

plot.mma plots the marginal effect of the selected variable on the outcome, and the marginal effectof the predictor on the selected variable. If the predictor is binary, draw a histogram or boxplot ofthe marginal density of the variable at each different value of the predictor.

Author(s)

Qingzhao Yu <[email protected]>

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"mma","boot.med"

Page 34: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

34 plot2.mma

Examples

data("weight_behavior")x=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,15]temp.b.b.glm<-mma(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,n=2,n2=2)plot(temp.b.b.glm,vari="exercises",xlim=c(0,50))plot(temp.b.b.glm,vari="sports")

plot2.mma Relative effects plot of the fitted mma object with moderator

Description

Plot the marginal effect of the selected variable on the outcome, and the marginal effect of thepredictor on the selected variable, at each level of the moderator.

Usage

plot2.mma(x,...,vari,xlim=NULL,alpha=0.95,quantile=F,moderator,xj=1)

Arguments

x a mma object created initially call to boot.mod.

vari an indices or the name of the variable to plot.

xlim the range of the variable to be plotted.

alpha for continuous predictor only, to draw the alpha confidence interval of the indi-rect effect.

quantile for continuous predictor only, if true to draw the alpha confidence interval of theindirect effect based on quantile, otherwise, based on the normal approximation.

... other arguments passed to the plot function.

moderator the name of the moderator.

xj the moderation effect on the xjth predictor.

Details

plot2.mma plots the marginal effect of the selected variable on the outcome, and the marginal effectof the predictor on the selected variable, at each level of the moderator. If the predictor is binary,draw a histogram or boxplot of the marginal density of the variable at each different value of thepredictor.

Author(s)

Qingzhao Yu <[email protected]>

Page 35: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

print.med 35

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"boot.mod"

Examples

#see boot.mod menu.

print.med Print an med object

Description

Print the estimation of mediation effects from an med object: from functions med.

Usage

## S3 method for class 'med'print(x,...,digit=4)

Arguments

x a med object created initially call to med.

... other arguments passed to the print function.

digit the number of digits to keep at printing.

Author(s)

Qingzhao Yu <[email protected]>

Page 36: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

36 print.mma

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"med"

Examples

data("weight_behavior")##binary x#binary yx=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<-med(data=data.bin,n=2)temp2<-med(data=data.bin,n=2,nonlinear=TRUE)temp1print(temp2,digit=5)

print.mma Print a mma object

Description

Print the estimation of mediation effects from an mma object.

Usage

## S3 method for class 'mma'print(x,...,digit=3)

Page 37: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

print.mma 37

Arguments

x a mma object created initially call to mma, boot.med.binx, or boot.med.contx.

... other arguments passed to the print function.

digit the number of decimal digits to keep.

Value

Return a LIST

ie estimation of the indirect effects from the mma object.

te estimation of the total effect from the mma object.

de estimation of the direct effect from the mma object.

Author(s)

Qingzhao Yu <[email protected]>

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"mma","boot.med"

Examples

data("weight_behavior")x=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,15]temp.b.b.glm<-mma(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,n=2,n2=2)print(temp.b.b.glm,digit=8)

Page 38: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

38 summary.med_iden

summary.med_iden Summary method for class "med_iden".

Description

Compute the estimations, standard deviations and confidence intervals of the mediation effects.

Usage

## S3 method for class 'med_iden'summary(object,...,only=F)## S3 method for class 'summary.med_iden'print(x,...)

Arguments

object a med_iden object created initially call to data.org.

x a summary.med_iden object created initially call to summary.med_iden

... other arguments passed to the print function.

only if only=T, show test results for selected covariates and mediators only.

Details

summary.med_iden gives a list of identified mediators, covariates and the test results.

Value

The function summary.med_iden return a list of covariates and mediators as identified by a seriestests.

mediator variable names of the identified mediators, either siginicant in both full modeland in relate to the predictor, or being a member of the pre-identified joint me-diators.

covariate variable names of covariates: being significant in the full model but not signifi-cantly relate with the predictor.

tests statistical test results.

results the original object.

Author(s)

Qingzhao Yu <[email protected]>

Page 39: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

summary.mma 39

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"mma","boot.med"

Examples

data("weight_behavior")x=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,15]data.b.b.2<-data.org(x,y,mediator=5:12,jointm=list(n=1,j1=c(5,7,9)),

pred=pred,predref="M", alpha=0.4,alpha2=0.4)summary(data.b.b.2)

summary.mma Summary of an mma project

Description

Compute the estimations, standard deviations and confidence intervals of the mediation effects.

Usage

## S3 method for class 'mma'summary(object,..., alpha=0.05, plot=TRUE, RE=FALSE,quant=F,ball.use=F,bymed=FALSE)## S3 method for class 'summary.mma'print(x,...,digit=3)

Page 40: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

40 summary.mma

Arguments

object a mma object created initially call to mma, boot.met.binx, or boot.met.contx.

x a summary.mma object created initially call to summary.mma.

... other arguments passed to the print function.

alpha the alpha level for confidence interval.

plot default is TRUE, if ture, draw a barplot of the mediation effects with confidenceintervals.

RE default is FALSE, if ture, show the inferences on relative mediation effects.

quant default is TRUE, if ture and ball.use is F, draw the confidence intervals of relativeeffects using quantile.

ball.use default is TRUE, if ture, draw the confidence intervals of relative effects usingthe confidence ball. If both quant and ball.use are false, draw the confidenceintervals based on the standard deviaitons from bootstrap estimates.

digit the number of decimal digits to keep.

bymed if true, show results by each mediator.

Details

summary.mma gives a list of the estimations and summary statistics based on the bootstrap results.If plot=T, draw a barplot of the relative effects of the direct effect of the predictor and indirect effectsof the mediators. Relative effects is defined as the (in)direct effect divided by the total effect. Theplot is arranged in order from the largest to the smallest relative effect.

Value

The function summary.mma return a list. The first item, results, is the list for mediation effects,and the second item, re, is the list for relative effects. Under them, results have the items ie, teand de; re has the items ie and de. In each of the items, est is the estimation of the corresponding(relative) mediation effects based on the whole data, mean is the average estimated (relative) effectsfrom the bootstrap samples, sd is the standard deviation of the estimates from the bootstrap sample.upbd and lwbd are the upper and lower bound of the confidence interval of the estimation usingparametric method from the bootstrap sample, upbd_q and lwbd_q are the corresponding quantilesof the estimation from the bootstrap sample.

ie a matrix of statistics inference on the (relative) indirect effects from the mmaobject. est is the estimate using the full sample. mean is the estimate that av-erage over the bootstrap estimates. sd is the standard deviation of the bootstrapestimates. upbd and lwbd are the confidence bounds based on sd. upbd_q andlwbd_q are the confidence bounds based on quantiles of the bootstrap estimates.upbd_b and lwbd_b are condidence ball bounds based on bootstap estimates.

te statistics inference on the total effects from the mma object.

de statistics inference on the (relative) direct effects from the mma object.

If plot=T, draw a barplot of the relative mediation effects.

Page 41: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

test.moderation 41

Author(s)

Qingzhao Yu <[email protected]>

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

See Also

"mma","boot.med"

Examples

data("weight_behavior")x=weight_behavior[,c(2,4:14)]pred=weight_behavior[,3]y=weight_behavior[,15]temp.b.b.glm<-mma(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,n=2,n2=2)summary(temp.b.b.glm, RE=TRUE, ball.use=FALSE)summary(temp.b.b.glm, ball.use=FALSE)

test.moderation Test for moderation effects.

Description

Used on a med object, test if there are moderation effects.

Usage

test.moderation(med1,vari,j=1,kx=NULL)

Page 42: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

42 test.moderation

Arguments

med1 a med object created initially call to med.

vari If med1 was from generalized linear method, vari is the vector of names of po-tential moderation effects – the interaction terms formed by the potential mod-erator(s) times the predictor(s). Those interaction terms have to be included inmediation analysis as covariates.If med1 was formed by nonlinear method, vari is the vector of names of potentialmoderators, which have been included in mediation analysis as covariates.

j To check the moderation effect on the jth response.

kx The moderation effect is with the kx-th predictor(s). kx can be a vector. If kx isnull, the moderation effect is with each predictor.

Details

test.moderation is used to test whether direct moderation effect is significant based on the med objectfrom med function (mediation analysis). If geralized linear models were used for mediation anlysis,the moderation effects (formed by the interactions of potential moderators and predictor) shouldbe included in the mediation analysis as covariates. The function test.modeartion will give thesignificance levels of these interaction terms. If nonlinear models were used for mediation analysis,the potential moderators (but not the interaction terms) should have been included in mediationanalysis as covarites. The function test.moderation will give not only significance levels of theirinteraction with the predictor(s) in generalized linear model, but also the H-statistics by Friedmanand Popescue (2008).

Author(s)

Qingzhao Yu <[email protected]>

References

Yu, Q., Fan, Y., and Wu, X. (2014) <doi:10.4172/2155-6180.1000189>. "General Multiple Media-tion Analysis With an Application to Explore Racial Disparity in Breast Cancer Survival," Journalof 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 con-sidering 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 mediationanalysis," Journal of Open Research Software, 5(1), 11.

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

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

Friedman, J.H. and Popescu B.E. (2008) "PREDICTIVE LEARNING VIA RULE ENSEMBLES,"Annals of Applied Statistics, 2(3): 916-954.

Page 43: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

weight_behavior 43

See Also

"med"„ "moderate"

Examples

data("weight_behavior")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)temp2<-med(data=data.bin,n=2,nonlinear=TRUE)test.moderation(temp2,c("sports","sweat"),j=1,kx=NULL)

x=cbind(x,form.interaction(x,pred,inter.cov=c("sports","sweat"),predref=NULL))

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<-med(data=data.bin,n=2)test.moderation(temp1,c("sports","sweat"),j=1,kx=NULL)

weight_behavior Weight_Behavior Data Set

Description

This database was obtained from the Louisiana State University Health Sciences Center, New Or-leans, by Dr. Richard Scribner. He explored the relationship between BMI and kids behaviorthrough a survey at children, teachers and parents in Grenada in 2014. This data set includes 691observations and 15 variables.

Usage

data(weight_behavior)

Format

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

Page 44: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

44 weight_behavior

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

Examples

data(weight_behavior)names(weight_behavior)

Page 45: Package ‘mma’ - R · 2020-03-23 · Package ‘mma’ March 23, 2020 Type Package Title Multiple Mediation Analysis Version 10.2-2 Date 2020-02-27 Author Qingzhao Yu and Bin Li

Index

∗Topic Continuous Predictorboot.med, 4

∗Topic Datasetscgd1, 13weight_behavior, 43

∗Topic Mediation Analysisboot.med, 4med, 19mma, 25

∗Topic Mediator Testsdata.org, 13mma, 25

∗Topic Moderation Effect withMediation Analysis

boot.mod, 9∗Topic Package

mma-package, 2

boot.med, 2, 4, 23, 28, 33, 37, 39, 41boot.mod, 9, 35

cgd1, 13

data.org, 2, 13, 16, 28

form.interaction, 18, 30

med, 2, 7, 11, 19, 28, 30, 32, 36, 43mma, 2, 25, 33, 37, 39, 41mma-package, 2moderate, 19, 30, 30, 43

plot.med, 31plot.mma, 32plot2.mma, 34print.med, 35print.mma, 36print.summary.med_iden

(summary.med_iden), 38print.summary.mma (summary.mma), 39

summary.med_iden, 38summary.mma, 39

test.moderation, 19, 30, 41

weight_behavior, 43

45