Learn R Programming

spgwr (version 0.5-7)

gwr: Geographically weighted regression

Description

The function implements the basic geographically weighted regression approach to exploring spatial non-stationarity for given global bandwidth and chosen weighting scheme.

Usage

gwr(formula, data=list(), coords, bandwidth, gweight=gwr.Gauss, 
	adapt=NULL, hatmatrix = FALSE, fit.points, 
	longlat=FALSE, se.fit=FALSE, weights, cl=NULL)
## S3 method for class 'gwr':
print(x, \dots)

Arguments

formula
regression model formula as in lm
data
model data frame, or SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package sp
coords
matrix of coordinates of points representing the spatial positions of the observations; may be omitted if the object passed through the data argument is from package sp
bandwidth
bandwidth used in the weighting function, possibly calculated by gwr.sel
gweight
geographical weighting function, at present gwr.Gauss() default, or gwr.gauss(), the previous default or gwr.bisquare()
adapt
either NULL (default) or a proportion between 0 and 1 of observations to include in weighting scheme (k-nearest neighbours)
hatmatrix
if TRUE, return the hatmatrix as a component of the result, ignored if fit.points given
fit.points
an object containing the coordinates of fit points; often an object from package sp; if missing, the coordinates given through the data argument object, or the coords argument are used
longlat
if TRUE, use distances on an ellipse with WGS84 parameters
se.fit
if TRUE, return local coefficient standard errors
weights
case weights used as in weighted least squares, beware of scaling issues, probably unsafe
cl
if NULL, ignored, otherwise cl must be an object describing a cluster created using makeCluster in the snow package. The cluster will then be used to hand off the calculation of local coefficients to cluster node
x
an object of class "gwr" returned by the gwr function
...
arguments to be passed to other functions

Value

  • A list of class gwr:
  • SDFa SpatialPointsDataFrame (may be gridded) or SpatialPolygonsDataFrame object (see package "sp") with fit.points, weights, GWR coefficient estimates, R-squared, and coefficient standard errors in its "data" slot.
  • lhatLeung et al. L matrix
  • lmOrdinary least squares global regression on the same model formula, as returned by lm.wfit().
  • bandwidththe bandwidth used.
  • this.callthe function call used.

Details

The function applies the weighting function in turn to each of the observations, or fit points if given, calculating a weighted regression for each point. The results may be explored to see if coefficient values vary over space. The local coefficient estimates may be made on a multi-node cluster using the cl argument to pass through a snow cluster. The function will then divide the fit points (which must be given separately) between the clusters for fitting. Note that each node will need to have the spgwr package present, so initiating by clusterEvalQ(cl, library(spgwr)) may save a little time per node. The function clears the global environment on the node of objects sent. Using two nodes reduces timings to a little over half the time for a single node.

References

Fotheringham, A.S., Brunsdon, C., and Charlton, M.E., 2002, Geographically Weighted Regression, Chichester: Wiley; http://www.nuim.ie/ncg/GWR/index.htm

See Also

gwr.sel, gwr.gauss, gwr.bisquare

Examples

Run this code
data(columbus)
col.lm <- lm(crime ~ income + housing, data=columbus)
summary(col.lm)
col.bw <- gwr.sel(crime ~ income + housing, data=columbus,
  coords=cbind(columbus$x, columbus$y))
col.gauss <- gwr(crime ~ income + housing, data=columbus,
  coords=cbind(columbus$x, columbus$y), bandwidth=col.bw, hatmatrix=TRUE)
col.gauss
col.d <- gwr.sel(crime ~ income + housing, data=columbus,
  coords=cbind(columbus$x, columbus$y), gweight=gwr.bisquare)
col.bisq <- gwr(crime ~ income + housing, data=columbus,
  coords=cbind(columbus$x, columbus$y), bandwidth=col.d, 
  gweight=gwr.bisquare, hatmatrix=TRUE)
col.bisq
data(georgia)
g.adapt.gauss <- gwr.sel(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov + PctBlack, data=gSRDF, adapt=TRUE)
res.adpt <- gwr(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov + PctBlack, data=gSRDF, adapt=g.adapt.gauss)
res.adpt
pairs(as(res.adpt$SDF, "data.frame")[,2:8], pch=".")
brks <- c(-0.25, 0, 0.01, 0.025, 0.075)
cols <- grey(5:2/6)
plot(res.adpt$SDF, col=cols[findInterval(res.adpt$SDF$PctBlack, brks, all.inside=TRUE)])
g.bw.gauss <- gwr.sel(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov + PctBlack, data=gSRDF)
  res.bw <- gwr(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov + PctBlack, data=gSRDF, bandwidth=g.bw.gauss)
  res.bw
  pairs(as(res.bw$SDF, "data.frame")[,2:8], pch=".")
  plot(res.bw$SDF, col=cols[findInterval(res.bw$SDF$PctBlack, brks, all.inside=TRUE)])
  g.bw.gauss <- gwr.sel(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov + PctBlack, data=gSRDF, longlat=TRUE)
  if (suppressWarnings(require(maptools)) &&
    suppressWarnings(require(gpclib))) {
    gSR <- as(gSRDF, "SpatialPolygons")
    length(slot(gSR, "polygons"))
    gSRouter <- unionSpatialPolygons(gSR, IDs=rep("Georgia", 159))
    SG <- GE_SpatialGrid(gSRouter, maxPixels = 100)
    SPxMASK0 <- overlay(gSRouter, SG$SG)
    SGDF <- SpatialGridDataFrame(slot(SG$SG, "grid"),
      data=data.frame(SPxMASK0=SPxMASK0),
      proj4string=CRS(proj4string(gSRouter)))
    SPxDF <- as(SGDF, "SpatialPixelsDataFrame")
    res.bw <- gwr(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov +
      PctBlack, data=gSRDF, bandwidth=g.bw.gauss, fit.points=SPxDF,
      longlat=TRUE)
    res.bw
    spplot(res.bw$SDF, "PctBlack")
  }

Run the code above in your browser using DataLab