Skip to content

BUG: Ignore time_varying_regression in SARIMAX without exog - #11088

Merged
bashtage merged 5 commits into
statsmodels:mainfrom
bashtage:wip-sarimax-tvr-without-exog
Nov 28, 2026
Merged

bashtage merged 5 commits into
statsmodels:mainfrom
bashtage:wip-sarimax-tvr-without-exog

Conversation

@bashtage

@bashtage bashtage commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

#11083, which this PR was stacked on, is merged. #10940 also appends a test at the end of test_sarimax.py: keep both appended blocks. No other conflict.

BUG: Ignore time_varying_regression in SARIMAX without exog

time_varying_regression lets the coefficients of exog vary over time. A
SARIMAX model without AR and MA terms puts its error in the measurement
equation when it has a state regression, so the option removed the ARMA
state. Without exog there is no state regression, so the model lost its
error term: SARIMAX(y, order=(0, 1, 0), time_varying_regression=True,
mle_regression=False) had no parameters and a log-likelihood of 0.0
(-28.19 at sigma2 = 1 without the option), a seasonal random walk had the
same problem, with measurement_error=True only the measurement variance
was left, and order=(0, 0, 0), simple_differencing=True, trend="t" or
concentrate_scale=True raised an error (ValueError, IndexError). With AR
or MA terms the option had no effect without exog.

Changes

  • Without exog, time_varying_regression is set to False with a
    SpecificationWarning ("time_varying_regression has no effect without exog
    and is set to False."), as mle_regression is already set to False
    without exog. The model is the one without the option.
  • The docstring of time_varying_regression says so, with a versionchanged
    note.

Not changed

  • Models with exog. Combining time_varying_regression=True with
    mle_regression=True still raises a ValueError, also without exog.
  • Models with AR or MA terms and no exog give the same results as before,
    now with the warning.

Tests

  • Without exog, for a random walk, a seasonal random walk, a random walk
    with measurement error, white noise and an AR(1): the option warns (at
    the caller's line), the attribute is False, and the parameter names,
    start parameters, log-likelihood and forecasts at fixed parameters equal
    those of the model without the option, which does not warn; the
    log-likelihood of the random walk equals that of its differences. All
    five fail on main.

  • check_concentrated_scale and test_recreate_model skip the combinations
    of time_varying_regression without exog, which are the same models as
    without the option and now warn.

  • 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

…s models

Add tests of the paths of statespace/sarimax.py, varmax.py,
dynamic_factor.py, structural.py and exponential_smoothing.py that the TSA
test suite did not reach, each checked against an independent value:

- SARIMAX: the Hamilton representation with differencing raises; simple
  differencing of a series with an int64 index 0, ..., n - 1 (replaced by
  a RangeIndex starting at one) or a RangeIndex, with the forecast index
  continuing at nobs and the forecasts phi**h times the last difference;
  initialize_default with an approximate diffuse variance v (the first
  observation of an ARIMA(0, 1, 0) has variance v + sigma2); explosive
  seasonal AR and non-invertible seasonal MA starting parameters warn and
  start at zero; the variances of time-varying coefficients are named
  snr.x with a concentrated scale, whose likelihood equals the likelihood
  at the scaled variances; trend_offset in extend_kwargs of forecast (a
  drift-only model in closed form); arfreq and mafreq (the roots of
  1 -/+ 0.5 L, None without roots); the summary model name with lag lists.
- VARMAX: explosive AR and MA starting parameters warn and start at zero;
  the starting measurement variances are the residual variances of the
  VAR(1) of the data or of its residuals (numpy least squares); fixing MA
  parameters (individual ones raise, all of them give the likelihood at
  the full parameter vector, marked in the summary); model.simulate with
  exog of the wrong shape raises; extending results without smoother
  output continues the filter of the full sample; a simulation without
  shocks from an anchor (also negative) is the dynamic prediction with
  exog after the sample, and an anchor after the sample raises; summary
  with separate_params=False; a univariate VARMAX is the SARIMAX AR(1).
- DynamicFactor: explosive factor (AR and VAR) and error VAR starting
  parameters raise, or are explosive without enforce_stationarity; with
  VAR errors the scalar starting variance is the mean of the diagonal
  ones; fixing error transition parameters (all or none for VAR(1) and
  AR(2) errors, individually for AR(1) errors) against the likelihood at
  the full parameters; factors with filter and smoother output and
  without factors; coefficients_of_determination are squared
  correlations, shown by the bars of plot_coefficients_of_determination
  with and without labels; summary with separate_params=False.
- UnobservedComponents: invalid frequency domain seasonals raise; the
  default cycle bounds of annual, quarterly, monthly and daily data and
  the starting cycle frequency; transform_params and untransform_params of
  an undamped cycle in closed form; a model with only an AR(1) (no trend
  specification) is the SARIMAX AR(1), also cloned; initialize_default
  with an approximate diffuse variance (local level in closed form);
  starting parameters ignore missing observations; deterministic
  seasonal, frequency domain seasonal and cycle components (parameters
  and summary); the component properties against the state vector at the
  documented offsets with filter and smoother output, and the components
  that are not in the model; plot_components without the observed panel
  and without dates.
- ExponentialSmoothing: the known initial state of pandas data without
  dates, and of numpy data in the summary.

Bugs found, not fixed here, which the tests avoid: the summary of a VARMAX
with measurement error shows the measurement variance of the last series
in the table of the first one (and so on); a bool level + trend
UnobservedComponents without stochastic level or trend has no trend
specification ("Model: None" in the summary; _mask_map has the key 8 for
"fixed slope" instead of 10); the starting parameters of an
UnobservedComponents without level are NaN with missing data; the cycle
frequency of annual data does not start at a three-year cycle on
pandas >= 2.2 (which is why the annual start is not checked);
time_varying_regression=True without exog removes the state error of a
SARIMAX.

Coverage of the five files by the TSA tests (not slow) goes from 98.0% to
99.5% of the lines and from 94.7% to 97.9% of the branches for
sarimax.py, 95.4% to 98.5% and 87.0% to 92.2% for varmax.py, 97.2% to
99.2% and 87.2% to 95.3% for dynamic_factor.py, 95.4% to 98.8% and 84.1%
to 97.5% for structural.py, and from 98.7% to 100% of the branches for
exponential_smoothing.py (100% of the lines before and after). The lines
left are unreachable through the public API or have no effect, are
reachable only through one of the bugs above, or (the annual start of the
cycle frequency) only on pandas < 2.2.
Fix the docstrings of statespace/sarimax.py, varmax.py, dynamic_factor.py,
structural.py and exponential_smoothing.py where they disagree with the
code. No code changes.

- UnobservedComponents: without annual, quarterly or monthly data the
  default cycle periods are at least 2 (the frequency is at most pi), not
  0.5; **kwargs are documented. plot_components shows confidence
  intervals only for the one-step-ahead predictions of the observed series
  (not for the components), has one panel per selected component (one per
  frequency domain seasonal) and returns the figure. The component
  properties return None for components that are not in the model (an
  empty list for freq_seasonal), their smoothed estimates are None without
  smoother output, and regression_coefficients is None (with an
  OutputWarning) if the coefficients are estimated by maximum likelihood.
  clone, update, initialize_default, transform_params and
  untransform_params get docstrings or their missing sections.
- DynamicFactor: the parameters are listed in the order of the signature;
  endog needs more than one series and k_factors must be less than their
  number. update returns nothing, and its Notes describe the whole
  parameter vector (regression coefficients, the three error covariance
  types, error transitions) and the order of the factor VAR coefficients
  (by equation, not one coefficient matrix after another); the docstring
  is raw, so its \times no longer renders as a tab. transform_params also
  constrains the error transition and only with enforce_stationarity.
  factors is None without factors; coefficients_of_determination are from
  regressions of the series on a factor (smoothed if available);
  plot_coefficients_of_determination returns the figure.
- VARMAX: order is a sequence of int with default (1, 0) (a generator
  raises); the Attributes no longer repeat the defaults of the
  parameters; the Notes of transform_params describe the VARMAX
  constraints, not a factor transition.
- SARIMAX: the seasonal autoregressive polynomial attribute is no longer
  described as moving average; concentrate_scale defaults to False and
  missing lists its values. initialize_default, clone and
  SARIMAXResults.extend (which continues the time trend and skips the
  constant exog check) get docstrings; arfreq and mafreq are None without
  roots; update returns the transformed parameters including the fixed
  ones.
- ExponentialSmoothing: initialization_method lists its values and refers
  to initial_trend (not initial_slope); bounds is a sequence (it is
  indexed); clone gets a docstring; ExponentialSmoothingResults documents
  its parameters and initial_state (an array, or a one-row DataFrame for
  pandas data).
- All five results classes document their constructor parameters,
  specification is a Bunch, and the coefficient matrices of VARMAX and
  DynamicFactor results are None without the corresponding lags;
  transform_params and untransform_params return ndarrays.
time_varying_regression lets the coefficients of exog vary over time. A
SARIMAX model without AR and MA terms puts its error in the measurement
equation when it has a state regression, so the option removed the ARMA
state. Without exog there is no state regression, so the model lost its
error term: SARIMAX(y, order=(0, 1, 0), time_varying_regression=True,
mle_regression=False) had no parameters and a log-likelihood of 0.0
(-28.19 at sigma2 = 1 without the option), a seasonal random walk had the
same problem, with measurement_error=True only the measurement variance
was left, and order=(0, 0, 0), simple_differencing=True, trend="t" or
concentrate_scale=True raised an error (ValueError, IndexError). With AR
or MA terms the option had no effect without exog.

Changes
- Without exog, time_varying_regression is set to False with a
  SpecificationWarning ("time_varying_regression has no effect without exog
  and is set to False."), as mle_regression is already set to False
  without exog. The model is the one without the option.
- The docstring of time_varying_regression says so, with a versionchanged
  note.

Not changed
- Models with exog. Combining time_varying_regression=True with
  mle_regression=True still raises a ValueError, also without exog.
- Models with AR or MA terms and no exog give the same results as before,
  now with the warning.

Tests
- Without exog, for a random walk, a seasonal random walk, a random walk
  with measurement error, white noise and an AR(1): the option warns (at
  the caller's line), the attribute is False, and the parameter names,
  start parameters, log-likelihood and forecasts at fixed parameters equal
  those of the model without the option, which does not warn; the
  log-likelihood of the random walk equals that of its differences. All
  five fail on main.
- check_concentrated_scale and test_recreate_model skip the combinations
  of time_varying_regression without exog, which are the same models as
  without the option and now warn.
@bashtage
bashtage force-pushed the wip-sarimax-tvr-without-exog branch from cc6ea1d to 57b450b Compare November 25, 2026 12:13
@bashtage
bashtage marked this pull request as ready for review November 28, 2026 11:32
@bashtage
bashtage merged commit 6b3b899 into statsmodels:main Nov 28, 2026
13 of 17 checks passed
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