An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100820/5c99b89e/attachment.pl>
Moran's I based on ZIP Code data
5 messages · Michael Haenlein, Sharon O'Donnell, Nikhil Kaza +2 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100820/2580a370/attachment.pl>
The national files for the zipcodes seems greyed out. I would caution against creating nb lists for each state separate and then creating a US wide neighbour list because, there will some zip codes in Alabama who are neighbours to zipcodes in GA, MS, TN. I would merge them first into one big file and then construct the poly list. you may run into memory issues for this operation, depending on your set up. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.list at gmail.com
On Aug 20, 2010, at 1:06 PM, Sharon O'Donnell wrote:
Check out http://www2.census.gov/cgi-bin/shapefiles2009/national-files - left hand side has national - level data. All 5 digit zipcode files are based on 2002 data but zipcode boundaries change less frequently than tracts and blockgroups, there may be some issues in correctly mapping out areas in high growth regions of the U.S. with new zipcodes. Sharon On Fri, Aug 20, 2010 at 12:47 PM, Michael Haenlein <haenlein at escpeurope.eu>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? -----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 [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
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
Nikhil has a point here. The combined shapefile is > 1 GB. As I am into working with national census datasets (and would eventually like to do the same for tracts and blocks), I created a neighbor list and then a weights list. The latter required using the zero.policy=TRUE switch as we are working with many islands that have no topological neighbors. I uploaded the two as R objects to http:giscience.hunter.cuny.edu/zcta/zcta.nb.R and http://giscience.hunter.cuny.edu/zcta/zcta.w.R. Cheers, Jochen
Nikhil Kaza wrote:
The national files for the zipcodes seems greyed out. I would caution against creating nb lists for each state separate and then creating a US wide neighbour list because, there will some zip codes in Alabama who are neighbours to zipcodes in GA, MS, TN. I would merge them first into one big file and then construct the poly list. you may run into memory issues for this operation, depending on your set up. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.list at gmail.com On Aug 20, 2010, at 1:06 PM, Sharon O'Donnell wrote:
Check out http://www2.census.gov/cgi-bin/shapefiles2009/national-files - left hand side has national - level data. All 5 digit zipcode files are based on 2002 data but zipcode boundaries change less frequently than tracts and blockgroups, there may be some issues in correctly mapping out areas in high growth regions of the U.S. with new zipcodes. Sharon On Fri, Aug 20, 2010 at 12:47 PM, Michael Haenlein <haenlein at escpeurope.eu>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? -----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 [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo