View source: R/mediation_analysis.R
mediation_analysis | R Documentation |
Apply mediation analysis for non-rare binary outcome with two continuous mediators
mediation_analysis(
dt,
cnfd = c(),
dt2 = NULL,
cnfd2 = c(),
dt3 = NULL,
cnfd3 = c(),
nb = 0,
intv = 4,
unit = 1,
reNAME = NULL,
grpID = NULL,
mc = 5,
autoR = T,
stra = 1,
seed = 217
)
dt |
Input data. |
cnfd |
Confounder values. |
nb |
Number of bootstrapping. Default is 0 (no bootstrapping applied). |
intv |
Number of intervention, 3 or 4. Default is 3. |
para=c(rep(-0.5,9),1,1)
dat1=sim_mediation_data(0.5,1000,para) #binary exposure
apply(dat1,2,mean) #the proportion of Y should not be too skew (nearly 0 or 1)
res1_3=mediation_analysis(dat1)
tru1_3=calc_true_value(para)
dat2=sim_mediation_data(c(0,1),1000,para) #continous exposure
res2_4=mediation_analysis(dat2, intv=4, nb=500)
tru2_4=calc_true_value(para, intv=4)
summary(eIVF) #subset eIVF data for demo
res3_3=mediation_analysis(eIVF, cnfd=c(age=log(36),bmi=log(26)))
res3_4=mediation_analysis(eIVF, cnfd=c(age=log(36),bmi=log(26)), intv=4)
para_sg=c(rep(-0.5,3),rep(0,4),rep(-0.5,2),1,1) # for single mediator, set exposure-related parameters into 0
dat_sg=sim_mediation_data(0.5,1000,para_sg)
dat_sg$S=0 # set the second mediator into 0
res_sg_3=mediation_analysis(dat_sg)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.