data("BSG2014")
## simple mediation
# fit the mediation model
fit_simple <- fit_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict")
# simulate data from the fitted mediation model
sim_simple <- sim_mediation(fit_simple, n = 100)
head(sim_simple)
## serial multiple mediators
# fit the mediation model
fit_serial <- fit_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamScore",
m = c("TaskConflict",
"TeamCommitment"),
model = "serial")
# simulate data from the fitted mediation model
sim_serial <- sim_mediation(fit_serial, n = 100)
head(sim_serial)
## parallel multiple mediators and control variables
# fit the mediation model
fit_parallel <- fit_mediation(BSG2014,
x = "SharedLeadership",
y = "TeamPerformance",
m = c("ProceduralJustice",
"InteractionalJustice"),
covariates = c("AgeDiversity",
"GenderDiversity"),
model = "parallel")
# simulate data from the fitted mediation model
# (here the explanatory variables are bootstrapped
# to maintain the correlations between them)
sim_parallel <- sim_mediation(fit_parallel, n = 100,
explanatory = "boot")
head(sim_parallel)
Run the code above in your browser using DataLab