This vignette introduces advanced estimation methods for Geographically Weighted Regression (GWR) that allow bandwidths to vary by covariate and adapt locally. While Multiscale GWR (MGWR) significantly improves upon standard GWR by allowing different spatial scales for different relationships, its standard backfitting implementation can be computationally intensive and prone to instability on large datasets or with complex spatial patterns.
To address these limitations, we introduce the Top-Down Scale
(TDS) framework, described in Geniaux (2026), which
includes three algorithms implemented in mgwrsar:
GWmodel), utilizing
mgwrsar’s efficient computational framework.tds_mgwr estimates and refines
them using a gradient boosting-like algorithm on
residuals. This allows for locally adaptive bandwidths,
capturing multiple spatial scales simultaneously for a single variable
(e.g., global trends mixed with local heterogeneity).Note: The TDS and ATDS algorithms involve frequent computation of
the hat matrix. mgwrsar includes approximation methods to
speed up these calculations.
We use the Data Generating Process (DGP) proposed by Geniaux (2026), designed to exhibit complex spatial structures that challenge standard estimators.
# Simulation setup
n <- 1000
# Simulate DGP 'GG2025' from the article
simu1 <- simu_multiscale(n, myseed = 1, config_snr = 0.7,
config_beta = 'default', config_eps = 'normal')
mydata <- simu1$mydata
coords <- simu1$coords
# Extract True Betas for RMSE calculation
TRUEBETA <- as.matrix(mydata[, c('Beta1', 'Beta2', 'Beta3', 'Beta4')], ncol = 4)
myformula <- as.formula('Y ~ X1 + X2 + X3')
(Note: Ensure the image DGPs.jpeg is in your
vignette directory, or the code below will need adjustment)
We start with a standard GWR (single bandwidth for all variables) to serve as a baseline.
# GWR Benchmark (using the whole dataset)
res1 <- golden_search_bandwidth(
formula = myformula,
data = mydata,
coords = coords,
fixed_vars = NULL,
kernels = c('gauss'),
Model = 'GWR',
control = list(verbose = FALSE, criterion = 'AICc', adaptive = FALSE),
lower.bound = 0,
upper.bound = 1,
show_progress = F,
tolerance = 0.001
)
summary(res1$best_model)
## ------------------------------------------------------
## Call:
## MGWRSAR(formula = formula, data = data, coords = coords, fixed_vars = fixed_vars,
## kernels = kernels, H = c(res, Ht), Model = Model, control = control_o)
##
## Model: GWR
## ------------------------------------------------------
## Kernels Configuration:
## Spatial Kernel : gauss (Fixed / Distance)
## ------------------------------------------------------
## Bandwidth Configuration:
## Spatial Bandwidth (H): 0.06
## ------------------------------------------------------
## Model Settings:
## Computation time: 0.091 sec
## Use of Target Points: NO
## Use of rough kernel approximation: NO
## Parallel computing: (ncore = 1)
## Number of data points: 1000
## ------------------------------------------------------
## Coefficients Summary:
## [Varying Parameters]
## Intercept X1 X2 X3
## Min. :-1.411 Min. :-1.245 Min. :-2.7764 Min. :-4.228415
## 1st Qu.: 1.098 1st Qu.: 1.135 1st Qu.:-0.3842 1st Qu.:-1.352400
## Median : 2.047 Median : 2.175 Median : 0.2250 Median : 0.163245
## Mean : 1.951 Mean : 2.229 Mean : 0.1870 Mean :-0.001153
## 3rd Qu.: 2.600 3rd Qu.: 3.157 3rd Qu.: 0.7723 3rd Qu.: 1.266348
## Max. : 5.973 Max. : 5.532 Max. : 2.9444 Max. : 4.341593
## ------------------------------------------------------
## Diagnostics:
## Effective degrees of freedom: 805.27
## AICc: 5660.23
## Residual sum of squares: 10348.86
## RMSE: 3.217
## ------------------------------------------------------
# Performance Metrics
Beta_RMSE_GWR <- apply((res1$best_model@Betav - TRUEBETA), 2, rmse)
cat("Mean Beta RMSE (GWR):", mean(Beta_RMSE_GWR), "\n")
## Mean Beta RMSE (GWR): 1.046707
cat("AICc (GWR):", res1$best_model@AICc, "\n")
## AICc (GWR): 5660.233
The GWR model finds a global bandwidth. However, if the underlying relationships operate at different scales, this single bandwidth will be a suboptimal compromise.
multiscale_gwr)The multiscale_gwr function implements the classic
backfitting algorithm (Fotheringham et al., 2017). *
Optimization: Optimizes bandwidth for each covariate at
every iteration using a golden-section search. * Stopping
Criteria: Based on the stability of bandwidths and relative
change in RMSE. * AICc: Computed using the method by Yu
et al. (2020).
model_ms_gwr <- multiscale_gwr(
formula = myformula,
data = mydata,
coords = coords,
kernels = 'gauss',
control_mgwr = list(verbose = FALSE, get_AIC = TRUE, init = 'GWR',
nstable = 5, tolerance = 0.0001),
control = list(adaptive = FALSE, verbose = FALSE)
)
summary(model_ms_gwr)
## ------------------------------------------------------
## Call:
## MGWRSAR(formula = myformula, data = data, coords = coords, fixed_vars = NULL,
## kernels = kernels, H = c(h, Ht), Model = "multiscale_gwr",
## control = control)
##
## Model: multiscale_gwr
## ------------------------------------------------------
## Kernels Configuration:
## Spatial Kernel : gauss (Fixed / Distance)
## ------------------------------------------------------
## Bandwidth Configuration:
## ------------------------------------------------------
## Model Settings:
## Method for spatial autocorrelation: 2SLS
## Computation time: 39.565 sec
## Use of Target Points: NO
## Use of rough kernel approximation: NO
## Parallel computing: (ncore = 1)
## Number of data points: 1000
## ------------------------------------------------------
## Coefficients Summary:
## [Varying Parameters]
## Intercept X1 X2 X3
## Min. :-0.512 Min. :-0.507 Min. :0.2188 Min. :-6.61826
## 1st Qu.: 1.467 1st Qu.: 1.492 1st Qu.:0.2258 1st Qu.:-1.85468
## Median : 2.027 Median : 2.181 Median :0.2289 Median : 0.18978
## Mean : 1.943 Mean : 2.361 Mean :0.2290 Mean :-0.02374
## 3rd Qu.: 2.502 3rd Qu.: 3.200 3rd Qu.:0.2324 3rd Qu.: 1.69370
## Max. : 4.193 Max. : 4.846 Max. :0.2390 Max. : 5.60360
## ------------------------------------------------------
## Diagnostics:
## Effective degrees of freedom: 914.82
## AICc: 5588.8
## Residual sum of squares: 12084.96
## RMSE: 3.4763
## ------------------------------------------------------
# Performance Metrics
Beta_RMSE_MS <- apply((model_ms_gwr@Betav - TRUEBETA), 2, rmse)
print(Beta_RMSE_MS)
## Intercept X1 X2 X3
## 0.3625952 0.5248136 1.6068701 1.5684918
cat("Mean Beta RMSE (Multiscale):", mean(Beta_RMSE_MS), "\n")
## Mean Beta RMSE (Multiscale): 1.015693
Observation: While conceptually superior, standard MGWR can struggle to find optimal bandwidths for complex patterns (e.g., \(\beta_3\) here). This is often due to the “yo-yo” effect in backfitting optimization and the risk of getting trapped in local optima, a known limitation of the golden-section search algorithm used for bandwidth selection.
tds_mgwr)tds_mgwr identifies a unique bandwidth
\(h_k\) for each variable \(k\), defined as: \[y_{i} = \sum_{k=0}^{K} \beta_{k}(u_{i}, v_{i};
h_k) x_{ik} + \epsilon_{i}\]
Innovation: Instead of full optimization, it tests a geometrically decreasing sequence of bandwidths. At each backfitting step \(m\), it efficiently checks if the current bandwidth \(h_m\) improves the AICc compared to the previous state, testing only a limited set of candidates (current, previous, next, and global minimum). This ensures faster convergence and avoids local minima.
# TDS-MGWR estimation
model_tds_mgwr <- TDS_MGWR(
formula = myformula,
Model = 'tds_mgwr',
data = mydata,
coords = coords,
kernels = 'gauss',
fixed_vars = NULL,
control_tds = list(nns = 20, get_AIC = TRUE, verbose = FALSE, ncore = 8),
control = list(adaptive = FALSE)
)
summary(model_tds_mgwr)
## ------------------------------------------------------
## Call:
## TDS_MGWR(formula = myformula, data = mydata, coords = coords,
## Model = "tds_mgwr", kernels = "gauss", fixed_vars = NULL,
## control_tds = list(nns = 20, get_AIC = TRUE, verbose = FALSE,
## ncore = 8), control = list(adaptive = FALSE))
##
## Model: tds_mgwr
## ------------------------------------------------------
## Kernels Configuration:
## Spatial Kernel : gauss (Fixed / Distance)
## ------------------------------------------------------
## Bandwidth Configuration:
## [TDS] Covariate-Specific Bandwidths:
## Variable Spatial_H
## Intercept 0.16
## X1 0.1
## X2 0.04
## X3 0.04
## ------------------------------------------------------
## Model Settings:
## Computation time: 46.907 sec
## Use of Target Points: NO
## Use of rough kernel approximation: NO
## Parallel computing: (ncore = 8)
## Number of data points: 1000
## ------------------------------------------------------
## Coefficients Summary:
## [Varying Parameters]
## Intercept X1 X2 X3
## Min. :-0.5236 Min. :-0.2118 Min. :-3.2804 Min. :-5.38577
## 1st Qu.: 1.4581 1st Qu.: 1.5393 1st Qu.:-0.3722 1st Qu.:-1.76772
## Median : 2.0913 Median : 2.1835 Median : 0.2603 Median : 0.16967
## Mean : 1.9959 Mean : 2.3461 Mean : 0.2285 Mean :-0.01719
## 3rd Qu.: 2.5511 3rd Qu.: 3.1280 3rd Qu.: 0.9341 3rd Qu.: 1.60734
## Max. : 4.4217 Max. : 4.6724 Max. : 3.1706 Max. : 5.36582
## ------------------------------------------------------
## Diagnostics:
## Effective degrees of freedom: 817.05
## AICc: 5531.75
## Residual sum of squares: 9433.4
## RMSE: 3.0714
## ------------------------------------------------------
# Performance Metrics
Beta_RMSE_TDS <- apply((model_tds_mgwr@Betav - TRUEBETA), 2, rmse)
cat("Mean Beta RMSE (TDS-MGWR):", mean(Beta_RMSE_TDS), "\n")
## Mean Beta RMSE (TDS-MGWR): 0.864073
atds_mgwr)atds_mgwr extends the model to allow
locally adaptive bandwidths: \[y_{i} = \sum_{k=0}^{K} \beta_{k}(u_{i}, v_{i};
h_k(u_i, v_i)) x_{ik} + \epsilon_{i}\]
It uses the estimates from tds_mgwr as a starting point.
Then, it applies a gradient boosting procedure on the
residuals for each variable, testing the decreasing bandwidth sequence.
This allows the model to capture, for a single variable, both global
trends (large \(h\)) and local
anomalies (small \(h\)).
model_atds_mgwr <- TDS_MGWR(
formula = myformula,
Model = 'atds_mgwr',
data = mydata,
coords = coords,
kernels = 'gauss',
fixed_vars = NULL,
control_tds = list(nns = 20, verbose = TRUE, ncore = 8),
control = list(adaptive = FALSE)
)
##
## i = 1 Starting model
##
##
## ########################################################################
## STAGE 1 : find unique bandwidth for each covariate
## using Top Down Scale Approach with backfitting for Type = GD ...
## ########################################################################
##
##
## 1 Intercept AICc : 6015.055 X1 AICc : 6014.656 X2 AICc : 6014.061 X3 AICc : 6012.993
## delta_AICc: 0.001460188 AICc : 6012.993 stable 0 0 0 0 delta_rmse 0.006138523 rmse 4.863687
##
## H = 1.060343 0.7139035 0.7139035 0.7139035
##
## 2 Intercept AICc : 6005.002 X3 AICc : 6004.37 X2 AICc : 6004.091 X1 AICc : 6002.839
## delta_AICc: 0.001688603 AICc : 6002.839 stable 0 0 0 0 delta_rmse 0.005923108 rmse 4.834879
##
## H = 0.7139035 0.5707511 0.5707511 0.5707511
##
## 3 Intercept AICc : 5996.04 X1 AICc : 5993.098 X2 AICc : 5992.905 X3 AICc : 5991.943
## delta_AICc: 0.00181522 AICc : 5991.943 stable 0 0 0 0 delta_rmse 0.006638958 rmse 4.802781
##
## H = 0.5707511 0.4632098 0.4632098 0.4632098
##
## 4 Intercept AICc : 5984.33 X1 AICc : 5977.984 X2 AICc : 5977.796 X3 AICc : 5976.352
## delta_AICc: 0.002601908 AICc : 5976.352 stable 0 0 0 0 delta_rmse 0.009679352 rmse 4.756293
##
## H = 0.4632098 0.3740086 0.3740086 0.3740086
##
## 5 Intercept AICc : 5968.2 X3 AICc : 5966.503 X2 AICc : 5966.16 X1 AICc : 5956.489
## delta_AICc: 0.003323651 AICc : 5956.489 stable 0 0 0 0 delta_rmse 0.01257879 rmse 4.696464
##
## H = 0.3740086 0.3079545 0.3079545 0.3079545
##
## 6 Intercept AICc : 5949.926 X1 AICc : 5937.44 X3 AICc : 5935.102 X2 AICc : 5934.672
## delta_AICc: 0.003662645 AICc : 5934.672 stable 0 0 0 0 delta_rmse 0.01475391 rmse 4.627173
##
## H = 0.3079545 0.2528957 0.2528957 0.2528957
##
## 7 Intercept AICc : 5929.733 X3 AICc : 5927.033 X2 AICc : 5926.095 X1 AICc : 5914.881
## delta_AICc: 0.003334922 AICc : 5914.881 stable 0 0 0 0 delta_rmse 0.01475273 rmse 4.55891
##
## H = 0.2528957 0.2132714 0.2132714 0.2132714
##
## 8 Intercept AICc : 5912.252 X2 AICc : 5910.86 X3 AICc : 5906.717 X1 AICc : 5897.735
## delta_AICc: 0.002898742 AICc : 5897.735 stable 0 0 0 0 delta_rmse 0.01455216 rmse 4.492568
##
## H = 0.2132714 0.1824835 0.1824835 0.1824835
##
## 9 Intercept AICc : 5896.77 X2 AICc : 5894.491 X1 AICc : 5887.607 X3 AICc : 5879.504
## delta_AICc: 0.003091235 AICc : 5879.504 stable 0 0 0 0 delta_rmse 0.01693557 rmse 4.416484
##
## H = 0.1824835 0.1561728 0.1561728 0.1561728
##
## 10 Intercept AICc : 5879.401 X2 AICc : 5876.083 X1 AICc : 5871.455 X3 AICc : 5855.471
## delta_AICc: 0.004087538 AICc : 5855.471 stable 1 0 0 0 delta_rmse 0.02041729 rmse 4.326311
##
## H = 0.1824835 0.1333764 0.1333764 0.1333764
##
## 11 Intercept AICc : 5855.376 X1 AICc : 5853.04 X2 AICc : 5848.439 X3 AICc : 5820.725
## delta_AICc: 0.005933955 AICc : 5820.725 stable 2 0 0 0 delta_rmse 0.02840702 rmse 4.203413
##
## H = 0.1824835 0.1140439 0.1140439 0.1140439
##
## 12 Intercept AICc : 5820.678 X2 AICc : 5813.558 X1 AICc : 5813.758 X3 AICc : 5770.148
## delta_AICc: 0.008689065 AICc : 5770.148 stable 3 0 0 0 delta_rmse 0.0409351 rmse 4.031346
##
## H = 0.1824835 0.09662845 0.09662845 0.09662845
##
## 13 Intercept AICc : 5770.189 X1 AICc : 5770.463 X2 AICc : 5760.912 X3 AICc : 5704.136
## delta_AICc: 0.01144034 AICc : 5704.136 stable 4 1 0 0 delta_rmse 0.04737355 rmse 3.840367
##
## H = 0.1824835 0.09662845 0.08150633 0.08150633
##
## 14 Intercept AICc : 5704.71 X1 AICc : 5705.031 X2 AICc : 5695.263 X3 AICc : 5642.243
## delta_AICc: 0.0108505 AICc : 5642.243 stable 0 2 0 0 delta_rmse 0.05061057 rmse 3.646004
##
## H = 0.1561728 0.09662845 0.07008527 0.07008527
##
## 15 Intercept AICc : 5642.494 X3 AICc : 5594.823 X2 AICc : 5585.243 X1 AICc : 5585.621
## delta_AICc: 0.01003534 AICc : 5585.621 stable 1 3 0 0 delta_rmse 0.05331805 rmse 3.451606
##
## H = 0.1561728 0.09662845 0.05962591 0.05962591
##
## 16 Intercept AICc : 5586.01 X2 AICc : 5579.585 X1 AICc : 5579.743 X3 AICc : 5542.238
## delta_AICc: 0.007766884 AICc : 5542.238 stable 2 4 0 0 delta_rmse 0.06140369 rmse 3.239665
##
## H = 0.1561728 0.09662845 0.04986022 0.04986022
##
## 17 Intercept AICc : 5542.515 X3 AICc : 5533.017 X1 AICc : 5532.651 X2 AICc : 5534.715
## delta_AICc: 0.001357495 AICc : 5534.715 stable 3 5 0 0 delta_rmse 0.04923669 rmse 3.080154
##
## H = 0.1561728 0.09662845 0.04296922 0.04296922
##
## 18 Intercept AICc : 5534.834 X2 AICc : 5534.978 X1 AICc : 5534.877 X3 AICc : 5531.258
## delta_AICc: 0.000624626 AICc : 5531.258 stable 4 6 1 1 delta_rmse 0.001885762 rmse 3.074346
##
## H = 0.1561728 0.09662845 0.04296922 0.04296922
##
## 19 Intercept AICc : 5531.398 X2 AICc : 5532.055 X1 AICc : 5532.128 X3 AICc : 5531.562
## delta_AICc: -5.508861e-05 AICc : 5531.562 stable 5 7 2 2 delta_rmse 0.0008429031 rmse 3.071754
##
## H = 0.1561728 0.09662845 0.04296922 0.04296922
##
## 20 Intercept AICc : 5531.601 X1 AICc : 5531.611 X2 AICc : 5531.793 X3 AICc : 5531.69
## delta_AICc: -2.311077e-05 AICc : 5531.69 stable 6 8 3 3 delta_rmse 0.0001034607 rmse 3.071437
##
## H = 0.1561728 0.09662845 0.04296922 0.04296922
##
## 21 Intercept AICc : 5531.708 X3 AICc : 5531.713 X2 AICc : 5531.78 X1 AICc : 5531.785
## delta_AICc: -1.714356e-05 AICc : 5531.785 stable 7 9 4 4 delta_rmse -2.65221e-05 rmse 3.071518
##
## H = 0.1561728 0.09662845 0.04296922 0.04296922
## Time = 46.84
## Start stage 2 :
## ------------------------------------------------------
## Call:
## TDS_MGWR(formula = myformula, data = mydata, coords = coords,
## Model = "atds_mgwr", kernels = "gauss", fixed_vars = NULL,
## control_tds = list(nns = 20, verbose = TRUE, ncore = 8),
## control = list(adaptive = FALSE))
##
## Model: tds_mgwr
## ------------------------------------------------------
## Kernels Configuration:
## Spatial Kernel : gauss (Fixed / Distance)
## ------------------------------------------------------
## Bandwidth Configuration:
## [TDS] Covariate-Specific Bandwidths:
## Variable Spatial_H
## Intercept 0.16
## X1 0.1
## X2 0.04
## X3 0.04
## ------------------------------------------------------
## Model Settings:
## Computation time: 46.84 sec
## Use of Target Points: NO
## Use of rough kernel approximation: NO
## Parallel computing: (ncore = 8)
## Number of data points: 1000
## ------------------------------------------------------
## Coefficients Summary:
## [Varying Parameters]
## Intercept X1 X2 X3
## Min. :-0.5349 Min. :-0.2103 Min. :-3.2804 Min. :-5.38529
## 1st Qu.: 1.4582 1st Qu.: 1.5403 1st Qu.:-0.3721 1st Qu.:-1.76584
## Median : 2.0915 Median : 2.1836 Median : 0.2564 Median : 0.16966
## Mean : 1.9953 Mean : 2.3460 Mean : 0.2279 Mean :-0.01747
## 3rd Qu.: 2.5513 3rd Qu.: 3.1282 3rd Qu.: 0.9342 3rd Qu.: 1.60699
## Max. : 4.4169 Max. : 4.6725 Max. : 3.1700 Max. : 5.36463
## ------------------------------------------------------
## Diagnostics:
## Effective degrees of freedom: 817.08
## AICc: 5531.69
## Residual sum of squares: 9433.72
## RMSE: 3.0714
## ------------------------------------------------------
##
##
## ########################################################################
## STAGE 2 : use multiple/adaptive bandwidth for each covariate
## using Top Down Scale Approach with backfitting ...
## ########################################################################
## Intercept updated; X1 updated; X2 not updated; X3 updated;
## nround 1 rmse 2.972638 AICc 5467.463
## Intercept updated; X1 updated; X2 not updated; X3 updated;
## nround 2 rmse 2.968857 AICc 5465.247
## Intercept updated; X1 updated; X2 not updated; X3 updated;
## nround 3 rmse 2.96866 AICc 5465.163
##
## Intercept : 1000 1.060343 0.7139035 0.5707511 0.4632098 0.3740086 0.3079545 0.2528957
##
## X1 : 1000 1.060343 0.7139035 0.5707511 0.4632098 0.3740086 0.3079545 0.2528957 0.2132714 0.1824835 0.1561728
##
## X2 :
##
## X3 : 1000 1.060343 0.7139035 0.5707511 0.4632098 0.3740086 0.3079545 0.2528957 0.2132714 0.1824835 0.1561728 0.1333764 0.1140439 0.09662845 0.08150633 0.07008527 0.05962591 0.04986022
##
## Time = 107.122
summary(model_atds_mgwr)
## ------------------------------------------------------
## Call:
## TDS_MGWR(formula = myformula, data = mydata, coords = coords,
## Model = "atds_mgwr", kernels = "gauss", fixed_vars = NULL,
## control_tds = list(nns = 20, verbose = TRUE, ncore = 8),
## control = list(adaptive = FALSE))
##
## Model: atds_mgwr
## ------------------------------------------------------
## Kernels Configuration:
## Spatial Kernel : gauss (Fixed / Distance)
## ------------------------------------------------------
## Bandwidth Configuration:
## [ATDS] Bandwidth correction during stage 2:
## Variable Spatial_H
## Intercept Adaptive [0.3-1.4]
## X1 Adaptive [0.2-1.4]
## X2 0.04
## X3 Adaptive [0-1.4]
## ------------------------------------------------------
## Model Settings:
## Computation time: 107.122 sec
## Use of Target Points: NO
## Use of rough kernel approximation: NO
## Parallel computing: (ncore = 8)
## Number of data points: 1000
## ------------------------------------------------------
## Coefficients Summary:
## [Varying Parameters]
## Intercept X1 X2 X3
## Min. :-1.098 Min. :-1.083 Min. :-3.2804 Min. :-6.54690
## 1st Qu.: 1.314 1st Qu.: 1.400 1st Qu.:-0.3721 1st Qu.:-2.27742
## Median : 2.043 Median : 2.243 Median : 0.2564 Median : 0.05855
## Mean : 1.976 Mean : 2.362 Mean : 0.2279 Mean :-0.06392
## 3rd Qu.: 2.696 3rd Qu.: 3.309 3rd Qu.: 0.9342 3rd Qu.: 1.98830
## Max. : 4.716 Max. : 5.033 Max. : 3.1700 Max. : 7.71499
## ------------------------------------------------------
## Diagnostics:
## Effective degrees of freedom: 816.56
## AICc: 5465.16
## Residual sum of squares: 8812.94
## RMSE: 2.9687
## ------------------------------------------------------
# Performance Metrics
Beta_RMSE_ATDS <- apply((model_atds_mgwr@Betav - TRUEBETA), 2, rmse)
cat("Mean Beta RMSE (ATDS-MGWR):", mean(Beta_RMSE_ATDS), "\n")
## Mean Beta RMSE (ATDS-MGWR): 0.7422554
The following table summarizes the RMSE for Beta estimates on the simulation (Single run):
| Intercept | X1 | X2 | X3 | |
|---|---|---|---|---|
| GWR | 0.614 | 0.593 | 1.204 | 1.775 |
| Multiscale | 0.363 | 0.525 | 1.607 | 1.568 |
| TDS_MGWR | 0.340 | 0.549 | 1.044 | 1.523 |
| ATDS_MGWR | 0.179 | 0.408 | 1.044 | 1.338 |
atds_mgwr typically yields the lowest error for complex coefficients (like \(\beta_3\) and \(\beta_4\) in this DGP) by adapting the smoothing level locally.
mgwrsar provides a robust framework for prediction. For
multiscale models, we cannot simply reuse a single bandwidth.
We employ Target Weights with Target Points
(tWtp_model) or Kernel
Sharpening. This involves prioritizing the most relevant
neighbors (similar to a k-NN approach with \(k
\approx 3\)) for the extrapolation weights, while retaining the
variable-specific scale structures learned during inference.
# 1. Split Data
length_out <- 200 # Using 20% for testing
set.seed(123)
index_in <- sample(1:n, (n - length_out))
index_out <- setdiff(1:n, index_in)
data_in <- mydata[index_in, ]
coords_in <- coords[index_in, ]
data_out <- mydata[index_out, ]
coords_out <- coords[index_out, ]
# 2. Train TDS-MGWR on Training Set
model_tds_in <- TDS_MGWR(
formula = myformula,
Model = 'tds_mgwr',
data = data_in,
coords = coords_in,
kernels = 'gauss',
control_tds = list(nns = 20, get_AIC = TRUE, ncore = 8),
control = list(adaptive = FALSE, verbose = FALSE)
)
# 3. Predict on Test Set
# method_pred='model' uses the calibrated bandwidths/kernels
res_pred <- predict(
model_tds_in,
newdata = data_out,
newdata_coords = coords_out,
method_pred = 'model',
beta_proj = TRUE
)
# 4. Evaluate Prediction Accuracy (Y)
Y_pred <- res_pred$Y_predicted
Y_true <- data_out$Y
rmse_y <- sqrt(mean((Y_true - Y_pred)^2))
cat("Out-of-sample RMSE (Y):", rmse_y, "\n")
## Out-of-sample RMSE (Y): 4.00263
# 5. Evaluate Coefficient Accuracy (Beta)
Beta_out_RMSE <- apply((res_pred$Beta_proj_out - TRUEBETA[index_out,]), 2, rmse)
print(Beta_out_RMSE)
## Intercept X1 X2 X3
## 0.4083685 0.6181874 1.3059649 1.7352450
The prediction results demonstrate that identifying the correct scale
for each variable (tds_mgwr) not only improves parameter
interpretation but also enhances the model’s ability to generalize to
new locations.