Metode Geographically Weighted Regression (GWR) adalah suatu teknik yang membawa kerangka dari model regresi sederhana menjadi model regresi yang terboboti (Fotheringham, et al., 2002). Setiap nilai parameter dihitung pada setiap titik lokasi georafis sehingga setiap titik lokasi geografis mempunyai nilai parameter regresi yang berbeda-beda. Hal ini menghasilkaan variasi pada nilai parameter regresi di suatu kumpulan wilayah geografis. Jika nilai parameter regresi konstan pada tiap-tiap wilayah geografis, maka model GWR adalah model regresi global. Artinya tiap-tiap wilayah geografis mempunyai model yang sama seperti pada model Regresi Linier Berganda.
Persamaan Model Regresi: \[ \mathbf{y} = \mathbf{X}\boldsymbol{\beta} + \boldsymbol{\epsilon} \]
dengan: \[ \mathbf{y} = \begin{bmatrix} y_1 \\ y_2 \\ \vdots \\ y_n \end{bmatrix}, \quad \mathbf{X} = \begin{bmatrix} 1 & x_{11} & x_{12} & \cdots & x_{1p} \\ 1 & x_{21} & x_{22} & \cdots & x_{2p} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & x_{n1} & x_{n2} & \cdots & x_{np} \end{bmatrix}, \quad \boldsymbol{\beta} = \begin{bmatrix} \beta_0 \\ \beta_1 \\ \vdots \\ \beta_p \end{bmatrix} \] Model GWR: \[ y_i = \mathbf{x}^T_i \boldsymbol{\beta}(u_i,v_i) + \epsilon_i \]
Import data dari paket spData.
data(columbus, package="spData") # Data columbus diambil dari spData
# Menampilkan Data
names(columbus)## [1] "AREA" "PERIMETER" "COLUMBUS." "COLUMBUS.I" "POLYID"
## [6] "NEIG" "HOVAL" "INC" "CRIME" "OPEN"
## [11] "PLUMB" "DISCBD" "X" "Y" "AREA"
## [16] "NSA" "NSB" "EW" "CP" "THOUS"
## [21] "NEIGNO" "PERIM"
## 'data.frame': 49 obs. of 22 variables:
## $ AREA : num 0.3094 0.2593 0.1925 0.0838 0.4889 ...
## $ PERIMETER : num 2.44 2.24 2.19 1.43 3 ...
## $ COLUMBUS. : int 2 3 4 5 6 7 8 9 10 11 ...
## $ COLUMBUS.I: int 5 1 6 2 7 8 4 3 18 10 ...
## $ POLYID : int 1 2 3 4 5 6 7 8 9 10 ...
## $ NEIG : int 5 1 6 2 7 8 4 3 18 10 ...
## $ HOVAL : num 80.5 44.6 26.4 33.2 23.2 ...
## $ INC : num 19.53 21.23 15.96 4.48 11.25 ...
## $ CRIME : num 15.7 18.8 30.6 32.4 50.7 ...
## $ OPEN : num 2.851 5.297 4.535 0.394 0.406 ...
## $ PLUMB : num 0.217 0.321 0.374 1.187 0.625 ...
## $ DISCBD : num 5.03 4.27 3.89 3.7 2.83 3.78 2.74 2.89 3.17 4.33 ...
## $ X : num 38.8 35.6 39.8 36.5 40 ...
## $ Y : num 44.1 42.4 41.2 40.5 38 ...
## $ AREA : num 10.39 8.62 6.98 2.91 16.83 ...
## $ NSA : num 1 1 1 1 1 1 1 1 1 1 ...
## $ NSB : num 1 1 1 1 1 1 1 1 1 1 ...
## $ EW : num 1 0 1 0 1 1 0 0 1 1 ...
## $ CP : num 0 0 0 0 0 0 0 0 0 0 ...
## $ THOUS : num 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 ...
## $ NEIGNO : num 1005 1001 1006 1002 1007 ...
## $ PERIM : num 2.44 2.24 2.19 1.43 3 ...
## AREA PERIMETER COLUMBUS. COLUMBUS.I POLYID NEIG HOVAL INC CRIME
## 1005 0.309441 2.440629 2 5 1 5 80.467 19.531 15.72598
## 1001 0.259329 2.236939 3 1 2 1 44.567 21.232 18.80175
## 1006 0.192468 2.187547 4 6 3 6 26.350 15.956 30.62678
## 1002 0.083841 1.427635 5 2 4 2 33.200 4.477 32.38776
## 1007 0.488888 2.997133 6 7 5 7 23.225 11.252 50.73151
## OPEN PLUMB DISCBD X Y AREA NSA NSB EW CP THOUS NEIGNO
## 1005 2.850747 0.217155 5.03 38.80 44.07 10.391 1 1 1 0 1000 1005
## 1001 5.296720 0.320581 4.27 35.62 42.38 8.621 1 1 0 0 1000 1001
## 1006 4.534649 0.374404 3.89 39.82 41.18 6.981 1 1 1 0 1000 1006
## 1002 0.394427 1.186944 3.70 36.50 40.52 2.908 1 1 0 0 1000 1002
## 1007 0.405664 0.624596 2.83 40.01 38.00 16.827 1 1 1 0 1000 1007
## PERIM
## 1005 2.440629
## 1001 2.236939
## 1006 2.187547
## 1002 1.427635
## 1007 2.997133
#Matriks Pembobot Peta Columbus
columbus.map = st_read("columbus.shp",quiet=TRUE)
coords <- st_coordinates(st_centroid(st_geometry(columbus.map)))
D <- as.matrix(dist(coords,method="euclidean"))
##Pembobot Gaussian ####
Wmat = gw_weight_mat(D,bw=10,kernel = "gaussian",adaptive = TRUE) #perhatikan bw
gauss.w<-mat2listw(Wmat, style="W")
summary(gauss.w)## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 49
## Number of nonzero links: 2401
## Percentage nonzero weights: 100
## Average number of links: 49
## Link number distribution:
##
## 49
## 49
## 49 least connected regions:
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 with 49 links
## 49 most connected regions:
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 with 49 links
##
## Weights style: W
## Weights constants summary:
## n nn S0 S1 S2
## W 49 2401 49 4.706282 202.7427
plot(st_geometry(columbus.map), border="white",col='gray', sub="Adaptive Gaussian Weighted")
plot(gauss.w, coords, add = TRUE, col = "red")##Pembobot Bisquare ####
Wmat = gw_weight_mat(D,bw=1,kernel = "bisquare",adaptive = FALSE)
bisq.w<-mat2listw(Wmat, style="W")
summary(bisq.w)## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 49
## Number of nonzero links: 609
## Percentage nonzero weights: 25.36443
## Average number of links: 12.42857
## Link number distribution:
##
## 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
## 2 5 2 3 2 3 2 2 3 2 3 2 6 2 5 1 1 1 2
## 2 least connected regions:
## 1 47 with 4 links
## 2 most connected regions:
## 25 26 with 22 links
##
## Weights style: W
## Weights constants summary:
## n nn S0 S1 S2
## W 49 2401 49 15.58238 196.8187
plot(st_geometry(columbus.map), border="white",col='gray', sub="Adaptive Bisquare Weighted")
plot(bisq.w, coords, add = TRUE, col = "red")#Membuat matriks jarak
mydata=SpatialPointsDataFrame(coords=cbind(columbus$X,columbus$Y),data=columbus)
DM=gw.dist(dp.locat=coordinates(mydata))
# Mencari bandwidth optimal (Adaptive bandwidth)
h.adapt = gwr.sel(CRIME ~ INC + HOVAL,
coords=cbind(columbus$X,columbus$Y),
data=columbus,gweight = gwr.Gauss, adapt = TRUE)## Adaptive q: 0.381966 CV score: 7289.144
## Adaptive q: 0.618034 CV score: 7367.486
## Adaptive q: 0.236068 CV score: 7116.264
## Adaptive q: 0.145898 CV score: 6583.375
## Adaptive q: 0.09016994 CV score: 6719.659
## Adaptive q: 0.1393854 CV score: 6543.973
## Adaptive q: 0.1251174 CV score: 6578.812
## Adaptive q: 0.1339355 CV score: 6538.707
## Adaptive q: 0.1354104 CV score: 6538.463
## Adaptive q: 0.1349632 CV score: 6538.386
## Adaptive q: 0.1349225 CV score: 6538.385
## Adaptive q: 0.1348818 CV score: 6538.386
## Adaptive q: 0.1349225 CV score: 6538.385
#print bandwidth optimum
h.adapt #ini menyatakan persentase banyaknya tetangga tiap lokasi (bukan jarak)## [1] 0.1349225
# Konversi q -> bandwidth jarak di setiap titik
coords=cbind(columbus$X,columbus$Y)
bw_local <- gw.adapt(dp = coords, fp=coords, quant = h.adapt)
bw_local## [1] 7.462505 6.118815 4.914829 4.285562 3.988683 6.380406 4.523120
## [8] 3.370805 4.285559 5.704667 2.662374 2.540075 2.707388 2.934781
## [15] 3.411033 2.231347 5.400495 2.754988 2.685458 4.019722 4.876870
## [22] 3.901746 5.506636 3.278215 2.835137 3.456567 3.728371 2.901755
## [29] 3.215426 3.549635 7.864694 5.551883 3.364302 6.933527 3.701679
## [36] 8.959613 3.674377 2.820972 12.326151 4.958034 7.432604 8.197290
## [43] 3.095135 3.736410 4.444260 11.656764 8.096119 4.114289 5.126791
## [1] 49 49
#Estimasi Adaptive bandwidth
gwr.model = gwr(CRIME ~ INC + HOVAL,
coords=cbind(columbus$X,columbus$Y),
data=columbus,adapt = h.adapt,hatmatrix=TRUE,gweight = gwr.Gauss)
#Cetak Hasilnya
gwr.model## Call:
## gwr(formula = CRIME ~ INC + HOVAL, data = columbus, coords = cbind(columbus$X,
## columbus$Y), gweight = gwr.Gauss, adapt = h.adapt, hatmatrix = TRUE)
## Kernel function: gwr.Gauss
## Adaptive quantile: 0.1349225 (about 6 of 49 data points)
## Summary of GWR coefficient estimates at data points:
## Min. 1st Qu. Median 3rd Qu. Max. Global
## X.Intercept. 61.045867 66.107912 68.865429 72.046543 75.823831 68.6190
## INC -2.746460 -1.979271 -1.817207 -0.995802 0.745660 -1.5973
## HOVAL -0.734161 -0.380004 -0.232414 -0.077966 0.180549 -0.2739
## Number of data points: 49
## Effective number of parameters (residual: 2traceS - traceS'S): 13.93087
## Effective degrees of freedom (residual: 2traceS - traceS'S): 35.06913
## Sigma (residual: 2traceS - traceS'S): 9.861483
## Effective number of parameters (model: traceS): 10.52469
## Effective degrees of freedom (model: traceS): 38.47531
## Sigma (model: traceS): 9.414856
## Sigma (ML): 8.342702
## AICc (GWR p. 61, eq 2.33; p. 96, eq. 4.21): 377.9159
## AIC (GWR p. 96, eq. 4.22): 357.4766
## Residual sum of squares: 3410.433
## Quasi-global R2: 0.7462139
## [1] "SDF" "lhat" "lm" "results" "bandwidth" "adapt"
## [7] "hatmatrix" "gweight" "gTSS" "this.call" "fp.given" "timings"
## [1] "sum.w" "(Intercept)" "INC"
## [4] "HOVAL" "(Intercept)_se" "INC_se"
## [7] "HOVAL_se" "gwr.e" "pred"
## [10] "pred.se" "localR2" "(Intercept)_se_EDF"
## [13] "INC_se_EDF" "HOVAL_se_EDF" "pred.se"
## [1] 7.462505 6.118815 4.914829 4.285562 3.988683 6.380406 4.523120
## [8] 3.370805 4.285559 5.704667 2.662374 2.540075 2.707388 2.934781
## [15] 3.411033 2.231347 5.400495 2.754988 2.685458 4.019722 4.876870
## [22] 3.901746 5.506636 3.278215 2.835137 3.456567 3.728371 2.901755
## [29] 3.215426 3.549635 7.864694 5.551883 3.364302 6.933527 3.701679
## [36] 8.959613 3.674377 2.820972 12.326151 4.958034 7.432604 8.197290
## [43] 3.095135 3.736410 4.444260 11.656764 8.096119 4.114289 5.126791
## (Intercept) INC HOVAL pred localR2
## 1 67.93675 -1.1095513 -0.41493412 12.877597 0.7582196
## 2 68.78471 -0.7802740 -0.55301174 27.571855 0.7629606
## 3 67.76768 -1.1349974 -0.40686845 38.936678 0.7521512
## 4 69.45563 -0.6326549 -0.62241975 45.958903 0.7648197
## 5 70.87282 -1.2993807 -0.38000400 47.426599 0.7207853
## 6 68.94521 -1.6259804 -0.23241373 36.200473 0.7571471
## 7 73.37971 -0.4554000 -0.73416068 14.474990 0.7713442
## 8 72.04654 -0.5079161 -0.68811416 40.742061 0.7610407
## 9 70.44415 -1.9344960 -0.13626335 29.256652 0.7474477
## 10 67.39893 -1.8878145 -0.10516439 31.590577 0.7909452
## 11 68.19425 -0.3941737 -0.47385567 55.915993 0.6324533
## 12 65.22649 0.1611538 -0.52841328 56.330335 0.6385808
## 13 64.98168 0.6514783 -0.68321540 42.712566 0.7244355
## 14 63.43005 0.6800495 -0.63725613 42.867094 0.6895369
## 15 71.29726 -1.2746063 -0.30868999 53.156649 0.5846358
## 16 65.20434 -0.3007844 -0.32289272 56.840479 0.2984023
## 17 66.10791 -1.8749786 -0.08438573 44.213767 0.8069409
## 18 62.94898 0.2717874 -0.45963899 38.954162 0.4797675
## 19 61.04587 0.7456598 -0.54982081 52.884425 0.5902285
## 20 65.85827 -1.8674068 -0.07668537 1.605954 0.8248133
## 21 75.82383 -1.9086492 -0.28576840 49.778951 0.6486721
## 22 70.73596 -1.9792706 -0.11128384 44.172084 0.7479390
## 23 64.96615 -1.8352400 -0.07631867 22.498728 0.8107406
## 24 68.31020 -0.7423000 -0.32669301 40.362750 0.3949633
## 25 68.81698 -0.9958021 -0.26363667 55.672399 0.3494666
## 26 72.36831 -1.8172072 -0.16469004 54.332982 0.6118520
## 27 69.71699 -2.0138945 -0.07796583 45.263988 0.7691359
## 28 72.64986 -2.0360065 -0.08203056 54.780597 0.5572291
## 29 72.62025 -1.7464407 -0.15206707 52.517221 0.4674819
## 30 72.31169 -1.6371770 -0.17744963 45.552485 0.4493023
## 31 73.87714 -1.8843261 -0.34037654 31.132681 0.7142543
## 32 63.76512 -1.7914048 -0.06647967 27.153206 0.8032211
## 33 68.86543 -2.1048572 -0.02496945 47.400176 0.7754178
## 34 74.23179 -2.0032678 -0.28888746 36.068097 0.7009305
## 35 68.75623 -2.1789141 0.01062462 41.122484 0.7410661
## 36 73.11300 -1.8792438 -0.31894403 26.320184 0.7147837
## 37 73.04377 -2.0390045 -0.08107946 34.835286 0.4894901
## 38 73.42707 -2.5557281 0.07598319 46.765419 0.5641675
## 39 71.77187 -1.7730848 -0.31727529 26.446478 0.7237335
## 40 63.31882 -1.7943231 -0.04961041 6.715417 0.7906905
## 41 65.37777 -1.8268576 -0.07953339 21.460385 0.7853187
## 42 73.18164 -1.9688473 -0.28095916 9.785890 0.7050208
## 43 71.33965 -2.7464604 0.18054854 39.232106 0.5731989
## 44 67.31573 -2.3984145 0.13142916 31.039099 0.6889290
## 45 70.55561 -2.4217650 0.06810823 38.212806 0.5757942
## 46 71.89348 -1.8094950 -0.30614550 15.438619 0.7205867
## 47 65.63481 -1.8380662 -0.07848241 27.467953 0.7718416
## 48 68.59502 -2.5171467 0.14896130 42.852129 0.6050542
## 49 67.10165 -2.2192583 0.05861432 27.486867 0.6737940
## sum.w (Intercept) INC HOVAL
## Min. : 7.892 Min. :61.05 Min. :-2.7465 Min. :-0.73416
## 1st Qu.:10.559 1st Qu.:66.11 1st Qu.:-1.9793 1st Qu.:-0.38000
## Median :12.205 Median :68.87 Median :-1.8172 Median :-0.23241
## Mean :12.281 Mean :69.08 Mean :-1.4496 Mean :-0.23826
## 3rd Qu.:13.377 3rd Qu.:72.05 3rd Qu.:-0.9958 3rd Qu.:-0.07797
## Max. :20.039 Max. :75.82 Max. : 0.7457 Max. : 0.18055
## (Intercept)_se INC_se HOVAL_se gwr.e
## Min. : 4.295 Min. :0.3407 Min. :0.1007 Min. :-16.207
## 1st Qu.: 5.217 1st Qu.:0.4063 1st Qu.:0.1215 1st Qu.: -8.310
## Median : 5.620 Median :0.4922 Median :0.1363 Median : -2.065
## Mean : 6.330 Mean :0.5688 Mean :0.1557 Mean : -1.859
## 3rd Qu.: 6.954 3rd Qu.:0.7204 3rd Qu.:0.1710 3rd Qu.: 3.305
## Max. :11.501 Max. :1.2697 Max. :0.3112 Max. : 23.340
## pred pred.se localR2 (Intercept)_se_EDF
## Min. : 1.606 Min. :1.951 Min. :0.2984 Min. : 4.499
## 1st Qu.:27.487 1st Qu.:2.530 1st Qu.:0.5902 1st Qu.: 5.465
## Median :39.232 Median :2.947 Median :0.7148 Median : 5.887
## Mean :36.987 Mean :3.375 Mean :0.6690 Mean : 6.631
## 3rd Qu.:46.765 3rd Qu.:3.707 3rd Qu.:0.7630 3rd Qu.: 7.284
## Max. :56.840 Max. :7.620 Max. :0.8248 Max. :12.047
## INC_se_EDF HOVAL_se_EDF pred.se
## Min. :0.3568 Min. :0.1054 Min. :2.043
## 1st Qu.:0.4256 1st Qu.:0.1273 1st Qu.:2.650
## Median :0.5155 Median :0.1428 Median :3.087
## Mean :0.5958 Mean :0.1630 Mean :3.535
## 3rd Qu.:0.7546 3rd Qu.:0.1791 3rd Qu.:3.883
## Max. :1.3299 Max. :0.3259 Max. :7.982
## OGR data source with driver: ESRI Shapefile
## Source: "C:\HASBI\KULIAH S1\Semeseter Genap 2024-2025\Statistika Spasial\Materi Spasial 2025\Kuliah Spasial\columbus.shp", layer: "columbus"
## with 49 features
## It has 20 fields
## Integer64 fields read as strings: COLUMBUS_ COLUMBUS_I POLYID
col.shp@data$gwr_hoval = gwr.coefs$HOVAL
col.shp@data$gwr_inc = gwr.coefs$INC
col.shp@data$local_R2 = gwr.coefs$localR2
# Peta untuk Koefisien HOVAL
spplot(col.shp, zcol="gwr_hoval", main = "Koefisien
GWR untuk Nilai Rumah (HOVAL)")# Peta untuk Koefisien INC
spplot(col.shp, zcol="gwr_inc", main = "Koefisien GWR
untuk Pendapatan (INC)")# Peta untuk akurasi setiap lokasi
spplot(col.shp, zcol="local_R2", main = "Koefisien
Determinasi Tiap Lokasi") ##
## Brunsdon, Fotheringham & Charlton (2002, pp. 91-2) ANOVA
##
## data: gwr.model
## F = 1.7637, df1 = 46.000, df2 = 35.069, p-value = 0.04172
## alternative hypothesis: greater
## sample estimates:
## SS OLS residuals SS GWR residuals
## 6014.893 3410.433
##
## Leung et al. (2000) F(2) test
##
## data: gwr.model
## F = 1.8222, df1 = 18.194, df2 = 46.000, p-value = 0.05117
## alternative hypothesis: greater
## sample estimates:
## SS OLS residuals SS GWR improvement
## 6014.893 2604.460
##
## Leung et al. (2000) F(1) test
##
## data: gwr.model
## F = 0.74373, df1 = 40.053, df2 = 46.000, p-value = 0.1708
## alternative hypothesis: less
## sample estimates:
## SS OLS residuals SS GWR residuals
## 6014.893 3410.433
##
## Leung et al. (2000) F(3) test
##
## F statistic Numerator d.f. Denominator d.f. Pr(>)
## (Intercept) 0.47378 19.95413 40.053 0.962042
## INC 2.89594 24.94005 40.053 0.001320 **
## HOVAL 3.18521 18.11781 40.053 0.001116 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#PERSAMAAN REGRESI
reg.eq = CRIME ~ INC + HOVAL
#OLS
reg.OLS=lm(reg.eq,data=columbus)
summary(reg.OLS)##
## Call:
## lm(formula = reg.eq, data = columbus)
##
## Residuals:
## Min 1Q Median 3Q Max
## -34.418 -6.388 -1.580 9.052 28.649
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 68.6190 4.7355 14.490 < 2e-16 ***
## INC -1.5973 0.3341 -4.780 1.83e-05 ***
## HOVAL -0.2739 0.1032 -2.654 0.0109 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.43 on 46 degrees of freedom
## Multiple R-squared: 0.5524, Adjusted R-squared: 0.5329
## F-statistic: 28.39 on 2 and 46 DF, p-value: 9.341e-09
## [1] 382.7545