Skip to content

Return probabilities of each response category for brms ordinal and categorical models (emmeans backend) - #723

Merged
strengejacke merged 2 commits into
mainfrom
hotfix-brms-ordinal-emmeans-prob
Nov 26, 2026
Merged

strengejacke merged 2 commits into
mainfrom
hotfix-brms-ordinal-emmeans-prob

Conversation

@jmgirard

@jmgirard jmgirard commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

With backend = "emmeans", estimate_means() gave 0.33 for every row of a brms ordinal or categorical model (for example insight::download_model("brms_ordinal_1") or "brms_categorical_2_num"), with no Response column. With epred = TRUE, brms adds the response categories to the reference grid as the pseudo-factor rep.meas, and emmeans averaged over it.

rep.meas is now added to specs for brms ordinal and categorical models and renamed to Response, so the output has one probability per response category. The values match the marginaleffects backend. Contrasts and slopes are unchanged.

The new tests compare the probabilities with emmeans::emmeans(..., epred = TRUE).

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.

🟢 Approval recommended

No active review issues remain, and the change includes targeted regression coverage for the corrected ordinal brms response-category probabilities.

No open issues 🎉

What changed in this PR

Updates the emmeans backend so ordinal brms models return one probability per response category instead of averaging across categories.

Changes:

  • Adds rep.meas to the emmeans specifications for ordinal brms models.
  • Renames the response-category column to Response.
  • Adds regression coverage, NEWS documentation, and a development version bump.
File Description
tests/​testthat/​test-ordinal.R Adds regression tests comparing ordinal brms response-category probabilities with direct emmeans(..., epred = TRUE) results.
R/​get_emmeans.R Adds ordinal brms response-category handling and renames the resulting column to Response.
NEWS.md Documents the corrected ordinal brms probability behavior.
DESCRIPTION Increments the development package version.

Review effort: Lite

@jmgirard jmgirard changed the title Return probabilities of each response category for brms ordinal models (emmeans backend) Return probabilities of each response category for brms ordinal and categorical models (emmeans backend) Nov 26, 2026
skip_if(is.null(m))

# one probability per response category
out <- suppressWarnings(estimate_means(m, "Sepal.Width", length = 3, backend = "emmeans"))

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.

[air] reported by reviewdog 🐶

Suggested change
out <- suppressWarnings(estimate_means(m, "Sepal.Width", length = 3, backend = "emmeans"))
out <- suppressWarnings(estimate_means(
m,
"Sepal.Width",
length = 3,
backend = "emmeans"
))

@strengejacke
strengejacke merged commit d232c26 into main Nov 26, 2026
10 of 20 checks passed
@strengejacke
strengejacke deleted the hotfix-brms-ordinal-emmeans-prob branch November 26, 2026 07:09
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