Repository navigation
Return slopes and contrasts of each response category for brms ordinal and categorical models (emmeans backend) - #724
Merged
Conversation
…l and categorical models (emmeans backend)
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Fixes backend = "emmeans" behavior for brms ordinal/categorical models so estimate_slopes() / estimate_contrasts() return per-response-category results instead of (incorrectly) averaging across categories.
Changes:
- Adjust emmeans specs to include the
rep.measpseudo-factor for brms ordinal/categorical models when computing slopes/contrasts. - Normalize output column naming by renaming
rep.meastoResponsevia a shared helper. - Add regression tests for slopes (downloaded brms model) and contrasts (small fitted brms model).
| File | Description |
|---|---|
| tests/testthat/test-ordinal.R | Adds test asserting one slope per brms response category with emmeans backend. |
| tests/testthat/test-brms.R | Adds contrast tests for brms ordinal models across response categories. |
| R/get_emtrends.R | Adds rep.meas to specs for brms ordinal/categorical slopes; cleans response-category column name. |
| R/get_emmeans.R | Introduces .clean_brms_response_categories() helper and reuses it for emmeans output. |
| R/get_emcontrasts.R | Ensures contrasts/slopes are computed within brms response categories; cleans response-category column name. |
| NEWS.md | Documents the corrected behavior for slopes/contrasts with emmeans backend for brms ordinal/categorical. |
| DESCRIPTION | Bumps patch version. |
Review effort: Lite
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_slopes()andestimate_contrasts()gave a single slope or difference of about 0 for brms ordinal and categorical models, because emmeans averaged over the response categories. For example,estimate_slopes(insight::download_model("brms_ordinal_1"), "mpg", backend = "emmeans")returned one slope of -2.5e-17.This follows #723, which fixed
estimate_means(): therep.measpseudo-factor is added tospecs, slopes and contrasts are computed within each response category, and the column is namedResponse, as for the frequentist ordinal models.The slope test uses
insight::download_model("brms_ordinal_1"). The contrast test is intest-brms.Rand fits a small model, because none of the brms models frominsight::download_model()has a factor predictor.