Skip to content

BUG: Drop missing data from the start params of UnobservedComponents - #11087

Draft
bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-uc-start-params-missing
Draft

bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-uc-start-params-missing

Conversation

@bashtage

@bashtage bashtage commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

#11083, which this PR was stacked on, is merged. The annual-cycle PR is stacked on this one. The fixed-slope PR also appends tests to test_structural.py: keep both appended blocks. No conflict in structural.py or with #10940.

BUG: Drop missing data from the start params of UnobservedComponents

UnobservedComponents.start_params drops missing observations before it
computes the starting parameters, but a model without a level used the
full series from the state space representation, NaN included, for the
remaining components. With missing data:

  • UnobservedComponents(y, "irregular", seasonal=4) (or a frequency-domain
    seasonal) had start_params [nan, nan], so fit() returned NaN parameters
    and a NaN log-likelihood with only a ConvergenceWarning;
  • "ntrend" with autoregressive=1, and a damped stochastic cycle, raised
    "LinAlgError: SVD did not converge";
  • an exog (estimated by maximum likelihood) raised "ValueError: shapes
    (1,38) and (40,) not aligned", because exog had the missing rows dropped
    and the series did not.

Changes

  • Without a level, the residual used for the other components is the
    series with the missing observations dropped, as with a level. The
    starting parameters are those of the model of the data without the
    missing observations, so fit() starts from finite values.
  • start_params has a docstring, with a versionchanged note.

Not changed

  • The starting parameters of models without missing data (identical, bit
    for bit, for int and float data, ndarray, list and Series, with seasonal,
    frequency-domain seasonal, autoregressive, cycle and exog components) and
    of models with a level.

Tests

  • Without a level, with three missing observations, for a seasonal, a
    frequency-domain seasonal, an AR(1), a damped stochastic cycle, an exog,
    and an exog with an AR(1) without irregular: the starting parameters
    equal those of the same model of the data without the missing
    observations; for the two seasonal models, every variance starts at the
    variance of the observed data and fit() gives finite parameters and
    log-likelihood. All six fail on main.

  • 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: finding the bug in a coverage audit of the state space models, writing the fix and its tests, and checking them (tests failing on main, 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

@bashtage

Copy link
Copy Markdown
Member Author

Merge order. These open PRs build on this one (their branches contain its commits), so please merge this PR first:

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

UnobservedComponents.start_params drops missing observations before it
computes the starting parameters, but a model without a level used the
full series from the state space representation, NaN included, for the
remaining components. With missing data:
- UnobservedComponents(y, "irregular", seasonal=4) (or a frequency-domain
  seasonal) had start_params [nan, nan], so fit() returned NaN parameters
  and a NaN log-likelihood with only a ConvergenceWarning;
- "ntrend" with autoregressive=1, and a damped stochastic cycle, raised
  "LinAlgError: SVD did not converge";
- an exog (estimated by maximum likelihood) raised "ValueError: shapes
  (1,38) and (40,) not aligned", because exog had the missing rows dropped
  and the series did not.

Changes
- Without a level, the residual used for the other components is the
  series with the missing observations dropped, as with a level. The
  starting parameters are those of the model of the data without the
  missing observations, so fit() starts from finite values.
- start_params has a docstring, with a versionchanged note.

Not changed
- The starting parameters of models without missing data (identical, bit
  for bit, for int and float data, ndarray, list and Series, with seasonal,
  frequency-domain seasonal, autoregressive, cycle and exog components) and
  of models with a level.

Tests
- Without a level, with three missing observations, for a seasonal, a
  frequency-domain seasonal, an AR(1), a damped stochastic cycle, an exog,
  and an exog with an AR(1) without irregular: the starting parameters
  equal those of the same model of the data without the missing
  observations; for the two seasonal models, every variance starts at the
  variance of the observed data and fit() gives finite parameters and
  log-likelihood. All six fail on main.
@bashtage
bashtage force-pushed the wip-uc-start-params-missing branch from d11b5c0 to 8ef11b8 Compare November 28, 2026 21:36
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