Skip to content

Color plots of emmeans ordinal output by response category or threshold - #676

Merged
strengejacke merged 7 commits into
easystats:mainfrom
jmgirard:emmeans-ordinal-plot-colors
Oct 13, 2026
Merged

strengejacke merged 7 commits into
easystats:mainfrom
jmgirard:emmeans-ordinal-plot-colors

Conversation

@jmgirard

Copy link
Copy Markdown
Contributor

Output of estimate_means(..., backend = "emmeans") had no model_info attribute, so plot() did not group ordinal output by its Response column. All categories were drawn as one group. There was also no handling for the Threshold column of predict = "cum.prob", "exc.prob" and "linear.predictor".

This PR:

  • attaches model_info (from insight::model_info(model, response = 1)) to emmeans estimate_means() output for all models. get_emmeans() output is unchanged.
  • adds a Threshold grouping in .find_aes() beside the existing Response grouping. It is skipped when a focal predictor is itself named Threshold, and it keeps the threshold levels in model order.
  • adds "cum.prob" and "exc.prob" to the predict values that get a percent y-axis.

Result for ordinal models (polr, clm, clmm): with one by variable, Response or Threshold goes to the color, and with two it goes to the facets. This matches the marginaleffects backend for Response. Because emmeans output now carries model_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 with predict = "link", and polr mean.class/latent are unchanged.

Tests: new blocks in test-visualisation_recipe.R. Three existing tests that list the attribute names of emmeans output now include model_info. devtools::check() locally: 0 warnings; the one test failure is test-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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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_info to emmeans estimates.
  • Adds Response/Threshold grouping 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.

Comment thread R/visualisation_recipe_internal.R
@strengejacke

Copy link
Copy Markdown
Member

Thanks, lgtm!

@strengejacke
strengejacke merged commit b964ea7 into easystats:main Oct 13, 2026
6 of 18 checks passed
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.
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.

3 participants