Created
August 23, 2021 11:47
-
-
Save EoinTravers/0e4d8b2331347e4efbf824474f3eb10f 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
plot_measurement_invariance = function(model){ | |
factor_loadings = parameterEstimates(model) %>% | |
rename(estimate = est, low = ci.lower, high = ci.upper) %>% | |
mutate(rhs = factor(rhs, levels = unique(rhs)), | |
lhs = factor(lhs, levels = unique(lhs)), | |
label = paste(lhs, op, rhs), | |
type = case_when( | |
op == '=~' ~ 'Loading', | |
op == '~~' ~ 'Covariance', | |
op == '~1' ~ 'Mean', | |
T ~ '???' | |
)) | |
if(!'group' %in% names(factor_loadings)){ | |
factor_loadings$group = 'Common' | |
} | |
ggplot(factor_loadings, | |
aes(fct_rev(label), estimate, | |
color = factor(group), | |
ymin = low, ymax = high)) + | |
facet_wrap(~type, scales = 'free') + | |
geom_point() + | |
geom_errorbar(width=.2) + | |
geom_hline(linetype = 'dashed', yintercept = 0) + | |
coord_flip() + | |
no_legend_bg() + | |
labs(x = 'Item', y = 'Weight', color = 'Group') | |
} | |
plot_measurement_invariance(model_full) + ggtitle('Full Invariance') | |
plot_measurement_invariance(model_strict) + ggtitle('Strict Invariance') | |
plot_measurement_invariance(model_strong) + ggtitle('Strong Invariance') | |
plot_measurement_invariance(model_weak) + ggtitle('Weak Invariance') | |
plot_measurement_invariance(model_configural) + ggtitle('Configural Invariance') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment