Skip to content

Fix std bayes error#1193

Merged
mattansb merged 7 commits into
mainfrom
fix-std-bayes-error
Feb 19, 2026
Merged

Fix std bayes error#1193
mattansb merged 7 commits into
mainfrom
fix-std-bayes-error

Conversation

@mattansb
Copy link
Copy Markdown
Member

Closes #1192

I basically re-wrote the standardization of Bayesian models to be more in-line with non-Bayesian model.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @mattansb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue with the standardization of Bayesian models, aiming to harmonize their behavior with non-Bayesian models. The core changes involve restructuring the internal logic for applying standardization, particularly when the "refit" method is specified, and refining how standardized coefficients are processed. This ensures a more consistent and robust approach to parameter standardization across different model types.

Highlights

  • Refactored Bayesian Model Standardization: The logic for standardizing Bayesian models has been rewritten to be more consistent with non-Bayesian models, particularly for the "refit" method.
  • Improved standardize Argument Handling: The internal handling of the standardize argument in model_parameters has been made more robust, especially for the "refit" method, and now excludes Bayes Factor tests for standardized parameters.
  • Enhanced Std_Coefficient Column Detection: The internal utility function .NA_inferential_cols now dynamically identifies the standardized coefficient column, improving flexibility and robustness.
  • Expanded Test Coverage for Bayesian Models: New test cases have been added to thoroughly validate the standardization of rstanarm::stan_glm models using both "basic" and "refit" methods.
Changelog
  • R/extract_parameters.R
    • Refactored the standardization process for Bayesian models, including a dedicated block for the "refit" method and dynamic identification of standardized coefficient columns.
    • Simplified the conditional logic for applying standardization.
  • R/methods_coxme.R
    • Updated the condition for the "refit" standardization method to use isTRUE() for improved robustness.
    • Applied minor formatting adjustments for improved code readability.
  • tests/testthat/test-standardize_parameters.R
    • Added comprehensive test cases for rstanarm::stan_glm models to verify correct standardization behavior for "basic" and "refit" methods.
    • Performed minor formatting and readability improvements across various test assertions.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the standardization of Bayesian models to align with the implementation for non-Bayesian models, which improves consistency across the package. The changes are generally well-structured and include corresponding updates to tests.

However, I've identified two high-severity issues in the new implementation. Both relate to the handling of inferential statistics (like Bayes Factors) after standardization. For the refit method, the logic to exclude these tests is incomplete. For post-hoc methods, invalid statistics from the unstandardized model are carried over to the standardized results. I've left specific comments with suggestions on how to address these correctness issues.

Comment thread R/extract_parameters.R Outdated
Comment thread R/extract_parameters.R
@mattansb
Copy link
Copy Markdown
Member Author

@strengejacke failure are only due to snapshots.

@strengejacke
Copy link
Copy Markdown
Member

Looks good to me! I'd say only two minor things are the linters you could address at lines 1108 and 1109. lintr line 1108 makes sense from the performance perspective (startsWith() is faster).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #1192 where model_parameters(standardize=) failed for Bayesian models with errors about differing row counts. The fix rewrites the standardization logic for Bayesian models to be more consistent with non-Bayesian models.

Changes:

  • Added support for standardize parameter in model_parameters() for Bayesian models
  • Implemented validation to prevent test = "all" when standardizing (not supported)
  • Added filtering of scale-dependent inferential statistics (rope, bayes_factor) when standardizing
  • Refactored code formatting across multiple files for consistency

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/testthat/test-standardize_parameters.R Added comprehensive tests for Bayesian model standardization with various test statistics; improved code formatting
R/methods_coxme.R Improved code formatting and consistent use of isTRUE() for standardize checks
R/extract_parameters.R Core fix: Added standardization support for Bayesian models, validation logic for test parameters, and setting standardize to NULL after refit

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/extract_parameters.R
Comment thread R/extract_parameters.R Outdated
@mattansb mattansb merged commit 28b7d74 into main Feb 19, 2026
13 of 21 checks passed
@mattansb mattansb deleted the fix-std-bayes-error branch February 19, 2026 07:10
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.

bayesian models don't play nice with model_parameters(standardize=)

3 participants