
Efficient approximate Bayesian inference for Structural Equation Models.
While Markov Chain Monte Carlo (MCMC) methods remain the gold
standard for exact Bayesian inference, they can be prohibitively slow
for iterative model development. {INLAvaan} offers a rapid
alternative for latent
variable analysis,
delivering Bayesian results at (or near) the speed of frequentist
estimators. It achieves this through a custom, ground-up implementation
of the Integrated Nested Laplace
Approximation (INLA), engineered specifically for the lavaan modelling framework.
{INLAvaan} is designed to fit seamlessly into your
existing workflow. If you are familiar with the (b)lavaan
syntax, you can begin using {INLAvaan} immediately.
As a first impression of the package, consider the canonical example of SEM applied to the Industrialisation and Political Democracy data set of Bollen (1989)1:
library(INLAvaan)
mod_poldem <- "
# Latent variable definitions
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3
dem65 =~ y5 + y6 + y7 + y8
# Latent regressions
dem60 ~ ind60
dem65 ~ ind60 + dem60
# Residual correlations
y1 ~~ y5
y2 ~~ y4 + y6
y3 ~~ y7
y4 ~~ y8
y6 ~~ y8
# Fixed loading
dem60 =~ 1.5*y4
# Custom priors on latent variances
ind60 ~~ prior('gamma(1, 1)[var]')*ind60
dem60 ~~ prior('gamma(2, 1)[var]')*dem60
dem65 ~~ prior('gamma(2, 4)[var]')*dem65
# Custom prior on a residual variance
x2 ~~ prior('gamma(2, 10)[sd]')*x2
"
utils::data("PoliticalDemocracy", package = "lavaan")
fit <- asem(model = mod_poldem, data = PoliticalDemocracy)
#> ✔ Found the posterior mode in 69 iterations [61ms]
#> ✔ Applied VB mean correction; max |δ| = 0.71σ [55ms]
#> ✔ Fitted 30 skew-normal posterior marginals [148ms]
#> ⠙ Drawing from the posterior and summarising.
#> ✔ Summarised 1,000 draws from the posterior [151ms]
#> ℹ Computed posterior fit measures: PPP, DIC.
summary(fit)
#> INLAvaan 0.4.2 ended normally after 69 iterations
#>
#> Estimator BAYES
#> Optimization method NLMINB
#> Number of model parameters 30
#>
#> Number of observations 75
#>
#> Model Test (User Model):
#>
#> Marginal log-likelihood -1641.935
#> PPP (Chi-square) 0.512
#>
#> Information Criteria:
#>
#> Deviance (DIC) 3172.919
#> Effective parameters (pD) 28.096
#>
#> Parameter Estimates:
#>
#> Marginalisation method SKEWNORM
#> Marginal scan LINEAR
#> VB correction ONESTEP
#>
#> Latent Variables:
#> Estimate SD 2.5% 97.5% NMAD Prior
#> ind60 =~
#> x1 1.000
#> x2 2.272 0.153 1.996 2.596 0.006 normal(0,10)
#> x3 1.844 0.159 1.547 2.170 0.005 normal(0,10)
#> dem60 =~
#> y1 1.000
#> y2 1.444 0.170 1.116 1.782 0.001 normal(0,10)
#> y3 1.169 0.157 0.867 1.482 0.001 normal(0,10)
#> dem65 =~
#> y5 1.000
#> y6 1.264 0.187 0.928 1.663 0.007 normal(0,10)
#> y7 1.360 0.175 1.050 1.735 0.008 normal(0,10)
#> y8 1.372 0.178 1.058 1.755 0.008 normal(0,10)
#> dem60 =~
#> y4 1.500
#>
#> Regressions:
#> Estimate SD 2.5% 97.5% NMAD Prior
#> dem60 ~
#> ind60 1.364 0.351 0.687 2.062 0.001 normal(0,10)
#> dem65 ~
#> ind60 0.515 0.234 0.064 0.981 0.001 normal(0,10)
#> dem60 0.882 0.102 0.689 1.090 0.012 normal(0,10)
#>
#> Covariances:
#> Estimate SD 2.5% 97.5% NMAD Prior
#> .y1 ~~
#> .y5 0.848 0.391 0.141 1.677 0.005 beta(1,1)
#> .y2 ~~
#> .y4 1.037 0.714 -0.199 2.597 0.004 beta(1,1)
#> .y6 2.155 0.738 0.836 3.735 0.011 beta(1,1)
#> .y3 ~~
#> .y7 1.017 0.638 -0.142 2.363 0.006 beta(1,1)
#> .y8 ~~
#> .y4 0.266 0.471 -0.584 1.265 0.003 beta(1,1)
#> .y6 ~~
#> .y8 1.271 0.588 0.230 2.537 0.005 beta(1,1)
#>
#> Variances:
#> Estimate SD 2.5% 97.5% NMAD Prior
#> ind60 0.454 0.089 0.306 0.655 0.003 gamma(1,1)[var]
#> .dem60 3.195 0.618 2.156 4.569 0.001 gamma(2,1)[var]
#> .dem65 0.323 0.163 0.081 0.700 0.021 gamma(2,4)[var]
#> .x2 0.089 0.055 0.014 0.218 0.025 gamma(2,10)[sd]
#> .x1 0.100 0.022 0.062 0.150 0.011 gamma(1,.5)[sd]
#> .x3 0.534 0.105 0.360 0.771 0.001 gamma(1,.5)[sd]
#> .y1 2.353 0.506 1.512 3.486 0.004 gamma(1,.5)[sd]
#> .y2 7.641 1.458 5.183 10.877 0.003 gamma(1,.5)[sd]
#> .y3 5.592 1.093 3.781 8.047 0.002 gamma(1,.5)[sd]
#> .y5 2.685 0.562 1.752 3.945 0.005 gamma(1,.5)[sd]
#> .y6 5.222 0.976 3.577 7.387 0.002 gamma(1,.5)[sd]
#> .y7 3.662 0.796 2.331 5.437 0.006 gamma(1,.5)[sd]
#> .y8 3.279 0.742 2.012 4.912 0.007 gamma(1,.5)[sd]
#> .y4 2.950 0.774 1.633 4.651 0.011 gamma(1,.5)[sd]Computation speed is valuable only when accuracy is preserved. Our
method yields posterior distributions that are visually and numerically
comparable to those obtained via MCMC (e.g., via
{blavaan}/Stan), but at a fraction of the computational
cost.
The figure below illustrates the posterior density overlap for the example above. The percentages refer to the one minus the normalised Jensen-Shannon divergence, which gives a measure of similarity between two probability distributions.
# install.packages("blavaan")
library(blavaan)
fit_blav <- bsem(model = mod_poldem, data = PoliticalDemocracy, seed = 2026)
res <- INLAvaan:::compare_mcmc(fit_blav, INLAvaan = fit)
print(res$p_compare)
Install the CRAN version of {INLAvaan} using:
install.packages("INLAvaan")Alternatively, install the development version of
{INLAvaan} from GitHub using:
# install.packages("pak")
pak::pak("haziqj/INLAvaan")There are two papers related to {INLAvaan} and its
underlying methodology. To cite {INLAvaan} in publications,
consider citing both.
To cite the methodological contribution exclusively, please use:
Jamil, H., & Rue, H. (in press). Approximate Bayesian inference for structural equation models using integrated nested Laplace approximations. Psychometrika. https://doi.org/10.48550/arXiv.2603.25690
To cite the software implementation and workflows, please use:
Jamil, H., & Rue, H. (2026). Implementation and workflows for INLA-based approximate Bayesian structural equation modelling (2604.00671 [stat.CO]). arXiv. https://doi.org/10.48550/arXiv.2604.00671
BibTeX entries for LaTeX users:
@Article{jamil2026approximate,
title = {Approximate Bayesian inference for structural equation models using integrated nested Laplace approximations},
author = {Haziq Jamil and Håvard Rue},
journal = {Psychometrika},
year = {in press},
eprint = {2603.25690},
primaryclass = {stat.ME},
doi = {10.48550/arXiv.2603.25690},
archiveprefix = {arXiv},
}
@Misc{jamil2026implementation,
title = {Implementation and workflows for INLA-based approximate Bayesian structural equation modelling},
author = {Haziq Jamil and Håvard Rue},
year = {2026},
number = {2604.00671 [stat.CO]},
eprint = {2604.00671},
primaryclass = {stat.CO},
publisher = {arXiv},
doi = {10.48550/arXiv.2604.00671},
archiveprefix = {arXiv},
copyright = {Creative Commons Attribution Non Commercial Share Alike 4.0 International},
}
The {INLAvaan} package is licensed under the GPL-3.
INLAvaan: Bayesian Latent Variable Analysis using INLA
Copyright (C) 2026 Haziq Jamil
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Bollen, K. A. (1989). Structural equations with latent variables (pp. xiv, 514). John Wiley & Sons. https://doi.org/10.1002/9781118619179↩︎