MGTWR¶
This page documents 1 public symbols. Each entry includes its purpose, import path, full API docstring, and the maintained example that exercises it.
MGTWR¶
Gaussian multiscale geographically and temporally weighted regression.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.models import MGTWR |
| Signature | MGTWR(bandwidths: 'BandwidthInput' = None, taus: 'TauInput' = None, *, kernel: 'str' = 'bisquare', adaptive: 'bool' = True, fit_intercept: 'bool' = True, bandwidth_method: 'str' = 'aicc', bandwidth_range: 'BandwidthRange' = None, tau_range: 'Tuple[float, float]' = (0.0, 4.0), init_bandwidth: 'Optional[Bandwidth]' = None, init_tau: 'Optional[float]' = None, tol: 'float' = 1e-06, tol_multi: 'float' = 1e-05, max_iter: 'int' = 200, rss_score: 'bool' = False, calculate_inference: 'bool' = True, n_chunks: 'int' = 1, verbose: 'bool' = False) -> 'None' |
| Maintained example | examples/models/17_mgtwr.py |
MGTWR ¶
MGTWR(
bandwidths: BandwidthInput = None,
taus: TauInput = None,
*,
kernel: str = "bisquare",
adaptive: bool = True,
fit_intercept: bool = True,
bandwidth_method: str = "aicc",
bandwidth_range: BandwidthRange = None,
tau_range: Tuple[float, float] = (0.0, 4.0),
init_bandwidth: Optional[Bandwidth] = None,
init_tau: Optional[float] = None,
tol: float = 1e-06,
tol_multi: float = 1e-05,
max_iter: int = 200,
rss_score: bool = False,
calculate_inference: bool = True,
n_chunks: int = 1,
verbose: bool = False
)
Bases: MGWR
Gaussian multiscale geographically and temporally weighted regression.
MGTWR represents the response as a sum of coefficient-specific spatiotemporal terms. Each fitted parameter receives an independent spatial bandwidth and temporal scale parameter. Calibration starts from a common GTWR fit and then updates one additive term at a time from its partial residual until the score of change converges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidths
|
BandwidthInput
|
Optional scalar or one spatial bandwidth per fitted
parameter. The fitted parameter count includes the intercept when
|
None
|
taus
|
TauInput
|
Optional scalar or one non-negative temporal scale per fitted
parameter. It must be supplied together with |
None
|
kernel
|
str
|
|
'bisquare'
|
adaptive
|
bool
|
Interpret spatial bandwidths as integer nearest-neighbour counts in combined spatiotemporal distance. |
True
|
fit_intercept
|
bool
|
Include a spatiotemporally varying intercept. |
True
|
bandwidth_method
|
str
|
Scale-selection criterion: |
'aicc'
|
bandwidth_range
|
BandwidthRange
|
Common lower and upper spatial bandwidth bounds for automatic selection. |
None
|
tau_range
|
Tuple[float, float]
|
Common lower and upper temporal-scale bounds for automatic selection. |
(0.0, 4.0)
|
init_bandwidth
|
Optional[Bandwidth]
|
Optional common spatial bandwidth for the initial GTWR fit. |
None
|
init_tau
|
Optional[float]
|
Optional common temporal scale for the initial GTWR fit. |
None
|
tol
|
float
|
Resolution target used by the deterministic two-dimensional scale search. |
1e-06
|
tol_multi
|
float
|
Backfitting score-of-change convergence tolerance. |
1e-05
|
max_iter
|
int
|
Maximum number of backfitting iterations. |
200
|
rss_score
|
bool
|
Use relative RSS change instead of smooth-function change as the convergence score. |
False
|
calculate_inference
|
bool
|
Compute exact smoother traces, effective parameter counts, local standard errors, and information criteria. |
True
|
n_chunks
|
int
|
Number of column chunks used by exact smoother inference. |
1
|
verbose
|
bool
|
Print scale-search and backfitting progress. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
bandwidths_ |
Optional[ndarray]
|
Final variable-specific spatial bandwidths. |
taus_ |
Optional[ndarray]
|
Final variable-specific temporal scale parameters. |
temporal_bandwidths_ |
Optional[ndarray]
|
Equivalent temporal bandwidths, computed as
|
bandwidth_history_ |
Optional[ndarray]
|
Spatial bandwidth vector from every iteration. |
tau_history_ |
Optional[ndarray]
|
Temporal-scale vector from every iteration. |
convergence_history_ |
Optional[Any]
|
Score of change from every iteration. |
params_ |
Optional[Any]
|
Local parameters including the intercept when fitted. |
effective_params_by_variable_ |
Optional[Any]
|
Exact effective parameter count for each coefficient surface when inference is enabled. |
parameter_standard_errors_ |
Optional[Any]
|
Local parameter standard errors when inference is enabled. |
parameter_t_values_ |
Optional[Any]
|
Local parameter t statistics when inference is enabled. |
Notes
Automatic scale selection uses a deterministic coarse-to-fine candidate
search with explicit boundary evaluation; it is not an exhaustive proof
of the global optimum. The numerical interpretation of tau depends
on the coordinate and time units. Independent-target prediction is not
exposed because a stable MGTWR prediction operator for independently
supplied locations is not yet part of the package contract. Use
fitted_values_ for calibration-location estimates.
References
Wu, C., Ren, F., Hu, W., and Du, Q. (2019). Multiscale geographically and temporally weighted regression: exploring the spatiotemporal determinants of housing prices. International Journal of Geographical Information Science, 33(3), 489-511.
Source code in src/pygwrx/models/mgtwr.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
fit ¶
Fit MGTWR and replace all prior fitted state atomically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
Predictor matrix with shape |
required |
y
|
VectorLike
|
Response vector with shape |
required |
coords
|
ArrayLike
|
Spatial coordinates with shape |
required |
times
|
VectorLike
|
Numeric time coordinate with one value per observation. |
required |
Returns:
| Type | Description |
|---|---|
'MGTWR'
|
The fitted model instance. |
Source code in src/pygwrx/models/mgtwr.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 | |
predict ¶
Reject unsupported independent-target prediction.
Source code in src/pygwrx/models/mgtwr.py
to_frame ¶
Return calibration-location parameters and diagnostics.
Source code in src/pygwrx/models/mgtwr.py
summary ¶
Return fitted model diagnostics as a plain-text table.
Source code in src/pygwrx/models/mgtwr.py
Runnable examples used on this page¶
examples/models/17_mgtwr.py
# SPDX-FileCopyrightText: 2026 Jinghao Hu
# SPDX-License-Identifier: MIT
"""Fit the self-contained multiscale geographically and temporally weighted regression."""
# 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, temporal_regression
from pygwrx import MGTWR
X, y, coords, times = temporal_regression(n=20, p=2)
model = MGTWR(
bandwidths=[12, 12, 12],
taus=[1.0, 1.0, 1.0],
adaptive=True,
calculate_inference=False,
).fit(X, y, coords, times)
print_model_result(model)
print("spatial_bandwidths=", model.bandwidths_)
print("temporal_scales=", model.taus_)
try:
model.predict(X.iloc[:2], coords.iloc[:2], times[:2])
except NotImplementedError as exc:
print("Expected MGTWR prediction limitation:", exc)