Skip to content

mismatch between {emmeans}\s and model_parameters()'s adjusted p-values#1194

Merged
strengejacke merged 9 commits into
mainfrom
strengejacke/issue1103
Feb 24, 2026
Merged

mismatch between {emmeans}\s and model_parameters()'s adjusted p-values#1194
strengejacke merged 9 commits into
mainfrom
strengejacke/issue1103

Conversation

@strengejacke
Copy link
Copy Markdown
Member

Fixes #1103

@gemini-code-assist
Copy link
Copy Markdown
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 where model_parameters() produced incorrect Tukey-adjusted p-values for emmeans objects, leading to inconsistencies with direct emmeans output. The changes ensure that p-value adjustments, particularly Tukey's, are accurately applied, improving the reliability of statistical results and maintaining consistency across different functions. The update also includes minor code refactoring for readability and expanded test coverage.

Highlights

  • P-value Adjustment Fix: Resolved a discrepancy in Tukey p-value adjustments when using model_parameters() with emmeans objects, ensuring consistency with direct emmeans output.
  • Tukey Adjustment Logic: Adjusted the calculation of nmeans for Tukey adjustment to ensure correct application based on the number of means being compared.
  • Correction Factor Enhancement: Enhanced the logic for determining the correction factor in p-value adjustments, particularly for grouped emmeans results.
  • Test Coverage: Introduced new test cases to validate the accuracy of Tukey p-value adjustments for emmeans objects, improving robustness.
  • Package Version Update: Incremented the package version to reflect these bug fixes and improvements.
Changelog
  • DESCRIPTION
    • Updated the package version from 0.28.3.3 to 0.28.3.4.
  • NEWS.md
    • Added a changelog entry for fixing issues with Tukey-p-value adjustment for emmeans objects.
  • R/format_p_adjust.R
    • Refactored code for improved readability and consistency in switch statements.
    • Corrected the nmeans calculation for Tukey adjustment.
    • Introduced a new correction factor calculation for grouped emmeans objects.
    • Improved formatting for warning messages and function calls.
  • tests/testthat/test-p_adjust.R
    • Added new test cases for emmeans objects with Tukey p-value adjustment.
    • Refactored existing test code for better readability and consistent formatting.
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 addresses a mismatch in adjusted p-values between emmeans and model_parameters(). The core of the fix is in the Tukey p-value adjustment logic, where the nmeans parameter for stats::ptukey is now correctly calculated. The method for determining the number of comparisons (rank_adjust) has also been improved with a fallback mechanism. The changes are well-supported by new unit tests that validate the fix against emmeans output. Additionally, the pull request includes several formatting improvements that enhance code readability by breaking up long lines, which is a welcome change. Overall, this is a solid contribution that fixes an important bug and improves code quality.

@strengejacke strengejacke requested a review from Copilot February 24, 2026 07:36
@strengejacke
Copy link
Copy Markdown
Member Author

@gemini-code-assist review

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 addresses a mismatch in adjusted p-values between {emmeans} and model_parameters(). The core of the fix involves correcting the nmeans argument for Tukey p-value adjustments and adding new tests to ensure correctness. The changes are well-implemented and improve the reliability of p-value adjustments. I have one suggestion to remove a redundant line of code to improve maintainability.

Comment thread R/format_p_adjust.R Outdated
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 #1103 by aligning model_parameters() p-value adjustment behavior with emmeans, focusing on Tukey adjustments for emmeans contrast objects.

Changes:

  • Updated Tukey p-value adjustment logic used by .p_adjust() for emmeans outputs.
  • Expanded test coverage to assert model_parameters() p-values match emmeans’ own adjusted p.value across additional Tukey scenarios.
  • Bumped package version and added a NEWS entry for the Tukey/emmeans adjustment fix.

Reviewed changes

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

File Description
tests/testthat/test-p_adjust.R Adds regression tests ensuring model_parameters() matches emmeans adjusted p-values (incl. additional Tukey cases).
R/format_p_adjust.R Adjusts Tukey adjustment computation and rank/correction logic used during p-value adjustment.
NEWS.md Documents the Tukey/emmeans p-value adjustment fix.
DESCRIPTION Version bump from 0.28.3.3 to 0.28.3.4.

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

Comment thread R/format_p_adjust.R Outdated
Comment thread R/format_p_adjust.R Outdated
@strengejacke strengejacke merged commit 806d308 into main Feb 24, 2026
13 of 21 checks passed
@strengejacke strengejacke deleted the strengejacke/issue1103 branch February 24, 2026 11: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.

mismatch between {emmeans}\s and model_parameters()'s adjusted p-values

2 participants