****
It employs a hybrid spatial approach to enhance spatial
prediction. This approach combines the variable selection capability of
LASSO (Least Absolute Shrinkage and Selection Operator) with the
Geographically Weighted Regression (GWR) model, effectively capturing
spatially varying relationships. The developed hybrid model efficiently
selects the relevant variables by using LASSO as the first step; these
selected variables are then incorporated into the GWR framework,allowing
the estimation of spatially varying regression coefficients at unknown
locations and finally it predicts the values of the response variable at
unknown test locations, while also considering the spatial heterogeneity
present in the data.The developed hybrid spatial model can be useful for
spatial modeling, especially in scenarios involving complex spatial
patterns and large datasets with multiple predictor variables.
****
# Examples: Variable selection and prediction at unknown test locations using GWRLASSO hybrid spatial model
# Generation of response variable and predictor variables as well as the locational coordinates
library(GWRLASSO)
n<- 100
p<- 7
m<-sqrt(n)
id<-seq(1:n)
x<-matrix(runif(n*p), ncol=p)
e<-rnorm(n, mean=0, sd=1)
xy_grid<-expand.grid(c(1:m),c(1:m))
Latitude<-xy_grid[,1]
Longitude<-xy_grid[,2]
B0<-(Latitude+Longitude)/6
B1<-(Latitude/3)
B2<-(Longitude/3)
B3<-(2*Longitude)
B4<-2*(Latitude+Longitude)/6
B5<-(4*Longitude/3)
B6<-2*(Latitude+Longitude)/18
B7<-(4*Longitude/18)
y<-B0+(B1*x[,1])+(B2*x[,2])+(B3*x[,3])+(B4*x[,4])+(B5*x[,5])+(B6*x[,6])+(B7*x[,7])+e
data_sp<-data.frame(y,x,Latitude,Longitude)
head(data_sp)## y X1 X2 X3 X4 X5 X6
## 1 2.268270 0.0837177 0.73331044 0.5228632 0.0375255 0.4040954 0.4052306
## 2 4.041281 0.2206308 0.02473605 0.7031131 0.4032008 0.6292430 0.6337736
## 3 4.050787 0.3527335 0.16759021 0.3344576 0.2841758 0.3179422 0.2689450
## 4 3.654452 0.6314952 0.05303901 0.2536854 0.3248769 0.4462537 0.5192944
## 5 4.114747 0.3922313 0.66278105 0.5935121 0.9072260 0.5567141 0.2078721
## 6 4.534832 0.5181998 0.03975134 0.1424282 0.3835751 0.6361432 0.2087146
## X7 Latitude Longitude
## 1 0.11122841 1 1
## 2 0.94248070 2 1
## 3 0.99113482 3 1
## 4 0.08483401 4 1
## 5 0.57614727 5 1
## 6 0.96861331 6 1
# Application of the GWRLASSO model with the exponential kernel function
library(GWRLASSO)
GWRLASSO_exp<-GWRLASSO_exponential(data_sp,0.8,0.7,exponential_kernel,10)
GWRLASSO_exp## $Important_vars
## [1] "X1" "X3" "X4" "X5" "X6"
##
## $Optimum_lamda
## [1] 0.5247797
##
## $GWR_y_pred_test
## [1] 4.227520 6.030844 6.389102 3.476339 3.898578 10.864902 11.971463
## [8] 7.872561 9.311549 7.207450 13.690786 7.726391 13.331292 14.393670
## [15] 7.959914 11.562664 16.819618 12.339541 10.939612 15.962189 18.041407
## [22] 21.129660 22.958704 15.778763 40.109041 29.344713 28.037242 22.046093
## [29] 22.782691 27.728336
##
## $R_square
## [1] 0.9991326
##
## $rrmse
## [1] 0.01772951
##
## $mse
## [1] 0.06888098
##
## $mae
## [1] 0.1882234
# Application of the GWRLASSO model with the gaussian kernel function
library(GWRLASSO)
GWRLASSO_gau<-GWRLASSO_gaussian(data_sp,0.8,0.7,gaussian_kernel,10)
GWRLASSO_gau## $Important_vars
## [1] "X1" "X3" "X4" "X5" "X6" "X7"
##
## $Optimum_lamda
## [1] 0.3779439
##
## $GWR_y_pred_test
## [1] 2.268313 4.050546 4.114731 5.853695 3.243999 3.779599 8.050115
## [8] 8.746655 12.195500 18.443068 7.682293 13.295386 21.320024 9.354837
## [15] 13.343511 17.726804 12.181701 10.886507 21.189363 25.434847 25.925376
## [22] 21.121630 33.062634 26.988441 40.122470 29.059647 22.424694 23.124539
## [29] 24.499347 37.836083
##
## $R_square
## [1] 0.9999805
##
## $rrmse
## [1] 0.002775786
##
## $mse
## [1] 0.002205741
##
## $mae
## [1] 0.01499499