****
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 3.652770 0.38713593 0.88878792 0.318878957 0.08349101 0.829535630 0.8827940
## 2 2.616542 0.05960695 0.42046941 0.258146452 0.89943003 0.442665417 0.7090780
## 3 3.420266 0.74908722 0.04745757 0.691701306 0.88362321 0.006854379 0.2445022
## 4 4.647046 0.92588240 0.48564826 0.009238425 0.02089103 0.399078661 0.3511706
## 5 6.849939 0.97554802 0.67029255 0.698217340 0.76321459 0.974569306 0.8482754
## 6 7.809946 0.98648199 0.41847504 0.285188701 0.44189221 0.681925152 0.5734794
## X7 Latitude Longitude
## 1 0.7137883 1 1
## 2 0.8271788 2 1
## 3 0.6745876 3 1
## 4 0.2093341 4 1
## 5 0.7585960 5 1
## 6 0.4120130 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] "X3" "X5"
##
## $Optimum_lamda
## [1] 1.034474
##
## $GWR_y_pred_test
## [1] 3.036006 7.082828 6.185260 7.499500 7.499006 6.137204 9.943815
## [8] 7.630053 11.038790 8.337755 10.733332 13.938962 15.882352 13.469881
## [15] 10.959123 14.417928 15.855668 20.038029 11.816538 22.009914 9.163395
## [22] 24.639455 13.362278 17.830706 30.430309 16.686637 20.758756 17.508464
## [29] 34.139489 28.031972
##
## $R_square
## [1] 0.997076
##
## $rrmse
## [1] 0.03183692
##
## $mse
## [1] 0.2138831
##
## $mae
## [1] 0.3554356
# 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
## character(0)
##
## $Optimum_lamda
## [1] 1.151683
##
## $GWR_y_pred_test
## [1] 4.818221 7.192558 10.239201 9.779426 8.659526 10.890020 10.724800
## [8] 9.722525 10.773919 11.290428 12.842528 16.619741 17.380423 19.005225
## [15] 14.272822 13.729572 14.223744 16.220363 14.587668 15.790206 16.392510
## [22] 17.192179 17.623584 25.131579 23.400582 24.562625 28.358342 16.720978
## [29] 24.458922 34.001082
##
## $R_square
## [1] 0.8635657
##
## $rrmse
## [1] 0.1837556
##
## $mse
## [1] 8.58821
##
## $mae
## [1] 1.909843