Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Lecture:PointPatternAnalysis
Lecture:PointPatternAnalysis
KeyConceptscoveredinthelectureinclude:
1.P.P.Terminology(point,event,window)
2.PoissonPointProcess
3.PurposeofPointPatternAnalysis
4.Typesofdistribution(random,uniform,clustered)
5.Kernelestimationandtypesofkernels
6.QuadrantbasedPPA
TheinclassexerciseexplorestheWikiLeaksIraqDataandperformsapointpatternanalysis.
Part1:Organizethedata
# Install all required libraries
library(spatstat)
## Loading required package: mgcv
## This is mgcv 1.7-22. For overview type 'help("mgcv-package")'.
## Loading required package: deldir
## deldir 0.0-21
## spatstat 1.30-0 Type 'help(spatstat)' for an overview of
spatstat
## 'latest.news()' for news on latest version 'licence.polygons()'
for
## licence information on polygon calculations
library(sp)
library(rgdal)
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
1/26
10/29/2016
Lecture:PointPatternAnalysis
deaths <read.csv("E:/Quant/inClassExercises/InClassExerciseData/Deaths
only.csv") #Read in the dataset
# Organize the data. Use sub(). This replaces one text string
for
# another.
deaths$Type <- sub(deaths$Type, pattern = "CRIMINAL EVENT",
replacement = "Criminal Event")
deaths$Type <- sub(deaths$Type, pattern = "criminal event",
replacement = "Criminal Event")
deaths$Type <- sub(deaths$Type, pattern = "EXPLOSIVE HAZARD",
replacement = "Explosive Hazard")
# Make sure the old fields are removed:
deaths$Type <- factor(deaths$Type)
levels(deaths$Type)
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
2/26
10/29/2016
Lecture:PointPatternAnalysis
"Enemy Action"
"Explosive
"Friendly Fire"
"Non-Combat
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
3/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
4/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
5/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
6/26
10/29/2016
Lecture:PointPatternAnalysis
Part3:ExploratorySpatialAnalysis
deaths.spp.rp <- spTransform(deaths.spp, CRS("+init=epsg:3839"))
#Somehow this projects data into meters...
# attach these values to the CSV...
deaths.spp.rp$Easting <- coordinates(deaths.spp.rp)[, 1]
deaths.spp.rp$Northing <- coordinates(deaths.spp.rp)[, 2]
# looking at the entire country can be difficult... Let's refocus
our
# study area to Baghdad...
deaths.df.rp.bag <- deaths.spp.rp@data[deaths.spp.rp@data$Region
== "MND-BAGHDAD",
] #Note, this is not a spatial data frame.
plot(x = deaths.df.rp.bag$Easting, y = deaths.df.rp.bag$Northing)
#plot the points. This can be very messy because distortion can
really easily creep into this.
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
7/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
8/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
9/26
10/29/2016
Lecture:PointPatternAnalysis
Someusefulinfo:
Aboutspatstat
Todaywewillusethreetypesofspatstat()objects:
ppp:isasetofpointslocatedinspace.Pointscanhaveattributescalledmarksortheppp
objectcanbeunmarkedinwhichcasetheobjectstoresonlylocations.Marksareusedto
differentiatetypesofpointsortostoreavariablethatdescribessomecontinuousvariablefor
eachpoint.Forexample,ifthepointsweretreesthemarksmightrecordspeciesanddbh.
owin:isawindowwhichdefinesthespatialextentofthepppobject.Allpppobjectsmusthave
anowin.im:apixelimage,likearasterlayerinaGIS.Oftenderivedfromthepppobject.
deaths.chull <- convexhull.xy(x = deaths.df.rp.bag$Easting, y =
deaths.df.rp.bag$Northing) #Define the Convex hull of the area of
interest...
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
10/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
Use colMeans() or
11/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
12/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
13/26
10/29/2016
Lecture:PointPatternAnalysis
## NULL
[,1]
[,2]
[,3]
[,4]
[1,] 2.016e-04 0.000e+00 0.000e+00 0.000e+00
[2,] 0.000e+00 5.219e-05 -1.948e-04 1.948e-04
[3,] 0.000e+00 1.866e+04 5.000e+03 -5.000e+03
[4,] -2.018e+03 -2.588e+02 9.602e+02 -9.592e+02
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
14/26
10/29/2016
Lecture:PointPatternAnalysis
##
##
##
##
##
[,1]
[,2]
[,3]
[,4]
[1,] -1.746e-04 -2.610e-05 9.739e-05 -9.739e-05
[2,] 1.008e-04 -4.520e-05 1.687e-04 -1.687e-04
[3,] -5.915e-13 1.866e+04 5.000e+03 -5.000e+03
[4,] 1.249e+03 4.839e+02 -1.811e+03 1.812e+03
[,1]
[,2]
[,3]
[,4]
[1,] -1.008e-04 -4.520e-05 1.687e-04 -1.687e-04
[2,] 1.746e-04 -2.610e-05 9.739e-05 -9.739e-05
[3,] -1.024e-12 1.866e+04 5.000e+03 -5.000e+03
[4,] 1.452e+02 5.805e+02 -2.172e+03 2.173e+03
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
15/26
10/29/2016
##
##
##
##
##
Lecture:PointPatternAnalysis
[,1]
[,2]
[,3]
[,4]
[1,] -3.502e-05 -5.140e-05 1.918e-04 -1.918e-04
[2,] 1.986e-04 -9.063e-06 3.382e-05 -3.382e-05
[3,] -1.165e-12 1.866e+04 5.000e+03 -5.000e+03
[4,] -6.317e+02 5.583e+02 -2.089e+03 2.090e+03
######################################
would be
######################################
legend...
######################################
a
######################################
plot(split(deaths.ppp))
plot(density(split(deaths.ppp)))
#Kernel maps
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
16/26
10/29/2016
Lecture:PointPatternAnalysis
contour(density(split(deaths.ppp)), axes = F)
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
#contour maps
17/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
18/26
10/29/2016
Lecture:PointPatternAnalysis
##
##
0
0.0
50
100
150
200
828.7 1657.5 2486.2 3314.9
Phew,thatwasalotofdatavisualizaiton.Part4:ExploratoryPointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
19/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
20/26
10/29/2016
Lecture:PointPatternAnalysis
# Change the color scheme... We can use colors() to see the all
the colors
# available in R. The results are somewhat overwhelming...
grRd <- colorRampPalette(c("grey60", "red"))
co <- colourmap(grRd(5), range = c(1e-06, 7e-05)) #Define legend
stretch for colors
plot(deaths.death.im, main = "Weighted Density Map of \nWikiLeaks
Deaths in Baghdad",
col = co)
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
21/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
22/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
23/26
10/29/2016
Lecture:PointPatternAnalysis
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
24/26
10/29/2016
Lecture:PointPatternAnalysis
#nothing happens?
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
25/26
10/29/2016
##
##
##
##
##
##
##
##
Lecture:PointPatternAnalysis
p
p
p
p
=
=
=
=
0.6355
0.5596
0.4912
0.4498
plot(split(nnc))
Oy,IhavenoideahowthisisgoingtobecondensedintomyRJournal
http://rstudiopubsstatic.s3.amazonaws.com/5272_9bfbb208c5e6425a93a2b2865d8a4c80.html
26/26