Skip to content

Return per-category and per-threshold estimates for ordinal models with the emmeans backend - #670

Merged
strengejacke merged 4 commits into
easystats:support_emmeans_ordinalfrom
jmgirard:emmeans-ordinal-modes
Sep 30, 2026
Merged

strengejacke merged 4 commits into
easystats:support_emmeans_ordinalfrom
jmgirard:emmeans-ordinal-modes

Conversation

@jmgirard

@jmgirard jmgirard commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

This PR goes into support_emmeans_ordinal (#669), not into main.

With #669, estimate_means(m, "Type", predict = "prob", backend = "emmeans") returns 0.333 in every row. For ordinal modes, emmeans adds a pseudo-factor to the reference grid. If that factor is not in specs, emmeans averages over it. This PR adds that factor to specs:

  • For predict = "prob", the response factor is added. The output has one row per response category, in a Response column.
  • For "cum.prob", "exc.prob" and "linear.predictor", the cut factor is added. The output has one row per threshold, in a Threshold column.
  • The estimate columns are Probability, Mean_class, Latent and Linear_predictor. These names are also added to the list of known estimate names, so coef_name is set.
  • emmeans names the response factor after the left-hand side of the formula, for example factor(y). The PR uses the same name.

For ordinal models (not brms), the default predict on the emmeans means path is now "prob". Before, the default was "response", which emmeans ignores for these models, so latent values were printed as "Probability". estimate_contrasts() and estimate_slopes() are not changed. A test pins their current output for polr.

Tests in test-ordinal.R:

  • predict = "prob" and the default, for one and two focal terms, compared with the marginaleffects backend (polr, clm), within 1e-6.
  • mean.class and latent, and the three threshold modes, compared with emmeans::emmeans() directly (polr).
  • A response written as factor(SatNum) in the formula.

The glmmTMB block keeps the version skip (needs glmmTMB >= 1.1.15.2). The NEWS entry and the predict docs are updated.

Found but not changed here:

  • estimate_means(m, "Type", backend = "emmeans", mode = "latent"), with mode passed through ..., fails with a memory error. It fails in the same way on main.
  • For nnet::multinom with predict = "prob" and the emmeans backend, every row is still 0.33, because only ordinal models get the pseudo-factor.
  • test-brms.R:26 fails at random, also on main.

… docs

- Name the response pseudo-factor after the formula's left-hand side, so
  that models with e.g. factor(y) as response no longer fail.
- Add Latent, Linear_predictor, and Mean_class to the known estimate names.
- Document the ordinal modes and the "prob" default for estimate_means().
- Check the number of matched rows in the glmmTMB test.
@strengejacke
strengejacke merged commit ff69ccb into easystats:support_emmeans_ordinal Sep 30, 2026
1 check failed
strengejacke added a commit that referenced this pull request Oct 1, 2026
* Support ordinal (argument `mode` for emmeans backend

* Return per-category and per-threshold estimates for ordinal models with the emmeans backend (#670)

* Add tests for ordinal modes with the emmeans backend (failing)

* Return per-category and per-threshold estimates for ordinal models with the emmeans backend

* Update NEWS entry for ordinal models with the emmeans backend

* Fix ordinal emmeans output for transformed responses, plot names, and docs

- Name the response pseudo-factor after the formula's left-hand side, so
  that models with e.g. factor(y) as response no longer fail.
- Add Latent, Linear_predictor, and Mean_class to the known estimate names.
- Document the ordinal modes and the "prob" default for estimate_means().
- Check the number of matched rows in the glmmTMB test.

* Update R/get_emmeans.R

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* skip test

---------

Co-authored-by: Jeffrey Girard <me@jmgirard.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants