library(lavaan)
library(semPlot)
# ---- Parallel Mediation Model
mod_parallel <-
'x04 ~ x01
x05 ~ x01
x06 ~ x01
x07 ~ x01
x10 ~ x04 + x05 + x06 + x07 + x01'
fit_parallel <- lavaan::sem(mod_parallel,
sem_example)
q_parallel(fit_parallel,
x = "x01",
m = c("x04", "x05", "x06", "x07"),
y = "x10")
q_parallel(fit_parallel,
x = "x01",
m = c("x04", "x05", "x06", "x07"),
y = "x10",
mediators_position = "top")
q_parallel(fit_parallel,
x = "x01",
m = c("x04", "x05", "x06", "x07"),
y = "x10",
mediators_position = "bottom")
# Suppress some elements for readability
q_parallel(fit_parallel,
x = "x01",
m = c("x04", "x05", "x06", "x07"),
y = "x10",
mediators_position = "bottom",
do_mark_se = FALSE)
# ---- Serial Mediation Model
mod_serial <-
'x04 ~ x01
x05 ~ x04 + x01
x06 ~ x04 + x05 + x01
x07 ~ x04 + x05 + x06 + x01
x08 ~ x04 + x05 + x06 + x07 + x01'
fit_serial <- lavaan::sem(mod_serial,
sem_example)
q_serial(fit_serial,
x = "x01",
m = c("x04", "x05", "x06", "x07"),
y = "x08")
q_serial(fit_serial,
x = "x01",
m = c("x04", "x05", "x06", "x07"),
y = "x08",
mediators_position = "bottom")
# Suppress some elements for readability
q_serial(fit_serial,
x = "x01",
m = c("x04", "x05", "x06", "x07"),
y = "x08",
mediators_position = "bottom",
do_mark_se = FALSE)
# ---- Simple Mediation Model: With Control Variables
mod_pa <-
'x3 ~ x1 + x2
x4 ~ x3 + x1 + x2'
fit_pa <- lavaan::sem(mod_pa,
pa_example)
mod_sem <-
'f1 =~ x01 + x02 + x03
f2 =~ x04 + x05 + x06 + x07
f3 =~ x08 + x09 + x10
f4 =~ x11 + x12 + x13 + x14
f3 ~ f1 + f2
f4 ~ f1 + f3'
fit_sem <- lavaan::sem(mod_sem,
sem_example)
q_simple(fit_pa,
x = "x1",
m = "x3",
y = "x4")
# Drawing latent factors only
q_simple(fit_sem,
x = "f1",
m = "f3",
y = "f4",
whatLabels = "std",
mediators_position = "bottom")
Run the code above in your browser using DataLab