Structural equation models (SEMs) rarely reject the null hypothesis that there is no model misspecification. One explanation for this problem is that covariance structures are influenced by major factors which we can hypothesize about and minor factors which we cannot predict a-priori, e.g. MacCallum and Tucker (1991).
The goal of
minorbsem is to facilitate fitting Bayesian SEMs that estimate the influence of minor factors on the covariance matrix, following the approach in Uanhoro (2023). Briefly, the method estimates all residual covariances with priors that shrink them towards zero, and the model returns the magnitude of the influence of minor factors.
The package only fits a limited number of model configurations:
- CFA, allowing cross-loadings (which may be automatically estimated), correlated errors terms, and fully oblique or orthogonal factors (useful for fitting bifactor models)
- SEMs allowing latent regressions (only), cross-loadings, and correlated error terms.
However, the package does not currently support fitting:
- multi-group models,
- multilevel models, or
- models with specially constrained parameters (e.g., setting two parameters equal).
All data are assumed multivariate normal, i.e. no binary, ordinal models.
minorbsem is hosted on GitHub, so we need the
remotes package to install it. We also need to install the
cmdstanr package and CmdStan in order to use Stan.
install.packages("remotes") # install remotes # next install cmdstanr and CmdStan: install.packages( "cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")) ) cmdstanr::check_cmdstan_toolchain(fix = TRUE) cmdstanr::install_cmdstan() # Then finally minorbsem: remotes::install_github("jamesuanhoro/minorbsem")
library(minorbsem) # Basic Holzinger-Swineford model syntax_1 <- " F1 =~ x1 + x2 + x3 F2 =~ x4 + x5 + x6 F3 =~ x7 + x8 + x9" # Expect a summary table output fit_1 <- minorbsem(syntax_1, HS) # Save output table to html file, see: ?pretty_print_summary for more options pretty_print_summary(fit_1, save_html = "baseline_model.html") # Histogram of parameters, see: ?parameter_hist for arguments parameter_hist(fit_1) # Traceplot of parameters, see: ?parameter_trace for arguments parameter_trace(fit_1) # Examine all standardized residual covariances plot_residuals(fit_1) plot_residuals(fit_1, type = "range")
Default method above is
method = "normal" assuming standardized residual covariances are on average 0 and vary from 0 in continuous fashion.
# Fit same model as above but use global-local prior to estimate # minor factor influences fit_gdp <- minorbsem(syntax_1, HS, method = "GDP") plot_residuals(fit_gdp) parameter_hist(fit_gdp) parameter_trace(fit_gdp) # Ignoring minor factor influences fit_none <- minorbsem(syntax_1, HS, method = "none") parameter_hist(fit_none) parameter_trace(fit_none) # Error!!!: Plotting residuals will give an error message # since minor factor influences are assumed null plot_residuals(fit_none)
All users of R (or SEM) are invited to submit functions or ideas for functions.
Feel free to:
- open an issue to report a bug or to discuss recommendations;
- submit pull requests to recommend modifications or suggest improvements.
You can also email the package maintainer, James Uanhoro (James dot Uanhoro at unt dot edu). Thank you for helping improve minorbsem :).