Skip to content

BUG: Restrict the revision impacts of the news to state_index - #11132

Draft
bashtage wants to merge 6 commits into
statsmodels:mainfrom
bashtage:wip-news-revision-impacts-state-index
Draft

bashtage wants to merge 6 commits into
statsmodels:mainfrom
bashtage:wip-news-revision-impacts-state-index

Conversation

@bashtage

@bashtage bashtage commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Stacked on #11054, merge that first (its commits are the first ones here; this PR adds one commit): both change the total revision impacts in SmootherResults.news. No conflict in kalman_smoother.py with #11025, #11044-#11047, #11052 or #11113 (#11054 conflicts with some of them only in test_smoothing.py, where both append). test_news.py conflicts with #11078 (and #11080-#11082, #11118, #11119 stacked on it) and the NewsResults weights PR only where both append tests at the end of the file: keep both blocks.

REF: Remove unreachable code in the statespace smoother and tools

Code that no public path reaches (found by the C9b coverage work on
kalman_smoother.py, tools.py and simulation_smoother.py):

kalman_smoother.py

  • KalmanSmoother._smooth: the check that the filter or the representation
    was just re-created. _smooth is only called by smooth() right after
    _filter() with the same arguments, so neither is ever re-created.
  • SmootherResults._smoothed_state_autocovariance: the extend_kwargs is None default. Its only caller always passes a dict, so the argument is
    now required.
  • SmootherResults.news: the out-of-sample prediction for the total
    revision impacts. The revision model is built through
    max(end, previous.nobs), so end never exceeds its sample.

tools.py

  • constrain_stationary_multivariate: the k_endog < 1 check. A zero
    k_endog fails earlier, in order //= k_endog.
  • _unconstrain_sv_less_than_one: the defaults of order and k_endog
    (always passed); they are now required.
  • _compute_multivariate_pacf_from_autocovariances: the order and
    k_endog arguments, which no caller passes (k_endog was not used).
  • _compute_multivariate_pacf_from_coefficients: the order and k_endog
    arguments, which were recomputed from the matrices, and the branch for an
    array of matrices (its only caller passes a list).
  • _compute_multivariate_acovf_from_coefficients: the branch for an array
    of matrices and the forward_autocovariances argument (its only caller
    passes a list and backward autocovariances). The existing direct test
    passes lists and does not change.
  • copy_missing_matrix, copy_missing_vector, copy_index_matrix and
    copy_index_vector: the blocks that kept an F-contiguous Cython
    memoryview unconverted. All callers pass ndarrays, so the source is
    always converted with np.require, as before.
  • _atleast_1d is only called with one input and _atleast_2d with five, so
    _atleast_1d takes one input and returns its array, and _atleast_2d
    always returns a list.

simulation_smoother.py

  • The simulate() error for a changed representation named the
    template-literal class _{{prefix}}Representation; it now says "the
    underlying compiled representation model object".

Not changed: results and errors of all public functions.
_safe_cond keeps its inf branch: with numpy's own LAPACK, np.linalg.cond
only fails for NaN entries, but other LAPACK builds may fail to converge
for inf entries.

Tests: no new tests; the statespace suite passes. Coverage of the
statespace tests: kalman_smoother.py 93.5/84.8% to 94.3/85.7% (lines /
branches), tools.py 93.7/83.6% to 96.4/90.4%.

DEP: Deprecate the unused design argument of SmootherResults.news

SmootherResults.news(design=...) documented design as the design matrix
for period t that a time-varying model needs when t is outside of its
sample. It had no effect: news raises a RuntimeError for impacts on
periods outside of the sample of a time-varying model, and otherwise the
design matrix of the results object is used, so the branches that read
design could not be reached.

Changes:

  • Passing design raises a FutureWarning; it will be removed after
    statsmodels 0.18 is released. The docstring says that it is not used.
  • The unreachable branches that read design are removed.

Not changed: the results of news, with or without design.

Tests (appended to test_smoothing.py): for a time-invariant and a
time-varying model, news(design=...) warns, from the caller, and the
update impacts with and without design equal the change in the smoothed
forecasts that the new observations cause.

BUG: Restrict the revision impacts of the news to state_index

SmootherResults.news (and so MLEResults.news and NewsResults) documents
state_index as "only the impacts to the observed variables arising from
the impacts to [these] states". update_impacts and
revision_detailed_impacts used the subset of states, but revision_impacts,
the total impact of the revisions, was the difference of the smoothed
forecasts after and before the revisions, through all states. So the
"impact of revisions" and "total impact" columns of NewsResults.impacts,
and the grouped revision impacts ("all prior revisions",
revision_impacts - revision_detailed_impacts), counted the impacts through
the other states. For the VAR(1) of the new test (identity design
matrix) with state_index=[0], the news impacts and the detailed revision
impacts on the second variable (unemp) were 0, but its revision impacts
were those through all states: 8.1 and 9.2 in 2009Q1 and 2009Q2 (its own
revisions from 0) and 6.5 to 8.1 in the following periods.

Changes

  • With state_index, revision_impacts is the design matrix of those states
    times the revisions of those smoothed states (the smoothed states of
    the revision results less those of the previous results, which are the
    predicted states after the sample), for every impact period, also with a
    time-varying design matrix.
  • versionchanged in the state_index docstring; the revision_impacts entry
    says that it follows state_index.

Results of news calls with state_index change: revision_impacts, the
grouped revision impacts, and the "impact of revisions" and "total
impact" columns of the impacts table (and rows of variables without
impacts through the given states are left out of it).

Not changed

  • news without state_index (the forecasts are used as before), and the
    estimates before and after (prev_impacted_forecasts,
    post_impacted_forecasts), which remain those of all states.

Tests

  • test_state_index_revision_impacts: in the VAR(1) with revisions of two
    periods and impacts through three periods after the sample, with all
    revisions detailed, all grouped, or those of one period grouped, the
    revision, detailed, grouped and news impacts through the state of each
    variable are the full impacts on that variable and zero on the other,
    and the impacts table has only that variable's rows; both states
    together give the impacts without state_index. Fails on the previous
    commit (the revision and grouped impacts on the other variable).

  • test_state_index_revision_impacts_time_varying_design: for a SARIMAX
    with the regression coefficient as a state (design [1, x_t]) and a new
    last value (so that the impacts include a period after the previous
    sample), the revision impacts through the AR state and through the
    coefficient add up to the impacts without state_index, and each agrees
    with the detailed impacts, which are computed from the smoothed state
    weights.
    Fails on the previous commit.

  • 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.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude Code (Claude Opus 5.5).
    Used for: implementing the maintainer's decision, writing the tests against independent values, and checking them (tests failing on the base, mutation check).
    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

Code that no public path reaches (found by the C9b coverage work on
kalman_smoother.py, tools.py and simulation_smoother.py):

kalman_smoother.py
- KalmanSmoother._smooth: the check that the filter or the representation
  was just re-created. _smooth is only called by smooth() right after
  _filter() with the same arguments, so neither is ever re-created.
- SmootherResults._smoothed_state_autocovariance: the `extend_kwargs is
  None` default. Its only caller always passes a dict, so the argument is
  now required.
- SmootherResults.news: the out-of-sample prediction for the total
  revision impacts. The revision model is built through
  max(end, previous.nobs), so `end` never exceeds its sample.

tools.py
- constrain_stationary_multivariate: the `k_endog < 1` check. A zero
  k_endog fails earlier, in `order //= k_endog`.
- _unconstrain_sv_less_than_one: the defaults of `order` and `k_endog`
  (always passed); they are now required.
- _compute_multivariate_pacf_from_autocovariances: the `order` and
  `k_endog` arguments, which no caller passes (k_endog was not used).
- _compute_multivariate_pacf_from_coefficients: the `order` and `k_endog`
  arguments, which were recomputed from the matrices, and the branch for an
  array of matrices (its only caller passes a list).
- _compute_multivariate_acovf_from_coefficients: the branch for an array
  of matrices and the `forward_autocovariances` argument (its only caller
  passes a list and backward autocovariances). The existing direct test
  passes lists and does not change.
- copy_missing_matrix, copy_missing_vector, copy_index_matrix and
  copy_index_vector: the blocks that kept an F-contiguous Cython
  memoryview unconverted. All callers pass ndarrays, so the source is
  always converted with np.require, as before.
- _atleast_1d is only called with one input and _atleast_2d with five, so
  _atleast_1d takes one input and returns its array, and _atleast_2d
  always returns a list.

simulation_smoother.py
- The simulate() error for a changed representation named the
  template-literal class `_{{prefix}}Representation`; it now says "the
  underlying compiled representation model object".

Not changed: results and errors of all public functions.
_safe_cond keeps its inf branch: with numpy's own LAPACK, np.linalg.cond
only fails for NaN entries, but other LAPACK builds may fail to converge
for inf entries.

Tests: no new tests; the statespace suite passes. Coverage of the
statespace tests: kalman_smoother.py 93.5/84.8% to 94.3/85.7% (lines /
branches), tools.py 93.7/83.6% to 96.4/90.4%.
SmootherResults.news(design=...) documented `design` as the design matrix
for period `t` that a time-varying model needs when `t` is outside of its
sample. It had no effect: news raises a RuntimeError for impacts on
periods outside of the sample of a time-varying model, and otherwise the
design matrix of the results object is used, so the branches that read
`design` could not be reached.

Changes:
- Passing `design` raises a FutureWarning; it will be removed after
  statsmodels 0.17 is released. The docstring says that it is not used.
- The unreachable branches that read `design` are removed.

Not changed: the results of news, with or without `design`.

Tests (appended to test_smoothing.py): for a time-invariant and a
time-varying model, news(design=...) warns, from the caller, and the
update impacts with and without `design` equal the change in the smoothed
forecasts that the new observations cause.
@bashtage
bashtage force-pushed the wip-news-revision-impacts-state-index branch from 8caca89 to e30221e Compare November 28, 2026 21:36
The release after 0.15.0 is 0.16.0, not 0.15.1, so the design argument
is deprecated in 0.16.0. Move its removal one release later, to after
statsmodels 0.18 is released, as xref statsmodels#11327 does for the deprecations
that named 0.17.
SmootherResults.news (and so MLEResults.news and NewsResults) documents
state_index as "only the impacts to the observed variables arising from
the impacts to [these] states". update_impacts and
revision_detailed_impacts used the subset of states, but revision_impacts,
the total impact of the revisions, was the difference of the smoothed
forecasts after and before the revisions, through all states. So the
"impact of revisions" and "total impact" columns of NewsResults.impacts,
and the grouped revision impacts ("all prior revisions",
revision_impacts - revision_detailed_impacts), counted the impacts through
the other states. For the VAR(1) of the new test (identity design
matrix) with state_index=[0], the news impacts and the detailed revision
impacts on the second variable (unemp) were 0, but its revision impacts
were those through all states: 8.1 and 9.2 in 2009Q1 and 2009Q2 (its own
revisions from 0) and 6.5 to 8.1 in the following periods.

Changes
- With state_index, revision_impacts is the design matrix of those states
  times the revisions of those smoothed states (the smoothed states of
  the revision results less those of the previous results, which are the
  predicted states after the sample), for every impact period, also with a
  time-varying design matrix.
- versionchanged in the state_index docstring; the revision_impacts entry
  says that it follows state_index.

Results of news calls with state_index change: revision_impacts, the
grouped revision impacts, and the "impact of revisions" and "total
impact" columns of the impacts table (and rows of variables without
impacts through the given states are left out of it).

Not changed
- news without state_index (the forecasts are used as before), and the
  estimates before and after (prev_impacted_forecasts,
  post_impacted_forecasts), which remain those of all states.

Tests
- test_state_index_revision_impacts: in the VAR(1) with revisions of two
  periods and impacts through three periods after the sample, with all
  revisions detailed, all grouped, or those of one period grouped, the
  revision, detailed, grouped and news impacts through the state of each
  variable are the full impacts on that variable and zero on the other,
  and the impacts table has only that variable's rows; both states
  together give the impacts without state_index. Fails on the previous
  commit (the revision and grouped impacts on the other variable).
- test_state_index_revision_impacts_time_varying_design: for a SARIMAX
  with the regression coefficient as a state (design [1, x_t]) and a new
  last value (so that the impacts include a period after the previous
  sample), the revision impacts through the AR state and through the
  coefficient add up to the impacts without state_index, and each agrees
  with the detailed impacts, which are computed from the smoothed state
  weights.
  Fails on the previous commit.
@bashtage
bashtage force-pushed the wip-news-revision-impacts-state-index branch from e30221e to 128c214 Compare November 28, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant