Add options to calculate context effects#608
Conversation
There was a problem hiding this comment.
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.
|
@gemini-code-assist review |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
No description provided.