BootstrapGWR¶
This page documents 1 public symbols. Each entry includes its purpose, import path, full API docstring, and the maintained example that exercises it.
BootstrapGWR¶
Test GWR coefficient non-stationarity by parametric bootstrap.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.models import BootstrapGWR |
| Signature | BootstrapGWR(bandwidth: 'Union[float, int, str, None]' = 'aicc', adaptive: 'bool' = False, kernel: 'str' = 'bisquare', bandwidth_method: 'str' = 'aicc', bandwidth_range: 'Optional[Tuple[float, float]]' = None, optimization_method: 'str' = 'golden_section', fit_intercept: 'bool' = True, distance_metric: 'str' = 'euclidean', n_bootstrap: 'int' = 99, reselect_bandwidth: 'bool' = True, pvalue_method: 'str' = 'plus_one', localized_tail: 'str' = 'two-sided', store_local_bootstrap: 'bool' = False, random_state: 'Optional[Union[int, np.random.Generator]]' = None, verbose: 'bool' = False) -> 'None' |
| Maintained example | examples/models/14_bootstrap_gwr.py |
BootstrapGWR ¶
BootstrapGWR(
bandwidth: Union[float, int, str, None] = "aicc",
adaptive: bool = False,
kernel: str = "bisquare",
bandwidth_method: str = "aicc",
bandwidth_range: Optional[Tuple[float, float]] = None,
optimization_method: str = "golden_section",
fit_intercept: bool = True,
distance_metric: str = "euclidean",
n_bootstrap: int = 99,
reselect_bandwidth: bool = True,
pvalue_method: str = "plus_one",
localized_tail: str = "two-sided",
store_local_bootstrap: bool = False,
random_state: Optional[Union[int, Generator]] = None,
verbose: bool = False,
)
Test GWR coefficient non-stationarity by parametric bootstrap.
For coefficient :math:j, the modified statistic is the sample standard
deviation across locations of the fitted GWR pseudo-t values,
.. math::
T_j = \operatorname{sd}_i\left(\hat\beta_j(s_i) / \widehat{se}_j(s_i)\right).
The localised statistic compares each local coefficient with the matching coefficient from the global null model,
.. math::
t_{ij}^{\mathrm{loc}} =
\frac{\hat\beta_j(s_i)-\hat\beta_j^{\mathrm{OLS}}}
{\widehat{se}_j(s_i)}.
Bootstrap responses are generated parametrically under the OLS null as
X @ beta_ols + Normal(0, sigma_ols). By default, an automatically
selected GWR bandwidth is selected again in every bootstrap replicate, as
in GWmodel. Set reselect_bandwidth=False to condition on the
observed selected bandwidth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidth
|
Union[float, int, str, None]
|
Numeric GWR bandwidth, automatic criterion ( |
'aicc'
|
adaptive
|
bool
|
Interpret a numeric or selected bandwidth as a neighbour count. |
False
|
kernel
|
str
|
GWR spatial kernel. |
'bisquare'
|
bandwidth_method
|
str
|
Criterion used when |
'aicc'
|
bandwidth_range
|
Optional[Tuple[float, float]]
|
Optional search interval for automatic bandwidth selection. |
None
|
optimization_method
|
str
|
Bandwidth search method forwarded to :class: |
'golden_section'
|
fit_intercept
|
bool
|
Include an intercept in both GWR and OLS null models. |
True
|
distance_metric
|
str
|
Distance metric forwarded to :class: |
'euclidean'
|
n_bootstrap
|
int
|
Number of parametric bootstrap replicates. |
99
|
reselect_bandwidth
|
bool
|
Re-select an automatic bandwidth in each replicate. |
True
|
pvalue_method
|
str
|
|
'plus_one'
|
localized_tail
|
str
|
|
'two-sided'
|
store_local_bootstrap
|
bool
|
Store the full |
False
|
random_state
|
Optional[Union[int, Generator]]
|
Seed or NumPy generator for reproducible simulation. |
None
|
verbose
|
bool
|
Print bootstrap progress. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
modified_statistics_ |
Observed coefficient-wise modified statistics. |
|
modified_p_values_ |
Bootstrap right-tail p-values for the modified test. |
|
localized_statistics_ |
Observed |
|
localized_p_values_ |
Observation- and coefficient-specific bootstrap p-values. |
|
coefficients_gwr_ |
Full local parameter matrix including the intercept. |
|
coefficients_global_ |
OLS null-model parameter vector. |
|
bandwidth_ |
Bandwidth selected for the observed GWR fit. |
References
Harris, P., Brunsdon, C., Lu, B., Nakaya, T., & Charlton, M. (2017). Introducing bootstrap methods to investigate coefficient non-stationarity in spatial regression models. Spatial Statistics, 21, 241-261. https://doi.org/10.1016/j.spasta.2017.07.006
Source code in src/pygwrx/models/bootstrap_gwr.py
fit ¶
fit(
X: Union[ndarray, DataFrame],
y: Union[ndarray, Series],
coords: Union[ndarray, DataFrame],
) -> "BootstrapGWR"
Fit the observed models and run the MLR-null parametric bootstrap.
Source code in src/pygwrx/models/bootstrap_gwr.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
to_frame ¶
Return local coefficients, inference, and bootstrap p-values.
Source code in src/pygwrx/models/bootstrap_gwr.py
summary ¶
Return a plain-text summary of the bootstrap test.
Source code in src/pygwrx/models/bootstrap_gwr.py
Runnable examples used on this page¶
examples/models/14_bootstrap_gwr.py
# SPDX-FileCopyrightText: 2026 Jinghao Hu
# SPDX-License-Identifier: MIT
"""Run coefficient-wise bootstrap tests for spatial variability."""
# 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 print_model_result, spatial_regression
from pygwrx import BootstrapGWR
X, y, coords = spatial_regression(n=42, p=2)
model = BootstrapGWR(
bandwidth=22,
adaptive=True,
n_bootstrap=9,
reselect_bandwidth=False,
store_local_bootstrap=True,
random_state=0,
).fit(X, y, coords)
print_model_result(model)
print("modified_pvalues=", model.modified_p_values_)
print("localized_p_values_shape=", model.localized_p_values_.shape)