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.
The pipeline (source: docs/source/diagrams/pipeline.mmd).¶
Notation¶
Symbol (attribute) |
Meaning |
|---|---|
\(p\) / \(T\) |
number of sites, stacked over the response variables ( |
\(y_t \in \mathbb{R}^p\) |
responses at time \(t\) ( |
\(X_t \in \mathbb{R}^{p \times b}\), \(\beta\) |
covariates ( |
\(x_t \in \mathbb{R}^q\) |
latent state: the latent fields at the inner mesh nodes, stacked
over the \(q_\ell\) latent factors ( |
\(\Phi_{ij}\) |
FEM basis of latent factor \(j\) at the sites of response
\(i\) ( |
\(A\), \(s^2_e\), \(f\), \(\kappa\) |
loadings ( |
The model¶
For \(t = 1, \dots, T\),
with independent errors and
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
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
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))
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
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,
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
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 defaultf_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 belowtol_relatand returns the last iterate. SeeFitOptionsfor 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_toltimes 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
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:
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,
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}\):
to_poly averages the predictions over polygons (change of support):
with \(W\) the matrix averaging the in-support prediction sites of
each polygon,