Linear: Latent Single‑Slope
INLA's model='linear' treats a single slope as a latent component with a Gaussian prior. pyINLA exposes the same helper via the model['random'] block.
Parametrization
The latent linear model is an alternative interface for a single fixed effect. It adds a one-column latent component whose contribution is
The slope $\beta$ follows a Gaussian prior
with $\mu$ and $\tau$ supplied via mean.linear and prec.linear. Conceptually, this is identical to a fixed effect with an informative prior: only the interface differs.
Hyperparameters
No additional hyperparameters are introduced beyond the Gaussian prior on $\beta$; the model does not expose a hyper block.
Allowed Parameters
| Parameter | Required | Description |
|---|---|---|
model | Yes | Must be 'linear'. |
covariate | Yes | Column name or 1D vector of covariate values. |
id | No | Label used in the section name and in summary_random. Defaults to the value of covariate when it is a column name. |
mean.linear | No | Prior mean $\mu$ of the slope (default: $0$). |
prec.linear | No | Prior precision $\tau$ of the slope (default: $0.001$). |
diagonal | No | Small constant added to the precision-matrix diagonal for numerical stability (default: $0$). |
pyINLA Usage
Declare the covariate as a linear latent component inside model['random']. Supply the covariate column (or vector) with covariate=... and set the prior via mean.linear / prec.linear.
import numpy as np import pandas as pd from pyinla import pyinla n = 100 rng = np.random.default_rng(123) z = rng.uniform(size=n) y = 1.0 + z + rng.normal(size=n) df = pd.DataFrame({"y": y, "z": z}) model = { "response": "y", "fixed": [], "random": [{ "model": "linear", "covariate": "z", "mean.linear": 1.0, "prec.linear": 1.0, }], } result = pyinla(model=model, family="gaussian", data=df) print(result.summary_fixed)
The model fits $y_i = \beta_0 + \beta_z\, z_i + \varepsilon_i$ with $\beta_z \sim \mathcal{N}(1,\; 1^{-1})$. pyINLA writes a dedicated linear section so INLA treats the slope as a latent component with the specified prior.
Notes on usage
covariateaccepts a column name or an explicit vector. Missing values are replaced with $0$.mean.linearandprec.linearmust be scalars; omit them to use the engine defaults ($\mu = 0$, $\tau = 0.001$).
Alternative via control['fixed']
You can obtain the same prior by keeping the slope in the fixed-effects block and setting label-specific entries in control['fixed']. This remains useful when you want to stay entirely within the fixed-effect design.
formula = {
"response": "y",
"fixed": ["1", "z"],
}
control = {
"fixed": {
"mean": {"z": 1.0},
"prec": {"z": 1.0},
},
}
result = pyinla(formula=formula, family="gaussian", data=df, control=control)
Notes
- Combine
model='linear'withcovariatewhen you need explicit slope priors outsidemodel['fixed']. - For bounded slopes, switch to the
clinearmodel which enforces hard limits on $\beta$ (see CLINEAR).