Approximate Bayesian inference for Structural Equation Models (SEM)

The INLA approach

Haziq Jamil

Research Specialist
BAYESCOMP @ CEMSE-KAUST

https://haziqj.ml/kaust-gradsem | 📥 PDF

October 8, 2026

\[ \definecolor{kaustorg}{RGB}{241, 143, 0} \definecolor{kausttur}{RGB}{0, 166, 170} \definecolor{kaustmer}{RGB}{177, 15, 46} \definecolor{kaustgrn}{RGB}{173, 191, 4} \definecolor{kaustblu}{RGB}{82, 132, 196} \definecolor{kaustpur}{RGB}{156, 111, 174} \]

Bayesian Computational Statistics and Modeling Research Group (BAYESCOMP)

Led by Prof. Håvard Rue—Integrated Nested Laplace Approximation (INLA, Rue et al., 2009)

Data context

Structural equation models (SEM) in a nutshell

Analyse multivariate data \(\mathbf y=(y_1,\dots,y_p)^\top\) to measure and relate hidden variables \(\boldsymbol\eta=(\eta_1,\dots,\eta_q)^\top\), \(q \ll p\), and uncover complex patterns.

In the social sciences, latent variables are used to represent constructs—the theoretical, unobserved concepts of interest.

(Psychology)
Personality traits

(Healthcare)
Quality of life

(Political science)
Social trust

(Education)
Competencies

European Social Survey (ESS) Round 5

Total \(n=52,458\) respondents from 27 countries. Example of items measuring the construct “Trust in Police Effectiveness”:

Ser. Question
D12 Based on what you have heard or your own experience how successful do you think the police are at preventing crimes in [country] where violence is used or threatened?
D13 How successful do you think the police are at catching people who commit house burglaries in [country]?
D14 If a violent crime were to occur near to where you live and the police were called, how slowly or quickly do you think they would arrive at the scene?


European Social Survey (ESS) Round 5 (cont.)

  • Modelling procedural fairness theory linking trust, legitimacy, and compliance with authorities (Jackson, Bradford, et al., 2011; Jackson, Hough, et al., 2011).

  • Big and layered data suited for Bayesian approaches. But model fit and evaluation can be computationally challenging or time-consuming.

  • Often, country-level effects are ignored, but they can be crucial in understanding the variability in the latent constructs across countries.

Programme for International Student Assessment (PISA)

PISA (cont.)

  • PISA uses 2PL item response theory (IRT) models to measure unobserved proficiency from item responses.

  • Estimation involves large-scale, multi-group calibration and latent population modelling, with incomplete forms and complex survey sampling.

  • Population inference uses plausible values (draws from students’ conditional proficiency posteriors), given fitted item and population parameters.

Advancing scalable Bayesian methods for latent variable modelling

Håvard Rue (PI) + Haziq Jamil (co-I)

  • Jamil, H., & Rue, H. (2026a). Approximate Bayesian inference for structural equation models using integrated nested Laplace approximations (arXiv:2603.25690 [stat.ME]).1
  • Jamil, H., & Rue, H. (2026b). Implementation and workflows for INLA-based approximate Bayesian structural equation modelling(arXiv:2604.00671 [stat.CO]).1
  • Alhyari, M., Jamil, H., Montcho, H., & Rue, H. (2026). Deterministic Leave-One-Cluster-Out Cross-Validation for Multilevel Bayesian Structural Equation Models (arXiv:2609.00670 [stat.ME]).1
  • R Package: https://github.com/haziqj/INLAvaan

Supported by the 2025 KAUST Competitive Research Grant (CRG)2.

WP1 Theory & model mapping
Fast Bayesian SEM for continuous, binary & ordinal items
WP2 Latent traits on a map
Spatial SEM & IRT with SPDE random fields
WP3 Latent traits in time
Growth curves & dynamic SEM
WP4 Software & dissemination
Open-source R package: INLAvaan

Outline

  1. Brief overview of SEMs
    • A running example
    • Bayesian inference
    • Marginal likelihood
  2. INLA-based inference
    • Joint Gaussian approximation with variational mean correction
    • Skew-normal Laplace profiling of posterior marginals
    • Gaussian copula sampling
  3. The INLAvaan R package

Latent variables related to KAUST’s agenda

🌾 Food Cafiero et al. (2018) The UN food insecurity measure A Rasch model (1PL IRT) on yes/no questions, from worrying about food to going a whole day without eating; SDG 2.1.2.

💧 Water Young et al. (2019) Household water insecurity measure Twelve questions, validated on 8,127 households at 28 sites in 23 countries, and unidimensional in factor analyses.

🤖 AI Burnell et al. (2023) LLMs have latent abilities too Factor analysis reveals abilities like reasoning and comprehension. IRT used to find the most informative questions.

🌿 Environment Grace et al. (2016) SEM sees what raw correlations hide Across 1,126 grassland plots on 5 continents, species richness boosts productivity, in contrast with data patterns.

Structural equation models

A running example

Glycemic control and kidney health

Does poorer glycemic control lead to greater severity of kidney disease?

Observe \(p=6\) variables for each patient:

Indicator Description Unit
\(y_1\) HbA1c 3-month avg. blood glucose %
\(y_2\) FPG Fasting plasma glucose mmol/L
\(y_3\) Insulin Fasting insulin level µU/mL
\(y_4\) PCr Plasma creatinine µmol/L
\(y_5\) ACR Albumin–creatinine ratio mg/g
\(y_6\) BUN Blood urea nitrogen mmol/L

“piecemeal” thinking leads to \[ \small \begin{align*} \textcolor{kaustmer}{y_{4}} &= \beta_0^{(4)} + \beta_1^{(4)} \textcolor{kaustblu}{y_{1}} + \beta_2^{(4)} \textcolor{kaustblu}{y_{2}} + \beta_3^{(4)} \textcolor{kaustblu}{y_{3}} + \epsilon^{(4)} \\ \textcolor{kaustmer}{y_{5}} &= \beta_0^{(5)} + \beta_1^{(5)} \textcolor{kaustblu}{y_{1}} + \beta_2^{(5)} \textcolor{kaustblu}{y_{2}} + \beta_3^{(5)} \textcolor{kaustblu}{y_{3}} + \epsilon^{(5)} \\ \textcolor{kaustmer}{y_{6}} &= \beta_0^{(6)} + \beta_1^{(6)} \textcolor{kaustblu}{y_{1}} + \beta_2^{(6)} \textcolor{kaustblu}{y_{2}} + \beta_3^{(6)} \textcolor{kaustblu}{y_{3}} + \epsilon^{(6)} \\ \end{align*} \]

  • Does not give a clear and direct answer.

  • Moreover, variables are assumed to be measured without error.

Covariance-based approach

Sample correlation matrix looks like this1:

  • The data suggests clustering of variables
    • \(y_1\),\(y_2\),\(y_3\) measure glycemic control (\(\texttt{GlyCon}\))
    • \(y_4\),\(y_5\),\(y_6\) measure kidney health (\(\texttt{KdnHlt}\))
  • Easier to hypothesize relationships, e.g. \[ {\color{kaustmer}\texttt{KdnHlt}} = \alpha + \beta \, {\color{kaustblu}\texttt{GlyCon}} + \texttt{error} \]

  • But these are unobserved—we only see their footprint on the correlation structure:

    • Items in a cluster share a latent cause, and
    • Cross-cluster correlation flows through \(\beta\).
  • SEM models the covariance structure \[ \boldsymbol\Sigma = \boldsymbol\Sigma(\boldsymbol\vartheta), \] where \(\boldsymbol\vartheta\) are model parameters.

Directed acyclic graph (DAG)

  • Measurement model: loadings \(\color{kaustpur}\lambda\), intercepts \(\color{Gray}\nu\), residual (co)variances \(\color{kaustorg}\theta\).
  • Structural model: regression coefficients \(\color{kaustgrn}\beta\), latent (co)variances \(\color{kausttur}\psi\).
  • Collect free parameters in \(\boldsymbol\vartheta \in\mathbb R^m\), where \(m < p(p+1)/2 + p\).

SEM equations

\[ \small \begin{gathered} \begin{pmatrix} y_1 \\ y_2 \\ y_3 \\ y_4 \\ y_5 \\ y_6 \end{pmatrix} = \begin{pmatrix} \nu_1 \\ \nu_2 \\ \nu_3 \\ \nu_4 \\ \nu_5 \\ \nu_6 \end{pmatrix} + \begin{pmatrix} \textcolor{kaustpur}{\lambda_{11}} & 0 \\ \textcolor{kaustpur}{\lambda_{21}} & 0 \\ \textcolor{kaustpur}{\lambda_{31}} & 0 \\ 0 & \textcolor{kaustpur}{\lambda_{42}} \\ 0 & \textcolor{kaustpur}{\lambda_{52}} \\ 0 & \textcolor{kaustpur}{\lambda_{62}} \\ \end{pmatrix} \begin{pmatrix} \eta_1 \\ \eta_2 \end{pmatrix} + {\color{Gray} \begin{pmatrix} \epsilon_1 \\ \epsilon_2 \\ \epsilon_3 \\ \epsilon_4 \\ \epsilon_5 \\ \epsilon_6 \end{pmatrix}} \\[1.1em] \begin{pmatrix} \eta_1 \\ \eta_2 \end{pmatrix} = \begin{pmatrix} \alpha_1 \\ \alpha_2 \end{pmatrix} + \begin{pmatrix} 0 & 0 \\ {\color{kaustgrn}\beta} & 0 \\ \end{pmatrix} \begin{pmatrix} \eta_1 \\ \eta_2 \end{pmatrix} + {\color{Gray} \begin{pmatrix} \zeta_1 \\ \zeta_2 \end{pmatrix}} \end{gathered} \]

Or, more compactly as

\[ \begin{gathered} \mathbf y = \boldsymbol\nu + {\color{kaustpur}\boldsymbol\Lambda} \boldsymbol\eta + {\color{Gray}\boldsymbol\epsilon} \\ \boldsymbol\eta = \boldsymbol\alpha + {\color{kaustgrn}\mathbf B} \boldsymbol\eta + {\color{Gray}\boldsymbol\zeta} \end{gathered} \]

with assumptions \({\color{Gray}\boldsymbol\epsilon}\sim\operatorname{N}_p(\mathbf 0, {\color{kaustorg}\boldsymbol\Theta})\), \({\color{Gray}\boldsymbol\zeta}\sim\operatorname{N}_q(\mathbf 0, {\color{kausttur}\boldsymbol\Psi})\), and \(\operatorname{Cov}({\color{Gray}\boldsymbol\epsilon}, {\color{Gray}\boldsymbol\zeta})=\mathbf 0\).

  • NB: Per person structure, assumed independent for each \(s=1,\dots,n\).

  • Additionally, assume prior distributions

    • \(\nu_i \sim \operatorname{N}(0, 32^2)\), \(\alpha_j \sim \operatorname{N}(0, 10^2)\)
    • \({\color{kaustpur}\lambda_{ij}}, {\color{kaustgrn}\beta} \sim \operatorname{N}(0, 10^2)\)
    • \(\sqrt{\color{kaustorg}\theta_{ii}}, \sqrt{\color{kausttur}\psi_{jj}} \sim \Gamma(1, 0.5)\), i.e. on the SDs

MCMC-based estimation

Data augmentation Gibbs

\[ \small \pi(\boldsymbol\vartheta, \boldsymbol\eta \mid \mathcal Y) \propto \pi(\boldsymbol\vartheta) \prod_{s=1}^n \pi(\mathbf y_s \mid \boldsymbol\eta_s, \boldsymbol\vartheta)\, \pi(\boldsymbol\eta_s \mid \boldsymbol\vartheta) \]

  • Treat \(\boldsymbol\eta\) as unknowns to be sampled; likelihood simplifies.

  • But problem scales with \(n\) (and \(m\)).

Marginal likelihood

\[ \small \pi(\mathcal Y \mid \boldsymbol\vartheta) = \prod_{s=1}^n \mathcal N_p\big(\mathbf y_s \,;\, \boldsymbol\mu(\boldsymbol\vartheta), \boldsymbol\Sigma(\boldsymbol\vartheta)\big) \]

where \[ \begin{align} \boldsymbol\mu(\boldsymbol\vartheta) &= \boldsymbol\nu + \boldsymbol\Lambda (\mathbf I - \mathbf B)^{-1} \boldsymbol\alpha \\ \boldsymbol\Sigma(\boldsymbol\vartheta) &= \boldsymbol\Lambda \boldsymbol\Phi \boldsymbol\Lambda^\top + \boldsymbol\Theta \\ \boldsymbol\Phi &:= (\mathbf I - \mathbf B)^{-1} \boldsymbol\Psi (\mathbf I - \mathbf B)^{-\top} \end{align} \]

MCMC-based estimation (cont.)

Many software choices to perform MCMC-based inference, e.g. blavaan (Merkle et al., 2021), Stan (Carpenter et al., 2017), Mplus (Muthén & Muthén, 2017).

INLA-based posterior approximation

Overview

  • Not quite R-INLA: This is a ✨bespoke✨ INLA for SEM, making use of relevant key ideas (Laplace, skew-normal marginals, VB correction).

  • Works because the exact posterior is cheap. For normal SEM, \(\pi(\mathbf y \mid \boldsymbol\vartheta)\) is closed form, so \(\pi(\boldsymbol\vartheta \mid \mathbf y)\) and its gradients are cheap to evaluate.

[Step 1a] Joint Gaussian approximation

Laplace approximation (Kass & Raftery, 1995; Tierney et al., 1989)

Assume that \(f(\boldsymbol\vartheta):=\log \left\{\pi(\mathbf y\mid \boldsymbol\vartheta) \, \pi(\boldsymbol\vartheta)\right\}\) is twice continuously differentiable with a unique interior maximiser \(\boldsymbol\vartheta^*\), at which \(\mathbf H=-\nabla^2 f(\boldsymbol\vartheta^*)\) is positive definite. Consider the Taylor expansion of \(f\) about \(\boldsymbol\vartheta^*\),

\[ f(\boldsymbol\vartheta) \approx f(\boldsymbol\vartheta^*) % + \cancel{\nabla f(\boldsymbol\vartheta^*)^\top (\boldsymbol\vartheta - \boldsymbol\vartheta^*)} - \frac12 (\boldsymbol\vartheta - \boldsymbol\vartheta^*)^\top \mathbf H (\boldsymbol\vartheta - \boldsymbol\vartheta^*). \tag{1}\]

Therefore, \(\pi(\boldsymbol\vartheta \mid \mathbf y) \approx \mathcal N_m(\boldsymbol\vartheta ;\, \boldsymbol\vartheta^*, \boldsymbol\Omega)\), where \(\boldsymbol\Omega = \mathbf H^{-1}\)

  • Work on an unconstrained scale (log variances, Fisher-\(z\) correlations). Make the log-posterior closer to quadratic, so Laplace is more accurate.
  • Under standard regularity conditions, the approximation achieves a relative error of \({O}(n^{-1})\) for the posterior density and marginal likelihood (Rue et al., 2017)—c.f. additive \({O}(n^{-1/2})\) error typical of simulation-based methods.

  • By the Bernstein-von Mises theorem, the posterior concentrates at a rate of \(n^{-1/2}\) and converges to a Gaussian in total variation (van der Vaart, 1998).

[Step 1a] Joint Gaussian approximation (cont.)

[Step 1b] Variational mean correction

  • Posterior mode is often far away from the “typical set”, especially for skewed distributions.

  • Laplace may misrepresent the bulk of the distribution—correction needed!

  • van Niekerk & Rue (2024) propose a Variational Bayes (VB) correction to the mean of global Laplace: \[ {\hat{\boldsymbol\delta}} = \operatorname{argmin}_{\boldsymbol\delta} \operatorname{D}_{\text{KL}}\big( \mathcal N_m(\cdot \,;\, \boldsymbol\vartheta^* + {\boldsymbol\delta}, \mathbf H^{-1}) \;\big\Vert\; \pi(\cdot \mid \mathbf y) \big). \]
    • Distribution that minimises information loss (Zellner, 1988).
    • Reuse the Laplace curvature (good locally) and correct only the centre: an \(m\)-dimensional optimisation instead of re-estimating an \(m \times m\) covariance.
    • Shift the whole Gaussian towards the posterior mean.

[Step 2] Posterior marginals

  • Use Laplace’s method (1), this time to approximate an integral:

\[ \class{marginal-lhs}{\pi(\vartheta_j \mid \mathbf y)} = \int_{\mathbb R^{m-1}} e^{\log \pi(\vartheta_j, \boldsymbol\vartheta_{-j} \mid \mathbf y)} \, d \boldsymbol\vartheta_{-j} \, \approx \, \overbrace{\pi\big(\vartheta_j, \boldsymbol\vartheta_{-j}^*(\vartheta_j) \mid \mathbf y\big)}^{\text{height}} \times \overbrace{(2\pi)^{\frac{m-1}{2}} \left| \mathbf H_{-j}(\vartheta_j) \right|^{-1/2 }}^{\text{(cond.) width}} \]

  • Geometric intuition: the marginal at each \(\vartheta_j\) is the volume of the posterior’s slice there, roughly the slice’s peak height times its width.

  • This is expensive to compute, as for every \(\vartheta_j\) evaluation, need

    1. An optimisation of \(\boldsymbol\vartheta_{-j}\in\mathbb R^{m-1}\) at this location; and
    2. The (log) determinant of the Hessian there.
  • Next slides: two important results.

[Step 2a] Posterior marginals—the “height”

Lemma 1 (Conditional Mean Path) = No need for reoptimisation

Let \(\small \boldsymbol\vartheta\sim\operatorname{N}_m(\boldsymbol\vartheta^*,\boldsymbol\Omega)\) with \(\small\boldsymbol\Omega \succ \mathbf 0\). Then the marginal density of the \(\small j\)th component, \(\small j=1,\dots,m\), is proportional to the joint density evaluated along its CMP: \[ \small \pi(\vartheta_j=x) \propto \pi\big(\vartheta_j=x, \, \boldsymbol\vartheta_{-j} = \operatorname{E}[ \boldsymbol\vartheta_{-j} \mid \vartheta_j=x] \big). \]

  • Operationally,

    1. Lay out a grid \(\mathcal G_j=\big\{\boldsymbol\vartheta^* + t\,\mathbf v_j \;\big|\;t\in[-4,4]\big\}\), \(\mathbf v_j = \Omega_{jj}^{1/2} \, \boldsymbol\Omega_{\cdot j}\).
    2. Evaluate joint posterior \(\pi(\boldsymbol\vartheta \mid \mathbf y)\) at each grid point.
  • Scanning along the CMP is cheap; no re-optimisation needed.

  • For Gaussian posteriors, this is exact; otherwise it provides a first-order approximation to a potentially curved ridge.

[Step 2b] Posterior marginals—the “width”

Lemma 2 (Efficient volume correction) = No need to factor dense Hessian

For the \(\small j\)th component along the CMP, \(\small-\frac12 \log | \mathbf H_{-j}(t) | \approx \text{const.} + t\gamma_j'\). Then \[ \small \gamma_j' = -\frac{1}{2} \sum_{k=1}^m \frac{d}{dt} \left[ \mathbf{L}_{\cdot k}^{\top}\,\frac{d}{d\mathbf{L}_{\cdot k}}\mathbf{g} \right]_{t=0} + \frac{1}{2}\, \frac{d}{dt} \left[ \mathbf{v}_j^{\top}\,\frac{d}{d\mathbf{v}_j}\mathbf{g} \right]_{t=0}, \] where \(\small\mathbf{g}(\boldsymbol\vartheta) = -\nabla \log \pi(\boldsymbol\vartheta \mid \mathbf{y})\), and \(\small\mathbf H(\boldsymbol\vartheta^*)^{-1}=\mathbf L\mathbf L^\top\).

  • For non-symmetric densities, the conditional spread (“width”) changes along the scan line. This change can be computed entirely via directional derivatives.

  • Forward difference cost is only \(m+2\) gradient evaluations for each \(j\). Note: Baseline is unity in whitened coordinates.

    1. [outer \(\small\nabla^3\)] Shift to \(\boldsymbol\vartheta^+\) along CMP, evaluate gradient.
    2. [inner \(\small\nabla^2\)] Perturb along \(\mathbf{L}_{\cdot k}\) and the scan direction \(\mathbf{v}_j\), evaluating gradients.

[Step 2c] Posterior marginals—SN curve fit

  • Consider the paired points \(\{\vartheta_j(t_k), h_{kj}\}_{k=1}^K\), where
    • \(t_k\in[-4,4]\) are standardised grid points,
    • \(\boldsymbol\vartheta(t_k) = \boldsymbol\vartheta^* + t_k \mathbf v_j\) from the CMP, and
    • \(h_{kj} := h_j(t_k) = \log \pi(\boldsymbol\vartheta(t_k) \mid y ) + t_k \gamma_j'\) are unnormalised ordinates.
  • Fit a skew normal pdf to these points via weighted least squares. A convenient default is \(w_{kj} \propto \exp(h_{kj})\), for \(j=1,\dots m\).

  • Map back from \(t\) to \(\vartheta_j\) scale via the affine \(\vartheta_j = \vartheta_j^* + t\sqrt{\Omega_{jj}}\).

\[(\hat\xi_j,\hat\omega_j,\hat\alpha_j,\hat c_j) = \operatorname{argmin}_{\xi,\omega,\alpha,c} \, \sum_{k=1}^K w_{kj}\big[ h_{kj}-\big\{\log f_{\mathrm{SN}}(\vartheta_j(t_k);\xi,\omega,\alpha)+c\big\} \big]^2\]

[Step 3] Gaussian copula sampling

\[ \underbrace{\mathbf z \sim N(\mathbf 0, \mathbf R)}_{\text{Gaussian correlation}} \xrightarrow{\quad \Phi(\cdot) \quad} \underbrace{\mathbf u}_{\ \text{Uniform} \ } \xrightarrow{\quad F_{\text{SN}}^{-1}(\cdot) \quad} \underbrace{\boldsymbol\vartheta}_{\text{SN Marginals}} \]

  • Reconstruct joint posterior samples \(\{\boldsymbol\vartheta^{(1)},\dots,\boldsymbol\vartheta^{(B)}\}\) using a Copula (Nelsen, 2006), preserving Gaussian correlations: \[ \mathbf R = \mathbf D^{-1/2} \boldsymbol \Omega \mathbf D^{-1/2}, \qquad \mathbf D = \operatorname{diag}(\boldsymbol\Omega). \]

  • This also allows us to derive approximate posteriors for

    1. Parameter transformations, e.g. standardised solutions, non-linear transforms, etc.
    2. Posterior Predictive P-value (PPP), e.g. \(\#\{ T(\mathbf S_{\text{obs}}, \boldsymbol\Sigma(\boldsymbol\vartheta)) > T(\mathbf S_{\text{rep}}, \boldsymbol\Sigma(\boldsymbol\vartheta)) \}\).
    3. Factor scores, \(\boldsymbol\eta \mid \{\mathcal Y, \boldsymbol\vartheta\} \sim \operatorname{N}_q(\mathbf m(\boldsymbol\vartheta), \mathbf V(\boldsymbol\vartheta))\).
    4. Prediction and imputation.

R/INLAvaan

The R/INLAvaan package

# Check data set
glimpse(Kidney)
Rows: 250
Columns: 6
$ y1 <dbl> 5.960822, 6.129040, 5.97609…
$ y2 <dbl> 4.767713, 6.616294, 5.64002…
$ y3 <dbl> 14.469238, 10.517574, 8.725…
$ y4 <dbl> 84.18186, 59.59659, 126.733…
$ y5 <dbl> 64.539671, 49.028101, 90.72…
$ y6 <dbl> 7.758444, 5.232205, 11.5583…
library(INLAvaan)
mod <- "
  # Measurement model
  GlyCon =~ y1 + y2 + y3
  KdnHlt =~ y4 + y5 + y6

  # Structural model
  KdnHlt ~ GlyCon
"

(b)lavaan S4 methods (Rosseel, 2012)

print(fit)
INLAvaan 0.3.2.9003 ended normally after 71 iterations

  Estimator                                      BAYES
  Optimization method                           NLMINB
  Number of model parameters                        19

  Number of observations                           250

Model Test (User Model):

   Marginal log-likelihood                   -4029.054 
   PPP (Chi-square)                              0.569 

Also available:

  • fitmeasures()
  • fitted()
  • predict()
  • standardisedsolution()
  • vcov()
  • plot()
coef(fit)
   GlyCon=~y1    GlyCon=~y2    GlyCon=~y3    KdnHlt=~y4    KdnHlt=~y5 
        1.090         1.161         5.027        21.610        19.651 
   KdnHlt=~y6 KdnHlt~GlyCon        y1~~y1        y2~~y2        y3~~y3 
        1.773         0.656         0.322         0.254         7.435 
       y4~~y4        y5~~y5        y6~~y6          y1~1           
      206.240        91.076         1.285         6.542         ... 

Summary

summary(fit)
<output truncated>

Information Criteria:

   Deviance (DIC)                             7910.072 
   Effective parameters (pD)                    19.026 

Parameter Estimates:

   Marginalisation method                     SKEWNORM
   VB correction                                  TRUE

Latent Variables:
                   Estimate       SD     2.5%    97.5%     NMAD    Prior       
  GlyCon =~                                                                    
    y1                1.090    0.063    0.972    1.218    0.005    normal(0,10)
    y2                1.161    0.063    1.042    1.290    0.005    normal(0,10)
    y3                5.027    0.292    4.476    5.625    0.005    normal(0,10)
  KdnHlt =~                                                                    
    y4               21.610    1.281   19.188   24.221    0.005    normal(0,10)
    y5               19.651    1.075   17.622   21.843    0.005    normal(0,10)
    y6                1.773    0.104    1.576    1.986    0.005    normal(0,10)

Regressions:
                   Estimate       SD     2.5%    97.5%     NMAD    Prior       
  KdnHlt ~                                                                     
    GlyCon            0.656    0.084    0.496    0.827    0.003    normal(0,10)

Intercepts:
                   Estimate       SD     2.5%    97.5%     NMAD    Prior       
   .y1                6.542    0.077    6.392    6.693    0.000    normal(0,32)
   .y2                6.161    0.079    6.007    6.316    0.000    normal(0,32)
   .y3               12.064    0.357   11.364   12.764    0.000    normal(0,32)
   .y4               84.700    1.846   81.081   88.319    0.000    normal(0,32)
   .y5               57.807    1.584   54.703   60.910    0.000    normal(0,32)
   .y6                7.862    0.150    7.568    8.156    0.000    normal(0,32)
    GlyCon            0.000                                                    
   .KdnHlt            0.000                                                    

Variances:
                   Estimate       SD     2.5%    97.5%     NMAD    Prior       
   .y1                0.322    0.043    0.244    0.411    0.002 gamma(1,.5)[sd]
   .y2                0.254    0.041    0.178    0.339    0.007 gamma(1,.5)[sd]
   .y3                7.435    0.938    5.728    9.404    0.002 gamma(1,.5)[sd]
   .y4              206.240   25.311  160.183  259.341    0.001 gamma(1,.5)[sd]
   .y5               91.076   16.419   60.419  124.678    0.014 gamma(1,.5)[sd]
   .y6                1.285    0.165    0.984    1.632    0.002 gamma(1,.5)[sd]
    GlyCon            1.000                                                    
   .KdnHlt            1.000                                                    

Comparison to MCMC

Comparison to MCMC (cont.)

Parameter recovery from simulated data

Effects of prior distributions

  • Loadings: \(\lambda \sim \operatorname{N}(0,10^2) \mapsto \lambda \sim \operatorname{N}(2,0.1^2)\)

  • Residual variances: \(\theta^{1/2} \sim \Gamma(1,0.5) \mapsto \theta \sim \Gamma(100,50)\)

Factor scores and latent regression

eta <- predict(fit, type = "lv")
print(eta)
First sample:
  GlyCon  KdnHlt
1 -0.370 -0.0255
2 -0.274 -1.1595
3  0.253  1.6439
4  1.311 -1.8157
5  0.431  1.0514
# ℹ 245 more rows
# ℹ Use `summary()` to see summary statistics
  • Posterior of \(\boldsymbol\eta_i\) for all \(n=250\) patients.
  • Halo: 95% posterior region (SD \(\approx\) 0.28 for \(\eta_1\), 0.33 for \(\eta_2\)).
  • Line: SEM’s \(\beta =\) 0.66 [0.49, 0.82], estimated jointly.

Refit-free Leave-One-Out Cross-Validation

tictoc::tic()
loo(fit)
── Leave-one-subject-out ───────────────────────── 250 subjects, second-order ──

         Estimate   SE
elpd_loo  -3955.0 28.7
p_loo        18.8  1.3
looic      7909.9 57.3

── Curvature check ─────────────────────────────────────────────────────────────

  first-to-second-order gap         9.7
  pD/2 (trace)                      9.3
  excess over pD/2 (trace)        +4.7%

ℹ The gap approaches pD/2 (trace) from above. A large excess says the
  second-order expansion has not settled over the sample.
tictoc::toc()
0.037 sec elapsed

Conclusion

Summary

  • 🚀 INLA methodology offers a rapid alternative for SEM, delivering Bayesian results at near the speed of frequentist estimators.
    • Not aiming to replace MCMC; use case is model development, testing, and exploratory analysis.

  • Vignettes and tutorials available on https://inlavaan.haziqj.ml/: Equality constraints, defined parameters, multigroup, multilevel, and missing data.

شكراً جزيلاً

https://haziqj.ml/kaust-gradsem

References

Burnell, R., Hao, H., Conway, A. R. A., & Orallo, J. H. (2023). Revealing the structure of language model capabilities. https://doi.org/10.48550/arXiv.2306.10062
Cafiero, C., Viviani, S., & Nord, M. (2018). Food security measurement in a global context: The food insecurity experience scale. Measurement, 116, 146–152. https://doi.org/10.1016/j.measurement.2017.10.065
Carpenter, B., Gelman, A., Hoffman, M. D., Lee, D., Goodrich, B., Betancourt, M., Brubaker, M., Guo, J., Li, P., & Riddell, A. (2017). Stan: A probabilistic programming language. Journal of Statistical Software, 76(1), 1–32. https://doi.org/10.18637/jss.v076.i01
Driver, C. C., Oud, J. H. L., & Voelkle, M. C. (2017). Continuous Time Structural Equation Modeling with R Package ctsem. Journal of Statistical Software, 77(5). https://doi.org/10.18637/jss.v077.i05
European Social Survey European Research Infrastructure (ESS ERIC). (2023). ESS5 - integrated file, edition 3.5 (Austria not included) (Version 1) [Data set]. Sikt - Norwegian Agency for Shared Services in Education and Research. https://doi.org/10.21338/ESS5E03_5
Freni-Sterrantino, A., van Niekerk, J., Krainski, E., Rustand, D., Jamil, H., & Rue, H. (2026). Informative distance-based priors for correlation matrices centred on a target reference. https://doi.org/10.48550/arXiv.2607.18926
Grace, J. B., Anderson, T. M., Seabloom, E. W., Borer, E. T., Adler, P. B., Harpole, W. S., Hautier, Y., Hillebrand, H., Lind, E. M., Pärtel, M., Bakker, J. D., Buckley, Y. M., Crawley, M. J., Damschen, E. I., Davies, K. F., Fay, P. A., Firn, J., Gruner, D. S., Hector, A., … Smith, M. D. (2016). Integrative modelling reveals mechanisms linking productivity and plant species richness. Nature, 529(7586), 390–393. https://doi.org/10.1038/nature16524
Jackson, J., Bradford, B., Hough, M., Kuha, J., Stares, S., Widdop, S., Fitzgerald, R., Yordanova, M., & Galev, T. (2011). Developing European indicators of trust in justice. European Journal of Criminology, 8(4), 267–285. https://doi.org/10.1177/1477370811411458
Jackson, J., Hough, M., Bradford, B., Pooler, T., Hohl, K., & Kuha, J. (2011, November 1). Trust in justice: Topline results from the round 5 of the european social survey (SSRN Scholarly Paper No. 2231094). https://papers.ssrn.com/abstract=2231094 (Pre-published)
Kass, R. E., & Raftery, A. E. (1995). Bayes factors. Journal of the American Statistical Association, 90(430), 773–795. https://doi.org/10.1080/01621459.1995.10476572
Krainski, E., Gómez-Rubio, V., Bakka, H., Lenzi, A., Castro-Camilo, D., Simpson, D. P., Lindgren, F., & Rue, H. (2018). Advanced spatial modeling with stochastic partial differential equations using R and INLA. Chapman and Hall/CRC. https://doi.org/10.1201/9780429031892
Merkle, E. C., Fitzsimmons, E., Uanhoro, J., & Goodrich, B. (2021). Efficient Bayesian structural equation modeling in Stan. Journal of Statistical Software, 100(6), 1–22. https://doi.org/10.18637/jss.v100.i06
Muthén, B., & Muthén, L. (2017). Mplus user’s guide version 8.1 (Version 8) [Computer software]. https://www.statmodel.com/
Nelsen, R. B. (2006). An introduction to copulas (2nd ed.). Springer.
Rosseel, Y. (2012). lavaan: An R package for structural equation modeling. Journal of Statistical Software, 48(2), 1–36. https://doi.org/10.18637/jss.v048.i02
Rue, H., Martino, S., & Chopin, N. (2009). Approximate Bayesian inference for latent Gaussian models by using integrated nested Laplace approximations. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 71(2), 319–392. https://doi.org/10.1111/j.1467-9868.2008.00700.x
Rue, H., Riebler, A., Sørbye, S. H., Illian, J. B., Simpson, D. P., & Lindgren, F. (2017). Bayesian computing with INLA: A review. Annual Review of Statistics and Its Application, 4(1), 395–421. https://doi.org/10.1146/annurev-statistics-060116-054045
Simpson, D. P., Rue, H., Riebler, A., Martins, T. G., & Sørbye, S. H. (2017). Penalising model component complexity: A principled, practical approach to constructing priors. Statistical Science, 32(1), 1–28. https://doi.org/10.1214/16-STS576
Song, X.-Y., & Lee, S.-Y. (2012). Basic and advanced Bayesian structural equation modeling: With applications in the medical and behavioral sciences. Wiley. https://doi.org/10.1002/9781118358887
Tierney, L., Kass, R. E., & Kadane, J. B. (1989). Fully exponential Laplace approximations to expectations and variances of nonpositive functions. Journal of the American Statistical Association, 84(407), 710–716. https://doi.org/10.1080/01621459.1989.10478824
van der Vaart, A. W. (1998). Asymptotic statistics. Cambridge University Press. https://doi.org/10.1017/CBO9780511802256
van Niekerk, J., & Rue, H. (2024). Low-rank variational Bayes correction to the Laplace method. Journal of Machine Learning Research, 25(62), 1–25. https://jmlr.org/papers/v25/21-1405.html
Young, S. L., Boateng, G. O., Jamaluddine, Z., Miller, J. D., Frongillo, E. A., Neilands, T. B., Collins, S. M., Wutich, A., Jepson, W. E., & Stoler, J. (2019). The Household Water InSecurity Experiences (HWISE) Scale: Development and validation of a household water insecurity measure for low-income and middle-income countries. BMJ Global Health, 4(5), e001750. https://doi.org/10.1136/bmjgh-2019-001750
Zellner, A. (1988). Optimal information processing and Bayes’s theorem. The American Statistician, 42(4), 278–280. https://doi.org/10.2307/2685143