Applied Spatial Statistics: Problem Set # 1

Doug Kossert

date()
## [1] "Mon Feb 10 17:40:00 2014"

Due Date: February 12, 2014

Total Points: 40

Use the Columbus, OH crime data from http://myweb.fsu.edu/jelsner/data/columbus.zip.

(1.) Read the data into R and create a choropleth map of the CRIME variable using the spplot method.

require(maptools)
## Loading required package: maptools
## Loading required package: sp
## Checking rgeos availability: FALSE
##      Note: when rgeos is not available, polygon geometry     computations in maptools depend on gpclib,
##      which has a restricted licence. It is disabled by default;
##      to enable gpclib, type gpclibPermit()
require(rgdal)
## Loading required package: rgdal
## rgdal: version: 0.8-16, (SVN revision 498)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.10.1, released 2013/08/26
## Path to GDAL shared files: C:/Users/urp21/Documents/R/win-library/3.0/rgdal/gdal
## GDAL does not use iconv for recoding strings.
## Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
## Path to PROJ.4 shared files: C:/Users/urp21/Documents/R/win-library/3.0/rgdal/proj
download.file("http://myweb.fsu.edu/jelsner/data/columbus.zip", "columbus.zip", 
    mode = "wb")
unzip("columbus.zip")
library(rgdal)
crime = readOGR(dsn = ".", "columbus")
## OGR data source with driver: ESRI Shapefile 
## Source: ".", layer: "columbus"
## with 49 features and 20 fields
## Feature type: wkbPolygon with 2 dimensions
require(RColorBrewer)
## Loading required package: RColorBrewer
rng = seq(0, 80, 10)
cls = brewer.pal(8, "OrRd")
spplot(crime, "CRIME", col.regions = cls, at = rng, sub = "Crime in Columbus, Ohio")

plot of chunk unnamed-chunk-6

(2.) Compute Moran's I for the CRIME variable.

require(spdep)
## Loading required package: spdep
## Loading required package: Matrix
## Loading required package: lattice
crime.nb = poly2nb(crime)
crime.wts = nb2listw(crime.nb)
m = length(crime$CRIME)
s = Szero(crime.wts)
moran(crime$CRIME, crime.wts, n = m, S0 = s)
## $I
## [1] 0.5002
## 
## $K
## [1] 2.226

(3.) Create a Moran's scatter plot using the CRIME variable. Label the axes and include the regression line.

Wcrim = lag.listw(crime.wts, crime$CRIME)
require(ggplot2)
## Loading required package: ggplot2
dat = data.frame(crim = crime$CRIME, Wcrim = Wcrim)
ggplot(dat, aes(x = crim, y = Wcrim)) + geom_point(col = "#00FF00") + geom_smooth(method = "lm", 
    col = "red") + xlab("Columbus, OH Crimes") + ylab("Spatial Lag of Crime") + 
    theme_bw()

plot of chunk unnamed-chunk-12

(4.) Check the value of Moran's I by determining the slope of the regression line.

lm(Wcrim ~ crim, data = dat)
## 
## Call:
## lm(formula = Wcrim ~ crim, data = dat)
## 
## Coefficients:
## (Intercept)         crim  
##        17.5          0.5