Skip to contents

Fit a geographically weighted lasso with the selected bandwidth

Usage

gwl_fit(
  bw,
  x.var,
  y.var,
  kernel,
  dist.mat,
  alpha,
  adaptive,
  progress = TRUE,
  nfolds = 5
)

Arguments

bw

Bandwidth

x.var

input matrix, of dimension nobs x nvars; each row is an observation vector. x should have 2 or more columns.

y.var

response variable for the lasso

kernel

the geographical kernel shape to compute the weight. passed to GWmodel::gw.weight() Can be gaussian, exponential, bisquare, tricube, boxcar

dist.mat

a distance matrix. can be generated by compute_distance_matrix()

alpha

the elasticnet mixing parameter. set 1 for lasso, 0 for ridge. see glmnet::glmnet()

adaptive

TRUE or FALSE Whether to perform an adaptive bandwidth search or not. A fixed bandwidth means that samples are selected if they fit a determined fixed radius around a location. In a adaptive bandwidth, the radius around a location varies to gather a fixed number of samples around the investigated location

progress

TRUE/FALSE whether to display a progress bar or not

nfolds

the number f folds for the glmnet cross validation

Value

a gwlfit object containing a fitted Geographically weighted Lasso.

Examples


predictors <- matrix(data = rnorm(2500), 50,50)
y_value <- sample(1:1000, 50)
coords <- data.frame("Lat" = rnorm(50), "Long" = rnorm(50))
distance_matrix <- compute_distance_matrix(coords)

my.gwl.fit <- gwl_fit(bw = 20,
                      x.var = predictors, 
                      y.var = y_value,
                      kernel = "bisquare",
                      dist.mat = distance_matrix, 
                      alpha = 1, 
                      adaptive = TRUE, 
                      progress = TRUE,
                      nfolds = 5)

my.gwl.fit
#> Bandwidth : 20 
#> adaptive : TRUE 
#> Number of models : 50 
#> RMSPE :  393.2292 
#> Number of predictors : 50