LCRGWR¶
This page documents 1 public symbols. Each entry includes its purpose, import path, full API docstring, and the maintained example that exercises it.
LCRGWR¶
Locally compensated ridge geographically weighted regression.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.models import LCRGWR |
| Signature | LCRGWR(kernel: 'Union[str, Callable[[np.ndarray, float], np.ndarray]]' = 'bisquare', bandwidth: 'Union[float, int, str, None]' = 'cv', bandwidth_method: 'str' = 'cv', adaptive: 'bool' = False, bandwidth_range: 'Optional[Tuple[float, float]]' = None, optimization_method: 'str' = 'golden_section', lambda_ridge: 'float' = 0.0, lambda_adjust: 'bool' = True, cn_thresh: 'float' = 30.0, fit_intercept: 'bool' = True, distance_metric: 'str' = 'euclidean', sigma2_v1: 'bool' = True, verbose: 'bool' = False) -> 'None' |
| Maintained example | examples/models/13_lcr_gwr.py |
LCRGWR ¶
LCRGWR(
kernel: Union[
str, Callable[[ndarray, float], ndarray]
] = "bisquare",
bandwidth: Union[float, int, str, None] = "cv",
bandwidth_method: str = "cv",
adaptive: bool = False,
bandwidth_range: Optional[Tuple[float, float]] = None,
optimization_method: str = "golden_section",
lambda_ridge: float = 0.0,
lambda_adjust: bool = True,
cn_thresh: float = 30.0,
fit_intercept: bool = True,
distance_metric: str = "euclidean",
sigma2_v1: bool = True,
verbose: bool = False,
)
Bases: GWR
Locally compensated ridge geographically weighted regression.
LCR-GWR diagnoses local collinearity from the weighted design matrix and
applies a location-specific ridge parameter only where the local condition
number exceeds a user-defined threshold. The compensation rule follows the
implementation in GWmodel::gwr.lcr::
lambda_i = (d_max - kappa_star * d_min) / (kappa_star - 1),
where d_max and d_min are the largest and smallest singular values
of the column-normalized, locally weighted design matrix, and
kappa_star is cn_thresh.
The local coefficient estimator uses the GWmodel scaling convention. With
A = diag(1 / x_scale) and local spatial weights W_i, the estimator is
.. math::
\hat\beta_i = A\left(A X^T W_i X A + \lambda_i I\right)^{-1}
A X^T W_i y.
Unlike the historical GWmodel diagnostics, pyGWRx constructs the hat matrix from the actual penalized estimator. Consequently, trace statistics, effective degrees of freedom, information criteria, influence, and standard errors remain internally consistent when a ridge term is active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Union[str, Callable[[ndarray, float], ndarray]]
|
Spatial kernel name or callable. |
'bisquare'
|
bandwidth
|
Union[float, int, str, None]
|
Fixed distance, adaptive neighbour count, |
'cv'
|
bandwidth_method
|
str
|
Automatic selection criterion. Only |
'cv'
|
adaptive
|
bool
|
Interpret the bandwidth as an integer neighbour count. |
False
|
bandwidth_range
|
Optional[Tuple[float, float]]
|
Optional lower and upper bandwidth-search bounds. |
None
|
optimization_method
|
str
|
|
'golden_section'
|
lambda_ridge
|
float
|
Constant ridge parameter used at every location before
optional local compensation. The GWmodel default is |
0.0
|
lambda_adjust
|
bool
|
Whether to replace |
True
|
cn_thresh
|
float
|
Maximum desired local condition number. Values from 20 to 30 are common in the LCR-GWR literature. |
30.0
|
fit_intercept
|
bool
|
Whether to include a local intercept. |
True
|
distance_metric
|
str
|
Distance metric used to construct spatial weights. |
'euclidean'
|
sigma2_v1
|
bool
|
Residual-variance convention inherited from :class: |
True
|
verbose
|
bool
|
Whether to print fit and bandwidth-selection progress. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
condition_numbers_ |
Local pre-compensation condition numbers using the GWmodel/Belsley column-normalization convention. |
|
local_lambda_ |
Ridge parameter used at each calibration location. |
|
compensated_condition_numbers_ |
Condition numbers implied by the GWmodel compensation formula. |
|
penalized_system_condition_numbers_ |
Numerical condition numbers of the actual penalized normal systems used for estimation. |
|
locally_compensated_mask_ |
Boolean mask identifying locations where the threshold-triggered local compensation was applied. |
|
ridge_applied_mask_ |
Boolean mask identifying all locations with a positive ridge parameter. |
|
cv_residuals_ |
Leave-one-out residuals when |
|
cv_contributions_ |
Squared leave-one-out residuals. |
|
bandwidth_cv_score_ |
Sum of squared leave-one-out residuals for the selected or supplied bandwidth when available. |
Notes
The reference GWmodel routine penalizes the intercept together with the slopes. This implementation preserves that convention for numerical comparability.
condition_numbers_ are diagnostics of the unpenalized local design;
they are therefore expected to remain above cn_thresh at affected
locations. Use compensated_condition_numbers_ or
penalized_system_condition_numbers_ to inspect post-penalty systems.
References
Wheeler, D. C. (2007). Diagnostic tools and a remedial method for collinearity in geographically weighted regression. Environment and Planning A, 39(10), 2464-2481.
Gollini, I., Lu, B., Charlton, M., Brunsdon, C., and Harris, P. (2015). GWmodel: An R package for exploring spatial heterogeneity using geographically weighted models. Journal of Statistical Software, 63(17), 1-50.
Source code in src/pygwrx/models/lcr_gwr.py
fit ¶
fit(
X: Union[ndarray, DataFrame],
y: Union[ndarray, Series],
coords: Union[ndarray, DataFrame],
*,
compute_hat_matrix: bool = True,
compute_local_r2: bool = True,
compute_inference: bool = True,
compute_cv: bool = True,
verbose: Optional[bool] = None
) -> "LCRGWR"
Fit LCR-GWR and return self.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Union[ndarray, DataFrame]
|
Predictor matrix with shape |
required |
y
|
Union[ndarray, Series]
|
Response vector with shape |
required |
coords
|
Union[ndarray, DataFrame]
|
Spatial coordinates with shape |
required |
compute_hat_matrix
|
bool
|
Whether to retain the complete penalized smoother matrix. Trace statistics are always computed. |
True
|
compute_local_r2
|
bool
|
Whether to compute local coefficients of determination. |
True
|
compute_inference
|
bool
|
Whether to compute local standard errors and t values. |
True
|
compute_cv
|
bool
|
Whether to compute leave-one-out residuals at the final bandwidth. |
True
|
verbose
|
Optional[bool]
|
Optional per-fit override of the estimator verbosity. |
None
|
Returns:
| Type | Description |
|---|---|
'LCRGWR'
|
The fitted estimator. |
Source code in src/pygwrx/models/lcr_gwr.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 | |
predict_result ¶
predict_result(
X: Union[ndarray, DataFrame],
coords: Union[ndarray, DataFrame],
) -> GWRPredictionResult
Predict responses and return local parameters and inference results.
Source code in src/pygwrx/models/lcr_gwr.py
get_local_diagnostics ¶
Return condition numbers and ridge parameters at target locations.
Source code in src/pygwrx/models/lcr_gwr.py
to_frame ¶
Return standard GWR outputs plus LCR diagnostics.
Source code in src/pygwrx/models/lcr_gwr.py
summary ¶
Return a stable text summary of the LCR-GWR fit.
Source code in src/pygwrx/models/lcr_gwr.py
Runnable examples used on this page¶
examples/models/13_lcr_gwr.py
# SPDX-FileCopyrightText: 2026 Jinghao Hu
# SPDX-License-Identifier: MIT
"""Fit locally compensated ridge GWR for collinear predictors."""
# 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))
from _common import collinear_regression, print_model_result
from pygwrx import LCRGWR
X, y, coords = collinear_regression()
model = LCRGWR(bandwidth=28, adaptive=True, cn_thresh=15.0, lambda_adjust=True).fit(
X, y, coords
)
print_model_result(model)
print("local_condition_numbers=", model.local_condition_numbers_[:5])
print("local_lambdas=", model.local_lambdas_[:5])