View source: R/gw_regr_functions.R
gw_get_lm_eval | R Documentation |
This returns an evaluation function for use in specifying GWR bandwidths for a given regression model formula. The options are "AIC" for a corrected AIC evaluation, or "CV" for a leave one out cross validation. It uses a matrix approach to assess the regression specified in the formula.
gw_get_lm_eval(eval)
eval |
Either "AIC" or "CV". |
The evaluation function.
library(sf) data(georgia) formula = as.formula(MedInc ~ PctBach + PctEld) # define a distance matrix, a location and an adaptive bandwidth dist_mat = as.matrix(dist(st_coordinates(st_centroid(georgia)), upper = T, diag = T)) # create the nearby function - see the help for `gw_get_nearby` in the gw package nearby_func = gw_get_nearby(adaptive = TRUE) # create the weighting function - see the help for `gw_get_weight` in the gw package weight_func = gw_get_weight(kernel = "bisquare", adaptive = TRUE) # adaptive r fixed bandwidth adaptive = TRUE # specify a bandwidth bw = 50 # create an index of observations indexMat = matrix(1:nrow(georgia), ncol = 1) # determine nearby locations for all observation (list for adaptive, matrix for fixed bandwidth) nearbyMat = apply(indexMat, 1, function(x) nearby_func(x, dist_mat, bw)) # apply the weight function to the nearby locations weightMat = apply(indexMat, 1, function(x) gw_do_weight(x, bw, nearbyMat, dist_mat, weight_func)) # define and run the evaluation function eval_func = gw_get_lm_eval(eval = "AIC") as.vector(eval_func(st_drop_geometry(georgia) , formula, indexMat, weightMat))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.