Skip to content

Bayesmixedglm predict which - #10554

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
tqa236:bayesmixedglm-predict-which
Oct 24, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
tqa236:bayesmixedglm-predict-which

Conversation

@tqa236

@tqa236 tqa236 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

I think this is a fairly straightforward and backward-compatible fix, apart from 1 point: what should be a good name for the case linear=False. I used "mean" here probably a bit liberally as it's the first case (AFAIK) where "mean" doesn't mean the marginal mean E(y | x), but E(y | x, b = 0) and it's still pretty close to how "mean" is used in GLM. I can change it if there's a better name.

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 Opus 5.5.
    Used for: drafting an implementation, writing tests, debugging, editing docstrings.
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.
Details

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass ruff. You can
    verify your changes are well formatted by running
    ruff check . --fix
    
    assuming ruff is installed. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.
  • If AI tools were used to help write this PR, see the
    AI Policy for what disclosure
    and review is expected of you before submitting.

tqa236 and others added 2 commits October 24, 2026 20:20
Add a which={"mean", "linear"} argument to the model and results predict
methods of the Bayes mixed GLMs, matching GLM.predict. The linear
argument is kept in its positional slot for backward compatibility, but
passing it now issues a FutureWarning, with removal planned for
statsmodels 0.17.0. Passing both linear and a non-default which raises.

Closes statsmodels#8562

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Describe the "mean" and "linear" options with the wording of the
original linear docstrings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
return BayesMixedGLMResults(self, params, cov, optim_retvals=r)

def predict(self, params, exog=None, linear=False):
def predict(self, params, exog=None, linear=None, which="mean"):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, this is a false positive, the warning is raised when a similar line is touched, like here

#10015 (comment)

@bashtage
bashtage merged commit 2555ed5 into statsmodels:main Oct 24, 2026
9 of 11 checks passed
@bashtage

Copy link
Copy Markdown
Member

Thanks

bashtage added a commit that referenced this pull request Oct 25, 2026
which is now case sensitive like in GLM.predict, a list exog is converted with array_like (it raised AttributeError) and a 1-d exog raises a ValueError. The predict docstrings say that only the fixed effects are used, so that mean is the mean given zero random effects, and which estimate fit_map and fit_vb provide. The tests cover fit_map and fit_vb, Binomial and Poisson, both values of which and all call forms of the deprecated linear argument.

Follow up to gh-10554.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit that referenced this pull request Oct 25, 2026
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.

REF: BayesMixedGLM predict still uses linear=True

3 participants