Advancing Scalable Bayesian Methods for Latent Variable Modelling

KAUST Statistics Research Day

Haziq Jamil

Research Specialist
BAYESCOMP @ CEMSE-KAUST

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

3 November 2026

What do we mean by “latent”?

\[ \definecolor{kaustorg}{RGB}{241,143,0} \definecolor{kausttur}{RGB}{0,166,170} \definecolor{kaustgry}{RGB}{140,140,140} \]

In statistics, all random variables are latent—but some are more latent than others. —me 😊

  • Regression of observed variables

    \[ \begin{aligned} {\color{kaustorg}\eta_{s2}} &= \alpha_2 + \beta\,{\color{kaustorg}\eta_{s1}} + {\color{kaustgry}\zeta_{s2}} \end{aligned} \]

    \[ \begin{aligned} {\color{kausttur}\eta_{s2}} &= \alpha_2 + \beta\,{\color{kausttur}\eta_{s1}} + {\color{kaustgry}\zeta_{s2}} \\ {\color{kausttur}\eta_{s1}} &= \alpha_1 + {\color{kaustgry}\zeta_{s1}} \end{aligned} \]

  • What if variables were unobserved?
  • Need to measure them \[ {\color{kaustorg}y_{si}} = \nu_i + \sum_{j}^{\phantom{\tiny .}} \lambda_{ij}\,{\color{kausttur}\eta_{sj}} + {\color{kaustgry}\epsilon_{si}} \]

Fountain pen on a notebook@dtravisphd

Psychology Anxiety

Doctor holding a stethoscope@impulsq

Public health Infection status

Police officers standing in a line@ev

Political science Trust in the police

Student writing with a pencil@benmullins

Education Science ability

Programme for International Student Assessment

760k+ students in 91 countries and economies

$115 trillion OECD GDP gain if average scores rose 25 points (Hanushek & Woessmann, 2010)

2 hours computerised test, randomised booklets

The Economist on YouTube Shorts

The Economist, 24 Sep 2026

Test answers different students, different questions

→

Latent variable model item response + latent regression

→

Student ability 10 plausible values = posterior draws

→

Country averages every point on the chart

Every point is an estimate of an ability nobody can observe. At national scale, the bottleneck is not data. It is inference.

Real data add structure, and structure adds cost

GROUPS Systematic differences between European countries, or do they just answer differently?

TIME In binge eating disorder, does momentary perseverance drive eating restraint?

SPACE Are regional gaps in aptitude real, and how sure can we be?

Current Bayesian estimation methods struggle to cope with modern data complexities.

CRG 2025 Award

Advancing scalable Bayesian methods for latent variable modelling KAUST Competitive Research Grant \(\;\cdot\;\) USD 900K \(\;\cdot\;\) Apr 2026–Mar 2029 \(\;\cdot\;\) Lead PI Håvard Rue \(\;\cdot\;\) Co-I Haziq Jamil

Work packages

WP1LVM at INLA speed

  • Gaussian SEM
  • Binary & ordinal items (IRT)
  • Mixed item types

WP2Measurements on a map

  • Spatial SEM & IRT
  • Spatial item functioning
  • SPDE fields

WP3Latent variables in time

  • Growth curves
  • Dynamic & continuous-time SEM
  • Trajectories & events

WP4Make it usable

  • INLAvaan on CRAN
  • Documentation and vignettes
  • Shared, compiled core

done in development planned month 8 of 36

People

  • Co-authors: M. Alhyari, H. Montcho
  • Contributors: L. Gaedke-Merzhäuser, E. Krainski, A. Simas, J. van Niekerk
  • Collaborators: G. Wallin (Lancaster), M. Garnier-Villarreal (VU Amsterdam)
  • Visiting students: A. Bong (UBD), J. Lee (KAIST), K. Li (Fudan)

Funded positions

  • 1 postdoc [pos. filled; starts Aug 2027]
  • 2 PhD students

3 papers, all submitted to Psychometrika [Q1]

3,000+ CRAN downloads* ¡ INLAvaan v0.3.3

1 keynote · EnviBayes–INLA 2027, Glasgow

3 invited seminars ¡ LSE, Fudan, Oslo

2 contributed talks ¡ Padova, Seoul

Approximate Bayesian structural equation models

Data \(\mathbf y_s \mid \boldsymbol\eta_s, \boldsymbol\vartheta \sim \mathrm N_p\big(\boldsymbol\nu + \boldsymbol\Lambda\boldsymbol\eta_{s},\ \boldsymbol\Theta\big)\)

Latent field \(\boldsymbol\eta_s \mid \boldsymbol\vartheta \hphantom{\boldsymbol\eta_s,} \sim \mathrm N_q\big(\boldsymbol\mu_\eta(\boldsymbol\vartheta), \boldsymbol\Phi(\boldsymbol\vartheta)\big)\)

Parameters \(\mathbb R^{m} \ni \boldsymbol\vartheta = (\boldsymbol\nu, \boldsymbol\lambda, \boldsymbol\beta, \boldsymbol\theta, \boldsymbol\psi) \sim \pi(\boldsymbol\vartheta)\)

Gaussian SEM: integrate the people out, exactly

\[ \begin{aligned} \pi(\mathbf y_s \mid \boldsymbol\vartheta) &= \int \pi(\mathbf y_s \mid \boldsymbol\eta_s, \boldsymbol\vartheta)\, \pi(\boldsymbol\eta_s \mid \boldsymbol\vartheta)\, d\boldsymbol\eta_s \\ &= \mathcal N_p\big(\mathbf y_s;\ \boldsymbol\mu(\boldsymbol\vartheta), \boldsymbol\Sigma(\boldsymbol\vartheta)\big) \end{aligned} \]

where \(\boldsymbol\mu(\boldsymbol\vartheta)\) and \(\boldsymbol\Sigma(\boldsymbol\vartheta)\) are the model-implied mean and covariance.

SEMs are latent Gaussian models, therefore suitable for INLA. But…

INLA’s sweet spot SEM
Latent field large, coupled; sparse precision (space, time) \(n\) small dense blocks, independent
Hyper-parameters a handful many (\(m\) = 20–250)
Conditional field (given \(\boldsymbol\vartheta\)) approximately Gaussian exactly Gaussian

Plugging SEM into R-INLA drags an \(O(n)\)-dimensional latent field through every one of many evaluations over \(\boldsymbol\vartheta\).

Instead, integrate the people out, and then bring INLA’s ideas to \(\boldsymbol\vartheta\)-space.

A ✨bespoke✨ INLA for SEM

Cheap exact posterior Gaussian SEM: closed-form \(\pi(\mathbf y \mid \boldsymbol\vartheta)\), so cheap \(\pi(\boldsymbol\vartheta \mid \mathbf y)\) and gradients

NEWVolume from gradients Volume correction from just \(m + 2\) gradients per param. (no Hessians)

Not R-INLA Rebuilt for SEM using INLA’s key approximation ideas

The R/INLAvaan package

library(INLAvaan)
mod <- "
  # Measurement model
  ind60 =~ x1 + x2 + x3
  dem60 =~ y1 + y2 + y3 + y4
  dem65 =~ y5 + y6 + y7 + y8

  # Structural model
  dem60 ~ ind60
  dem65 ~ ind60 + dem60
  
  # Residual correlations
  y1 ~~ y5
  y2 ~~ y4 + y6
  y3 ~~ y7
  y4 ~~ y8
  y6 ~~ y8
"

  • Lightweight R implementation
  • Familiar (b)lavaan syntax and methods
    (Merkle et al., 2021; Rosseel, 2012)
  • Very fast—complexity \(\uparrow\) with \(m\) only!

Check out the vignettes at inlavaan.haziqj.ml →

Comparison with MCMC

Refit-free leave-one-cluster-out cross-validation

  • In multilevel SEM, predict a whole group the fit has not seen \[ \mathrm{elpd}_{\text{loco}} = \sum_{g=1}^{G} \log \pi(\mathbf y_g \mid \mathbf y_{-g}) \]
  • Usually resort to importance sampling

  • NEW Closed-form Laplace approximation of \(\mathrm{elpd}_{\text{loco}}\) from a single fit avoids sampling
fit <- asem(model, pisa, cluster = "school")
loo(fit)          
compare(fit0, fit, loo = TRUE)

Application PISA 2022 Saudi Arabia

  • 6,125 students in 186 schools
  • 1 fit takes ~23 s, loo() takes ~4 s

Which school-level covariate predicts school safety? Compare 3 models:

M1Safetybaseline  M2BelongingSafety+17.4 (6.2)MCMC +16.8 (6.8) M3BelongingSafetySES+16.7 (6.2)MCMC +19.7 (6.6)

213× faster than exact refits

~18× faster than MCMC + PSIS

\[ \small \begin{aligned} \frac{\pi(\boldsymbol\vartheta \mid \mathbf y_{-g})}{\pi(\mathbf y_g \mid \mathbf y_{-g})} &= \frac{\pi(\boldsymbol\vartheta \mid \mathbf y)}{\pi(\mathbf y_g \mid \boldsymbol\vartheta)} \\ \therefore \, \pi(\mathbf y_g \mid \mathbf y_{-g}) &= \Big\{ \mathrm E_{\boldsymbol\vartheta \mid \mathbf y} \Big[ \frac{1}{\pi(\mathbf y_g \mid \boldsymbol\vartheta)} \Big] \Big\}^{-1} \end{aligned} \]

What’s next?

Extending INLAvaan in three directions

شكراً جزيلاً

Bring us your latent variables.

install.packages("INLAvaan") ¡ haziqj.ml/kaust-stat26

arXiv
J&R (2026a) 2603.25690 ¡ J&R (2026b) 2604.00671 ¡ A et al. (2026) 2609.00670

Backup: the volume correction, from gradients alone

The mode chases height. The marginal counts height × width.

Lemma 3.1 ¡ Walk the line For a Gaussian, slice summits lie on a known line, the conditional mean path (CMP): 21 evaluations per parameter, no re-optimising. Also Lemma 1 in Martins et al. (2013)

NEWLemma 3.2 + Corollary 3.3 · Volume from gradients \(\gamma_j' = -\tfrac12\,\mathrm{tr}\big(\mathbf P_j^{\perp}\,\mathbf J'\big)\), a projected trace → m + 2 gradient calls per parameter: no Hessians, no determinants along the scan

NEWProposition 3.4 · Two routes, one centre Scan + tilt puts each marginal’s mean on the VB-corrected centre, to \(O(n^{-2})\); both are Lindley’s (1980) correction

Error vs MCMC ¡ with the volume correction 0.19% ¡ without 0.91% ¡ as accurate as the full-Hessian slope

Backup: speed and accuracy, and the gap grows with size

1.28 s whole fit ¡ 42 parameters ¡ on a laptop

≥ 98.5% agreement with 30,000 HMC draws, on every marginal

9 s vs ~8 min 156 parameters ¡ INLAvaan vs one MCMC chain

Backup: honest limits

  • The conditional mean path is only a tangent to a curved ridge.
  • Weak measurement: max discrepancy 0.69–1.63 SD; min JS similarity 44%; only 36 of 100 MCMC references usable.
  • The error shrinks with data, not compute; built-in diagnostics flag it.

References

Alhyari, M., Jamil, H., Montcho, H., & Rue, H. (2026). Deterministic leave-one-cluster-out cross-validation for multilevel Bayesian structural equation models (2609.00670 [stat.ME]). arXiv. https://doi.org/10.48550/arXiv.2609.00670 (Pre-published)
Bollen, K. A. (1989). Structural equations with latent variables. Wiley. https://doi.org/10.1002/9781118619179
Burnell, R., Hao, H., Conway, A. R. A., & HernĂĄndez-Orallo, J. (2023). Revealing the structure of language model capabilities. https://doi.org/10.48550/arXiv.2306.10062
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
Hanushek, E. A., & Woessmann, L. (2010). The high cost of low educational performance: The long-run economic impact of improving PISA outcomes. OECD Publishing. https://doi.org/10.1787/9789264077485-en
Jamil, H., Rosseel, Y., Kemp, O., & Kosmidis, I. (2026). Bias-reduced estimation of structural equation models. Structural Equation Modeling: A Multidisciplinary Journal, 33(3), 376–392. https://doi.org/10.1080/10705511.2025.2610462
Jamil, H., & Rue, H. (2026a). Approximate Bayesian inference for structural equation models using integrated nested Laplace approximations (2603.25690 [stat.ME]). arXiv. https://doi.org/10.48550/arXiv.2603.25690 (Pre-published)
Jamil, H., & Rue, H. (2026b). Implementation and workflows for INLA-based approximate Bayesian structural equation modelling (2604.00671 [stat.CO]). arXiv. https://doi.org/10.48550/arXiv.2604.00671 (Pre-published)
Lindgren, F., & Rue, H. (2015). Bayesian spatial modelling with R-INLA. Journal of Statistical Software, 63, 1–25. https://doi.org/10.18637/jss.v063.i19
Lindley, D. V. (1980). Approximate Bayesian methods. Trabajos de Estadística y de Investigación Operativa, 31(1), 223–245. https://doi.org/10.1007/BF02888353
Martins, T. G., Simpson, D. P., Lindgren, F., & Rue, H. (2013). Bayesian computing with INLA: New features. Computational Statistics & Data Analysis, 67, 68–83. https://doi.org/10.1016/j.csda.2013.04.014
McNeish, D., MacKinnon, D. P., Marsch, L. A., & Poldrack, R. A. (2021). Measurement in intensive longitudinal data. Structural Equation Modeling: A Multidisciplinary Journal, 28(5), 807–822. https://doi.org/10.1080/10705511.2021.1915788
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
OECD. (2024). PISA 2022 technical report. OECD Publishing. https://doi.org/10.1787/01820d6d-en
OECD. (2026). PISA 2025 results (Volume I). OECD Publishing. https://www.oecd.org/content/dam/oecd/en/publications/reports/2026/09/pisa-2025-results-volume-i_5265bfb1/73451bc5-en.pdf
Riebler, A., Sørbye, S. H., Simpson, D. P., & Rue, H. (2016). An intuitive Bayesian spatial model for disease mapping that accounts for scaling. Statistical Methods in Medical Research, 25(4), 1145–1165. https://doi.org/10.1177/0962280216660421
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
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
Vehtari, A., Gelman, A., & Gabry, J. (2017). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing, 27(5), 1413–1432. https://doi.org/10.1007/s11222-016-9696-4