[R-sig-Geo] exporting local estimates of gwr to csv file

Roger Bivand Roger.Bivand at nhh.no
Fri Jan 25 08:24:59 CET 2013


On Fri, 25 Jan 2013, Antonio Cabrera wrote:

> I ran a gwr model, with 2491 obs. No problems there, and mapping it all
> went smoothly. But I don't see all the local coefficients estimates in the
> summary (it only gives min, max, median, and quartile values), and would
> really like to use the beta coefficients in other programs, such as GeoDa.
> How can I take the estimated local coefficients and export them to a csv
> file?

Please DO read the function help page, and DO follow list rules, provide a 
small working example from the built-in data sets showing which package(s) 
you used, report the output of sessionInfo(), and NEVER post HTML.

library(spgwr)
# spgwr_0.6-18
data(columbus)
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)

So you have an object "col.gauss" - what is inside it? Typing its name 
shows it using its print method, use str() to see inside:

str(col.gauss)

It contains, as ?gwr documents:

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.

and a couple of other things returned when the lhat is returned. Read what 
the SDF component is, you can export it to shapefile with writeOGR() in 
rgdal or writeSpatialShape() in maptools. So:

writeSpatialShape(col.gauss$SDF, "my_GWR_results")

can be read into programs using shapefiles.

Please note that GWR is an unproven method, should never be used in work 
with policy consequences, and is ever only a diagnostic aid for finding 
model misspecification. Your aim is always to find and resolve the 
misspecification, then fit a global model (with the possible exception of 
Bayesian varying-coefficient approaches).

Hope this clarifies,

Roger

>
> Thanks in advance!
>
>
> - Tito
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list