Description Usage Arguments Author(s) Examples
utility functions for the gwselect package
1  | 
formula | 
|
data | 
|
coords | 
|
gweight | 
|
bw | 
|
D | 
|
verbose | 
|
longlat | 
|
adapt | 
|
s | 
|
family | 
|
weights | 
|
nearest.neighbors | 
Wesley Brooks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81  | ##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.
## The function is currently defined as
function (formula, data, coords, gweight, bw, D = NULL, verbose = FALSE, 
    longlat = FALSE, adapt = FALSE, s, family, weights = NULL, 
    nearest.neighbors = FALSE) 
{
    if (!is.logical(adapt)) 
        stop("adapt must be logical")
    if (is(data, "Spatial")) {
        if (!missing(coords)) 
            warning("data is Spatial* object, ignoring coords argument")
        coords <- coordinates(data)
        if ((is.null(longlat) || !is.logical(longlat)) && !is.na(is.projected(data)) && 
            !is.projected(data)) {
            longlat <- TRUE
        }
        else longlat <- FALSE
        data <- as(data, "data.frame")
    }
    if (is.null(longlat) || !is.logical(longlat)) 
        longlat <- FALSE
    if (missing(coords)) 
        stop("Observation coordinates have to be given")
    mf <- match.call(expand.dots = FALSE)
    m <- match(c("formula", "data"), names(mf), 0)
    mf <- mf[c(1, m)]
    mf$drop.unused.levels <- TRUE
    mf[[1]] <- as.name("model.frame")
    mf <- eval(mf, parent.frame())
    mt <- attr(mf, "terms")
    dp.n <- length(model.extract(mf, "response"))
    if (!is.null(weights) && !is.numeric(weights)) 
        stop("'weights' must be a numeric vector")
    if (is.null(weights)) 
        weights <- rep(as.numeric(1), dp.n)
    if (any(is.na(weights))) 
        stop("NAs in weights")
    if (any(weights < 0)) 
        stop("negative weights")
    y <- model.extract(mf, "response")
    x <- model.matrix(mt, mf)
    if (is.null(D)) {
        n = dim(coords)[1]
        if (longlat) {
            D = as.matrix(earth.dist(coords), n, n)
        }
        else {
            Xmat = matrix(rep(coords[, 1], times = n), n, n)
            Ymat = matrix(rep(coords[, 2], times = n), n, n)
            D = sqrt((Xmat - t(Xmat))^2 + (Ymat - t(Ymat))^2)
        }
    }
    if (!nearest.neighbors) {
        weight.matrix = gweight(D, bw)
    }
    else {
        n = dim(D)[1]
        bandwidths = sapply(1:n, function(x) {
            neighbor.weight(q = bw, D = D[x, ], weight.function = gweight, 
                verbose = verbose, tol = 0.001)
        })
        weight.matrix = as.matrix(rbind(sapply(1:n, function(k) {
            gweight(as.vector(D[k, ]), as.numeric(bandwidths[1, 
                k]))
        })), n, n)
    }
    if (!adapt) {
        res = gwglmnet.fit(x, y, coords, weight.matrix, s, verbose, 
            family, weights)
    }
    else {
        res = gwglmnet.adaptive.fit(x, y, coords, weight.matrix, 
            s, verbose, family, weights)
    }
    res[["data"]] = data
    res[["response"]] = as.character(formula[[2]])
    res
  }
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.