gwr: Geographically Weighted Regression (GWR)

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

View source: R/gwr.R

Description

This function allows for the calibration of a local model using a simple Geographically Weighted Regression (GWR)

Usage

1
gwr(formula, dframe, bw, kernel, coords)

Arguments

formula

the local model to be fitted 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)

bw

a positive number that may be an integer in the case of an "adaptive kernel" or a real in the case of a "fixed kernel". In the first case the integer denotes the number of nearest neighbours, whereas in the latter case the real number refers to the bandwidth (in meters if the coordinates provided are Cartesian). This argument can be also the result of a bandwidth selection algorithm such as those available in the function gwr.bw

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)

coords

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

Details

The Geographically Weighted Regression (GWR) is a method of local regression introduced in the late 1990s. It allows for the investigation of the existence of spatial non-stationarity in the relationship between a dependent and a set of independent variables. This is possible by fitting a sub-model for each observation is space, taking into account the neighbour observations weighted by distance. A detailed description of the GWR method along with examples from the real estate market can be found in the book by Fotheringham et al. (2000). An application of GWR in internal migration modelling has been presented by Kalogirou (2003). The difference of this functions to existing ones is that each time the sub-dataset is selected and the sub-model is fitted using R's lm function instead of fitting the complete GWR model with matrix algebra. The latter approach may be faster but more prone to rounding error and code crashing.

Value

LM_LEst

a numeric data frame with the local intercepts and the local parameter estimates for each independent variable in the model's formula.

LM_LPvalues

a numeric data frame with the local p-value for the local intercepts and the local parameter estimates for each independent variable in the model's formula.

LM_GofFit

a numeric data frame with residuals and local goodness of fit statistics (AIC, Deviance)

Warning

Large datasets may take long to calibrate.

Note

This function is under development. There should be improvements in future versions of the package lctools. Any suggestion is welcome!

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.bw gw.glm gw.zi

Examples

1
2
3
data(GR.Municipalities)
Coords<-cbind(GR.Municipalities@data$X, GR.Municipalities@data$Y)
local.model<-gwr(Income01 ~ UnemrT01, GR.Municipalities@data, 50, kernel = 'adaptive', Coords)

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: 325
Kernel: Adaptive
Neightbours: 50
Number of Variables: 1
--------------- Global Model Summary ---------------

Call:
lm(formula = Income01 ~ UnemrT01, data = GR.Municipalities@data)

Residuals:
    Min      1Q  Median      3Q     Max 
-4961.3 -1883.6  -542.4  1297.5 13967.1 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 10926.16     377.47  28.946   <2e-16 ***
UnemrT01      -75.01      56.67  -1.324    0.187    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2940 on 323 degrees of freedom
Multiple R-squared:  0.005396,	Adjusted R-squared:  0.002317 
F-statistic: 1.752 on 1 and 323 DF,  p-value: 0.1865


--------------- Local Model Summary ---------------

Residuals:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-4511.1 -1307.5  -332.4  -123.2   866.9  7156.4 

Coefficients:
                   Min       Max       Mean       StD
X.Intercept.  6921.137 27053.701 12128.9317 6089.2907
UnemrT01     -2144.949   511.236  -264.9792  745.9507

Residual Sum of Squares: 1015076895
R-squared: 0.6383522
Adjusted R-squared: 0.6361059

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