Spatial Randomness Evaluation in R: Monte Carlo Test

Posted: May 14, 2012 in Spatial data
Tags: , , , ,

This post is a some kind of reply to this one.

So our goal is to determine whether our point process is random or not. We will use R and spatstat package in particular. Spatstat provides a very handy function for this, that uses K-function combined with Monte Carlo tests. I will spear you from burbling  about theory behind it – the necessary links were already provided. Lets get directly to action.

In this example I will test data about location of my “favourite” illegal dumps in St. Petersburg and Leningrad region.

# we will need: 

library(maptools)

library(rgdal)

library(spatstat)

# import data for analysis

S <- readShapePoints(“custom_path/dump_centroids.shp”, proj4string= CRS(“+proj=tmerc +lat_0=0 +lon_0=33 +k=1 +x_0=6500000 +y_0=0 +ellps=krass +towgs84=23.92,-141.27,-80.9,-0,0.35,0.82,-0.12 +units=m +no_defs”))

SP <- as(S, “SpatialPoints”)

P <- as(SP, “ppp”)

# perform the test itself with a 100 simulations

E <- envelope(P, Kest, nsim = 100)

plot(E, main = NULL)

And here is what we’ve got in the end, a fancy graph, which demonstrates that our data (Kobs) significantly deviates from a random process (Ktheo):

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s