Skip to content

Conversation

@strengejacke
Copy link
Member

Fixes #1156

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.

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 refines the model_parameters() function's integration with the marginaleffects package. The primary goal is to enhance the tidy() method's output by intelligently removing redundant columns, ensuring a cleaner and more focused presentation of model parameters. This improves data clarity and usability for users analyzing marginal effects.

Highlights

  • Refined marginaleffects Integration: The model_parameters.marginaleffects method now includes logic to identify and remove superfluous columns from the tidy() output generated by the marginaleffects package. This ensures that only relevant data, such as variable names and by variables, are retained.
  • Improved Data Clarity: By stripping redundant columns, the output of model_parameters() when used with marginaleffects objects becomes more concise and easier to interpret, reducing visual clutter and focusing on essential statistical results.
  • Expanded Test Coverage: New test cases have been added to validate the correct handling of marginaleffects objects, specifically verifying that redundant columns are successfully removed and that the output structure and column names are as expected, including scenarios involving by variables.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

@strengejacke strengejacke requested a review from Copilot August 25, 2025 18:14
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 fixes an issue where model_parameters() for marginaleffects objects would include redundant columns from the original data. The change introduces logic to identify and remove these columns, cleaning up the output. The fix is accompanied by new unit tests that verify the corrected behavior.

My review focuses on improving the readability of the new logic. The implementation is correct, but breaking it down into smaller, named steps can enhance maintainability.

Comment on lines 29 to 37
to_remove <- setdiff(
# all columns
union(
colnames(marginaleffects::components(model, "newdata")),
colnames(marginaleffects::components(model, "modeldata"))
),
# columns we want to keep
marginaleffects::components(model, "variable_names_by")
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For improved readability and maintainability, consider breaking down the calculation of to_remove into intermediate variables. This makes the logic easier to follow by explicitly naming the sets of columns being manipulated.

    all_data_cols <- union(
      colnames(marginaleffects::components(model, "newdata")),
      colnames(marginaleffects::components(model, "modeldata"))
    )
    by_cols <- marginaleffects::components(model, "variable_names_by")
    to_remove <- setdiff(all_data_cols, by_cols)

Copy link
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 fixes the tidy() method in the marginaleffects methods for model_parameters() by removing redundant columns that are not needed in the output. The fix addresses issue #1156 by ensuring that only relevant columns are retained in the model parameters output.

  • Adds logic to identify and remove redundant columns from marginaleffects tidy output
  • Implements comprehensive test coverage for the new column filtering functionality
  • Updates package version to reflect the bug fix

Reviewed Changes

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

File Description
R/methods_marginaleffects.R Adds column filtering logic to remove redundant columns from tidy output
tests/testthat/test-marginaleffects.R Adds test cases to verify correct column dimensions and names after filtering
DESCRIPTION Increments package version number

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

),
# columns we want to keep
marginaleffects::components(model, "variable_names_by")
)
Copy link

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

The marginaleffects::components() function calls may fail if the model object doesn't have the expected components. Consider adding error handling or checking if these components exist before calling colnames() on them.

Copilot uses AI. Check for mistakes.
# columns we want to keep
marginaleffects::components(model, "variable_names_by")
)
tidy_model <- tidy_model[, !colnames(tidy_model) %in% to_remove, drop = FALSE]
Copy link

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

If to_remove is empty or contains non-existent column names, this subsetting could behave unexpectedly. Consider adding a check to ensure to_remove contains valid column names that exist in tidy_model.

Suggested change
tidy_model <- tidy_model[, !colnames(tidy_model) %in% to_remove, drop = FALSE]
# Only remove columns that exist in tidy_model
valid_to_remove <- intersect(to_remove, colnames(tidy_model))
if (length(setdiff(to_remove, valid_to_remove)) > 0 && length(to_remove) > 0) {
warning("Some columns specified for removal do not exist in tidy_model: ", paste(setdiff(to_remove, valid_to_remove), collapse = ", "))
}
tidy_model <- tidy_model[, !colnames(tidy_model) %in% valid_to_remove, drop = FALSE]

Copilot uses AI. Check for mistakes.
@strengejacke strengejacke merged commit 74cb53e into main Aug 25, 2025
18 of 19 checks passed
@strengejacke strengejacke deleted the strengejacke/issue1156 branch August 25, 2025 19:11
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.

Deal with / fix tidy() method in the _marginaleffects_ methods for model_parameters()

2 participants