Multicollinearity diagnostics + GLM χ² (#27 batch 4) - #31
Merged
Conversation
Add 4 diagnostic expressions following the established pattern from
batches 1-3:
- high_vif_predictors_fit + pl_high_vif_predictors: boolean mask of
features whose VIF exceeds the threshold (default 10.0). Computes
VIF internally then thresholds.
- generalized_vif_fit + pl_generalized_vif: VIF generalized to
grouped predictors (e.g. categorical dummies). Takes a
comma-separated `group_sizes` string parsed in Rust.
- pearson_chi_squared_logistic_fit + pl_pearson_chi_squared_logistic:
Σ pearson_residual² from a logistic fit, plus df_resid and
n_observations.
- pearson_chi_squared_poisson_fit + pl_pearson_chi_squared_poisson:
same for Poisson.
Three new struct output schemas:
vif_mask_output_dtype{is_high: List<Bool>, n_high, n_features}
gvif_output_dtype{gvif: List<Float64>, n_groups}
chi_squared_output_dtype{chi_squared: Float64, df_resid, n_observations}
Python (exprs/regression.py): high_vif_predictors, generalized_vif,
pearson_chi_squared_logistic, pearson_chi_squared_poisson — all
exported from the top-level package.
Tests:
tests/test_mc_dispersion.py: 9 pytests covering shape, threshold
behaviour, GVIF group bookkeeping, and χ²/df_resid magnitude on
well-specified data.
tests/rust_api.rs: 4 smoke-test blocks added to diagnostic_fits.
Full Python suite: 457/457 pass (448 prior + 9 new).
Rust integration: 12/12 pass.
Deferred to a final small follow-up: estimate_dispersion_pearson,
estimate_dispersion_deviance, classify_condition_number,
variance_decomposition_proportions, probit/cloglog/negative_binomial/
tweedie residual variants, standardized Pearson/deviance residuals.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced May 28, 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.
Batch 4 of 4 for #27. Adds 4 multicollinearity + dispersion-related diagnostics.
Implemented
All four follow the rlib split pattern. The Pearson χ² statistics are just
Σ pearson_residual²— reusing batch-2 plumbing without needing the genericGlmFamilytrait.Tests
tests/test_mc_dispersion.py, 9 new pytests:[2, 3]returns 2 GVIF values.tests/rust_api.rs: 4 smoke tests appended todiagnostic_fits.Full Python suite: 457/457 pass (448 prior + 9 new). Rust integration: 12/12 pass.
Issue #27 status after this PR
This completes the user-facing scope I had time for. Remaining items I intentionally deferred:
estimate_dispersion_pearson/estimate_dispersion_deviance— trivially computed from χ²/df_resid, so callers can derive them from this PR's output.classify_condition_number—ConditionSeverityis already returned by the existingcondition_numberdiagnostic.variance_decomposition_proportions(Belsley-Kuh-Welsch) — returns a full Mat, needs a more complex output schema.*_pearson_residuals/*_deviance_residuals/*_working_residualstriple for each family, ~12 more functions.Recommend closing #27 with this PR and filing a smaller follow-up issue for the GLM extensions if/when there's demand.
Test plan
cargo build --no-default-featurescleancargo clippy --all-targets -- -D warningscleancargo fmt --checkcleancargo test --no-default-features— 12/12 passpytest— 457/457 pass🤖 Generated with Claude Code