Skip to content

Support ordinal (argument mode for emmeans backend - #669

Merged
strengejacke merged 4 commits into
mainfrom
support_emmeans_ordinal
Oct 1, 2026
Merged

strengejacke merged 4 commits into
mainfrom
support_emmeans_ordinal

Conversation

@strengejacke

@strengejacke strengejacke commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

@jmgirard is there something I am missing, or is this the expected output? For polr::MASS, the result is the same. Not sure I'm missing a combination of mode and type arguments, or how are ordinal models handled?

data(housing, package = "MASS")
m <- glmmTMB::glmmTMB(Sat ~ Infl + Type + Cont, data = housing, family = glmmTMB::ordinal())

emmeans::emmeans(m, "Type", mode = "prob")
#>  Type       prob SE  df asymp.LCL asymp.UCL
#>  Tower     0.333  0 Inf     0.333     0.333
#>  Apartment 0.333  0 Inf     0.333     0.333
#>  Atrium    0.333  0 Inf     0.333     0.333
#>  Terrace   0.333  0 Inf     0.333     0.333
#> 
#> Results are averaged over the levels of: Sat, Infl, Cont 
#> Confidence level used: 0.95

Created on 2026-09-30 with reprex v2.1.1

@jmgirard

Copy link
Copy Markdown
Contributor

The 0.333 values are expected emmeans behavior. With mode = "prob", emmeans adds the response (Sat) to the reference grid as a pseudo-factor, and emmeans(m, "Type", mode = "prob") averages over it. The three category probabilities sum to 1, so each average is 1/3. emmeans(m, ~ Type | Sat, mode = "prob") gives the per-category probabilities, and these match estimate_means(m, "Type") with the marginaleffects backend (difference below 1e-15 for polr and clm). The cum.prob, exc.prob, and linear.predictor modes add a cut pseudo-factor in the same way, so get_emmeans() needs to add that pseudo-factor to specs. Separately, on main the emmeans backend returns latent-scale values labeled "Probability" for polr, because emmeans ignores type = "response" for these models. I will open a PR into this branch with a fix.

jmgirard and others added 2 commits September 30, 2026 23:43
…th 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.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment thread R/get_emmeans.R

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.

Copilot review overview

🟡 Changes recommended

Resolve ordinal mode handling, preserve non-ordinal behavior, correct inherited documentation, and ensure tests run independently.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds ordinal-model support for the emmeans backend in estimate_means(), with updated output handling, tests, documentation, NEWS, and version metadata.

Changes:

  • Routes ordinal predictions through emmeans modes.
  • Normalizes ordinal output columns.
  • Adds ordinal backend tests and documentation updates.
File Summary
tests/​testthat/​test-ordinal.R Adds ordinal backend coverage.
R/​utils.R Adds ordinal estimate column names.
R/​get_emmeans.R Implements ordinal mode handling and formatting.
R/​estimate_means.R Documents ordinal prediction modes.
NEWS.md Records the new functionality.
man/​get_emmeans.Rd Updates generated documentation.
man/​estimate_slopes.Rd Updates inherited documentation.
man/​estimate_means.Rd Updates generated documentation.
man/​estimate_contrasts.Rd Updates inherited documentation.
DESCRIPTION Increments the package version.
Files not reviewed (4)
  • man/estimate_contrasts.Rd: Generated file
  • man/estimate_means.Rd: Generated file
  • man/estimate_slopes.Rd: Generated file
  • man/get_emmeans.Rd: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread R/get_emmeans.R
@strengejacke
strengejacke merged commit e6e1f18 into main Oct 1, 2026
10 of 20 checks passed
@strengejacke
strengejacke deleted the support_emmeans_ordinal branch October 1, 2026 11:00
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