Context_effects_stratify#614
Conversation
There was a problem hiding this comment.
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.
| # 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)] |
There was a problem hiding this comment.
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]
No description provided.