Have a personal or library account? Click to login
Using SAS Macros for Multiple Mediation Analysis in R Cover

Using SAS Macros for Multiple Mediation Analysis in R

By: Paige Fisher,  Wentao Cao and  Qingzhao Yu  
Open Access
|Oct 2020

Figures & Tables

Table 1

Arguments for Proc_R_dataorg Macro.

ArgumentsDescriptionNotes
PATHPath where the macro is saved.
PATHDPath where the SAS dataset is stored.By default, the SAS dataset will be saved in the “Work’’ SAS library.
DATAName of the SAS dataset that contains the data for mediation analysis.Needs to read the data into SAS format before implementing the macro.
PATH_RPath where R dataset and txt file will be stored.Make sure the path includes only forward slashes (/).
XThe dataset that contains all potential mediators and covariates.
MEDIATORThe list of names or the column numbers in x of all potential mediators. If listed, the function tells whether the potential mediator is continuous or categorical by the type and number of unique values of each variable.The arguments CATMED and BINMED are used only when specific reference groups are needed to be specified (by BINREF and CATREF).
CONTMEDNames or column numbers of continuous mediators in X.
BINMEDNames or column numbers of binary mediators in X.
BINREFReference group(s) of the potential binary mediators in BINMED.The default reference group is the first level of the mediator.
CATMEDNames or column numbers of categorical mediators in X.If the categorical variable has 3 or more groups and numeric values, it must be specified using CATMED to be treated as categorical.
CATREFReference groups of the potential categorical mediators in CATMED.The default is the first level of the mediator.
PREDREFIf the predictor is categorical, the reference group for the predictor.The default is the first level of the predictor.
JOINTMGroup(s) of variables whose joint effect is of interest.The first item is the number of groups of joint mediators and the following items identify the column numbers of the mediators in X for each group of joint mediators.
REFYThe reference group for Y if Y is binary.
ALPHAThe significance level to test if the potential mediators is significant in estimating Y.The default is ALPHA=0.1.
ALPHA2The significance level to test if a potential mediator is significantly related with the predictor.The default is ALPHA2=0.1.
PREDThe vector or matrix of predictor(s).
YThe vector or matrix of the outcome variable.If Y is a survival outcome, then define it using the Surv(time,status) function.
TIMEIf Y is a time-to-event outcome, this is the variable in the dataset that indicates follow up time.
STATUSIf Y is a time-to-event outcome, this is a 0 to 1 indicator identifies no event or event separately.
jors-8-277-g1.png
Figure 1

Summary of identified mediators.

Table 2

Arguments for Proc_R_med Macro.

ArgumentsDescriptionNotes
MARGINThe change in predictor when calculating the mediation effects.The argument is useful only when the predictor is continuous. By default, MARGIN=1.
DIf MART is used, the parameter specifies the “interaction.depth” in gbm function.The default is D=3.
DISTNIf MART is used for the final full model, the assumed distribution of the outcome.The default is DISTN=“gaussian” for continuous y and DISTN=“bernoulli” for binary y.
nThe time of resampling in calculating the indirect effects.The default is n=20.
NUIf MART is used, set the parameter “shrinkage” in gbm function.The default is nu=0.001.
NONLINEARIf NONLINEAR=TRUE, MART will be used to fit the final full model in estimating the outcome. Splines with degree freedom DF1 are used to fit the relationship between the predictor and potential mediators.The default is NONLINEAR=FALSE, a generalized linear model will be used.
DF1The degrees of freedom in the ns() function when MART is used.The default is DF1=1.
TYPEThe type of prediction when Y is class Surv.The default is “risk”.
jors-8-277-g2.png
Figure 2

SAS output with the final full model.

Table 3

Arguments for Proc_R_bootmed Macro.

ArgumentsDescriptionNotes
n2The number of times of bootstrap resampling.The default is n2 = 50.
REThe summary function will also report the summaries of the relative effects, calculated as the “(in)direct effect/total effect” if RE=TRUE.
jors-8-277-g3.png
Figure 3

The estimated mediation effects.

jors-8-277-g4.png
Figure 4

Summary of the bootmed function.

Table 4

Arguments for Proc_R_bootmed_Plot Macro.

ArgumentsDescriptionNotes
VARIThe name of the variable to plot.
XLIMThe range of the variable to be plotted.
ALPHAFor continuous predictor only, to draw the 1-alpha confidence interval of the indirect effect.
QUANTILEFor continuous predictor only, to draw the alpha confidence interval of the indirect effect based on quantile QUANTILE=TRUE.
jors-8-277-g5.png
Figure 5

The marginal effects of exercise on overweight and the marginal effect of sex on exercise.

DOI: https://doi.org/10.5334/jors.277 | Journal eISSN: 2049-9647
Language: English
Submitted on: May 1, 2019
|
Accepted on: Sep 16, 2020
|
Published on: Oct 7, 2020
Published by: Ubiquity Press
In partnership with: Paradigm Publishing Services
Publication frequency: 1 issue per year

© 2020 Paige Fisher, Wentao Cao, Qingzhao Yu, published by Ubiquity Press
This work is licensed under the Creative Commons Attribution 4.0 License.