Last active
May 16, 2019 22:57
Star
You must be signed in to star a gist
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