gwr.bw: Optimal bandwidth estimation for Geographically Weighted...

Description Usage Arguments Details Value Warning Note Author(s) References See Also Examples

View source: R/gwr.bw.R

Description

This function helps choosing the optimal bandwidth for the simple Geographically Weighted Regression (GWR).

Usage

1
2
gwr.bw(formula, dframe, coords, kernel, algorithm="exhaustive", 
       optim.method="Nelder-Mead", b.min=NULL, b.max=NULL, step=NULL)

Arguments

formula

the local model formula using the same syntax used in the lm function in R. This is a sting that is passed to the sub-models' lm function. For more details look at the class formula.

dframe

a numeric data frame of at least two suitable variables (one dependent and one independent)

coords

a numeric matrix or data frame of two columns giving the X,Y coordinates of the observations

kernel

the kernel to be used in the regression. Options are "adaptive" or "fixed". The weighting scheme used here is defined by the bi-square function (weight = (1-(ndist/H)^2)^2 for distances less than or equal to H, 0 otherwise)

algorithm

a character argument that specifies whether the function will use an exhaustive or a heuristic algorithm. In the first case all possible bandwidths within a range are being tested. In the second case the optim function is being used allowing for the choice of various optimisation methods (such as Brent or BFGS) that may find a global or local optimum. The default algorithm is "exhaustive"

optim.method

the optimisation method to be used. A detailed discussion is available at the 'Details' section of the function optim (stats). Example methods are "Nelder-Mead", "Brent", "BFGS", "CG" and "L-BFGS-B". The default method is "Nelder-Mead".

b.min

the minimum bandwidth. This is important for both algorithms. In the case of the exhaustive algorithm it sets the lower boundary for the range in which the function will compute the CV score for each possible bandwidth. In the case of the heuristic algorithm it provides the initial value for the bandwidth to be optimised which is very important. In the latter case b.min and b.max should be provided if the optimisation method "L-BFGS-B" or "Brent" has been selected.

b.max

the maximum bandwidth. This is important for both algorithms. In the case of the exhaustive algorithm it sets the upper boundary for the range in which the function will compute the CV score for each possible bandwidth. In the case of the heuristic algorithm b.max and b.min should be provided if the optimisation method "L-BFGS-B" or "Brent" has been selected.

step

this numeric argument is used only in the case of a fixed kernel indicating the increment of the sequence of bandwidths in between the b.min and the b.max. In the case of the adaptive kernel the increment is 1 neighbour.

Details

Please carefully read the optim (stats) when using a heuristic algorithm.

Value

bw

The optimal bandwidth (fixed or adaptive)

CV

The corresponding Cross Validation score for the optimal bandwidth

CVs

Available only in the case of the exhaustive algorithm. This is a numeric matrix in which the first column refers to the bandwidth in test and the second to the corresponding CV score.

Warning

Large datasets increase the processing time.

Note

Please select the optimisation algorithm carefully. To be on safe grounds use the "Brent" optim.method with well defined b.min and b.max. This function needs further testing. Please report any bugs!

Author(s)

Stamatis Kalogirou <stamatis@lctools.science>

References

Fotheringham, A.S., Brunsdon, C., Charlton, M. (2000). Geographically Weighted Regression: the analysis of spatially varying relationships. John Wiley and Sons, Chichester.

Kalogirou, S. (2003) The Statistical Analysis and Modelling of Internal Migration Flows within England and Wales, PhD Thesis, School of Geography, Politics and Sociology, University of Newcastle upon Tyne, UK. http://gisc.gr/?mdocs-file=1245&mdocs-url=false

See Also

gwr

Examples

1
2
3
RDF <- random.test.data(9,9,3,"normal")
bw <- gwr.bw(dep ~ X1 + X2, RDF, cbind(RDF$X,RDF$Y), kernel = 'adaptive', 
             b.min = 54, b.max=55)

Example output

Loading required package: reshape
Loading required package: weights
Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

    format.pval, round.POSIXt, trunc.POSIXt, units

Loading required package: gdata
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to locate valid perl interpreter
gdata: 
gdata: read.xls() will be unable to read Excel XLS and XLSX files
gdata: unless the 'perl=' argument is used to specify the location of a
gdata: valid perl intrpreter.
gdata: 
gdata: (To avoid display of this message in the future, please ensure
gdata: perl is installed and available on the executable search path.)
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package: 'gdata'

The following object is masked from 'package:Hmisc':

    combine

The following object is masked from 'package:stats':

    nobs

The following object is masked from 'package:utils':

    object.size

The following object is masked from 'package:base':

    startsWith

Loading required package: mice
Loading required package: pscl
Loading required package: MASS
Classes and Methods for R developed in the

Political Science Computational Laboratory

Department of Political Science

Stanford University

Simon Jackman

hurdle and zeroinfl functions by Achim Zeileis


Number of Observations: 81
Bandwidth:  54 CV:  9.176138
Bandwidth:  55 CV:  9.155787

lctools documentation built on April 14, 2020, 6:04 p.m.