Repository navigation
Conversation
This was referenced Nov 24, 2026
Member
Author
|
Merge order. These open PRs build on this one (their branches contain its commits), so please merge this PR first: Indented PRs build on the PR above them, so merge them after it. Once this PR is merged, their diffs shrink to their own changes. Each of them also says "Stacked on #..." at the top of its description. Merge-order note generated with Claude Code (updated 2026-11-25). |
This was referenced Nov 24, 2026
bashtage
force-pushed
the
wip-ss-timing-converged-cov
branch
from
November 24, 2026 16:17
a40df43 to
2023e1c
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 24, 2026
FilterResults.predict computes out-of-sample forecasts and dynamic in-sample predictions by running a filter on missing data that starts from a known initialization at the predicted state (and covariance matrix) of its first period. The new filter copied the timing convention of the model. With the filtered timing (timing_init_filtered=True), it treated that predicted state as the filtered state of the period before, so the predictions were silently one period late: for an AR(1) observed with noise (SARIMAX(y, order=(1, 0, 0), measurement_error=True)), get_forecast(2).predicted_mean was [0.058, 0.029] instead of [0.117, 0.058], with the same log-likelihood. This affects forecast, get_forecast, predict and get_prediction with dynamic prediction or out-of-sample periods, and the forecasts that news compares. Stacked on statsmodels#11141, which sets the predicted state covariance matrix for the period after the sample of a converged filter with the filtered timing; without it, the forecast variances would still be wrong. Changes - The filter run by FilterResults.predict always uses the predicted timing convention (alternate_timing=False), which matches its initialization. - A versionchanged note in FilterResults.predict. Not changed - Models with the default (predicted) timing convention. - One-step-ahead in-sample predictions, which use the stored filter output. Tests (test_kalman.py) - For an AR(1) observed with noise with the filtered timing, the out-of-sample forecasts and the dynamic in-sample predictions (means and variances) equal those with the predicted timing and the closed form from the last filtered state and its variance; the first two predictions of the dynamic case are the one-step-ahead forecasts. Both cases fail without the change.
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 24, 2026
…iming
With the filtered timing convention (timing_init_filtered=True), the
compiled Kalman filter predicted the state of period t from the filtered
state of period t-1 with the time-varying transition matrix, state
intercept and selected state covariance matrix of period t
(a_t = T_t a_{t-1|t-1} + c_t), and the period after the sample with those
of the last period again. Everything else reads column t of these
matrices as the transition from period t to t+1, as with the default
(predicted) timing and as the Representation docstring says: the smoother
(L_t = T_t - K_t Z_t), FilterResults.predict and extend (statsmodels#11152, statsmodels#11162),
and the models that fill time-varying matrices. So with time-varying
matrices and the filtered timing:
- the smoothed states did not belong to the filter: the filtered states
equalled those of the model with the matrices shifted by one period,
its smoothed states were up to 0.146 away in a time-varying AR(1);
- VARMAX with exog raised "array must not contain infs or NaNs" (the NaN
last column of the state intercept entered the last in-sample period);
- VARMAX with a time trend silently used the trend one period ahead.
Stacked on statsmodels#11152 (which is stacked on statsmodels#11141): the VARMAX forecast test
with the filtered timing needs its forecasting fix.
Changes
- With the filtered timing, the filter predicts period t >= 1 with the
transition matrix, state intercept and selected state covariance matrix
of period t-1; period 0 is predicted from the initialization with those
of period 0, as before. A filtered-timing model is then the
predicted-timing model with the same matrices whose initial state is the
initialization pushed through the period 0 transition
(a_0 = T_0 m + c_0, P_0 = T_0 P T_0' + R_0 Q_0 R_0'), for the filter, the
smoother and prediction. This covers the conventional, univariate and
collapsed filters, missing data and the memory conservation options,
which share the prediction step in _kalman_filter.pyx.in; the
Chandrasekhar recursions and exact diffuse initialization already raise
with the filtered timing.
- VARMAXResults._set_final_predicted_state (forecasts and simulations
with exog) runs its temporary model with the predicted timing, since its
initial state is the predicted state of the last period (as statsmodels#11162 does
for extend). With measurement error, the forecasts with exog under the
filtered timing were wrong otherwise.
- Notes and a versionchanged note in KalmanFilter.set_filter_timing.
Not changed
- The predicted timing, and the filtered timing with time-invariant
matrices: 349 output arrays (filter and smoother output and forecasts of
time-varying generic models with each filter, SARIMAX,
UnobservedComponents, DynamicFactor and VARMAX with exog or trends, and
time-invariant models with the filtered timing) are bit-identical to
those of the base.
- The prediction of the first period from the initialization.
Tests
- test_kalman.py: a model in which every system matrix is time-varying
(conventional, univariate and collapsed filters, missing data,
memory_conserve) and models in which only the transition, state
intercept, state covariance or selection matrix is time-varying. With
the filtered timing, the loglikelihood, forecasts, predicted and
filtered states and covariances, Kalman gain, smoothed states,
covariances and disturbances equal those of the predicted-timing model
with the pushed-through initialization, and each predicted state and
covariance equals the prediction step computed from the initialization
or the previous filtered state with the previous period's matrices. A
time-invariant case checks the same (passes before and after). The
time-varying AR(1) of the smoother example: filtered and smoothed states
agree with the equivalent model.
- test_varmax.py: VARMAX(1, 0) with exog and with trend="ct" under the
filtered timing. Without measurement error, the one-step-ahead
predictions and the forecasts equal the VAR recursion; with measurement
error and a known initialization, the loglikelihood, fitted values,
smoothed states and covariances, and the forecast means and variances
equal those of the predicted-timing model with the pushed-through
initialization.
bashtage
force-pushed
the
wip-ss-timing-converged-cov
branch
from
November 25, 2026 12:14
2023e1c to
3c178ba
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
FilterResults.predict computes out-of-sample forecasts and dynamic in-sample predictions by running a filter on missing data that starts from a known initialization at the predicted state (and covariance matrix) of its first period. The new filter copied the timing convention of the model. With the filtered timing (timing_init_filtered=True), it treated that predicted state as the filtered state of the period before, so the predictions were silently one period late: for an AR(1) observed with noise (SARIMAX(y, order=(1, 0, 0), measurement_error=True)), get_forecast(2).predicted_mean was [0.058, 0.029] instead of [0.117, 0.058], with the same log-likelihood. This affects forecast, get_forecast, predict and get_prediction with dynamic prediction or out-of-sample periods, and the forecasts that news compares. Stacked on statsmodels#11141, which sets the predicted state covariance matrix for the period after the sample of a converged filter with the filtered timing; without it, the forecast variances would still be wrong. Changes - The filter run by FilterResults.predict always uses the predicted timing convention (alternate_timing=False), which matches its initialization. - A versionchanged note in FilterResults.predict. Not changed - Models with the default (predicted) timing convention. - One-step-ahead in-sample predictions, which use the stored filter output. Tests (test_kalman.py) - For an AR(1) observed with noise with the filtered timing, the out-of-sample forecasts and the dynamic in-sample predictions (means and variances) equal those with the predicted timing and the closed form from the last filtered state and its variance; the first two predictions of the dynamic case are the one-step-ahead forecasts. Both cases fail without the change.
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
MLEResults.extend (and VARMAXResults.extend, which does not call it) initializes the new model with the predicted state of the first new period, predicted_state[..., -1], but the clone keeps the timing convention of the model. With the filtered timing convention (timing_init_filtered=True), the new model treated that predicted state as the filtered state of the period before, so the extended results were one period late: SARIMAX(y, order=(1, 0, 0), measurement_error=True, timing_init_filtered=True).smooth([.5, 1, 1]).extend([.4, .3]).fittedvalues gave [0.058, 0.115] instead of [0.117, 0.134], the values of the model of the whole sample (and of the predicted timing). The log-likelihood, filtered and smoothed states of the extension were wrong too. Same class as the forecasting fix of statsmodels#11152. Changes - extend sets the predicted timing convention on the new model, in MLEResults.extend (used by SARIMAX, UnobservedComponents, DynamicFactor, DynamicFactorMQ, ...) and in VARMAXResults.extend. Nothing changes with the predicted timing convention, the default. - Docstrings: the new model uses the predicted timing; versionchanged 0.15.1. Not changed - append and apply refilter their whole sample with the model's initialization (or a copy of it), so they were right with the filtered timing; the new tests check them. - With the filtered timing, a filter that converged leaves the last predicted state covariance at zero on main (statsmodels#11141 fixes that in the compiled filter), so the extension of a converged filter starts from a zero covariance until statsmodels#11141 is merged too. The tests use tolerance=0; with the converged covariance the extension matches the whole sample. Tests - SARIMAX with each timing: the fittedvalues, llf_obs, filtered and smoothed states and smoothed state covariances of extend equal the last periods of the model of the whole sample; append (with and without copy_initialization) equals the model of the whole sample and apply a model built on the new data. The filtered-timing case fails on main. - VARMAX with each timing: extend equals the last periods of the model of the whole sample. The filtered-timing case fails on main.
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
…iming
With the filtered timing convention (timing_init_filtered=True), the
compiled Kalman filter predicted the state of period t from the filtered
state of period t-1 with the time-varying transition matrix, state
intercept and selected state covariance matrix of period t
(a_t = T_t a_{t-1|t-1} + c_t), and the period after the sample with those
of the last period again. Everything else reads column t of these
matrices as the transition from period t to t+1, as with the default
(predicted) timing and as the Representation docstring says: the smoother
(L_t = T_t - K_t Z_t), FilterResults.predict and extend (statsmodels#11152, statsmodels#11162),
and the models that fill time-varying matrices. So with time-varying
matrices and the filtered timing:
- the smoothed states did not belong to the filter: the filtered states
equalled those of the model with the matrices shifted by one period,
its smoothed states were up to 0.146 away in a time-varying AR(1);
- VARMAX with exog raised "array must not contain infs or NaNs" (the NaN
last column of the state intercept entered the last in-sample period);
- VARMAX with a time trend silently used the trend one period ahead.
Stacked on statsmodels#11152 (which is stacked on statsmodels#11141): the VARMAX forecast test
with the filtered timing needs its forecasting fix.
Changes
- With the filtered timing, the filter predicts period t >= 1 with the
transition matrix, state intercept and selected state covariance matrix
of period t-1; period 0 is predicted from the initialization with those
of period 0, as before. A filtered-timing model is then the
predicted-timing model with the same matrices whose initial state is the
initialization pushed through the period 0 transition
(a_0 = T_0 m + c_0, P_0 = T_0 P T_0' + R_0 Q_0 R_0'), for the filter, the
smoother and prediction. This covers the conventional, univariate and
collapsed filters, missing data and the memory conservation options,
which share the prediction step in _kalman_filter.pyx.in; the
Chandrasekhar recursions and exact diffuse initialization already raise
with the filtered timing.
- VARMAXResults._set_final_predicted_state (forecasts and simulations
with exog) runs its temporary model with the predicted timing, since its
initial state is the predicted state of the last period (as statsmodels#11162 does
for extend). With measurement error, the forecasts with exog under the
filtered timing were wrong otherwise.
- Notes and a versionchanged note in KalmanFilter.set_filter_timing.
Not changed
- The predicted timing, and the filtered timing with time-invariant
matrices: 349 output arrays (filter and smoother output and forecasts of
time-varying generic models with each filter, SARIMAX,
UnobservedComponents, DynamicFactor and VARMAX with exog or trends, and
time-invariant models with the filtered timing) are bit-identical to
those of the base.
- The prediction of the first period from the initialization.
Tests
- test_kalman.py: a model in which every system matrix is time-varying
(conventional, univariate and collapsed filters, missing data,
memory_conserve) and models in which only the transition, state
intercept, state covariance or selection matrix is time-varying. With
the filtered timing, the loglikelihood, forecasts, predicted and
filtered states and covariances, Kalman gain, smoothed states,
covariances and disturbances equal those of the predicted-timing model
with the pushed-through initialization, and each predicted state and
covariance equals the prediction step computed from the initialization
or the previous filtered state with the previous period's matrices. A
time-invariant case checks the same (passes before and after). The
time-varying AR(1) of the smoother example: filtered and smoothed states
agree with the equivalent model.
- test_varmax.py: VARMAX(1, 0) with exog and with trend="ct" under the
filtered timing. Without measurement error, the one-step-ahead
predictions and the forecasts equal the VAR recursion; with measurement
error and a known initialization, the loglikelihood, fitted values,
smoothed states and covariances, and the forecast means and variances
equal those of the predicted-timing model with the pushed-through
initialization.
bashtage
force-pushed
the
wip-ss-timing-converged-cov
branch
from
November 25, 2026 18:39
3c178ba to
1d1777c
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
FilterResults.predict computes out-of-sample forecasts and dynamic in-sample predictions by running a filter on missing data that starts from a known initialization at the predicted state (and covariance matrix) of its first period. The new filter copied the timing convention of the model. With the filtered timing (timing_init_filtered=True), it treated that predicted state as the filtered state of the period before, so the predictions were silently one period late: for an AR(1) observed with noise (SARIMAX(y, order=(1, 0, 0), measurement_error=True)), get_forecast(2).predicted_mean was [0.058, 0.029] instead of [0.117, 0.058], with the same log-likelihood. This affects forecast, get_forecast, predict and get_prediction with dynamic prediction or out-of-sample periods, and the forecasts that news compares. Stacked on statsmodels#11141, which sets the predicted state covariance matrix for the period after the sample of a converged filter with the filtered timing; without it, the forecast variances would still be wrong. Changes - The filter run by FilterResults.predict always uses the predicted timing convention (alternate_timing=False), which matches its initialization. - A versionchanged note in FilterResults.predict. Not changed - Models with the default (predicted) timing convention. - One-step-ahead in-sample predictions, which use the stored filter output. Tests (test_kalman.py) - For an AR(1) observed with noise with the filtered timing, the out-of-sample forecasts and the dynamic in-sample predictions (means and variances) equal those with the predicted timing and the closed form from the last filtered state and its variance; the first two predictions of the dynamic case are the one-step-ahead forecasts. Both cases fail without the change.
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
…iming
With the filtered timing convention (timing_init_filtered=True), the
compiled Kalman filter predicted the state of period t from the filtered
state of period t-1 with the time-varying transition matrix, state
intercept and selected state covariance matrix of period t
(a_t = T_t a_{t-1|t-1} + c_t), and the period after the sample with those
of the last period again. Everything else reads column t of these
matrices as the transition from period t to t+1, as with the default
(predicted) timing and as the Representation docstring says: the smoother
(L_t = T_t - K_t Z_t), FilterResults.predict and extend (statsmodels#11152, statsmodels#11162),
and the models that fill time-varying matrices. So with time-varying
matrices and the filtered timing:
- the smoothed states did not belong to the filter: the filtered states
equalled those of the model with the matrices shifted by one period,
its smoothed states were up to 0.146 away in a time-varying AR(1);
- VARMAX with exog raised "array must not contain infs or NaNs" (the NaN
last column of the state intercept entered the last in-sample period);
- VARMAX with a time trend silently used the trend one period ahead.
Stacked on statsmodels#11152 (which is stacked on statsmodels#11141): the VARMAX forecast test
with the filtered timing needs its forecasting fix.
Changes
- With the filtered timing, the filter predicts period t >= 1 with the
transition matrix, state intercept and selected state covariance matrix
of period t-1; period 0 is predicted from the initialization with those
of period 0, as before. A filtered-timing model is then the
predicted-timing model with the same matrices whose initial state is the
initialization pushed through the period 0 transition
(a_0 = T_0 m + c_0, P_0 = T_0 P T_0' + R_0 Q_0 R_0'), for the filter, the
smoother and prediction. This covers the conventional, univariate and
collapsed filters, missing data and the memory conservation options,
which share the prediction step in _kalman_filter.pyx.in; the
Chandrasekhar recursions and exact diffuse initialization already raise
with the filtered timing.
- VARMAXResults._set_final_predicted_state (forecasts and simulations
with exog) runs its temporary model with the predicted timing, since its
initial state is the predicted state of the last period (as statsmodels#11162 does
for extend). With measurement error, the forecasts with exog under the
filtered timing were wrong otherwise.
- Notes and a versionchanged note in KalmanFilter.set_filter_timing.
Not changed
- The predicted timing, and the filtered timing with time-invariant
matrices: 349 output arrays (filter and smoother output and forecasts of
time-varying generic models with each filter, SARIMAX,
UnobservedComponents, DynamicFactor and VARMAX with exog or trends, and
time-invariant models with the filtered timing) are bit-identical to
those of the base.
- The prediction of the first period from the initialization.
Tests
- test_kalman.py: a model in which every system matrix is time-varying
(conventional, univariate and collapsed filters, missing data,
memory_conserve) and models in which only the transition, state
intercept, state covariance or selection matrix is time-varying. With
the filtered timing, the loglikelihood, forecasts, predicted and
filtered states and covariances, Kalman gain, smoothed states,
covariances and disturbances equal those of the predicted-timing model
with the pushed-through initialization, and each predicted state and
covariance equals the prediction step computed from the initialization
or the previous filtered state with the previous period's matrices. A
time-invariant case checks the same (passes before and after). The
time-varying AR(1) of the smoother example: filtered and smoothed states
agree with the equivalent model.
- test_varmax.py: VARMAX(1, 0) with exog and with trend="ct" under the
filtered timing. Without measurement error, the one-step-ahead
predictions and the forecasts equal the VAR recursion; with measurement
error and a known initialization, the loglikelihood, fitted values,
smoothed states and covariances, and the forecast means and variances
equal those of the predicted-timing model with the pushed-through
initialization.
…filter With the filtered timing convention (`timing_init_filtered = True`), the Kalman filter predicts the state for the period after the sample in a last prediction step. Once the filter has converged, the prediction step no longer computes the predicted state covariance matrix (`post_convergence` copies the converged matrix into each period's storage at the start of the period instead), so the last column of `predicted_state_cov` was left at zero. For example, in a local level model with 50 observations the last two columns were [1.1328, 0.0], and [1.1328, 1.1328] with `tolerance=0`. The predicted state itself was right, and the default (predicted) timing was not affected. Results that start from the end of the sample, such as forecasts from the filter output, used the zero matrix. Changes - In the last prediction step, a converged filter copies the converged predicted state covariance matrix into the last column before the prediction. - `versionchanged` note on `FilterResults.predicted_state_cov`. Not changed - All other columns, the predicted states, and filters that have not converged. Tests (test_kalman.py) - One- and two-state models, with the multivariate and the univariate filter: with filtered timing the filter converges before the last period, and the last column of `predicted_state_cov` equals that of the same filter with `tolerance=0` (no convergence) and the solution of the discrete algebraic Riccati equation; the last predicted state is unchanged.
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 28, 2026
MLEResults.extend (and VARMAXResults.extend, which does not call it) initializes the new model with the predicted state of the first new period, predicted_state[..., -1], but the clone keeps the timing convention of the model. With the filtered timing convention (timing_init_filtered=True), the new model treated that predicted state as the filtered state of the period before, so the extended results were one period late: SARIMAX(y, order=(1, 0, 0), measurement_error=True, timing_init_filtered=True).smooth([.5, 1, 1]).extend([.4, .3]).fittedvalues gave [0.058, 0.115] instead of [0.117, 0.134], the values of the model of the whole sample (and of the predicted timing). The log-likelihood, filtered and smoothed states of the extension were wrong too. Same class as the forecasting fix of statsmodels#11152. Changes - extend sets the predicted timing convention on the new model, in MLEResults.extend (used by SARIMAX, UnobservedComponents, DynamicFactor, DynamicFactorMQ, ...) and in VARMAXResults.extend. Nothing changes with the predicted timing convention, the default. - Docstrings: the new model uses the predicted timing; versionchanged 0.16.0. Not changed - append and apply refilter their whole sample with the model's initialization (or a copy of it), so they were right with the filtered timing; the new tests check them. - With the filtered timing, a filter that converged leaves the last predicted state covariance at zero on main (statsmodels#11141 fixes that in the compiled filter), so the extension of a converged filter starts from a zero covariance until statsmodels#11141 is merged too. The tests use tolerance=0; with the converged covariance the extension matches the whole sample. Tests - SARIMAX with each timing: the fittedvalues, llf_obs, filtered and smoothed states and smoothed state covariances of extend equal the last periods of the model of the whole sample; append (with and without copy_initialization) equals the model of the whole sample and apply a model built on the new data. The filtered-timing case fails on main. - VARMAX with each timing: extend equals the last periods of the model of the whole sample. The filtered-timing case fails on main.
bashtage
force-pushed
the
wip-ss-timing-converged-cov
branch
from
November 28, 2026 21:36
1d1777c to
25cc021
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 28, 2026
…iming
With the filtered timing convention (timing_init_filtered=True), the
compiled Kalman filter predicted the state of period t from the filtered
state of period t-1 with the time-varying transition matrix, state
intercept and selected state covariance matrix of period t
(a_t = T_t a_{t-1|t-1} + c_t), and the period after the sample with those
of the last period again. Everything else reads column t of these
matrices as the transition from period t to t+1, as with the default
(predicted) timing and as the Representation docstring says: the smoother
(L_t = T_t - K_t Z_t), FilterResults.predict and extend (statsmodels#11152, statsmodels#11162),
and the models that fill time-varying matrices. So with time-varying
matrices and the filtered timing:
- the smoothed states did not belong to the filter: the filtered states
equalled those of the model with the matrices shifted by one period,
its smoothed states were up to 0.146 away in a time-varying AR(1);
- VARMAX with exog raised "array must not contain infs or NaNs" (the NaN
last column of the state intercept entered the last in-sample period);
- VARMAX with a time trend silently used the trend one period ahead.
Stacked on statsmodels#11152 (which is stacked on statsmodels#11141): the VARMAX forecast test
with the filtered timing needs its forecasting fix.
Changes
- With the filtered timing, the filter predicts period t >= 1 with the
transition matrix, state intercept and selected state covariance matrix
of period t-1; period 0 is predicted from the initialization with those
of period 0, as before. A filtered-timing model is then the
predicted-timing model with the same matrices whose initial state is the
initialization pushed through the period 0 transition
(a_0 = T_0 m + c_0, P_0 = T_0 P T_0' + R_0 Q_0 R_0'), for the filter, the
smoother and prediction. This covers the conventional, univariate and
collapsed filters, missing data and the memory conservation options,
which share the prediction step in _kalman_filter.pyx.in; the
Chandrasekhar recursions and exact diffuse initialization already raise
with the filtered timing.
- VARMAXResults._set_final_predicted_state (forecasts and simulations
with exog) runs its temporary model with the predicted timing, since its
initial state is the predicted state of the last period (as statsmodels#11162 does
for extend). With measurement error, the forecasts with exog under the
filtered timing were wrong otherwise.
- Notes and a versionchanged note in KalmanFilter.set_filter_timing.
Not changed
- The predicted timing, and the filtered timing with time-invariant
matrices: 349 output arrays (filter and smoother output and forecasts of
time-varying generic models with each filter, SARIMAX,
UnobservedComponents, DynamicFactor and VARMAX with exog or trends, and
time-invariant models with the filtered timing) are bit-identical to
those of the base.
- The prediction of the first period from the initialization.
Tests
- test_kalman.py: a model in which every system matrix is time-varying
(conventional, univariate and collapsed filters, missing data,
memory_conserve) and models in which only the transition, state
intercept, state covariance or selection matrix is time-varying. With
the filtered timing, the loglikelihood, forecasts, predicted and
filtered states and covariances, Kalman gain, smoothed states,
covariances and disturbances equal those of the predicted-timing model
with the pushed-through initialization, and each predicted state and
covariance equals the prediction step computed from the initialization
or the previous filtered state with the previous period's matrices. A
time-invariant case checks the same (passes before and after). The
time-varying AR(1) of the smoother example: filtered and smoothed states
agree with the equivalent model.
- test_varmax.py: VARMAX(1, 0) with exog and with trend="ct" under the
filtered timing. Without measurement error, the one-step-ahead
predictions and the forecasts equal the VAR recursion; with measurement
error and a known initialization, the loglikelihood, fitted values,
smoothed states and covariances, and the forecast means and variances
equal those of the predicted-timing model with the pushed-through
initialization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merges cleanly with the other open
kalman_filter.pyPRs. #11035 also appends tests totest_kalman.pyand adds a name to itskalman_filterimport list: keep both names and both blocks.With the filtered timing convention (
timing_init_filtered = True), theKalman filter predicts the state for the period after the sample in a last
prediction step. Once the filter has converged, the prediction step no
longer computes the predicted state covariance matrix (
post_convergencecopies the converged matrix into each period's storage at the start of the
period instead), so the last column of
predicted_state_covwas left atzero. For example, in a local level model with 50 observations the last two
columns were [1.1328, 0.0], and [1.1328, 1.1328] with
tolerance=0. Thepredicted state itself was right, and the default (predicted) timing was not
affected. Results that start from the end of the sample, such as forecasts
from the filter output, used the zero matrix.
Changes
predicted state covariance matrix into the last column before the
prediction.
versionchangednote onFilterResults.predicted_state_cov.Not changed
converged.
Tests (test_kalman.py)
One- and two-state models, with the multivariate and the univariate
filter: with filtered timing the filter converges before the last period,
and the last column of
predicted_state_covequals that of the samefilter with
tolerance=0(no convergence) and the solution of thediscrete algebraic Riccati equation; the last predicted state is
unchanged.
tests added / passed.
code/documentation is well formatted.
properly formatted commit message. See
NumPy's guide.
AI Disclosure
Contributions must comply with the statsmodels AI Policy.
Tick exactly one of the following. If AI tools were used, replace the
<...>placeholders in the second option with the tool name(s) and how the tool's output was
used.
Tool(s): Claude Code (Claude Opus 5.5).
Used for: finding the bug in a coverage audit of the compiled state space code, writing the fix and its tests, and checking them (tests failing on main, mutation check with a rebuild of the extension per mutant).
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.
🤖 Generated with Claude Code