Created
May 3, 2019 18:57
-
-
Save ha0ye/87d955633c82f630b677a14448c965ba to your computer and use it in GitHub Desktop.
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(lavaan) | |
library(visNetwork) | |
model <- ' | |
# measurement model | |
ind60 =~ x1 + x2 + x3 | |
dem60 =~ y1 + y2 + y3 + y4 | |
dem65 =~ y5 + y6 + y7 + y8 | |
# regressions | |
dem60 ~ ind60 | |
dem65 ~ ind60 + dem60 | |
# residual correlations | |
y1 ~~ y5 | |
y2 ~~ y4 + y6 | |
y3 ~~ y7 | |
y4 ~~ y8 | |
y6 ~~ y8 | |
' | |
fit <- sem(model, data=PoliticalDemocracy) | |
df <- parameterEstimates(fit) | |
v <- union(df$lhs, df$rhs) | |
nodes <- data.frame(id = seq_along(v), | |
label = v, | |
shape = "circle") | |
edges <- data.frame(from = match(df$lhs, v), | |
to = match(df$rhs, v), | |
label = round(df$est, 2), | |
arrows = "to") | |
visNetwork(nodes, edges) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment