Applied Spatial Statistics: Problem Set # 1

Tyler Fricker

date()
## [1] "Mon Feb 10 21:07:59 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
## Warning: package 'sp' was built under R version 3.0.2
## Checking rgeos availability: TRUE
require(ggplot2)
## Loading required package: ggplot2
require(rgdal)
## Loading required package: rgdal
## Warning: package 'rgdal' was built under R version 3.0.2
## rgdal: version: 0.8-14, (SVN revision 496) Geospatial Data Abstraction
## Library extensions to R successfully loaded Loaded GDAL runtime: GDAL
## 1.9.2, released 2012/10/08 Path to GDAL shared files:
## /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rgdal/gdal
## Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480] Path to
## PROJ.4 shared files:
## /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rgdal/proj
require(RColorBrewer)
## Loading required package: RColorBrewer
download.file("http://myweb.fsu.edu/jelsner/data/columbus.zip", "columbus.zip")
unzip("columbus.zip")
CBUS = readOGR(dsn = ".", layer = "columbus", p4s = "+proj=longlat +ellps=clrk66")
## OGR data source with driver: ESRI Shapefile 
## Source: ".", layer: "columbus"
## with 49 features and 20 fields
## Feature type: wkbPolygon with 2 dimensions
slotNames(CBUS)
## [1] "data"        "polygons"    "plotOrder"   "bbox"        "proj4string"
head(CBUS@data)
##      AREA PERIMETER COLUMBUS_ COLUMBUS_I POLYID NEIG HOVAL    INC CRIME
## 0 0.30944     2.441         2          5      1    5 80.47 19.531 15.73
## 1 0.25933     2.237         3          1      2    1 44.57 21.232 18.80
## 2 0.19247     2.188         4          6      3    6 26.35 15.956 30.63
## 3 0.08384     1.428         5          2      4    2 33.20  4.477 32.39
## 4 0.48889     2.997         6          7      5    7 23.23 11.252 50.73
## 5 0.28308     2.336         7          8      6    8 28.75 16.029 26.07
##     OPEN  PLUMB DISCBD     X     Y NSA NSB EW CP THOUS NEIGNO
## 0 2.8507 0.2172   5.03 38.80 44.07   1   1  1  0  1000   1005
## 1 5.2967 0.3206   4.27 35.62 42.38   1   1  0  0  1000   1001
## 2 4.5346 0.3744   3.89 39.82 41.18   1   1  1  0  1000   1006
## 3 0.3944 1.1869   3.70 36.50 40.52   1   1  0  0  1000   1002
## 4 0.4057 0.6246   2.83 40.01 38.00   1   1  1  0  1000   1007
## 5 0.5631 0.2541   3.78 43.75 39.28   1   1  1  0  1000   1008
range(CBUS$CRIME)
## [1]  0.1783 68.8920
rng = seq(0, 70, 10)
cls = brewer.pal(7, "Reds")
spplot(CBUS, "CRIME", col.regions = cls, at = rng, sub = "Columbus, Ohio Crime")

plot of chunk unnamed-chunk-2

  1. Compute Moran's I for the CRIME variable.
require(spdep)
## Loading required package: spdep
## Warning: package 'spdep' was built under R version 3.0.2
## Loading required package: Matrix Loading required package: lattice
CBUS.nb = poly2nb(CBUS)
CBUS.wts = nb2listw(CBUS.nb)
m = length(CBUS$CRIME)
s = Szero(CBUS.wts)
moran(CBUS$CRIME, CBUS.wts, n = m, S0 = s)
## $I
## [1] 0.5002
## 
## $K
## [1] 2.226
  1. Create a Moran's scatter plot using the CRIME variable. Label the axes and include the regression line.
Wcrime = lag.listw(CBUS.wts, CBUS$CRIME)
Wcrime[1]
## [1] 24.71
dat = data.frame(CRIME = CBUS$CRIME, Wcrime = Wcrime)
ggplot(dat, aes(x = CRIME, y = Wcrime)) + geom_point() + geom_smooth(method = "lm") + 
    xlab("Columbus, Ohio Crime") + ylab("Spatial Lag of Crime")

plot of chunk scatterplot

  1. Check the value of Moran's I by determining 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