Repository navigation
Fix estimate_contrasts() error for multivariate models with many observations - #685
Merged
strengejacke merged 2 commits intoOct 16, 2026
Merged
Conversation
…rvations .split_contrast_response_levels() turned a data frame or matrix response into one regex pattern per column of observed values, which fails to compile when the response has many observations. It now uses the column names of the response. Fixes easystats#682
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The fix is covered by regression tests and no unresolved issues remain.
0 open findings
What changed in this PR
Fixes estimate_contrasts() for multivariate models by using response column names instead of observed values.
Changes:
- Corrects multivariate response-level extraction.
- Adds a large
brmsregression test. - Updates NEWS and the development version.
| File | Description |
|---|---|
tests/testthat/test-brms.R |
Adds regression coverage for multivariate models. |
R/format.R |
Uses response column names for multivariate responses. |
NEWS.md |
Documents the bug fix. |
DESCRIPTION |
Increments the development version. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
estimate_contrasts()failed with "invalid regular expression" for multivariate models with many observations, for example a brms model withmvbind()..split_contrast_response_levels()reads the response withinsight::get_response(). For a multivariate model this returns a data frame (or a matrix), andas.character()turned each column into one long string of observed values. These strings were then used as regex patterns in.split_response_prefix(). With about 500 rows of full-precision values, the pattern no longer compiles. The fix uses the column names of a matrix or data frame response as the response levels, as suggested in the issue.The new test in
test-brms.Rfitsmvbind(y1, y2) ~ gon 600 rows. It fails on main with the reported error and passes with the fix:estimate_contrasts(m, "g", resp = "y1")returns the 3 contrasts, andestimate_contrasts(m, "g")splits the labels intoResponse1/Response2.Fixes #682