Skip to content

Fix estimate_contrasts() error for multivariate models with many observations - #685

Merged
strengejacke merged 2 commits into
easystats:mainfrom
jmgirard:hotfix-multivariate-brms-contrasts
Oct 16, 2026
Merged

strengejacke merged 2 commits into
easystats:mainfrom
jmgirard:hotfix-multivariate-brms-contrasts

Conversation

@jmgirard

Copy link
Copy Markdown
Contributor

estimate_contrasts() failed with "invalid regular expression" for multivariate models with many observations, for example a brms model with mvbind().

.split_contrast_response_levels() reads the response with insight::get_response(). For a multivariate model this returns a data frame (or a matrix), and as.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.R fits mvbind(y1, y2) ~ g on 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, and estimate_contrasts(m, "g") splits the labels into Response1/Response2.

Fixes #682

…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

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

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 brms regression 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.

@strengejacke
strengejacke merged commit ba44428 into easystats:main Oct 16, 2026
9 of 18 checks passed
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.

Bug: estimate_contrasts() fails for multivariate brmsfit models due to incorrect response-level extraction

3 participants