gw.glm: Generalised Geographically Weighted Regression (GGWR)

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

View source: R/gw.glm.R

Description

This function allows for the calibration of a local model using a Generalised Geographically Weighted Regression (GGWR). At the moment this function has been coded in order to fit a Geographically Weighted Poisson Regression (GWPR) model.

Usage

1
gw.glm(formula, family, dframe, bw, kernel, coords)

Arguments

formula

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

family

a description of the error distribution and link function to be used in the local model as in the glm function. Currently the only option tested is "poisson".

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 gw.glm.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 Generalised Geographically Weighted Regression is a method recently proposed building on the simple GWR. It allows for the investigation of the existence of spatial non-stationarity in the relationship between a dependent and a set of independent variables in the cases in which the dependent function does not follow a normal distribution. 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 Geographically Weighted Poisson Regression currently supported here along with examples from internal migration modelling can be found in two publication by Kalogirou (2003, 2015). 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 glm function instead of fitting the complete local model with matrix algebra. The latter approach may be faster but more prone to rounding error and code crashing.

Value

GGLM_LEst

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

GGLM_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.

GGLM_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

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

Kalogirou, S. (2016) Destination Choice of Athenians: an application of geographically weighted versions of standard and zero inflated Poisson spatial interaction models, Geographical Analysis, 48(2),pp. 191-230. DOI: 10.1111/gean.12092 http://onlinelibrary.wiley.com/doi/10.1111/gean.12092/abstract

See Also

gw.glm.bw gw.zi gwr

Examples

1
2
RDF <- random.test.data(12,12,3,"poisson")
gwpr <- gw.glm(dep ~ X1 + X2, "poisson", RDF, 50, kernel = 'adaptive', cbind(RDF$X,RDF$Y))

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

Call:
glm(formula = dep ~ X1 + X2, family = "poisson", data = RDF)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-2.42765  -0.83447  -0.03358   0.78343   2.47366  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  2.03803    0.08368  24.356   <2e-16 ***
X1           0.02096    0.10859   0.193   0.8469    
X2          -0.17450    0.10339  -1.688   0.0914 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 156.82  on 143  degrees of freedom
Residual deviance: 153.94  on 141  degrees of freedom
AIC: 697.99

Number of Fisher Scoring iterations: 4


Residual Sum of Squares: 1050.833
R-squared: 0.01911024
Adjusted R-squared: -0.001908831
--------------- Local Model Summary ---------------

Residuals:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-5.5399 -1.7775 -0.1643  0.0000  1.8498  6.7896 

Coefficients:
                    Min       Max       Mean       StD
X.Intercept.  1.6445704 2.3109455  2.0524551 0.1430297
X1           -0.5965192 0.3458790 -0.0380475 0.2005946
X2           -0.6126465 0.3972789 -0.1465251 0.2062113

Residual Sum of Squares: 880.615
R-squared: 0.1779982
Adjusted R-squared: 0.1603839

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