Leveraging INLA for estimating Bayesian latent variable models

STAT Workshop 2024, KAUST

Haziq Jamil

Assistant Professor in Statistics, Universiti Brunei Darussalam
Visiting Fellow, London School of Economics and Political Science

https://haziqj.ml/kaust-stat24/

November 18, 2024

Appreciation

{lavaan} and {blavaan}

  • Yves Rosseel (Universiteit Gent, Belgium)
  • Ed Merkle (University of Missouri, USA)

The {INLA} team

  • Håvard Rue (KAUST, KSA)
  • Elias Krainski (KAUST, KSA)
  • Denis Rustand (KAUST, KSA)

Introduction

Latent variable models

In a nutshell

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

In the social sciences, LVs are used to represent abstract constructs.

(Psychology)
Personality traits

(Healthcare)
Quality of life

(Political science)
Social trust

(Education)
Competencies

Latent variable models (cont.)

Measurement model

  • Define how manifest variables represent latent variables.
  • Also useful as a tool for dimensionality reduction.

\[\begin{gather} y_i \sim f(\cdot \mid \mu_i,\Theta) \\ g(\mu_i) = \class{ubdblue}{\nu} + \class{ubdred}{\Lambda} \eta_i \\ \eta_i \sim \operatorname{N}_q(0,\Psi) \\ i=1,\dots,n \end{gather}\]

Latent variables

Manifest Variables

Metrical Categorical
Metrical Factor analysis Latent trait analysis
Categorical Latent profile analysis Latent class analysis

Bartholomew, Knott, and Moustaki (2011)

  • Continuous factor models: \(f \equiv \operatorname{N}_p(\mu_i,\Theta)\) and \(g(x)=x\).

  • Item Response Theory models: \(f \equiv \operatorname{Cat}_p(\mu_i)\) and \(g(x)=\operatorname{logit}(x)\).

  • Focus on normal observed and LVs for now.

LVs interacting: Structural equation models

\[\begin{gather} y_i = \nu + \Lambda \eta_i + \epsilon_i \\ \epsilon_i \sim \operatorname{N}_p(0,\Theta) \\ \eta_i \sim \operatorname{N}_q(0,\Psi) \\ i=1,\dots,n \end{gather}\]

Bollen (1989)

\[\begin{gather} y_i = \nu + \Lambda \eta_i + \epsilon_i \\ \epsilon_i \sim \operatorname{N}_p(0,\Theta) \\ \eta_i \sim \operatorname{N}_q(0,\Psi) \\ i=1,\dots,n \end{gather}\]

Bollen (1989)

\[\begin{gather} y_i = \nu + \Lambda \eta_i + \epsilon_i \\ \epsilon_i \sim \operatorname{N}_p(0,\Theta) \\[0.4em] \eta_i = \alpha + B \eta_i + \zeta_i \\ \zeta_i \sim \operatorname{N}_q(0,\Psi) \\[0.4em] i=1,\dots,n \end{gather}\]

Bollen (1989)

\[\begin{gather} y_i = \nu + \Lambda \eta_i + \epsilon_i \\ \epsilon_i \sim \operatorname{N}_p(0,\Theta) \\[0.4em] \eta_i = \alpha + B \eta_i + \zeta_i \\ \zeta_i \sim \operatorname{N}_q(0,\Psi) \\[0.4em] i=1,\dots,n \end{gather}\]

Reduced form (aka marginal model)

  • The normal SEM can be written in reduced form as \(y_i \,\overset{\text{iid}}{\sim}\,\operatorname{N}_p(\mu, \Sigma)\), where \[\begin{gather} \mu := \mu(\kappa) = \nu + \cancelto{0}{\Lambda\alpha} \\ \Sigma := \Sigma(\kappa) = \Lambda(I-B)^{-1}\Psi(I-B)^{-\top} \Lambda^\top + \Theta \end{gather}\] as a function of model parameters \(\kappa\in\mathbb R^M\).
  • In the frequentist approach, estimates obtained by minimising discrepancy between \(S\) and \(\Sigma(\kappa)\) (Muthén and Satorra 1995), using

    • \(F_{ML}(\kappa) = \log |\Sigma(\kappa)| + \operatorname{tr}(S \Sigma(\kappa)^{-1}) - p\)
    • \(F_{GLS}(\kappa) = \operatorname{tr}[ (\Sigma(\kappa)-S)S^{-1} ]^2\)
    • \(F_{WLS}(\kappa) = (s-\sigma(\kappa))^\top W^{-1} (s-\sigma(\kappa))\)
    • Etc.
  • Fast and efficient, with nice asymptotic properties. See, e.g. {lavaan} (Rosseel 2012).

Conditional model

  • Alternatively, the normal SEM can be viewed as \[\begin{gather} y_i \mid \eta_i \sim \operatorname{N}_p(\nu + \Lambda \eta_i, \Theta)\\ \eta_i \sim \operatorname{N}_q\big(\cancelto{0}{(I-B)^{-1}\alpha}, (I-B)^{-1}\Psi(I-B)^{-\top} \big) \end{gather}\]

  • Adding suitable priors \(\kappa\sim f(\kappa)\) to the system, this form seems conducive for Bayesian estimation.

    • Many Bayesian SEM applications use Gibbs sampling (Congdon 2014; Lee 2007) available through software such as BUGS and JAGS.
    • Hamiltonian Monte Carlo (HMC) with Stan (Carpenter et al. 2017) may also be used. This is the default sampler in {blavaan} (Merkle and Rosseel 2018).
    • Lately, for efficiency, {blavaan} uses the marginal model instead, effectively turning SEM into covariance matrix model (Merkle et al. 2021).

Why Bayesian anyway?

  1. Flexibility
    • Move beyond standard assumptions (e.g., multivariate normality) to handle skewed distributions, non-normal errors, and outliers.
    • Enables robust handling of missing data.
  2. Extended inference and complex correlations
    • Support the estimation of full posterior distributions for LVs.
    • Model complex correlations, e.g. spatial or time-based dependencies across factors.
  3. + all other Bayesian good stuff

However, with it of course comes all the challenges: Slow convergence, label switching, sensitivity to priors, etc.

Stolen from xkcd

Bibliometric analysis

But 🔎👀 Keywords: “Structural Equation Model INLA” and the like… 0 hits.

Integrated Nested Laplace Approximations

The SEM structure is also seemingly conducive for INLA (Rue, Martino, and Chopin 2009; van Niekerk et al. 2023). Ingredients:

  1. Latent Gaussian model \([\eta\sim\operatorname{N}_q(0,\Psi)]\)
  2. Additive linear predictor \([g(\mu) = \nu + \Lambda\eta + \cdots]\)
  3. Gaussian Markov Random Field [\(\eta \mid y, \kappa\)]
  4. Laplace approximations [marginals]

formula = y ~ nu +
  f(y1, model = "iid") +
  f(y2, copy = "y1", hyper = list(beta = list(fixed = FALSE))) +
  f(y3, copy = "y1", hyper = list(beta = list(fixed = FALSE))) + ...

inla(formula = formula, data = data, family = rep("gaussian", p))

Rue et al. (2017)

A quick comparison

Still working out the kinks, but initial results are promising!

Case studies

Case 1: Multigroup SEM & measurement invariance

CFA model examining cognitive abilities in children from two different schools (Holzinger and Swineford 1939).

Are constructs measured equivalently across groups?

  • Three types of measurement invariant models:

    1. Configural invariance (i.e. no constraints)
    2. Weak invariance: \(\Lambda_{g=1} \equiv \Lambda_{g=2}\)
    3. Strong invariance: \(\Lambda_{g=1} \equiv \Lambda_{g=2}\) and \(\nu_{g=1} \equiv \nu_{g=2}\)
  • Classically, these are formally tested using Likelihood Ratio Test (LRT) or Wald Test (in addition to comparing fit measures).

Bayesian model comparison

  • Under MCMC sampling schemes, we can only afford to perform approximate measurement invariant studies using informative prior distributions.

  • Using INLA, we can perform exact equality constraints and compare models.

    formula <- y ~ -1 + nu.g +
      f(y1.grp1, model = "iidkd", order = 3, n = nrow(data)) +
      f(y2.grp1, copy = "y1.grp1", hyper = list(beta = list(fixed = FALSE))) +
      ... +
      f(y1.grp2, model = "iidkd", order = 3, n = nrow(data)) +
      f(y2.grp2, copy = "y1.grp2", same.as = "y2.grp1") +
      ...
Invariance Marg. Log Lik. DIC

\(p_{\text{eff}}\)

\(\log_{10}(\text{BF})\)

Configural -4120 6942 448 —
Weak -4089 6748 681 13.1
Strong -4075 6824 680 19.2
  • Marginal likelihood and DIC gotten for free. Other fit measures can be calculated with the help of inla.posterior.sample().

Case 2: Multilevel SEM

  • Building a model based on procedural fairness theory, which links trust, legitimacy, and compliance with authorities (Jackson, Bradford, et al. 2011; Jackson, Hough, et al. 2011).

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

European Social Survey (ESS) Round 5

Total \(n=52,458\) respondents from \(m=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?


Adding country-specific random effects

  • Let \(i=1,\dots,n_k\) index respondents, \(j=1,\dots,m\) index countries, and \(k=1,\dots,p\) index items. Additionally, let \(l=1,\dots,5\) index the latent factors.

  • Measurement model: \[\begin{align} y_{ijk} &= \lambda_{kl} (\eta_{il} + u_{jl}) + \varepsilon_{ijk} \\ &= \lambda_{kl} \eta_{il} + \tilde u_{jl} + \varepsilon_{ijk} \end{align}\] where the \(\tilde u_{jl}\) are Gaussian random effects. In {INLA}, we can specify this using an f(i, "iidkd", order = 5) term.

  • Structural model, e.g.: \[\begin{align} \eta_{i3}^{(j)} &= \beta_{1}^{(j)} \eta_{i1}^{(j)} + \beta_{2}^{(j)} \eta_{i2}^{(j)} + \zeta_{i3}^{(j)} \\ \end{align}\] by specifying multilevel priors for the \(\beta\) coefficients.

Inference on random effects

Between-country variability of construct “Obligation to obey the police”

Case 3: Item Response Theory (IRT)

  • Suppose now observed data \(y_i = (y_{i1},\dots,y_{ip}) \in \{0,1\}^p\). Assuming each component \(y_{ik}\sim \operatorname{Bern}(\pi_{ik})\), we could model instead \[ \operatorname{logit}(\pi_{ik}) = \nu_k + \lambda_k \eta_i \] where \(\eta_i\,\overset{\text{iid}}{\sim}\,\operatorname{N}(0,1)\).
  • In the educational testing literature, this is so-called two parameter logistic (2PL) model1

    • \(\nu_k\) is the “easiness” parameter for item \(k\);
    • \(\lambda_k\) is the discrimination parameter for item \(k\); and
    • \(z_i\) is the unobserved latent trait for respondent \(i\).

Spatial IRT

  • Traditional IRT analyses overlook regional disparities in educational outcomes, which can provide crucial insights for targeted interventions.
    • Increase funding, improving infrastructure, and teacher training in targeted areas.
    • Reveal socioeconomic factors that impact performance in specific regions.
  • A simple modification would be \[ \operatorname{logit}(\pi_{ijk}) = \nu_k + \lambda_k \eta_i + \phi_{j}, \] where \(\phi_{j}\) is a spatial random effect, e.g. (Besag 1974): \[ \phi_j \mid \phi_{-j} \sim \operatorname{N}\Big(\rho \sum_{j'\sim j} w_{jj'}\phi_j, \ \tau^{-1}(1-\rho)^{-1}\Big), \hspace{2em} w_{jj'} = [j\sim j']. \]
  • In {INLA}, we make use of an f(region, model = "besagproper") term with family = "binomial" likelihood.

Brazilian ENEM data set

  • Could also consider spatially varying differential item functioning (DIF).

  • If latent traits are of interest, INLA provides this under $summary.random.

Conclusions

INLA for SEM

  • INLA is a promising alternative to MCMC sampling for 🚀 estimating Bayesian latent variable models and structural equation models.

  • Several gaps in {b/lavaan} that are easily filled by {INLA}:

    • Exact measurement invariance testing 📏
    • Multilevel SEM 🏗️
    • Spatial SEM 🌍
    • Non-normal likelihoods 📊
  • A pivotal advancement in psychometric research, opening doors for innovative modelling of real-world data.

  • The ultimate goal is to provide an R software implementation for estimating Bayesian SEM using INLA.

{INLAvaan}

Work in progress, but feel free to check out the GitHub repo!


mod <- "
  dem60 =~ y1 + y2 + y3 + y4
  dem65 =~ y5 + y6 + y7 + y8
  ind60 =~ x1 + x2 + x3

  dem60 ~ ind60
  dem65 ~ ind60 + dem60

  y1 ~~ y5
  y2 ~~ y4 + y6
  y3 ~~ y7
  y4 ~~ y8
  y6 ~~ y8
"
fit <- insem(
  model = mod, 
  data = lavaan::PoliticalDemocracy
)

Thanks!

https://haziqj.ml/kaust-stat24

References

Bartholomew, David J., M. Knott, and Irini Moustaki. 2011. Latent Variable Models and Factor Analysis: A Unified Approach. 3rd ed. Wiley Series in Probability and Statistics. Chichester, West Sussex: Wiley.
Besag, Julian. 1974. “Spatial Interaction and the Statistical Analysis of Lattice Systems.” Journal of the Royal Statistical Society: Series B (Methodological) 36 (2): 192–225. https://doi.org/10.1111/j.2517-6161.1974.tb00999.x.
Bollen, Kenneth A. 1989. Structural Equations with Latent Variables. Structural Equations with Latent Variables. Oxford, England: John Wiley & Sons. https://doi.org/10.1002/9781118619179.
Carpenter, Bob, Andrew Gelman, Matthew D. Hoffman, Daniel Lee, Ben Goodrich, Michael Betancourt, Marcus Brubaker, Jiqiang Guo, Peter Li, and Allen Riddell. 2017. “Stan : A Probabilistic Programming Language.” Journal of Statistical Software 76 (1). https://doi.org/10.18637/jss.v076.i01.
Congdon, Peter. 2014. Applied Bayesian Modelling. 1st ed. Wiley Series in Probability and Statistics. Wiley. https://doi.org/10.1002/9781118895047.
European Social Survey European Research Infrastructure (ESS ERIC). 2023. “ESS5 - Integrated File, Edition 3.5 (Austria Not Included).” Sikt - Norwegian Agency for Shared Services in Education and Research. https://doi.org/10.21338/ESS5E03_5.
Holzinger, K. J., and F. Swineford. 1939. “A Study in Factor Analysis: The Stability of a Bi-Factor Solution.” Supplementary Educational Monographs 48: xi + 91–91.
Jackson, Jonathan, Ben Bradford, Mike Hough, Jouni Kuha, Sally Stares, Sally Widdop, Rory Fitzgerald, Maria Yordanova, and Todor Galev. 2011. “Developing European Indicators of Trust in Justice.” European Journal of Criminology 8 (4): 267–85. https://doi.org/10.1177/1477370811411458.
Jackson, Jonathan, Mike Hough, Ben Bradford, Tia Pooler, Katrin Hohl, and Jouni Kuha. 2011. “Trust in Justice: Topline Results from the Round 5 of the European Social Survey.” {{SSRN Scholarly Paper}}. Rochester, NY.
Lee, Sik-Yum. 2007. Structural Equation Modeling: A Bayesian Approach. Wiley Series in Probability and Statistics. Chichester, England ; Hoboken, NJ: Wiley.
Merkle, Edgar C., Ellen Fitzsimmons, James Uanhoro, and Ben Goodrich. 2021. “Efficient Bayesian Structural Equation Modeling in Stan.” Journal of Statistical Software 100 (November): 1–22. https://doi.org/10.18637/jss.v100.i06.
Merkle, Edgar C., and Yves Rosseel. 2018. “Blavaan: Bayesian Structural Equation Models via Parameter Expansion.” Journal of Statistical Software 85 (June): 1–30. https://doi.org/10.18637/jss.v085.i04.
Muthén, Bengt O., and Albert Satorra. 1995. “Complex Sample Data in Structural Equation Modeling.” Sociological Methodology 25: 267–316. https://doi.org/10.2307/271070.
Rosseel, Yves. 2012. “lavaan: An R Package for Structural Equation Modeling.” Journal of Statistical Software 48 (2). https://doi.org/10.18637/jss.v048.i02.
Rue, Håvard, Sara Martino, and Nicolas Chopin. 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–92. https://doi.org/10.1111/j.1467-9868.2008.00700.x.
Rue, Håvard, Andrea Riebler, Sigrunn H. Sørbye, Janine B. Illian, Daniel P. Simpson, and Finn K. Lindgren. 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.
van Niekerk, Janet, Elias Krainski, Denis Rustand, and Håvard Rue. 2023. “A New Avenue for Bayesian Inference with INLA.” Computational Statistics & Data Analysis 181 (May): 107692. https://doi.org/10.1016/j.csda.2023.107692.