Model and estimation

This page gives the statistical model fitted by LRStateSpaceModel, the estimation algorithm, and the quantities reported after the fit, in the notation used by the code.

geossm pipeline: data, design matrices, latent spatial field, EM estimation, inference and prediction

The pipeline (source: docs/source/diagrams/pipeline.mmd).

Notation

Symbol (attribute)

Meaning

\(p\) / \(T\)

number of sites, stacked over the response variables (block_p separates them) / number of time steps

\(y_t \in \mathbb{R}^p\)

responses at time \(t\) (y_obs; missing values are NaN)

\(X_t \in \mathbb{R}^{p \times b}\), \(\beta\)

covariates (Xbeta, block-diagonal over the responses) and their coefficients (beta)

\(x_t \in \mathbb{R}^q\)

latent state: the latent fields at the inner mesh nodes, stacked over the \(q_\ell\) latent factors (block_q)

\(\Phi_{ij}\)

FEM basis of latent factor \(j\) at the sites of response \(i\) (latent_basis)

\(A\), \(s^2_e\), \(f\), \(\kappa\)

loadings (A, responses × factors), measurement-error variances (s2e, one per response), AR coefficients (f) and SPDE scales (ks, one per factor)

The model

For \(t = 1, \dots, T\),

\[\begin{split}\begin{aligned} y_t &= X_t \beta + H x_t + e_t, & e_t &\sim \mathcal{N}(0, R),\\ x_t &= F x_{t-1} + \eta_t, & \eta_t &\sim \mathcal{N}(0, Q),\\ x_0 &\sim \mathcal{N}(x_0, \Sigma_0), \end{aligned}\end{split}\]

with independent errors and

\[\begin{split}\begin{aligned} H &= \bigl[A_{ij}\, \Phi_{ij}\bigr]_{ij}, & R &= \operatorname{diag}\bigl(s^2_{e,i}\ \text{on the sites of response } i\bigr),\\ Q &= \operatorname{blockdiag}\bigl(\Lambda(\kappa_j)^{-1}\bigr), & F &= \operatorname{diag}\bigl(f_j\ \text{on the nodes of factor } j\bigr). \end{aligned}\end{split}\]

So the latent term of site \(s\) of response \(i\) is \(\sum_j A_{ij}\, \Phi_{ij}(s)\, x_{t,j}\): each response loads on every latent factor (A is \(n_\text{resp} \times q_\ell\)).

The latent field: SPDE approximation

Each latent factor is a Matérn field with smoothness \(\nu = 1\) in two dimensions, represented through the SPDE

\[(\kappa^2 - \Delta)\, x(s) = \mathcal{W}(s)\]

solved by linear finite elements on a triangular mesh, with Neumann boundary conditions (SPDEApproxCov). With \(\tilde C\) the lumped mass matrix and \(G\) the stiffness matrix (FEMSolver), the precision of the field at the mesh nodes is

\[\tilde\Lambda(\kappa) = \sigma^2(\kappa)\, K_\kappa \tilde C^{-1} K_\kappa, \qquad K_\kappa = \kappa^2 \tilde C + G, \qquad \sigma^2(\kappa) = \frac{\Gamma(\nu)}{\Gamma(\nu + 1)\, 4\pi \kappa^{2\nu}} = \frac{1}{4\pi\kappa^2},\]

scaled to unit marginal variance (the scale of the latent term is carried by \(A\)). The latent state uses the inner nodes (inside the latent domain); the outer nodes, a buffer against boundary effects, are integrated out by the Schur complement (precision(marginal=True))

\[\Lambda(\kappa) = \tilde\Lambda_{11} - \tilde\Lambda_{12}\, \tilde\Lambda_{22}^{-1}\, \tilde\Lambda_{12}^\top.\]

The practical range is \(\sqrt{8\nu}/\kappa\) (emp_range), in the units of the data CRS: the FEM is planar in those units (see Covariance models and meshes).

The basis row of a site is the FEM interpolant restricted to the inner nodes and normalised to sum to 1. A site outside the latent domains, or with an empty basis row, is outside the support of the latent field (in_support): its observations are treated as missing in the fit.

Log-likelihood

With \(o_t\) the observed entries of \(y_t\) (NaN and out-of-support entries are missing) and \(n = \sum_t |o_t|\) (nobs), the observed-data log-likelihood is

\[\begin{split}\begin{aligned} \ell(\theta) &= -\frac12 \sum_{t=1}^T \Bigl(\log\lvert S_t\rvert + v_t^\top S_t^{-1} v_t + \lvert o_t\rvert \log 2\pi\Bigr),\\ v_t &= y_{t,o_t} - X_{t,o_t}\beta - H_{o_t} x_{t\mid t-1}, \qquad S_t = H_{o_t} P_{t\mid t-1} H_{o_t}^\top + R_{o_t}, \end{aligned}\end{split}\]

computed by the Kalman filter without forming the \(p \times p\) matrix \(S_t\): with \(H_t\) the rows of \(H\) with the missing rows set to zero,

\[\begin{split}\begin{aligned} M_t &= P_{t\mid t-1}^{-1} + H_t^\top R^{-1} H_t, & \lvert S_t\rvert &= \lvert M_t\rvert\, \lvert P_{t\mid t-1}\rvert\, \lvert R_{o_t}\rvert,\\ P_{t\mid t} &= M_t^{-1}, & K_t &= M_t^{-1} H_t^\top R^{-1}, \end{aligned}\end{split}\]

and \(x_{t\mid t} = x_{t\mid t-1} + K_t v_t\) (information form of the update, symmetric positive definite by construction).

Estimation: the EM algorithm

fit() maximises \(\ell\) by expectation-maximisation.

E-step. The Kalman filter and the Rauch-Tung-Striebel smoother give \(\hat x_t = x_{t\mid T}\), \(P_t = P_{t\mid T}\) and the lag-one covariances, hence the sufficient statistics

\[S_{11} = \sum_{t=1}^T \mathbb{E}[x_t x_t^\top \mid y], \qquad S_{10} = \sum_{t=1}^T \mathbb{E}[x_t x_{t-1}^\top \mid y], \qquad S_{00} = \sum_{t=1}^T \mathbb{E}[x_{t-1} x_{t-1}^\top \mid y].\]

M-step. Each update maximises the expected complete-data log-likelihood given the latest values of the others (an ECM algorithm, so \(\ell\) does not decrease), with FitOptions(f_update="weighted"). With the default f_update="unweighted" the \(f\) step is not a maximiser, see below. A parameter fixed in params0 keeps its value, and the later steps use it.

  • AR coefficients, given the current \(\kappa\), for each factor \(j\) (blocks of the matrices on its nodes):

    \[f_j = \frac{\operatorname{tr}\bigl(\Lambda_j\, S_{10,jj}\bigr)}{\operatorname{tr}\bigl(\Lambda_j\, S_{00,jj}\bigr)}, \qquad \Lambda_j = \Lambda(\kappa_j).\]

    This is FitOptions(f_update="weighted"). With the default f_update="unweighted" the update is \(f_j = \operatorname{tr}(S_{10,jj}) / \operatorname{tr}(S_{00,jj})\), the lag-one autocorrelation pooled over the nodes. It solves the unbiased estimating equation \(\operatorname{tr}(S_{10,jj} - f_j S_{00,jj}) = 0\) and measures the persistence of the large-scale modes. It is not a conditional maximiser, so with it \(\ell\) can decrease and the fixed point is not the maximum likelihood estimate. A decrease of \(\ell\) therefore does not stop the algorithm: it stops when \(\lvert \ell_k - \ell_{k-1} \rvert / n_{\mathrm{obs}}\) falls below tol_relat and returns the last iterate. See FitOptions for when to use each.

  • SPDE scales, given the new \(f\): with \(\Omega = S_{11} - S_{10} F^\top - F S_{10}^\top + F S_{00} F^\top\),

    \[\kappa = \arg\min_{\kappa > 0}\; \Bigl\{\operatorname{tr}\bigl(\Lambda(\kappa)\, \Omega\bigr) - T \log\lvert\Lambda(\kappa)\rvert\Bigr\},\]

    by L-BFGS-B over \(\log\kappa\) with exact JAX gradients, until the gradient is below FitOptions.ks_tol times the objective.

  • Measurement-error variances, from the E-step residuals \(r_t = y_t - X_t\beta - H\hat x_t\) over the observed entries of response \(i\):

    \[s^2_{e,i} = \frac{1}{n_i} \sum_{t=1}^T \sum_{s \in o_{t,i}} \Bigl(r_{t,s}^2 + \bigl(H P_t H^\top\bigr)_{ss}\Bigr).\]
  • Regression coefficients, with \(D_t\) the diagonal selector of the observed entries:

    \[\beta = \Bigl(\sum_{t} X_t^\top D_t X_t\Bigr)^{-1} \sum_{t} X_t^\top D_t \bigl(y_t - H \hat x_t\bigr).\]
  • Loadings, given the new \(\beta\), one row \(a_i\) of \(A\) per response: with \(u_{it} = y_{it} - X_{it}\beta\),

    \[\sum_k \Bigl(\sum_t \mathbb{E}\bigl[(\Phi_{ij} x_{t,j})^\top D_{it}\, \Phi_{ik} x_{t,k} \mid y\bigr]\Bigr) A_{ik} = \sum_t u_{it}^\top D_{it}\, \Phi_{ij}\, \hat x_{t,j} \quad \text{for every factor } j.\]
  • Initial state: \(x_0 = \hat x_0\), \(\Sigma_0 = P_0\).

The algorithm stops when \(\lvert\ell_k - \ell_{k-1}\rvert / n <\) tol_relat or after max_iter iterations (FitOptions). A final E-step evaluates \(\ell\), the states and the fitted values at the returned parameters.

Inference

compute_cov_params() computes the Hessian of \(\ell\) with respect to the free parameters (excluding \(x_0, \Sigma_0\)) by automatic differentiation, one Hessian-vector product per free parameter (for its memory, see JAX configuration: devices, memory and precision), and

\[\widehat{\operatorname{Cov}}(\hat\theta) = -\bigl(\nabla^2 \ell(\hat\theta)\bigr)^{-1}.\]

This is a covariance matrix only at a maximum of \(\ell\); it is not checked. Confidence intervals (conf_int) use the Student-\(t\) quantile \(c\) with df_resid degrees of freedom. They are Wald intervals \(\hat\theta \pm c\, \mathrm{se}\), except for the bounded parameters, which are mapped from a transformed scale:

\[s^2_e, \kappa:\ \ \hat\theta\, \exp\bigl(\pm c\, \mathrm{se}/\hat\theta\bigr), \qquad f:\ \ \tanh\Bigl(\operatorname{atanh}\hat f \pm c\, \frac{\mathrm{se}}{1 - \hat f^2}\Bigr).\]

The information criteria are \(\mathrm{AIC} = 2k - 2\ell(\hat\theta)\) and \(\mathrm{BIC} = k \log n - 2\ell(\hat\theta)\), with \(k\) the number of free parameters (n_params).

Prediction

At new sites and times within the training period (get_prediction()), with the basis \(H^\ast\) and covariates \(X_t^\ast\) of the new sites,

\[\hat y_t^\ast = X_t^\ast \hat\beta + H^\ast \hat x_t, \qquad \operatorname{Cov}(\hat y_t^\ast) = H^\ast P_t H^{\ast\top},\]

the smoothed (plug-in) mean and covariance of the latent signal. The measurement error is not included: for a prediction interval of a new observation add \(s^2_e\). Sites outside the latent support get \(X_t^\ast\hat\beta\) and variance 0 (in_support).

For a transformed response \(g(y)\) (e.g. np.log(y)), back_transform(g_inv) applies the delta method with \(h = g^{-1}\):

\[\mathbb{E}[h(Y)] \approx h(\mu) + \tfrac12 h''(\mu)\, \sigma^2, \qquad \operatorname{Cov}\bigl(h(Y_s), h(Y_{s'})\bigr) \approx h'(\mu_s)\, \Sigma_{ss'}\, h'(\mu_{s'}).\]

to_poly averages the predictions over polygons (change of support): with \(W\) the matrix averaging the in-support prediction sites of each polygon,

\[\hat y^{\text{poly}}_t = W \hat y_t, \qquad \operatorname{sd}\bigl(\hat y^{\text{poly}}_t\bigr) = \sqrt{\operatorname{diag}\bigl(W \Sigma_t W^\top\bigr)}.\]