Local collinearity¶
This page documents 1 public symbols. Each entry includes its purpose, import path, full API docstring, and the maintained example that exercises it.
LocalCollinearityDiagnostics¶
Diagnose spatially varying multicollinearity in a fitted GWR model.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.diagnostics import LocalCollinearityDiagnostics |
| Signature | LocalCollinearityDiagnostics(gwr_model: Any, tolerance: float = 1e-10) -> None |
| Maintained example | examples/diagnostics/02_inference_and_collinearity.py |
LocalCollinearityDiagnostics ¶
Diagnose spatially varying multicollinearity in a fitted GWR model.
The diagnostic is intended for fitted, single-bandwidth spatial GWR-like estimators. It uses the model's training coordinates, kernel, fitted bandwidth, adaptive/fixed bandwidth setting, distance metric, and intercept setting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gwr_model
|
Any
|
Fitted GWR-like model. The model must expose |
required |
tolerance
|
float
|
Numerical tolerance used for constant columns, rank checks, and small singular values. |
1e-10
|
Notes
The following quantities are computed at every calibration location:
- local weighted correlations between predictor pairs;
- variance inflation factors (VIF), excluding the intercept;
- condition number (CN), using the actual local design matrix and therefore
including the intercept when
fit_intercept=True; - variance decomposition proportions (VDP), with axes ordered as
(location, condition component, design variable).
This implementation does not silently approximate MGWR, GTWR, STWR, SGTWR, or other multiscale/spatiotemporal weighting schemes. Those models require model-specific diagnostics.
Source code in src/pygwrx/diagnostics/collinearity.py
compute_local_correlations ¶
Return local weighted correlations for every predictor pair.
Returns:
| Type | Description |
|---|---|
ndarray
|
ndarray of shape (n_samples, n_feature_pairs): Pair order is available from |
Source code in src/pygwrx/diagnostics/collinearity.py
compute_vif ¶
Return local VIF values with shape (n_samples, n_features).
The intercept is excluded. Locally constant predictors and singular
local correlation matrices are represented by np.inf rather than
by deceptively finite pseudo-inverse values.
Source code in src/pygwrx/diagnostics/collinearity.py
compute_condition_number ¶
compute_vdp ¶
Return variance decomposition proportions.
Returns:
| Type | Description |
|---|---|
ndarray
|
ndarray of shape (n_samples, n_design_variables, n_design_variables): |
Source code in src/pygwrx/diagnostics/collinearity.py
diagnose ¶
Run and summarize the complete local collinearity diagnostic.
Source code in src/pygwrx/diagnostics/collinearity.py
to_frame ¶
Return row-wise collinearity diagnostics as a tidy table.
Source code in src/pygwrx/diagnostics/collinearity.py
summary_frame ¶
Runnable examples used on this page¶
examples/diagnostics/02_inference_and_collinearity.py
# SPDX-FileCopyrightText: 2026 Jinghao Hu
# SPDX-License-Identifier: MIT
"""Use coefficient inference, multiple-testing correction, and collinearity tools."""
# Allow this script to run directly from any working directory.
import sys
from pathlib import Path
_PROJECT_ROOT = Path(__file__).resolve().parents[2]
_EXAMPLES_ROOT = _PROJECT_ROOT / "examples"
_SRC_ROOT = _PROJECT_ROOT / "src"
for _path in (_SRC_ROOT, _EXAMPLES_ROOT):
if str(_path) not in sys.path:
sys.path.insert(0, str(_path))
import numpy as np
from _common import collinear_regression
from pygwrx import GWR
from pygwrx.diagnostics import (
LocalCollinearityDiagnostics,
ParameterInference,
adjust_pvalues,
feature_names,
parameter_inference,
parameter_significance,
)
X, y, coords = collinear_regression(n=44)
model = GWR(bandwidth=24, adaptive=True).fit(X, y, coords)
view = parameter_inference(model, "x1")
assert isinstance(view, ParameterInference)
print("feature_names=", feature_names(model))
print("inference_label=", view.label)
print(parameter_significance(model, "x1", correction="bh").head())
print("adjusted=", adjust_pvalues(np.array([0.01, 0.04, 0.2, 0.8]), method="bh"))
collinearity = LocalCollinearityDiagnostics(model)
print(collinearity.summary_frame().head())
print("vif_shape=", collinearity.compute_vif().shape)
print("vdp_shape=", collinearity.compute_vdp().shape)
print("correlation_shape=", collinearity.compute_local_correlations().shape)
print("condition_numbers=", collinearity.compute_condition_number()[:5])
print("diagnosis_keys=", sorted(collinearity.diagnose(verbose=False)))