Skip to content

Context_effects_stratify#614

Open
strengejacke wants to merge 2 commits intomainfrom
context_effects_stratify
Open

Context_effects_stratify#614
strengejacke wants to merge 2 commits intomainfrom
context_effects_stratify

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 enhances the modelbased package by allowing contrasts to be stratified by multiple variables. It updates the internal logic in get_contexteffects.R and get_marginalcontrasts.R to handle multiple grouping variables in the by argument and ensures correct formula construction for pairwise comparisons. Documentation and tests have been updated accordingly, and the package version was incremented to 0.14.0.10. A review comment suggests a more robust implementation for selecting stratification variables to future-proof the code against potential increases in the allowed number of grouping variables.

Comment thread R/get_contexteffects.R
# save original levels for formatting
original_levels <- .safe(out[[my_args$by]])
# if we have more than one by-variable, use the last one for stratification
stratify_by <- my_args$by[length(my_args$by)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation of stratify_by only selects the last element of the by vector. While the current code limits by to two variables (via the check at line 16), it is more robust and future-proof to select all variables except the first one for stratification. This ensures that if the limit is ever increased, the logic of 'contrasting the first variable and stratifying by all others' remains consistent with the formatting logic at lines 85-86.

    stratify_by <- my_args$by[-1]

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.

1 participant