gwr                  package:spgwr                  R Documentation

_G_e_o_g_r_a_p_h_i_c_a_l_l_y _w_e_i_g_h_t_e_d _r_e_g_r_e_s_s_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

 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 - if
          'hatmatrix' is TRUE and no fit.points are given, two
          effective degrees of freedom sigmas will be used to generate
          alternative 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 nodes, if fit points have been
          given as an argument, and 'hatmatrix=FALSE'

predictions: default FALSE; if TRUE and no fit points given, return GW
          fitted values at data points, if fit points given and are a
          Spatial*DataFrame object containing the RHS variables in the
          formula, return GW predictions at the fit points

fittedGWRobject: a fitted 'gwr' object with a hatmatrix (optional), if
          given, and if fit.points are given and if 'se.fit' is TRUE,
          two effective degrees of freedom sigmas will be used to
          generate alternative coefficient standard errors

se.fit.CCT: default TRUE, compute local coefficient standard errors
          using formula (2.14), p. 55, in the GWR book

       x: an object of class "gwr" returned by the 'gwr' function

     ...: arguments to be passed to other functions

_D_e_t_a_i_l_s:

     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.

_V_a_l_u_e:

     A list of class gwr: 

     SDF: a 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.

    lhat: Leung et al. L matrix

      lm: Ordinary least squares global regression on the same model
          formula, as returned by lm.wfit().

bandwidth: the bandwidth used.

this.call: the function call used.

_A_u_t_h_o_r(_s):

     Roger Bivand Roger.Bivand@nhh.no

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     'gwr.sel', 'gwr.gauss', 'gwr.bisquare'

_E_x_a_m_p_l_e_s:

     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)])
     data(meuse)
     coordinates(meuse) <- c("x", "y")
     meuse$ffreq <- factor(meuse$ffreq)
     data(meuse.grid)
     coordinates(meuse.grid) <- c("x", "y")
     meuse.grid$ffreq <- factor(meuse.grid$ffreq)
     gridded(meuse.grid) <- TRUE
     xx <- gwr(cadmium ~ dist, meuse, bandwidth = 228, hatmatrix=TRUE)
     xx
     x <- gwr(cadmium ~ dist, meuse, bandwidth = 228, fit.points = meuse.grid, predict=TRUE, se.fit=TRUE, fittedGWRobject=xx)
     x
     library(lattice)
     trellis.par.set(sp.theme())
     spplot(x$SDF, "pred")
     spplot(x$SDF, "pred.se")
     ## Not run: 
       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")
       }
     ## End(Not run)

