Applied Spatial Statistics: Problem Set # 1

Sarah Strazzo

date()
## [1] "Mon Feb 04 15:29:12 2013"

Due Date: February 13, 2013

Total Points: 40

Activate necessary packages:

require(maptools)
require(sp)
require(RColorBrewer)
require(spdep)
require(ggplot2)

Use the Columbus, OH crime data from “http://geodacenter.org/downloads/data-files/columbus.zip”.

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

tmp = download.file("http://geodacenter.org/downloads/data-files/columbus.zip", 
    "columbus.zip", mode = "wb")
unzip("columbus.zip")
CC = readShapeSpatial("columbus")
range(CC$CRIME)
## [1]  0.1783 68.8920
rng = seq(0, 70, 10)
cls = brewer.pal(7, "Reds")
spplot(CC, "CRIME", col.regions = cls, at = rng, colorkey = list(space = "bottom"), 
    sub = "Crime")

plot of chunk mapCrime

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

CC.nb = poly2nb(CC)
CC.wts = nb2listw(CC.nb)

m = length(CC$CRIME)
s = Szero(CC.wts)
moran(CC$CRIME, CC.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.

crime = CC$CRIME
wCrime = lag.listw(CC.wts, crime)
dat = data.frame(crime = crime, wCrime = wCrime)
ggplot(dat, aes(x = crime, y = wCrime)) + geom_point() + geom_smooth(method = "lm") + 
    xlab("Crime") + ylab("Spatial Lag of Crime")

plot of chunk MoransScatterPlot

4. Check the value of Moran's I by finding the slope of the regression line.

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