geossm.ssm.StateSpaceResults¶
- class geossm.ssm.StateSpaceResults(model, y_hat, Sigma_y_hat=None, tdelta_hat=None, params=None, params_names=None, params_dim=None, y_obs=None, yname=None, Xbeta=None, backend=None, dtype=None, llf=None, time_filter=0.0, time_smoother=0.0, time_expectation=0.0, time_total=0.0, x_filtered=None, P_filtered=None, x_pred=None, P_pred=None, K=None, x_smoothed=None, P_smoothed=None, P_pred_smoothed=None, S11=None, S10=None, S00=None)[source]¶
Bases:
objectContainer for state-space model estimation results (filter and/or smoother outputs), with convenience methods for residuals, error metrics, confidence intervals, diagnostics and a printable summary.
Instances are normally created by geossm.ssm.statespace.StateSpaceModel.filter, geossm.ssm.statespace.StateSpaceModel.smoother or geossm.ssm.statespace.StateSpaceModel.estimate, not directly by user code. All array-valued attributes are stored as NumPy arrays (converted from JAX arrays on construction, see to_numpy) in the dtype of the originating model.
- model¶
The geossm.ssm.statespace.StateSpaceModel (or subclass) instance that produced these results.
- Type:
objectorNone
- y_obs¶
Observed data used for fitting (may contain
NaN).- Type:
numpy.ndarray,shape (p,T)
- y_hat¶
Predicted/fitted observation means.
- Type:
numpy.ndarray,shape (p,T)
- Sigma_y_hat¶
State-driven predictive covariance of
y_hat(excludes observation noiseR); see geossm.ssm.statespace._compute_predict_kernel_JAX.- Type:
numpy.ndarray,shape (p,p,T)orNone
- x_filtered, P_filtered
Filtered state means/covariances (
Nonewhen unavailable, e.g. aftersmoother(..., light=True)).- Type:
numpy.ndarrayorNone
- x_pred, P_pred
One-step-ahead predicted state means/covariances from the filter.
- Type:
numpy.ndarrayorNone
- K¶
Kalman gain at the final time step.
- Type:
numpy.ndarrayorNone
- x_smoothed, P_smoothed
Smoothed state means/covariances.
- Type:
numpy.ndarrayorNone
- P_pred_smoothed¶
Smoothed lag-one state covariances.
- Type:
numpy.ndarrayorNone
- S11, S10, S00
EM sufficient statistics; see geossm.ssm.statespace._compute_expected_values_kernelJAX.
- Type:
numpy.ndarrayorNone
- llf¶
Model log-likelihood.
- Type:
floatorNone
- time_filter, time_smoother, time_expectation, time_total
Wall-clock runtimes (seconds) of the filter, smoother, expected- value/sufficient-statistics computation, and their sum.
- Type:
float
Methods
Return a plain dict snapshot of the main results.
Compute pointwise Gaussian confidence intervals for the latent state.
Compute pointwise Gaussian confidence/prediction intervals for the predicted observations
y_hat.Empirical coverage probability of the conf_int_y prediction intervals.
Compute standard residual-normality/autocorrelation diagnostics.
Build the two small key/value tables (model identity/config and fit runtime on the left, fit-quality/residual diagnostics on the right) used by summary.
Mean squared error of the residuals.
Root mean squared error of the residuals.
Build a
statsmodels-style structured summary of the fit: model identity/shape/runtime, log-likelihood, MSE/RMSE, coverage probability and residual diagnostics (Jarque-Bera, Omnibus, skewness, kurtosis, Durbin-Watson).Convert array-like attributes to numpy arrays in the results' dtype (the model's dtype, by default), so results stay numerically consistent with the precision the model was fit in.
Return a new StateSpaceResults with some fields replaced.
Attributes
JAX compute device any further computation on these results runs on (defaults to the originating model's geossm.ssm.statespace.StateSpaceModel.backend).
Floating-point precision results are stored in (defaults to the originating model's dtype).
Observation residuals, or None if unavailable.
- property backend¶
JAX compute device any further computation on these results runs on (defaults to the originating model’s geossm.ssm.statespace.StateSpaceModel.backend).
- Type:
jax.Device
- property dtype¶
Floating-point precision results are stored in (defaults to the originating model’s dtype).
- Type:
numpy.dtype
- to_numpy()[source]¶
Convert array-like attributes to numpy arrays in the results’ dtype (the model’s dtype, by default), so results stay numerically consistent with the precision the model was fit in.
- update(**kwargs)[source]¶
Return a new StateSpaceResults with some fields replaced.
Copies every current public (non-underscore-prefixed) attribute except
today, overrides the ones given inkwargs, and constructs a new instance from the result. Does not mutateself.- Parameters:
**kwargs – Attribute name/value pairs to override; each key must already be a public attribute of this instance.
- Returns:
StateSpaceResults– A new instance with the requested fields updated.- Raises:
AttributeError – If a key in
kwargsis not an existing public attribute.- Return type:
- property residuals: ndarray | None¶
Observation residuals, or None if unavailable.
- Returns:
numpy.ndarrayorNone–y_obs - y_hat, shape(p, T)(NaNwherey_obsis missing), or None if eithery_obsory_hatis unavailable.
- mse(which='global')[source]¶
Mean squared error of the residuals.
- Parameters:
which (
{'global', 'space', 'time'}, default'global') – Aggregation axis:'global'averages over all (non-missing) entries;'space'averages over time, returning one value per observed location/variable, shape(p,);'time'averages over space, returning one value per time step, shape(T,).NaNresiduals (missing observations) are ignored.- Returns:
floatornumpy.ndarray– Mean squared error, aggregated as requested.- Raises:
ValueError – If
whichis not one of'global','space','time'.- Return type:
float
- rmse(which='global')[source]¶
Root mean squared error of the residuals.
- Parameters:
which (
{'global', 'space', 'time'}, default'global') – Aggregation axis; forwarded to mse.- Returns:
floatornumpy.ndarray– Square root of mse, aggregated as requested.- Return type:
float
- conf_int_state(which='smoothed', alpha=0.05)[source]¶
Compute pointwise Gaussian confidence intervals for the latent state.
For each time step, uses the marginal state mean/variance (\(x_t\), \(\mathrm{diag}(P_t)\)) and a two-sided Normal quantile: \(x_t \pm z_{1-\alpha/2} \sqrt{\mathrm{diag}(P_t)}\). Does not account for cross-state covariances (only the marginal per-component variance is used).
- Parameters:
which (
{'smoothed', 'filtered'}, default'smoothed') – Whether to use the smoothed (x_smoothed/P_smoothed) or filtered (x_filtered/P_filtered) state estimates.alpha (
float, default0.05) – Significance level; the interval has nominal coverage1 - alpha.
- Returns:
lower, upper (
numpy.ndarray,shape (q,T+1)) – Lower and upper confidence bounds for the state mean.- Raises:
ValueError – If
whichis invalid, or the required state means/ covariances are not available on this results object.- Return type:
Tuple[ndarray, ndarray]
- conf_int_y(alpha=0.05, prediction=False)[source]¶
Compute pointwise Gaussian confidence/prediction intervals for the predicted observations
y_hat.For each time step, uses \(\hat y_t \pm z_{1-\alpha/2} \sqrt{\mathrm{diag}(\Sigma_{\hat y, t})}\), where \(\Sigma_{\hat y, t}\) is Sigma_y_hat (the state-driven predictive covariance, excluding observation noise) plus, when
prediction=True, the observation noise covarianceRread fromself.model- turning a confidence interval for the mean response into a prediction interval for a new observation.- Parameters:
alpha (
float, default0.05) – Significance level; the interval has nominal coverage1 - alpha.prediction (
bool, defaultFalse) – If True, add the model’s observation noise covarianceRtoSigma_y_hatbefore computing the interval (prediction interval); if False, useSigma_y_hatalone (confidence interval for the mean).
- Returns:
lower, upper (
numpy.ndarray,shape (p,T)) – Lower and upper interval bounds fory_hat.- Raises:
ValueError – If
y_hator Sigma_y_hat is not available on this results object.- Return type:
Tuple[ndarray, ndarray]
- coverage_probability(alpha=0.05, which='global')[source]¶
Empirical coverage probability of the conf_int_y prediction intervals.
Computes the fraction of observed values
y_obsthat fall within the1 - alphaprediction interval fromconf_int_y(alpha, prediction=True); for a well-calibrated model this should be close to1 - alpha.- Parameters:
alpha (
float, default0.05) – Significance level used for the prediction interval.which (
{'global', 'space', 'time'}, default'global') – Aggregation axis:'global'averages over all entries;'space'averages over time (shape(p,));'time'averages over space (shape(T,)).
- Returns:
floatornumpy.ndarray– Empirical coverage probability in[0, 1], aggregated as requested.
- diagnostics()[source]¶
Compute standard residual-normality/autocorrelation diagnostics.
Flattens the (non-missing) residuals and computes:
Jarque-Bera test statistic and p-value (
jb/jb_pvalue) for normality, based on sample skewness and kurtosis.Omnibus normality test statistic and p-value (
omni/omni_pvalue,statsmodels’omni_normtest).Sample skewness and excess kurtosis (
skew/kurtosis).Durbin-Watson statistic (
dw) for first-order autocorrelation (values near 2 indicate little autocorrelation).
- Returns:
dictofstrtofloat– Keysjb,jb_pvalue,omni,omni_pvalue,dw,skew,kurtosis.- Return type:
Dict[str, float]
- generate_summary()[source]¶
Build the two small key/value tables (model identity/config and fit runtime on the left, fit-quality/residual diagnostics on the right) used by summary.
As a side effect, sets
self.nobs,self.nspace,self.ntimeandself.missingfromy_obs.- Returns:
tupleoflist–(gen_top_left, gen_top_right), each a list of(label, [value])pairs suitable forstatsmodels.iolib.summary.Summary.add_table_2cols.
- summary()[source]¶
Build a
statsmodels-style structured summary of the fit: model identity/shape/runtime, log-likelihood, MSE/RMSE, coverage probability and residual diagnostics (Jarque-Bera, Omnibus, skewness, kurtosis, Durbin-Watson).- Returns:
statsmodels.iolib.summary.Summary– Printable summary table;str()/repr()of this results object render this summary.- Return type:
Summary
- as_dict()[source]¶
Return a plain dict snapshot of the main results.
Ensures all array attributes are NumPy arrays first (via to_numpy). Useful for serialization or for passing results to code that should not depend on the StateSpaceResults class.
- Returns:
dict– Keys:y_obs,y_hat,Sigma_y_hat,x_filtered,P_filtered,x_smoothed,P_smoothed,llf,mse(global),rmse(global),diagnostics(see diagnostics),S11,S10,S00.- Return type:
Dict[str, Any]