Skip to content

BUG: Fix observed_information_matrix with untransformed or fixed params - #11055

Draft
bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-mlemodel-oim-params
Draft

bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-mlemodel-oim-params

Conversation

@bashtage

Copy link
Copy Markdown
Member

#11029 (the C10 coverage chunk) appends tests to the same test file, so whichever merges second needs a rebase (keep both test blocks). The other C10F PRs and #11043 also append to test_mlemodel.py: keep every appended block.

MLEModel.observed_information_matrix replaced params by the constrained
parameter vector (with the fixed parameters included) and then passed that
vector to the numerical derivatives, together with the caller's
transformed and includes_fixed flags.

  • With transformed=False, the derivatives transformed the already
    constrained parameters a second time, while the base point of the
    differences was the correct one. For SARIMAX(1, 0, 0) with a trend on
    the macrodata inflation series, at params [1, 0.5, 4], the diagonal was
    [4.7e16, 1.9e17, 2.9e15] instead of J' I(p) J = [0.2525, 2.767, 0.5],
    and [0.249, 3.371, 1.999] with approx_centered=True.
  • With fixed parameters (fix_params) and includes_fixed=False, it raised
    "ValueError: shape mismatch: value array of shape (3,) could not be
    broadcast to indexing result of shape (2,)", and so did
    hessian(params, method="oim").

Changes

  • The numerical derivatives are taken with respect to params as given,
    so with transformed=False the information matrix is with respect to the
    untransformed parameters, J' I(p) J, and with fixed parameters it is the
    matrix of the free parameters.
  • The docstring says so, with a versionchanged note.

Not changed

  • transformed=True without fixed parameters, or with includes_fixed=True.
  • hessian(..., transformed=False, method="oim"), which uses the chain rule
    and does not reach this path.

Tests

  • With transformed=False, forward and centered differences match
    J' I(p) J, with I(p) by complex step and J by centered differences of
    transform_params, for an AR(1) and an AR(2) (whose transformation is not
    diagonal). Main is off by a factor of 1e16 (forward) or up to 4
    (centered).

  • With fixed parameters, transformed True and False, the matrix equals
    that of the model without fixed parameters at the same values,
    restricted to the free parameters; hessian(method="oim") likewise. These
    raise 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 contract audit, 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

MLEModel.observed_information_matrix replaced params by the constrained
parameter vector (with the fixed parameters included) and then passed that
vector to the numerical derivatives, together with the caller's
transformed and includes_fixed flags.

- With transformed=False, the derivatives transformed the already
  constrained parameters a second time, while the base point of the
  differences was the correct one. For SARIMAX(1, 0, 0) with a trend on
  the macrodata inflation series, at params [1, 0.5, 4], the diagonal was
  [4.7e16, 1.9e17, 2.9e15] instead of J' I(p) J = [0.2525, 2.767, 0.5],
  and [0.249, 3.371, 1.999] with approx_centered=True.
- With fixed parameters (fix_params) and includes_fixed=False, it raised
  "ValueError: shape mismatch: value array of shape (3,) could not be
  broadcast to indexing result of shape (2,)", and so did
  hessian(params, method="oim").

Changes
- The numerical derivatives are taken with respect to params as given,
  so with transformed=False the information matrix is with respect to the
  untransformed parameters, J' I(p) J, and with fixed parameters it is the
  matrix of the free parameters.
- The docstring says so, with a versionchanged note.

Not changed
- transformed=True without fixed parameters, or with includes_fixed=True.
- hessian(..., transformed=False, method="oim"), which uses the chain rule
  and does not reach this path.

Tests
- With transformed=False, forward and centered differences match
  J' I(p) J, with I(p) by complex step and J by centered differences of
  transform_params, for an AR(1) and an AR(2) (whose transformation is not
  diagonal). Main is off by a factor of 1e16 (forward) or up to 4
  (centered).
- With fixed parameters, transformed True and False, the matrix equals
  that of the model without fixed parameters at the same values,
  restricted to the free parameters; hessian(method="oim") likewise. These
  raise on main.
@bashtage
bashtage force-pushed the wip-mlemodel-oim-params branch from 4220c01 to f67565f 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