Skip to content

BUG: Make the ProcessMLE.from_formula parameters explicit and use cov - #11227

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-formula-process-mle-kwargs
Nov 26, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-formula-process-mle-kwargs

Conversation

@bashtage

@bashtage bashtage commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #11225, found while writing it: that PR passes eval_env on from ProcessMLE.from_formula; this one makes every documented parameter part of the signature and passes cov and the model's other keywords.

ProcessMLE.from_formula(formula, data, subset=None, drop_cols=None, *args, **kwargs) documented scale_formula, smooth_formula,
noise_formula, time, groups and eval_env as parameters but took
them from **kwargs, and passed only the matrices it built to the model.
Every other keyword was silently dropped. In particular cov, the
covariance model of ProcessMLE, was ignored: the model always used the
default GaussianCovariance, so a model created with the formula API had a
different likelihood, and different estimates, than the same model created
from arrays.

Changes

  • Every documented parameter is part of the signature, after drop_cols
    as keyword-only parameters: scale_formula, smooth_formula, time and
    groups (required), noise_formula, cov and eval_env.
  • cov is documented and passed to the model, and so are other keywords
    of the model (for example hasconst), as in other models' from_formula.
  • A missing required argument raises Python's TypeError, which names it,
    instead of a ValueError, and further positional arguments, which were
    ignored, raise a TypeError.

Not changed

  • Calls that pass these arguments by keyword, as the docstring required,
    give the same model unless they pass cov or another model keyword.

Tests

  • The parameters in the docstring are the parameters of the signature, in
    the same order.

  • With a covariance that is twice the Gaussian one, the model holds that
    covariance, and its log-likelihood equals that of the model constructed
    from arrays with the same covariance (and differs from the default).

  • hasconst=False reaches the model (k_constant is 0 instead of 1).

  • A missing scale_formula, and a positional argument after drop_cols,
    raise a TypeError. All 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 and contract audit of statsmodels.formula, writing the fix and its tests, and checking them (tests failing on main, a mutation check of the changed lines, and the tests in the oldest, middle, latest and formulaic-only environments).
    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

`ProcessMLE.from_formula(formula, data, subset=None, drop_cols=None,
*args, **kwargs)` documented `scale_formula`, `smooth_formula`,
`noise_formula`, `time`, `groups` and `eval_env` as parameters but took
them from `**kwargs`, and passed only the matrices it built to the model.
Every other keyword was silently dropped. In particular `cov`, the
covariance model of `ProcessMLE`, was ignored: the model always used the
default `GaussianCovariance`, so a model created with the formula API had a
different likelihood, and different estimates, than the same model created
from arrays.

Changes
- Every documented parameter is part of the signature, after `drop_cols`
  as keyword-only parameters: `scale_formula`, `smooth_formula`, `time` and
  `groups` (required), `noise_formula`, `cov` and `eval_env`.
- `cov` is documented and passed to the model, and so are other keywords
  of the model (for example `hasconst`), as in other models' `from_formula`.
- A missing required argument raises Python's TypeError, which names it,
  instead of a ValueError, and further positional arguments, which were
  ignored, raise a TypeError.

Not changed
- Calls that pass these arguments by keyword, as the docstring required,
  give the same model unless they pass `cov` or another model keyword.

Tests
- The parameters in the docstring are the parameters of the signature, in
  the same order.
- With a covariance that is twice the Gaussian one, the model holds that
  covariance, and its log-likelihood equals that of the model constructed
  from arrays with the same covariance (and differs from the default).
- `hasconst=False` reaches the model (`k_constant` is 0 instead of 1).
- A missing `scale_formula`, and a positional argument after `drop_cols`,
  raise a TypeError. All fail on main.
@bashtage
bashtage force-pushed the wip-formula-process-mle-kwargs branch from 1e96115 to a84d919 Compare November 26, 2026 14:19
@bashtage bashtage changed the title BUG: Pass the other keywords of ProcessMLE.from_formula to the model BUG: Make the ProcessMLE.from_formula parameters explicit and use cov Nov 26, 2026
Comment on lines +393 to +403
ProcessMLE.from_formula(
"y ~ x",
data,
None,
None,
"0 + x",
scale_formula="0 + x",
smooth_formula="0 + x",
time="time",
groups="g",
)
@bashtage
bashtage marked this pull request as ready for review November 26, 2026 14:30
@bashtage
bashtage merged commit d005266 into statsmodels:main Nov 26, 2026
10 of 13 checks passed
@bashtage
bashtage deleted the wip-formula-process-mle-kwargs branch November 26, 2026 14:30
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