Bayesian Latent Variable Analysis

Fit a variety of Bayesian latent variable models, including confirmatory factor analysis, structural equation models, and latent growth curve models. References: Merkle & Rosseel (2018) ; Merkle et al. (2021) .

blavaan is a free, open source R package for Bayesian latent variable analysis. It relies on JAGS and Stan to estimate models via MCMC.

The blavaan functions and syntax are similar to lavaan. For example, consider the Political Democracy example from Bollen (1989):


model <- '
   # latent variable definitions
     ind60 =~ x1 + x2 + x3
     dem60 =~ y1 + y2 + y3 + y4
     dem65 =~ y5 + y6 + y7 + y8
   # regressions
     dem60 ~ ind60
     dem65 ~ ind60 + dem60
   # residual covariances
     y1 ~~ y5
     y2 ~~ y4 + y6
     y3 ~~ y7
     y4 ~~ y8
     y6 ~~ y8
fit <- bsem(model, data=PoliticalDemocracy)

For further information, see:

Merkle, E. C., & Rosseel, Y. (2018). blavaan: Bayesian structural equation models via parameter expansion. Journal of Statistical Software, 85(4), 1–30.


Changes in Version 0.3-4 o Add function standardizedPosterior() for standardizing posterior draws.

o Rearrange posterior predictive internals.

o Turn off posterior modes for target="jags", due to conflict between current
  versions of runjags and modeest.

Changes in Version 0.3-3 o Fix bug in Stan models, where an ov is regressed on an lv (or vice versa) and

o Small fixes to blavInspect().

o For convergence="auto", max time was previously 5 min (undocumented).
  It is now Inf.

o Axis labels are now more sensible on convergence plots.

o Relative effective sample size now used to compute loo/waic SEs, and SEs
  are now returned via fitMeasures().

o Added unit testing via testthat.

o Other bug fixes.

Changes in Version 0.3-2 o Improved handling of Stan models, including missing data, defined variables, 0-variance latents, multi-group.

o Conditional (on latent variables) information criteria available when save.lvs = TRUE.

o Added CITATION to JSS publication and corresponding references updated.

o Experimental function blavFitIndices() added for Bayesian versions of SEM metrics, contributed by Terrence Jorgensen.

o blavaan 'intelligently' chooses target, if either runjags or rstan (but not both) is installed.

o Version dependencies updated, including lavaan and loo.

o Bug fixes from previous version.

Changes in Version 0.3-1 o Stan export/estimation now supported.

o Improved handling of complex models, including growth/change models.

o Logical argument save.lvs added to sample factor scores. Samples/means can be obtained by supplying arguments 'lvs' and 'lvmeans' to blavInspect().

o Bug fixes from previous version.

Changes in Version 0.2-4 o Add 'seed' argument for setting the random seeds in each JAGS chain.

o Bug fixes found in previous version.

Changes in Version 0.2-3 o New function blavCompare() for comparing models via ICs and BFs (code from Mauricio Garnier-Villarreal).

o Defined parameters are now sampled via MCMC, vs estimated via delta method.

o blavInspect() gains 'jagnames' option, showing correspondence between blavaan parameter names and JAGS parameter names.

o Fix bugs in (i) marginal log-lik computation under cp='fa', and (ii) calculated number of parameters under complex equality constraints.

Changes in Version 0.2-2 o Fix bug in 0.2-1 causing model estimation to crash on Windows only.

Changes in Version 0.2-1 o Major update to internals: Model matrices/parameters now correspond to the Lisrel representation used in lavaan.

o General parameter equality constraints using '==' are now available (with one parameter on the lhs).

o New function blavInspect() for extracting various pieces of the MCMC run, including HPDs using an optional 'level' argument.

o JAGS syntax now uses the original observed variable names. It also assigns all prior/constraints to a single parameter vector, then defines model matrices based on this parameter vector.

o A list of user-defined initial values can be supplied via the inits argument.

o Posterior predictive computations are parallelized, if package parallel is installed.

o Improved timings for various parts of the model estimation.

Changes in Version 0.1-4 o New convergence="auto" option to run chains until convergence.

o Bug fixes in model estimation: single-indicator lvs, equality constraints
  on exogenous lvs, models with n.chains=1, force runjags parameter summary.

Changes in Version 0.1-3 o Improved support for growth models, including latent variances fixed to 0.

o Extra monitors supplied via jagextra become defined parameters
  in summary().

Changes in Version 0.1-2 o Bayes factors for loadings/regressions now available from summary() via argument bf=TRUE. These are computed via the Savage-Dickey density ratio (assuming normal posterior).

o Bug fix in generation of random initial values when some
  covariance parameters are fixed to 0 (and we use srs priors).

o Explicit translations from JAGS parameterizations to R
  parameterizations. This leads to the availability of
  more fitMeasures under a wider variety of priors.

Changes in Version 0.1-1 o Added plot method related to plot.runjags().

o Added argument jagextra for supplying extra code to JAGS.

o Changes to summary():
  Improving look and operability with lavaan
  Posterior medians/modes now available

o runjags slot in blavaan objects is moved to 

o fitMeasures() now includes BIC and loglik (at posterior means).

o now works, returns only JAGS syntax.

o Random initial values less likely to fail.

o Bug fixes related to equality constraints on mv variances + vs TRUE.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.4-1 by Edgar Merkle, a day ago

Browse source code at

Authors: Edgar Merkle [aut, cre] , Yves Rosseel [aut] , Ben Goodrich [aut] , Mauricio Garnier-Villarreal [ctb] , R/blav_compare.R , R/ctr_bayes_fit.R) , Terrence D. Jorgensen [ctb] , R/ctr_bayes_fit.R , R/ctr_ppmc.R) , Huub Hoofs [ctb] (R/ctr_bayes_fit.R) , Rens van de Schoot [ctb] (R/ctr_bayes_fit.R)

Documentation:   PDF Manual  

Task views: Psychometric Models and Methods, Bayesian Inference

GPL (>= 3) license

Imports stats, utils, graphics, MCMCpack, coda, mnormt, nonnest2, loo, rstan, rstantools, RcppParallel, bayesplot, Matrix, future.apply, tmvnsim

Depends on methods, lavaan, Rcpp

Suggests runjags, modeest, rjags, semTools, tinytest

Linking to StanHeaders, rstan, BH, Rcpp, RcppEigen, RcppParallel

System requirements: GNU make

Depended on by Replication, brxx.

Suggested by bayestestR, insight, semTools.

See at CRAN