gwglmnet.nen: Create a GW-GLM model using the LASSO for variable selection...

Description Usage Arguments Author(s) Examples

Description

Create a GW-GLM model using the LASSO for variable selection and Nearest Effective Neighbors for bandwidth selection.

Usage

1
gwglmnet.nen(formula, data, coords, gweight, bw, D = NULL, verbose = FALSE, longlat = FALSE, adapt = FALSE, s = NULL, family, weights = NULL, tolerance = .Machine$double.eps^0.25, beta1 = NULL, beta2 = NULL, type, parallel = FALSE)

Arguments

formula
data
coords
gweight
bw
D
verbose
longlat
adapt
s
family
weights
tolerance
beta1
beta2
type
parallel

Author(s)

Wesley Brooks

Examples

 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
##---- 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 = NULL, family, weights = NULL, 
    tolerance = .Machine$double.eps^0.25, beta1 = NULL, beta2 = NULL, 
    type, parallel = 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)
        }
    }
    n = dim(D)[1]
    if (is.null(beta1) || is.null(beta2)) {
        bbox <- cbind(range(coords[, 1]), range(coords[, 2]))
        difmin <- spDistsN1(bbox, bbox[2, ], longlat)[1]
        if (any(!is.finite(difmin))) 
            difmin[which(!is.finite(difmin))] <- 0
        beta1 <- difmin/1000
        beta2 <- 2 * difmin
    }
    res = list()
    if (adapt) {
        if (parallel) {
            res[["model"]] = gwglmnet.nen.adaptive.fit.parallel(x, 
                y, coords, D, s, verbose, family, weights, gweight, 
                bw, beta1, beta2, type, tol = toelrance, longlat = longlat)
        }
        else {
            res[["model"]] = gwglmnet.nen.adaptive.fit(x, y, 
                coords, D, s, verbose, family, weights, gweight, 
                bw, beta1, beta2, type, tol = toelrance, longlat = longlat)
        }
    }
    if (!adapt) {
        if (!parallel) {
            res[["model"]] = gwglmnet.nen.fit(x, y, coords, D, 
                s, verbose, family, weights, gweight, bw, beta1, 
                beta2, type = type, tol = tolerance, longlat = longlat)
        }
        else {
            res[["model"]] = gwglmnet.nen.fit.parallel(x, y, 
                coords, D, s, verbose, family, weights, gweight, 
                bw, beta1, beta2, type = type, tol = tolerance, 
                longlat = longlat)
        }
    }
    res[["data"]] = data
    res[["response"]] = as.character(formula[[2]])
    res
  }

wrbrooks/gwselect documentation built on May 4, 2019, 11:59 a.m.