Learn PyINLA

The Latent Field

Understanding how fixed effects, random effects, and the linear predictor η combine to form the latent Gaussian structure at the heart of INLA.

What is the Latent Field?

The latent field x is the collection of all unobserved Gaussian random variables in an INLA model. It includes:

  • Intercept α: the global baseline
  • Fixed effect coefficients β: regression parameters for covariates
  • Random effect values f(k): structured or unstructured latent components (IID, temporal, spatial, ...)

Together, these form a high-dimensional Gaussian Markov Random Field (GMRF) that INLA approximates efficiently. The linear predictor η is then computed from x via a single sparse multiplication η = Apred x (defined in Model Representation below).

Three-Level Hierarchy

INLA models have a natural three-level hierarchical structure:

Level 1

Hyperparameter Model

$$\pi(\boldsymbol{\theta})$$

Priors on hyperparameters (precisions, correlations, etc.)

Level 2

Latent Field Model

$$\mathbf{x} \mid \boldsymbol{\theta}_x \sim \mathcal{N}(\boldsymbol{\mu}, \mathbf{Q}^{-1}(\boldsymbol{\theta}_x))$$

The latent field as a GMRF with sparse precision matrix Q

Level 3

Observation Model

$$y_i \mid \mathbf{x}, \boldsymbol{\theta}_y \sim \pi(y_i \mid \eta_i, \boldsymbol{\theta}_y)$$

Likelihood connecting the linear predictor to observations

The Linear Predictor

The linear predictor ηi combines all model components for observation i:

$$\eta_i = \alpha + \sum_{j=1}^{J} \beta_j \cdot z_{ji} + \sum_{k=1}^{K} f^{(k)}(u_{ki}) + \text{offset}_i$$
α
Intercept Global baseline level
βj · zji
Fixed Effects Covariate effects (linear, categorical)
f(k)(uki)
Random Effects IID, temporal, spatial components
offseti
Offset Known fixed value added to η (e.g., log(E) for Poisson)

Model Representation

INLA uses a compact representation where the linear predictor is computed via a single sparse matrix multiplication that combines every component of the latent field:

$$\boldsymbol{\eta} \;=\; \mathbf{A}_{\text{pred}}\, \mathbf{x} \;=\; \big[\, \mathbf{A}^{(\beta)} \;\big|\; \mathbf{A}^{(1)} \;\big|\; \cdots \;\big|\; \mathbf{A}^{(K)} \,\big] \begin{bmatrix} \boldsymbol{\beta} \\ \mathbf{f}^{(1)} \\ \vdots \\ \mathbf{f}^{(K)} \end{bmatrix}$$

Each block A(k) is the projector for one component of the latent field. The global Apred stacks them side by side, so fixed effects, IID effects, and an SPDE term can all contribute to the same row of η.

Two different "A" matrices. In the SPDE literature, A often refers specifically to the mesh-to-observation projector for that one term. On this page, Apred is the global predictor matrix that bundles every component, including the SPDE block, into one row-stacked operator.

Per-component blocks A(k)

Each block extracts the contribution of one latent component to each observation. Typical shapes:

  • Fixed effects: A(β) is the design matrix of covariate values (one row per observation, one column per coefficient).
  • IID / temporal / areal: a selection matrix that picks the group, time index, or region for each observation.
  • SPDE: a barycentric projector that interpolates the mesh-node field at each observation location.

The Latent Field x

The vector x stacks all latent Gaussian variables in the same order as the blocks of Apred:

  • Intercept and fixed-effect coefficients β
  • Random effect vectors f(1), ..., f(K)
  • Dimension can far exceed n (e.g., SPDE mesh nodes, large group counts)

Building a Complete Model

Here's how the components combine in a typical model:

# Model: y ~ 1 + x1 + x2 + f(group)
# η_i = α + β₁·x1_i + β₂·x2_i + f_group[i]

formula = {
    'response': 'y',
    'fixed': ['1', 'x1', 'x2'],     # Intercept + 2 covariates
    'random': [
        {'id': 'group', 'model': 'iid'}  # Random intercepts
    ]
}

result = pyinla(
    formula=formula,
    family='gaussian',
    data=df
)

# The latent field x contains:
# - α (intercept)
# - β₁ (coefficient for x1)
# - β₂ (coefficient for x2)
# - f_1, f_2, ..., f_G (G group effects)

Latent Model Components

PyINLA documents the latent model components below, grouped by what kind of dependence structure they impose. Each tile links to a dedicated article with the spec surface, math, runnable code snippets, and parity status. New models are added as their per-model schema and parity sweep land.

Conditional Independence

A key assumption in INLA is that observations are conditionally independent given the latent field:

$$\pi(\mathbf{y} \mid \mathbf{x}, \boldsymbol{\theta}) = \prod_{i=1}^{n} \pi(y_i \mid \eta_i, \boldsymbol{\theta}_y)$$

This means all dependence between observations is captured through the latent field structure. The precision matrix Q encodes the conditional independence structure of the latent field itself, making computations efficient via sparse matrix methods.

Key Takeaways