Skip to content

Fix term labels in check_collinearity() for brms models with 0 + Intercept syntax - #958

Open
jmgirard wants to merge 1 commit into
mainfrom
hotfix-brms-intercept-collinearity
Open

jmgirard wants to merge 1 commit into
mainfrom
hotfix-brms-intercept-collinearity

Conversation

@jmgirard

Copy link
Copy Markdown
Contributor

For brms models fit with y ~ 0 + Intercept + x1 + x2 + ..., check_collinearity() took the term labels from labels(terms(formula)), which includes Intercept as a term. The intercept column is already dropped from the covariance matrix and the term assignment, so each VIF was shown under the name of the previous term, an Intercept row appeared, and the last term was missing. The VIF values themselves were correct.

m <- brms::brm(mpg ~ 0 + Intercept + cyl + disp + hp, data = mtcars)
check_collinearity(m)
#> before: Intercept, cyl, disp  (values belong to cyl, disp, hp)
#> after:  cyl, disp, hp

The fix removes the Intercept pseudo-term from the term labels for brmsfit models. The "Model without intercept" alert from the original report no longer fires, because insight::has_intercept() now recognizes this syntax.

A regression test fits the model above (guarded by skip_on_cran() and skip_if_not_installed("brms"), since it compiles a Stan model). It checks the term labels and compares the VIFs with the ones computed from the slope correlation matrix.

Fixes #417

…rcept syntax

brms formulas like y ~ 0 + Intercept + x list "Intercept" as a term label,
so each VIF was shown under the previous term's name and the last term was
dropped. Remove the Intercept pseudo-term from the term labels for brmsfit
models.

Fixes #417

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 all reviewed changes are ready for approval.

0 open findings

What changed in this PR

Fixes incorrect VIF term labels for brms models using 0 + Intercept syntax.

Changes:

  • Removes the pseudo-Intercept term from labels.
  • Adds guarded regression coverage for labels and VIFs.
  • Updates NEWS.md and the development version.
File Description
tests/​testthat/​test-check_collinearity.R Adds regression coverage.
R/​check_collinearity.R Corrects brms term-label alignment.
NEWS.md Documents the fix.
DESCRIPTION Bumps 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 branch has not been deployed

No deployments
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.

check_colinearity() returns warning for no intercept with 0 + Intercept syntax in {brms}

2 participants