Skip to content

Conversation

@strengejacke
Copy link
Member

Fixes #866

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @strengejacke, 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 a critical bug in the check_predictions() function within the performance package. Previously, the function encountered issues when processing binomial mixed-effects models fitted with lme4::glmer() if the input data contained NA values, especially when the response variable was specified using cbind(successes, failures). The core of the fix involves enhancing the internal simulation handling to correctly convert matrix-based responses into proportions while robustly managing missing data, thereby ensuring accurate prediction checks under these conditions.

Highlights

  • Bug Fix: Resolved an issue where check_predictions() would fail or produce incorrect results when used with lme4::glmer() for binomial mixed-effects models containing NA values, particularly with cbind responses.
  • Proportion Conversion: Introduced a new as_proportion argument and logic within the internal .check_re_formula function to correctly convert simulated matrix responses (from cbind binomial models) into proportions, ensuring NA values are handled gracefully during this conversion.
  • New Test Case: Added a comprehensive test case specifically for glmer models with cbind binomial responses and NA values, validating the fix and ensuring future stability.
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
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 addresses an issue where NA values were causing problems in the check_predictions() function for binomial mixed-effects models using lme4::glmer(). The changes include adding an as_proportion argument to the .check_re_formula() function and modifying the function to handle matrix responses by converting them to proportions when as_proportion is TRUE. A new test case is also added to verify the fix.

Comment on lines +457 to +465
out <- .check_re_formula(
out,
object,
iterations,
re_formula,
verbose,
as_proportion = TRUE,
...
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The added as_proportion = TRUE argument here ensures that when dealing with binomial mixed-effects models, the simulated responses are correctly converted to proportions, addressing the issue with NA values. This is crucial for the correctness of the posterior predictive checks.

However, it would be helpful to add a brief comment explaining why as_proportion = TRUE is specifically needed in this context to improve code understanding.

  out <- .check_re_formula(
    out,
    object,
    iterations,
    re_formula,
    verbose,
    as_proportion = TRUE, # Ensure correct handling of proportions for binomial models
    ...
  )

Comment on lines +639 to +647
.check_re_formula <- function(
out,
object,
iterations,
re_formula,
verbose,
as_proportion = FALSE,
...
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Adding as_proportion = FALSE as a default argument to .check_re_formula enhances the function's flexibility and ensures it behaves correctly in different scenarios. This is a good practice for maintainability and extensibility.

Consider adding a brief description of the as_proportion argument in the function's documentation to clarify its purpose.

.check_re_formula <- function(
  out,
  object,
  iterations,
  re_formula,
  verbose,
  as_proportion = FALSE, # Indicates whether to convert matrix responses to proportions
  ...
)

@strengejacke strengejacke merged commit 391f879 into main Oct 24, 2025
20 of 21 checks passed
@strengejacke strengejacke deleted the strengejacke/issue866 branch October 24, 2025 10:12
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.

NA values trip up check_predictions() for binomial mixed-effects models using lme4::glmer()

2 participants