Skip to content

BUG: Start the DynamicFactor error covariance of AR errors by its type - #11157

Draft
bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-dynamic-factor-ar-errors-start
Draft

bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-dynamic-factor-ar-errors-start

Conversation

@bashtage

@bashtage bashtage commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

#11133 and #11083, which this PR was stacked on, are merged. It changes the error block of start_params next to the change of #11133. Merges cleanly with #11085-#11089 and #11121.

BUG: Start the DynamicFactor error covariance of AR errors by its type

With autoregressive errors (error_order > 0, error_var=False),
DynamicFactor.start_params filled the error covariance parameters with the
innovation variance of each series' autoregression whatever the
error_cov_type, so with error_cov_type="scalar" (one parameter) or
"unstructured" (k_endog (k_endog + 1) / 2 parameters) it raised
"ValueError: could not broadcast input array from shape (3,) into shape
(1,)" (or "(6,)"), and so did fit without start_params.

Stacked on #11133 (the start of an unstructured error covariance with VAR
errors), which changes the neighbouring lines.

Changes

  • As for white noise and VAR errors, the start is the mean of the
    innovation variances ("scalar") or the Cholesky factor of their diagonal
    matrix ("unstructured"); "diagonal" is unchanged.

Not changed

  • error_cov_type="diagonal", and the other starting parameters.

Tests (test_dynamic_factor.py)

  • Without factors and with an AR(1) error, and with a factor and AR(1) or
    AR(2) errors: the "scalar" and "unstructured" error covariance starts are
    the mean and the square roots (on the diagonal of the lower triangle) of
    the "diagonal" start, the other starting parameters equal those with
    "diagonal", and the "unstructured" start gives the log-likelihood of the
    "diagonal" start (the same covariance matrix). All six cases fail on
    ENH: Add error_cov_start to choose the DynamicFactor error covariance start #11133.

  • 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 code, writing the fix and its tests, 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

# The innovation variances of the autoregressions, as in the
# other cases: their mean ("scalar"), themselves ("diagonal") or
# the Cholesky factor of their diagonal matrix ("unstructured")
error_cov_params = np.r_[error_cov_params]
@bashtage
bashtage force-pushed the wip-dynamic-factor-ar-errors-start branch from 64f1379 to eeaaccc Compare November 25, 2026 12:14
With autoregressive errors (error_order > 0, error_var=False),
DynamicFactor.start_params filled the error covariance parameters with the
innovation variance of each series' autoregression whatever the
error_cov_type, so with error_cov_type="scalar" (one parameter) or
"unstructured" (k_endog (k_endog + 1) / 2 parameters) it raised
"ValueError: could not broadcast input array from shape (3,) into shape
(1,)" (or "(6,)"), and so did fit without start_params.

Stacked on statsmodels#11133 (the start of an unstructured error covariance with VAR
errors), which changes the neighbouring lines.

Changes
- As for white noise and VAR errors, the start is the mean of the
  innovation variances ("scalar") or the Cholesky factor of their diagonal
  matrix ("unstructured"); "diagonal" is unchanged.

Not changed
- error_cov_type="diagonal", and the other starting parameters.

Tests (test_dynamic_factor.py)
- Without factors and with an AR(1) error, and with a factor and AR(1) or
  AR(2) errors: the "scalar" and "unstructured" error covariance starts are
  the mean and the square roots (on the diagonal of the lower triangle) of
  the "diagonal" start, the other starting parameters equal those with
  "diagonal", and the "unstructured" start gives the log-likelihood of the
  "diagonal" start (the same covariance matrix). All six cases fail on
  statsmodels#11133.
@bashtage
bashtage force-pushed the wip-dynamic-factor-ar-errors-start branch from eeaaccc to 02713f7 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.

2 participants