# GWRLASSO:A Hybrid Model for Spatial Prediction Through Local Regression

## Introduction

****
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.720604 0.6410128 0.3432473 0.82265743 0.6775485 0.1700892 0.1572447
    ## 2 2.387129 0.5523559 0.3254626 0.58385628 0.2423218 0.2919340 0.3007875
    ## 3 3.510059 0.1849868 0.1904331 0.82822611 0.2164584 0.4965265 0.7298879
    ## 4 2.472992 0.2433313 0.4402201 0.20150292 0.4533992 0.3619362 0.9146913
    ## 5 3.154455 0.1164649 0.3207218 0.08147567 0.8469949 0.4752099 0.7020875
    ## 6 5.071645 0.2380063 0.6704473 0.78930532 0.7533523 0.4147849 0.5248812
    ##          X7 Latitude Longitude
    ## 1 0.8438608        1         1
    ## 2 0.6166068        2         1
    ## 3 0.3372518        3         1
    ## 4 0.6801313        4         1
    ## 5 0.1857550        5         1
    ## 6 0.2984087        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" "X2" "X3" "X5"
    ##
    ## $Optimum_lamda
    ## [1] 0.7350842
    ##
    ## $GWR_y_pred_test
    ##  [1]  5.431670  9.033500  8.216045  4.462453  7.726292 10.806703 12.153382
    ##  [8]  9.222939  5.284106 10.124038 10.258651  8.977877  7.466054 14.627856
    ## [15] 10.922631 20.504277  9.459618 19.068414 23.094269 23.256571 14.017168
    ## [22] 29.130194 24.872261 22.784103 21.270518 32.097782 31.235266 23.342698
    ## [29] 19.400974 37.736339
    ##
    ## $R_square
    ## [1] 0.9989679
    ##
    ## $rrmse
    ## [1] 0.01828528
    ##
    ## $mse
    ## [1] 0.0877203
    ##
    ## $mae
    ## [1] 0.2298292

    # 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" "X2" "X3" "X5" "X6"
    ##
    ## $Optimum_lamda
    ## [1] 0.5892334
    ##
    ## $GWR_y_pred_test
    ##  [1]  3.510073  3.154573  8.160326  4.433836  4.479514  9.628513 11.740188
    ##  [8]  8.992912 12.943149 11.499875 20.401727 19.863923 11.264239 14.614429
    ## [15] 17.112898 13.042575 23.448817 23.190637 23.869374 24.327500 21.812814
    ## [22]  9.915087 23.010532 34.707073 23.147561 26.012514 21.262098 23.332749
    ## [29] 30.666449 19.392829
    ##
    ## $R_square
    ## [1] 0.9998479
    ##
    ## $rrmse
    ## [1] 0.006108527
    ##
    ## $mse
    ## [1] 0.01046588
    ##
    ## $mae
    ## [1] 0.04915014