Repository navigation
Suffix by variables named like an output column (marginaleffects backend) - #678
Merged
strengejacke merged 8 commits intoOct 14, 2026
Merged
Conversation
…ackend) Tests for SE, CI_low and CI_high still fail for estimate_means() and estimate_contrasts(): marginaleffects renames these columns itself.
Also repeat the Bayesian and inequality exceptions in NEWS and bump the development version.
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
R/format.R can remove the focal variable from datagrid, causing a mismatch with the returned data.
0 open findings
What changed in this PR
Updates marginaleffects handling so conflicting focal/by variables receive a .1 suffix while output columns retain their names.
Changes:
- Propagates renamed focal variables through attributes, filters, printing, plotting, and labels.
- Adds regression tests for collisions and datagrid metadata.
- Documents the change and bumps the development version.
R/format.Rstill needs adjustment to preserve the focal variable indatagrid.
| File | Summary |
|---|---|
tests/testthat/test-focal-name-clashes.R |
Adds collision, filtering, plotting, and datagrid tests. |
R/visualisation_recipe_internal.R |
Resolves original model-data names for labels. |
R/get_marginalmeans.R |
Preserves renamed focal metadata. |
R/get_marginalcontrasts.R |
Supports filtering renamed focal variables. |
R/format.R |
Implements focal-column suffixing and attribute restoration. |
R/estimate_slopes.R |
Applies renamed focal attributes to slopes. |
R/estimate_means.R |
Applies renamed focal attributes to means. |
R/estimate_contrasts.R |
Applies renamed focal attributes to contrasts. |
NEWS.md |
Documents the behavior change and limitations. |
DESCRIPTION |
Bumps the development version. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This follows #677 and the answer in easystats/parameters#1274. With the marginaleffects backend, a
byvariable can have the name of an output column of the same call. Such a variable now gets the suffix.1, and the output column keeps its name. Before, the variable kept its name and the output column was renamed. For example, withlmand a factorbyvariable:estimate_means()kept a variable namedMeanand renamed the means toMean.1. A variable namedtrenamed the t column tot.1.estimate_contrasts(by = "p")renamed the p-values top.1.estimate_slopes(by =)did the same forSlope,SE,CI_low,CI_high,tandp.Now the variable is
Mean.1,t.1orp.1. Thefocal_terms,byandatattributes and the columns of thedatagridattribute use the new name.print()andplot()find the column, and the plot keeps the variable label.byfilters such asby = "p='4'"work, also withestimate = "average".coef_namestays on the estimate column.If a focal name is already a column, the restore step in
.standardize_marginaleffects_columns()appends.1. It saves the old and new names in arenamed_focalattribute..rename_focal_attributes()uses that attribute each time the attributes are copied back from the unformatted object.Not fixed here:
SE,CI_low,CI_highandPredictedwithestimate_means()andestimate_contrasts().marginaleffects::predictions()renames these columns tostd.error,conf.low,conf.highandestimatebefore modelbased sees them. The output then holds the variable's values in place of the standard errors or intervals, with no warning (also on main).estimate_contrasts()on the output ofestimate_relation().plot(show_data = TRUE)and residual plots for a suffixed variable, because the model data has noMean.1column. These also failed on main, with another error.<name>.1next to<name>.Tests:
test-focal-name-clashes.Rgets new loops. Each one compares a call with the same call for a variable namedsafe_var, withsafe_varreplaced by<name>.1. They cover:estimate_means()with one and two focal terms (Mean,t),estimate_slopes(by =)(Slope,SE,CI_low,CI_high,t,p),estimate_contrasts(by =)(Difference,t,p),by, with and withoutestimate = "average",print(),plot()and the plot label.The comparison now also checks the column names of the
datagridattribute.devtools::test()anddevtools::check()locally: 0 failures, 0 errors, 0 warnings.The version is bumped to 0.17.0.12.