Last active
May 16, 2019 22:57
-
-
Save scolwell/a7a57b3496d7e29dce2fa9a60b0194bb to your computer and use it in GitHub Desktop.
Simple Mediation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(simsem) | |
population <- " | |
# Fix means of each to 1 <-- for normal distrubuted N(0,1) | |
x ~ 0*1 | |
m ~ 0*1 | |
y ~ 0*1 | |
# Fix variance of each to 1 <-- for normal distribution N(0,1) | |
x ~~ 1*x | |
m ~~ 1*m | |
y ~~ 1*y | |
# Specify the relationships between the variables | |
y ~ .18*m + .22*x | |
m ~ .20*x | |
" | |
sample <- " | |
# Estimate the direct effects | |
y ~ b*m + c*x | |
m ~ a*x | |
# Estimate the indirect effects | |
ind.ab := a*b | |
# Estimate the total effects | |
total := a*b + c | |
" | |
# Run the simulation. First number is number of replications. | |
results <- sim(1000, sample, n = 150, generate=population, std.lv=TRUE, lavaanfun = "sem") | |
summary(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment