Skip to content

Add options to calculate context effects#608

Merged
strengejacke merged 19 commits intomainfrom
context_effects
Apr 1, 2026
Merged

Add options to calculate context effects#608
strengejacke merged 19 commits intomainfrom
context_effects

Conversation

@strengejacke
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

@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 introduces support for calculating context effects in models with within-between effects. It adds a new internal helper function get_contexteffects.R and updates get_marginalcontrasts.R and get_marginalmeans.R to handle the new context comparison type. Additionally, the PR includes extensive code reformatting to align with line length and spacing standards, and increments the package version to 0.14.0.3. Feedback is provided regarding the naming of the new internal function to ensure it follows the repository's convention of prefixing non-exported functions with a dot.

@strengejacke strengejacke requested a review from Copilot April 1, 2026 10:03
@strengejacke
Copy link
Copy Markdown
Member Author

@gemini-code-assist review

Copy link
Copy Markdown

@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 implements 'context effects' calculations, allowing users to estimate the difference between within- and between-effects via the comparison = "slope" or "context" options. Key updates include the addition of the .get_contexteffects helper, support for exponentiated coefficients (Odds Ratios and IRRs) in .guess_estimate_name, and a version bump to 0.14.0.3. Feedback identifies style guide violations regarding function brace placement and line length, and suggests naming list arguments to improve code maintainability.

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 introduces support for “context effects” (within–between slope differences) in estimate_contrasts() by adding a new comparison option and wiring it through the marginaleffects backend, along with corresponding formatting/attribute updates and tests.

Changes:

  • Add a context-effects computation path (and related attributes) to marginaleffects-based contrasts.
  • Update formatting/footers and attribute expectations to account for context_effects.
  • Add new test coverage for context effects and bump package version.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
R/get_marginalcontrasts.R Adds context_effects flow and stores it in attributes; adjusts class handling and error messaging.
R/get_contexteffects.R New helper to compute context effects using marginaleffects::avg_comparisons().
R/get_marginalmeans.R Extends .info_elements() to include context_effects; adds a special-case early return in argument guessing.
R/format.R Adjusts formatting for context effects and improves estimate naming using transform.
R/table_footer.R Uses transform to refine the footer’s scale description; mostly formatting refactors.
R/get_inequalitycontrasts.R Renames helper to .get_inequalitycontrasts(); adds minor logic changes and refactors.
R/estimate_contrasts.R Documents the new "slope"/context behavior in comparison.
man/get_emmeans.Rd Mirrors updated comparison docs.
man/estimate_contrasts.Rd Mirrors updated comparison docs.
tests/testthat/test-estimate_contrasts_context.R New tests validating context-effects estimates for lm and glm.
tests/testthat/test-attributes_estimatefun.R Updates expected attributes to include context_effects.
tests/testthat/test-keep_iterations.R Formatting-only refactor of test calls.
R/clean_names.R Updates calls to .guess_estimate_name() after signature change.
DESCRIPTION Version bump.

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

@strengejacke strengejacke merged commit 6b5ef97 into main Apr 1, 2026
12 of 20 checks passed
@strengejacke strengejacke deleted the context_effects branch April 1, 2026 10:46
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.

2 participants