Repository navigation
Color plots of emmeans ordinal output by response category or threshold - #676
Merged
strengejacke merged 7 commits intoOct 13, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Grand-mean ordinal emmeans plots can error when generated grouping columns are appended to the language-valued by expression.
1 open finding
What changed in this PR
Updates emmeans visualization recipes for ordinal outputs, including response/threshold grouping and probability-axis handling.
Changes:
- Attaches
model_infotoemmeansestimates. - Adds
Response/Thresholdgrouping and percentage scales. - Adds regression tests, NEWS documentation, and a version bump.
| File | Reviewed changes |
|---|---|
tests/testthat/test-visualisation_recipe.R |
Adds visualization coverage. |
tests/testthat/test-keep_iterations.R |
Updates expected attributes. |
tests/testthat/test-attributes_estimatefun.R |
Updates emmeans attribute expectations. |
R/visualisation_recipe_internal.R |
Implements ordinal grouping and probability scales. |
R/estimate_means.R |
Attaches model metadata to emmeans results. |
NEWS.md |
Documents the plotting changes. |
DESCRIPTION |
Bumps the package version. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Member
|
Thanks, lgtm! |
strengejacke
pushed a commit
that referenced
this pull request
Oct 13, 2026
…end) (#677) * Keep by variables whose names insight renames (marginaleffects backend) model_parameters() renames columns such as type, n or value, and the format step removes columns such as p, CI or S by name. A by variable with one of these names was dropped, renamed, or mislabeled other columns. Focal columns that hold the data grid values now get temporary names until the renaming is done. * Close the test block that lost its closing brace in #676 The "recipes that do not change" test in test-visualisation_recipe.R had no closing "})", so the file did not parse and devtools::test() stopped there. * Build the focal-name test models from local data only Another test file assigns a global d, which the formula environment could find before the local data. * Narrow the NEWS examples to estimate_means() * Make the brms subsample test stable The test asked every median from a random 200-draw subsample to differ from the full-draw median by more than 0.001, which failed in 6 of 10 local runs. It now tests that the medians differ and that 200 draws are kept. * Say in NEWS which cases the focal-name fix does not cover * Bump version to 0.17.0.11 * Check focal columns against the grid used for predictions With a custom newdata, the datagrid attribute holds the generated grid, not the one passed to marginaleffects, so focal columns were not protected. Temporary column names are now also unique against the existing columns.
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.

Output of
estimate_means(..., backend = "emmeans")had nomodel_infoattribute, soplot()did not group ordinal output by itsResponsecolumn. All categories were drawn as one group. There was also no handling for theThresholdcolumn ofpredict = "cum.prob","exc.prob"and"linear.predictor".This PR:
model_info(frominsight::model_info(model, response = 1)) to emmeansestimate_means()output for all models.get_emmeans()output is unchanged.Thresholdgrouping in.find_aes()beside the existingResponsegrouping. It is skipped when a focal predictor is itself namedThreshold, and it keeps the threshold levels in model order."cum.prob"and"exc.prob"to thepredictvalues that get a percent y-axis.Result for ordinal models (polr, clm, clmm): with one
byvariable,ResponseorThresholdgoes to the color, and with two it goes to the facets. This matches the marginaleffects backend forResponse. Because emmeans output now carriesmodel_info, emmeans probability plots of binomial, beta and multinomial models also get the percent y-axis that the marginaleffects backend already shows.Printed tables do not change:
format()output of 25 emmeans outputs (polr, clm, clmm, lm, log lm, Poisson and logistic glm) is identical to main. Plot recipes for lm, log lm, Poisson, logistic glm withpredict = "link", and polrmean.class/latentare unchanged.Tests: new blocks in
test-visualisation_recipe.R. Three existing tests that list the attribute names of emmeans output now includemodel_info.devtools::check()locally: 0 warnings; the one test failure istest-brms.R:26, which fails at random and uses the marginaleffects path.The version is bumped to 0.17.0.10, as in #673 and #675, so the PR that merges later needs a rebase.