Repository navigation
Fix the VIFs of the zero-inflation component of glmmTMB models in check_collinearity() - #991
Merged
strengejacke merged 4 commits intoOct 19, 2026
Merged
Conversation
… `check_collinearity()`, and note the pscl fix in NEWS
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Handle intercept detection for ziformula = ~1 when the conditional formula omits its intercept.
No open issues 🎉
What changed in this PR
Fixes incorrect zero-inflation VIF calculations for glmmTMB and pscl models.
Changes:
- Uses component-specific model matrices and intercept handling.
- Improves diagnostics and
verbosebehavior. - Adds regression tests and updates package metadata.
| File | Summary |
|---|---|
tests/testthat/test-check_collinearity.R |
Adds zero-inflation regression coverage. |
R/check_collinearity.R |
Corrects component handling and diagnostics. |
NEWS.md |
Documents the fixes. |
DESCRIPTION |
Updates the development version. |
Review effort: Lite
… = ~1` from its model matrix in `check_collinearity()`
Contributor
Author
|
Copilot summary point addressed in f3924c7: for |
strengejacke
approved these changes
Oct 19, 2026
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.
check_collinearity()gave wrong VIFs for the zero-inflation component of glmmTMB models whose zero-inflation formula differs from the conditional formula..zi_term_assignment()calledinsight::get_modelmatrix()on a formula and got no "assign" attribute, so.term_assignments()fell back to the term blocks of the conditional formula.An example is a poisson model with
ziformula = ~ x2 + x1 + f, wherefhas three levels. Withy ~ x1, main returns one row,x2, with the VIF ofx1. Withy ~ x1 + f, thex2row has the VIF ofx1, and thex1row has the VIF off. There is nofrow.What changes
model.matrix(x, component = "zi"). glmmTMB 1.1.12, the minimum in DESCRIPTION, has this argument. If the call fails, the component gets the "Could not extract model terms" alert, not the conditional blocks.insight::has_intercept()decided this from the conditional formula, soziformula = ~ 0 + x2 + x1 + flost itsx2row.component = "all"andverbose = TRUE, a message says so. Before, the zero-inflation part was checked withverbose = FALSEand dropped with no message. glmmTMB models withziformula = ~0stay silent.hurdle,zeroinfl, andzerocountmethods had the defaultverbose = verbose. If a message was due for these models on main, for example forzeroinfl(y ~ x1 | x2 + x1), the call failed with "promise already under evaluation". The default is nowTRUE.Tests
ziformula = ~ x2 + x1 + fand the conditional formulasy ~ x1,y ~ x1 + f, andy ~ f + x2. Four more zero-inflation formulas:~ log(x2 + 5) + x1 + f,~ x2 * f + x1,~ x2 + x1 + f + (1 | g), and~ x2 + x1 + fwith missing values inx2. Each VIF equals the generalized VIF computed directly fromcov2cor(vcov(m)$zi), within 1e-8.verbose = FALSE.zeroinfl()andhurdle()with the defaultverbose, and their zero-inflation VIFs against the direct computation. The VIF tests pass on main too.The new glmmTMB tests and the pscl
verbosetests fail on main and pass with this change. The full test suite has one failure, "test_performance - lavaan" in test-test_performance.R, which also fails on main with lavaan 0.7.2.