[R-sig-Geo] Moran's I based on ZIP Code data

Roger Bivand Roger.Bivand at nhh.no
Sat Aug 21 00:33:41 CEST 2010


On Fri, 20 Aug 2010, Michael Haenlein wrote:

> Thanks very much for your reply, Roger!
>
> I have downloaded the shape files from the US Census ZCTA webpage. In case
> anyone else is interested in obtaining them the URL is:
> http://www.census.gov/geo/www/cob/z52000.html#shp
>
> I also managed to import those files into R and to convert them into
> a neighbour list:
>
> Alabama <-readShapePoly("c:/111/zt01_d00")
> Alaska <-readShapePoly("c:/111/zt02_d00")
> Arizona <-readShapePoly("c:/111/zt04_d00")
> ...
>
> Alabama.nb <- poly2nb(Alabama)
> Alaska.nb <- poly2nb(Alaska)
> Arizona.nb  <- poly2nb(Arizona)
> ...
>
> The problem is that instead of having one neighbour list I now have 52 ones
> (one for each state).
> Is there a way to combine all of them into one large neighbour list which I
> can then use as an input for my analysis?
>

Combine the imported SpatialPolygonsDataFrames, possibly after filtering 
out the ones with no hits, and possibly after checking for ZIP uniqueness. 
If not unique (if a ZIP crosses a state boundary or if the input maps 
assign a single ZIP code to multiple Polygons objects) use 
unionSpatialPolygons in maptools (usual warning about gpclib) or 
gUnionCascade() in rgeos. If you can install rgeos, you can also speed up 
the poly2nb() step for the whole map by providing a GEOS-generated list of 
candidate neighbours.

It is feasible, but perhaps tedious - there are a lot of polygons!

Good luck!

Roger

>
>
>
> -----Original Message-----
> From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
> Sent: Thursday, August 19, 2010 23:54
> To: Michael Haenlein
> Cc: r-sig-geo at stat.math.ethz.ch
> Subject: Re: [R-sig-Geo] Moran's I based on ZIP Code data
>
> On Thu, 19 Aug 2010, Michael Haenlein wrote:
>
> The first thing is to get the locations of the zip codes (about 30,000?) -
> they are published as shapefiles by state (US Census ZCTA), so a polygon
> representation is possible, but you could also look for a point
> representation. Next make a neighbour list (nb) object to the zip code
> entities for which you have observations. Then you could use nb2blocknb() in
> spdep to "block up" observations where more than one belongs to the same zip
> code, which effectively makes all the observations in a zip code neighbours,
> and adds all the observations in neighbouring zip codes too.
> It was written for housing data with only a postcode but no geocoded
> address.
>
> Hope this helps,
>
> Roger
>
>
> --
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School of
> Economics and Business Administration, 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
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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