Skip to content

Support ordinal (argument mode for emmeans backend - #669

Open
strengejacke wants to merge 3 commits into
mainfrom
support_emmeans_ordinal
Open

strengejacke wants to merge 3 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

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.

…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.
Comment thread tests/testthat/test-ordinal.R
Comment thread tests/testthat/test-ordinal.R
Comment thread tests/testthat/test-ordinal.R
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment thread R/get_emmeans.R

This branch has not been deployed

No deployments
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