Skip to content

Fix standardize() on stan_lmer() models - #746

Merged
strengejacke merged 2 commits into
mainfrom
hotfix-standardize-stanreg
Nov 3, 2026
Merged

strengejacke merged 2 commits into
mainfrom
hotfix-standardize-stanreg

Conversation

@jmgirard

@jmgirard jmgirard commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

standardize.lmerMod() from #716 also catches stan_lmer() models, because their class vector ends in lmerMod. Its helper then reads model@frame, which fails on a stanreg object, so standardize() stops with "Unable to refit the model with standardized data." 1.4.1 works, and the error also fails test-report_performance.R in report.

stanreg models now go to standardize.default() again. No release has this bug, so there's no NEWS.md bullet.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A moderate active finding remains because the test mutates and unconditionally removes a pre-existing global stan_glmer binding, risking shared test-state corruption.

1 open issue
What changed in this PR

Fixes standardize() dispatch for rstanarm::stan_lmer() models by routing stanreg objects through the default standardization path instead of the incompatible lmerMod implementation.

Changes:

  • Adds standardize.stanreg as an alias of standardize.default().
  • Registers the new S3 method in NAMESPACE.
  • Adds regression coverage for standardized stan_lmer() response and predictor data.

This pull request requires changes.

File Summary
tests/​testthat/​test-standardize_models.R Adds stan_lmer() regression coverage. Moderate finding (2 votes): the test overwrites and unconditionally removes any pre-existing stan_glmer binding in the global environment; it should save and restore the original state or avoid mutating globalenv().
R/​standardize.models.R Routes stanreg models through the compatible default standardization implementation.
NAMESPACE Registers the standardize.stanreg S3 method.

Review effort: Lite

@jmgirard

jmgirard commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Copilot's review was right that the test overwrote and then deleted any stan_glmer in the global environment. In 2081dbd, the test attaches a temporary environment with withr::local_environment() instead, so the global environment stays as it was.

@jmgirard
jmgirard requested a review from strengejacke November 3, 2026 21:12
@jmgirard jmgirard mentioned this pull request Nov 3, 2026
@strengejacke
strengejacke merged commit a42d2b3 into main Nov 3, 2026
27 checks passed
@strengejacke
strengejacke deleted the hotfix-standardize-stanreg branch November 3, 2026 21:22
@jmgirard jmgirard mentioned this pull request Nov 3, 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.

3 participants