Repository navigation
Return probabilities of each response category for brms ordinal and categorical models (emmeans backend) - #723
Merged
Conversation
…s (emmeans backend)
Contributor
There was a problem hiding this comment.
🟢 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.measto theemmeansspecifications for ordinalbrmsmodels. - 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
| skip_if(is.null(m)) | ||
|
|
||
| # one probability per response category | ||
| out <- suppressWarnings(estimate_means(m, "Sepal.Width", length = 3, backend = "emmeans")) |
Contributor
There was a problem hiding this comment.
[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" | |
| )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
backend = "emmeans",estimate_means()gave 0.33 for every row of a brms ordinal or categorical model (for exampleinsight::download_model("brms_ordinal_1")or"brms_categorical_2_num"), with noResponsecolumn. Withepred = TRUE, brms adds the response categories to the reference grid as the pseudo-factorrep.meas, and emmeans averaged over it.rep.measis now added tospecsfor brms ordinal and categorical models and renamed toResponse, 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).