These are two methods of looking at the spatial patterns in a dataset. Understanding how things are related in space can help us better understand the underlying mechanisms driving these patterns. We look for clumping, repulsion, and randomness of points at several distances.
First, I will load some required packages to perform some spatial patterns analyses and investigate a few datasets.
# foo <- clickppp(n = 50) # 50 points
# KDE
# plot(density(foo))
# points(foo,pch=20)
# K
# env <- envelope(foo, Kest, nsim = 100)
# plot(env)
library(spatstat)
## Warning: package 'spatstat' was built under R version 3.3.2
## Loading required package: nlme
## Warning: package 'nlme' was built under R version 3.3.2
## Loading required package: rpart
## Warning: package 'rpart' was built under R version 3.3.2
##
## spatstat 1.51-0 (nickname: 'Poetic Licence')
## For an introduction to spatstat, type 'beginner'
##
## Note: R version 3.3.1 (2016-06-21) is more than 9 months old; we strongly recommend upgrading to the latest version
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.2
library(sp)
## Warning: package 'sp' was built under R version 3.3.2
library(maptools)
## Warning: package 'maptools' was built under R version 3.3.2
## Checking rgeos availability: TRUE
This is the first dataset I will investigate. It contains the spatial data of three species of fungi. I will start off by looking at the summary of the data to get a general idea of how this dataset is structured and plot the data to get a visual overview.
data(sporophores)
summary(sporophores)
## Marked planar point pattern: 330 points
## Average intensity 0.004998072 points per square cm
##
## Coordinates are given to 6 decimal places
##
## Multitype:
## frequency proportion intensity
## L laccata 190 0.57575760 0.0028776780
## L pubescens 11 0.03333333 0.0001666024
## Hebloma spp 129 0.39090910 0.0019537920
##
## Window: polygonal boundary
## single connected closed polygon with 128 vertices
## enclosing rectangle: [-145, 145] x [-145, 145] cm
## Window area = 66025.5 square cm
## Unit of length: 1 cm
## Fraction of frame area: 0.785
plot(sporophores)
This is a marked planar point pattern datafile, which means it gives us attribute information for each point in space. For this dataset, it tells us which species of fungi resides at each point in space: L laccata, L pubescens, or Hebloma spp. There are very few L pubescens. The window is a polygon measured in 1 cm units.
From this general plot, it looks like the sporophores are generally clumping. Specifically the L. laccata species appears to form denser clumps than the other species. The Hebloma spp appears to spread out more than clump together, but they occur in generally the same areas. Perhaps this is how they grow. There are fewer individuals of the L. pubescens, but they also appear to form one distint clump and a few others outside of this clump. It looks like the Hembloms spp. may be repulsed from the other two species.
Next, I will look at some density displays of these data to investigate these patterns further.
# Create object to hold density function and get ask for summary
spore.den <- density(sporophores)
# Three axis density plot
persp(spore.den, theta=30, phi=30)
# Density plot with contour lines and points showing where the fungi are located.
plot(spore.den, main="Density of Fungi")
contour(spore.den, add=T)
points(sporophores, pch=20)
Both density plots indicate a high density cluster in the upper right corner of the plot. It looks like there are other clusters to the left, but the density plot indicates that this isn’t as clustered as the upper corner.
Next, I will perfrom Ripley’s K-functions on these data and plot the results to investigate the patterns within these data.
n <- 100
sporeK <- envelope(sporophores, fun= Kest, nsim= n, verbose=F)
plot(sporeK)
The observed \(\hat K(r)\) function falls above the envelope, indicating these three species of sporophores are highly clumped at every distance. Although the K function plot for all the data together indicates clumping, perhaps there is some species variation. I will subset the data by species and invesitage further…
# Create an array of K function plots for this dataset
spore.spp <- alltypes(sporophores, "K", envelope=T, verbose=F)
plot(spore.spp)
The three diagonal plots show the K functions within species. These plots indicate that each species clumps together at all distances. There is a wider envelope (indicating confidence interval) for L. pubescens because there are only 11 individuals of this species within the dataset and less information to perform the calculations. The middle left plot indicates that L.laccata and L. pubescens tend to clump at distances less than 40cm, but then tend to repel at distances greater than 60cm. These values appear to ride just along the upper and lower edge of the envelope, so they are not dramatically clumped or repelled. The lower left hand plot indicates that L.laccata and Hebloma spp. are randomly distributed at distances less than 40 cm, but tend to clump at distances greater than 40cm. The bottom middle plot indicates L.pubescens is randomly distributed at shorter disastances and then tends towards clumping at distances greater than about 65cm.
Spatial pattern of nests of two ant species.
data("ants")
summary(ants)
## Marked planar point pattern: 97 points
## Average intensity 0.0002261486 points per square unit (one unit = 0.5
## feet)
##
## Coordinates are integers
## i.e. rounded to the nearest unit (one unit = 0.5 feet)
##
## Multitype:
## frequency proportion intensity
## Cataglyphis 29 0.2989691 6.761144e-05
## Messor 68 0.7010309 1.585372e-04
##
## Window: polygonal boundary
## single connected closed polygon with 11 vertices
## enclosing rectangle: [-25, 803] x [-49, 717] units
## Window area = 428922 square units
## Unit of length: 0.5 feet
## Fraction of frame area: 0.676
This is a marked planar point pattern datafile, which means it gives us attribute information for each point in space. For this dataset, it tells us which species of ant occupies each nest: Catagyphic or Messor. There are over 50% more Messor ant nests in this dataset. The window is a polygon and the units are 0.5 feet.
# Create object to hold density function and get ask for summary
ants.den <- density(ants)
summary(ants.den)
## real-valued pixel image
## 128 x 128 pixel array (ny, nx)
## enclosing rectangle: [-25, 803] x [-49, 717] units (one unit = 0.5 feet)
## dimensions of each pixel: 6.47 x 5.984375 units
## (one unit = 0.5 feet)
## Image is defined on a subset of the rectangular grid
## Subset area = 429038.731933594 square units
## Subset area fraction = 0.676
## Pixel values (inside window):
## range = [0.0001244011, 0.0003996359]
## integral = 97.57579
## mean = 0.0002274289
# plot the three-axis density plot
persp(ants.den, theta=30, phi=30)
# Density plot with contour lines and points showing where the nests are located.
plot(ants.den, main="Density of Ant nests")
contour(ants.den, add=T)
points(ants, pch=20)
These density plots indicate that ant nests are more dense in the bottom right hand corner of the polygon. The is also the only location with a density this high, which suggest the ant nests are only clumped together in this one location. The rest of the plot looks pretty random. We can investigate these patterns further with Ripley’s K functions.
n <- 100
antsK <- envelope(ants, fun=Kest, nsim=n, verbose=FALSE)
plot(antsK)
The observed \(\hat K (r)\) function is within the envelope, which indicates that the ants data follow CSR at every distance.
Now, let’s see what the spatial pattern looks like for the two species of ants: Cataglyphis and Messor.
# Create subsets of the data for each ant species
catsp <- subset(ants, marks=="Cataglyphis", drop=T)
messorsp <- subset(ants, marks=="Messor", drop=T)
# Density plot for the Cataglyphis species with points added
plot(density(catsp), main="Density of Cataglyphis Ant Nests")
points(catsp, pch=20)
# Density plot for the Messor species with points added
plot(density(messorsp), main="Density of Messor Ant Nests")
points(messorsp, pch=20)
The density plots indicate that there are more ant nests of both species in the lower right hand corner of the study area. There are no Cataglyphis ant nests in the upper right side of the plot, but several Messor ant nests. This is the only location on the plot where the two species of ant nests appear to be repelled.
# K function plots for each species of ants
plot(envelope(catsp, fun= Kest, nsim= n, verbose=F))
plot(envelope(messorsp, fun= Kest, nsim=n, verbose=F))
# Array of K function plots for dataset
ants2 <- alltypes(ants, "K", envelope= TRUE, verbose= FALSE)
plot(ants2)
K-function plots indicate that within and between ant nests follow a CSR at all distances, which indicatest that there is not clear clumping or repelling pattern in this dataset.