What we do today:
- Learn the concept of IRP/CSR
- Learn how to test IRP/CSR for a given point pattern
- Learn the tests for ANN and K/L functions
Two conditions for independent random process (IRP)/complete spatial random (CSR) point patterns
1. Any event has equal probability of being in any location, a 1st order effect
2. The location of one event is independent of the location of another event, a 2nd order effect
Skip
Below: Three different outcomes from simulated patterns following a CSR point process.
Below: Histogram of simulated ANN values (from 1000 simulations)
Skip: interested students are encouraged to check the chapter.
Below: Examples of two randomly generated point patterns using population density as the underlying process.
Below: Histogram of the distribution of ANN values, if population density affects Walmart locations
Below: Histogram of the distribution of ANN values with income distribution affects Walmart locations
Below: Simulation results for the IRP/CSR hypothesized process
Below: Simulation results for an inhomogeneous hypothesized process.
library(tidyverse)
library(rgdal)
library(maptools)
library(raster)
library(spatstat)
# load the data
load(url("http://github.com/mgimond/Spatial/raw/master/Data/ppa.RData"))
# rescale from meter to kilometer
marks(starbucks) <- NULL
starbucks.km <- rescale(starbucks, 1000, "km")
ma.km <- rescale(ma, 1000, "km")
pop.km <- rescale(pop, 1000, "km")
pop.lg <- log(pop)
pop.lg.km <- rescale(pop.lg, 1000, "km")
ann.p <- mean(nndist(starbucks.km, k=1))
ann.p
## [1] 3.275492
n <- 599L # Number of simulations
ann.r <- vector(length = n) # Create an empty object to be used to store simulated ANN values
for (i in 1:n){
rand.p <- rpoint(n=starbucks.km$n, win=ma.km) # Generate random point locations
ann.r[i] <- mean(nndist(rand.p, k=1)) # Tally the ANN values
}
plot(rand.p, pch=16, main=NULL, cols=rgb(0,0,0,0.5))
hist(ann.r, main=NULL, las=1, breaks=40, col="bisque", xlim=range(ann.p, ann.r))
abline(v=ann.p, col="blue")
pop.km should be used to define where a point should be most likely placed (high population density) and least likely placed (low population density) under this new null model.n <- 599L
ann.r <- vector(length=n)
for (i in 1:n){
rand.p <- rpoint(n=starbucks.km$n, f=pop.km) # f defines the probability density of the points
ann.r[i] <- mean(nndist(rand.p, k=1))
}
Window(rand.p) <- ma.km # Replace raster mask with ma.km window
plot(rand.p, pch=16, main=NULL, cols=rgb(0,0,0,0.5))
hist(ann.r, main=NULL, las=1, breaks=40, col="bisque", xlim=range(ann.p, ann.r))
abline(v=ann.p, col="blue")
N.greater <- sum(ann.r > ann.p)
p <- min(N.greater + 1, n + 1 - N.greater)/(n+1)
p
## [1] 0.001666667
PPM1 <- ppm(starbucks.km ~ pop.lg.km)
PPM1
## Nonstationary Poisson process
##
## Log intensity: ~pop.lg.km
##
## Fitted trend coefficients:
## (Intercept) pop.lg.km
## -13.380761 1.231207
##
## Estimate S.E. CI95.lo CI95.hi Ztest Zval
## (Intercept) -13.380761 0.47393184 -14.309650 -12.45187 *** -28.23351
## pop.lg.km 1.231207 0.05706877 1.119354 1.34306 *** 21.57409
## Problem:
## Values of the covariate 'pop.lg.km' were NA or undefined at 41% (497 out
## of 1199) of the quadrature points
PPM0 <- ppm(starbucks.km ~ 1)
PPM0
## Stationary Poisson process
## Intensity: 0.004583629
## Estimate S.E. CI95.lo CI95.hi Ztest Zval
## log(lambda) -5.385264 0.07647191 -5.535146 -5.235382 *** -70.42147
starbucks.km$n / area(ma.km)
## [1] 0.008268627
anova(PPM0, PPM1, test="LRT")
## Analysis of Deviance Table
##
## Model 1: ~1 Poisson
## Model 2: ~pop.lg.km Poisson
## Npar Df Deviance Pr(>Chi)
## 1 498
## 2 499 1 492.28 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1