Source-linked AI summary
blavaan: Bayesian structural equation models via parameter expansion
Edgar C. Merkle, Yves Rosseel
TL;DR
Bayesian SEM estimation becomes difficult when models require general priors, novel structures, or correlated residuals. The paper presents blavaan, an R package that translates lavaan specifications into JAGS models, adds parameter expansion for residual covariances, and organizes Bayesian summaries and fit measures. The resulting tools support many multivariate normal SEMs and let researchers export JAGS code for extensions, while some model classes and prior specifications remain limited.
Problem
General priors, novel Bayesian SEMs, and correlated residuals are difficult to estimate and extend with existing procedures, motivating a more accessible approach.
Method
blavaan translates lavaan model syntax into JAGS code and uses parameter-expansion strategies, including approaches for covariance parameters, to estimate and summarize Bayesian SEMs.
Results
blavaan is useful for estimating many multivariate normal SEMs, with JAGS export enabling researchers to extend models as desired.
Takeaways & Limitations
Applied researchers can use expanded prior choices without learning an MCMC package, while methodologists can extend Bayesian SEMs without coding JAGS models from scratch.
Takeaways & Limitations
Support remains incomplete for latent interactions, ordinal variables, mixture models, and multilevel components, whose efficient sampling and lavaan specification still require work.
Abstract
from arXiv · showhide
This article describes blavaan, an R package for estimating Bayesian structural equation models (SEMs) via JAGS and for summarizing the results. It also describes a novel parameter expansion approach for estimating specific types of models with residual covariances, which facilitates estimation of these models in JAGS. The methodology and software are intended to provide users with a general means of estimating Bayesian SEMs, both classical and novel, in a straightforward fashion. Users can estimate Bayesian versions of classical SEMs with lavaan syntax, they can obtain state-of-the-art Bayesian fit measures associated with the models, and they can export JAGS code to modify the SEMs as desired. These features and more are illustrated by example, and the parameter expansion approach is explained in detail.
1. Introduction
blavaan is designed to make Bayesian SEM estimation and extension accessible through lavaan-style specification and JAGS-based computation. It addresses the difficulty of estimating models with general priors or correlated residuals while organizing summaries and Bayesian fit measures.
- blavaan implements Bayesian SEMs using JAGS while simplifying model specification, result summarization, and model extension.
- Classical SEMs represent observed variables through latent variables, factor loadings, intercepts, directed latent-variable paths, and residual terms under stated distributional assumptions.
- General MCMC programs are useful for general priors and novel models, but implementing or extending such models can be time-consuming and difficult.
- blavaan includes a parameter-expansion approach for JAGS estimation of models with correlated residuals, a setting that complicates covariance-matrix priors.
- The package uses lavaan syntax for model specification, converts models to JAGS syntax, and returns objects that use many lavaan functions.
- The package uses runjags for sampling and chain summaries, then organizes results and computes Bayesian fit measures.
2. Bayesian SEM
Bayesian SEM estimation becomes difficult for non-diagonal covariance structures, especially correlated residuals, under conventional conjugate-prior approaches. blavaan addresses this with JAGS-compatible parameter expansion, flexible covariance handling, fit measures, and alternative prior strategies.
- Motivation: Diagonal covariance assumptions restrict Bayesian SEMs when researchers need correlated residuals, whose partially zero covariance matrices complicate MCMC estimation.Existing alternatives include custom MCMC or general programs such as BUGS, JAGS, and Stan, but these can be time-consuming and difficult to extend.
- Parameter expansion: Parameter expansion introduces phantom latent variables so working-model covariance matrices become diagonal and can be estimated with univariate normals.The inferential covariance matrix is subsequently re-obtained from the working-model parameters.
- Parameter expansion: For many correlated latent variables, the reparameterization can converge slowly; blavaan instead uses multivariate normal sampling where possible and reparameterizes only when necessary.The reported problematic case is models with many, approximately > 5, correlated latent variables.
- Parameter expansion: Freeing phantom-variable loadings, rather than fixing them to 1, permits residual-covariance posteriors that overlap zero or become negative.The choice of nonzero loading locations follows the row and column positions of nonzero lower-triangular residual covariances.
- Priors on covariances: The alternative "fa" approach can favor speed in complex models, but its implied inferential priors are nonstandard and its working parameters are likelihood-unidentified.The paper therefore prefers the "srs" approach for observed-variable covariances and does not allow direct prior modification of "fa" working parameters.
- Model fit and comparison: blavaan provides posterior predictive checks, DIC, Laplace-approximated log-Bayes factors, WAIC, and LOO through fitMeasures() for Bayesian model evaluation and comparison.Because JAGS conditions on latent variables, blavaan separately computes the integrated likelihood after sampling so these statistics use the appropriate likelihood.
3. Overview of blavaan
blavaan extends lavaan-style Bayesian SEM specification with Bayesian-specific priors, JAGS export, convergence diagnostics, and initial-value controls. It converts models to JAGS syntax, supports customizable priors and manual extensions, and provides tools for monitoring MCMC convergence.
- Model specification: blavaan estimates confirmatory factor analysis and structural equation models through bcfa(), bsem(), and the general blavaan() function using syntax nearly identical to lavaan.The package also reuses many lavaan functions, making it familiar to lavaan users.
- Bayesian extensions: Bayesian-specific features include prior specification, JAGS syntax export and use, convergence diagnostics, and initial-value specification.These features are presented as additions to the main lavaan functionality.
- Prior specification: blavaan defines default priors for eight parameter types, including normal priors for several parameters, gamma priors for precisions, beta priors for correlations, and Wishart priors for covariance blocks.The defaults are placed on precisions rather than variances for most variance-related parameters.
- Prior specification: Users can override default priors globally with dp or assign a prior to a specific parameter with the prior() modifier in model syntax.The modifiers [sd] and [var] allow priors on standard deviations or variances instead of corresponding precisions.
- Prior specification: Priors for rho and ibpsi are less flexible through dp, although users can modify them by exporting and manually editing the JAGS syntax.The rho prior must currently be beta, while the default ibpsi prior is Wishart with identity scale and degrees of freedom equal to matrix dimension plus one.
- JAGS syntax: blavaan converts specified models to JAGS syntax and can export files for manual estimation or modification with rjags or runjags.The export includes sem.jag with the model and semjags.rda with JAGS-formatted data, initial values, and parameter labels.
- JAGS syntax: Users export syntax with jagfile=TRUE or a folder name, then may need to adjust monitor and inits arguments after modifying the JAGS file.Observed-variable changes may also require data changes, whereas the data generally remain usable for other edits.
- Convergence diagnostics: Convergence monitoring supports automatic PSRF-based assessment or manual adaptation, burn-in, and sampling settings, with three chains by default.The auto option also determines the iterations needed for precise posterior estimates; manual defaults are 1,000 adaptation, 4,000 burn-in, and 10,000 sampling iterations.
4. Applications
The applications demonstrate blavaan’s support for Bayesian SEM specification, assessment, prior customization, measurement invariance, and extensions through modified JAGS syntax.
- General features: Bayesian models can be specified using lavaan syntax and fitted with customizable priors and JAGS controls.The examples include prior distributions for intercepts, residual standard deviations, and residual correlations, plus parallel chain sampling.
- Political democracy: The “fa” covariance option took 65 seconds versus 76 seconds for “srs”, while “srs” averaged 1.44 times the effective sample size of “fa”.The authors characterize “fa” as somewhat faster and “srs” as somewhat more efficient, with results varying by model.
- General features: blavaan output combines lavaan-like summaries with posterior estimates, highest posterior density intervals, convergence diagnostics, marginal log-likelihood, and posterior predictive p-values.The political democracy example reports 10,000 samples after 5,000 adaptation and burn-in iterations, with 75 observations and a posterior predictive p-value of 0.556.
- Measurement invariance: Measurement-invariance models can be transferred from classical lavaan parameter tables to Bayesian CFA, but neither of the first two demonstrated models had good posterior predictive fit.Information criteria nevertheless favored the second model because it had smaller DIC, WAIC, and LOOIC values.
- Informative prior distributions: Informative priors produced generally similar fit measures but altered selected variance and loading posterior estimates.The factor variance ψ1 and numerical-test residual variance increased, while λ2 and λ3 posterior means and standard deviations became somewhat smaller.
- Extensions of JAGS syntax: Exported JAGS syntax can be modified to estimate robust factor analysis models using t distributions and a prior for the shared degrees-of-freedom parameter.The example illustrates using blavaan-generated syntax as a starting point for novel models instead of writing JAGS code entirely from scratch.
5. Conclusion
blavaan combines existing tools to simplify Bayesian SEM estimation and extension through open-source software. Its current scope covers many multivariate normal SEMs, while additional model classes remain planned for future versions.
- 5. Conclusion: blavaan combines tools to simplify Bayesian SEM estimation for applied and methodological researchers using open-source software.It separates model specification from MCMC coding and reduces the need to learn MCMC software or write JAGS models from scratch.
- 5. Conclusion: Future versions are planned to support latent interactions, ordinal variables, and mixture and multilevel components.Efficient sampling and lavaan-based specification remain unresolved for these models.
- 5. Conclusion: The package is currently useful for estimating many types of multivariate normal SEMs.
- 5. Conclusion: JAGS export lets researchers extend the estimated models in any desired fashion.
A. Details on model assessment statistics
blavaan supplies several model evaluation and comparison metrics for Bayesian SEMs.
- A. Details on model assessment statistics: blavaan supplies a variety of model evaluation and comparison metrics.
Posterior predictive checks
Posterior predictive checks compare observed and replicated likelihood-ratio statistics across posterior draws. blavaan also computes DIC using a marginal likelihood approach, but posterior predictive p-values are currently impractical with missing data.
- Posterior predictive checks: The likelihood-ratio test statistic compares the fitted model with a saturated parameter vector matching the observed mean and covariance matrix.It is computed as LRT(Y, ϑ) = −2 log L(ϑ|Y) + 2 log L(ϑsat|Y).
- Posterior predictive checks: For each posterior draw, blavaan computes the observed LRT, generates replicated data, and computes the replicated LRT.
- Posterior predictive checks: The posterior predictive p-value is the proportion of draws whose replicated LRT exceeds the observed LRT.Values near .5 indicate fit, whereas values near 0 indicate poor fit; a .05 threshold is used in practice.
- Posterior predictive checks: Posterior predictive p-values are currently impractical with missing data because saturated log-likelihood calculations require repeated EM-algorithm computations.Users can bypass these calculations with test="none".
- Posterior predictive checks: blavaan avoids automatic JAGS DIC because conditioning on latent variables can inflate the effective number of parameters and impair inferences.It calculates its own likelihood instead.
WAIC and LOO
WAIC and LOO assess predictive accuracy using observation-level log-likelihoods and effective-parameter estimates. LOO uses a cross-validation perspective and smoothed importance sampling to avoid repeated posterior re-estimation.
- WAIC and LOO: WAIC and LOO are asymptotically equivalent predictive-accuracy measures that improve on DIC but are more difficult to compute.
- WAIC and LOO: WAIC uses observation-level log-likelihoods to estimate expected log pointwise predictive density and an effective number of parameters.Its first term concerns observed-data log-likelihoods, while its second uses posterior-draw variability.
- WAIC and LOO: LOO estimates each observation’s predictive density by holding it out and updating the prior with the remaining observations.Analytical results allow estimation from the full-data posterior without sequentially re-estimating the posterior.
- WAIC and LOO: LOO importance-sampling weights are smoothed with a generalized Pareto distribution to improve the estimate.
- WAIC and LOO: The effective number of parameters under LOO can be estimated by comparing LOO with the WAIC lppd.
Bayes factor
The Bayes factor compares two models through the ratio of their marginal likelihoods. Because marginal-likelihood integrals are generally difficult to calculate, blavaan uses a Laplace–Metropolis approximation based on posterior output.
- The Bayes factor is the ratio of two models’ marginal likelihoods, with values greater than 1 favoring Model 1.
- The Laplace–Metropolis estimator approximates the difficult marginal-likelihood integral using a Laplace approximation.The approximation is formulated for integrals involving a natural exponent and uses the value maximizing h().
- blavaan obtains the approximation from posterior means or another central-tendency estimate derived from MCMC output.The package computes the logarithm of the approximation for numerical stability.
- Bayes factors are sensitive to prior distributions, and the interpretability of common log-Bayes-factor rules may be unclear in specific applications.Researchers are therefore advised to consider their priors carefully.
- The Bayes factor can also be understood as updating the prior odds that Model 1 is correct relative to Model 2 after observing data.