Load packages & set working directory
library(sf)
## Warning: package 'sf' was built under R version 3.6.2
## Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library(spatstat)
## Warning: package 'spatstat' was built under R version 3.6.2
## Loading required package: spatstat.data
## Warning: package 'spatstat.data' was built under R version 3.6.2
## Loading required package: spatstat.geom
## Warning: package 'spatstat.geom' was built under R version 3.6.2
## spatstat.geom 2.3-0
## Loading required package: spatstat.core
## Warning: package 'spatstat.core' was built under R version 3.6.2
## Loading required package: nlme
## Warning: package 'nlme' was built under R version 3.6.2
## Loading required package: rpart
## spatstat.core 2.3-2
## Loading required package: spatstat.linnet
## Warning: package 'spatstat.linnet' was built under R version 3.6.2
## spatstat.linnet 2.3-0
##
## spatstat 2.2-0 (nickname: 'That's not important right now')
## For an introduction to spatstat, type 'beginner'
setwd("~/Documents/geog6000/lab14")
Read in Data & Convert to ppp object (point pattern object)
# Tree locations
urkiola.sf <- st_read("../datafiles/urkiola/urkiola.shp")
## Reading layer `urkiola' from data source
## `/Users/serenamadsen/Documents/geog6000/datafiles/urkiola/urkiola.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 1245 features and 5 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 2.1 ymin: 0.1 xmax: 219.1 ymax: 149.9
## CRS: NA
# Park boundary
urkiola.win <- st_read("../datafiles/urkiola/urkiolaWindow.shp")
## Reading layer `urkiolaWindow' from data source
## `/Users/serenamadsen/Documents/geog6000/datafiles/urkiola/urkiolaWindow.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 1 feature and 3 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: 0.05 ymin: 0.05 xmax: 219.95 ymax: 149.95
## CRS: NA
urkiola.win <- as.owin(urkiola.win)
# First extract coordinates
urkiola.crds <- st_coordinates(urkiola.sf)
## Convert to ppp
urkiola.ppp <- ppp(x = urkiola.crds[, 1], y = urkiola.crds[,2],
marks = as.factor(urkiola.sf$tree), window = urkiola.win)
plot(urkiola.ppp)
Give the intensity (spatial density) of the combined set of two tree species by using the summary() function
summary(urkiola.ppp)
## Marked planar point pattern: 1245 points
## Average intensity 0.06564029 points per square unit
##
## Coordinates are given to 1 decimal place
## i.e. rounded to the nearest multiple of 0.1 units
##
## Multitype:
## frequency proportion intensity
## birch 886 0.7116466 0.04671269
## oak 359 0.2883534 0.01892760
##
## Window: polygonal boundary
## single connected closed polygon with 44 vertices
## enclosing rectangle: [0.05, 219.95] x [0.05, 149.95] units
## (219.9 x 149.9 units)
## Window area = 18967 square units
## Fraction of frame area: 0.575
Spatial density: 0.06564029 points per square unit
Plot the distribution of the two tree species as separate figures
oakplot <- plot(split(urkiola.ppp)$oak, "Oak Trees")
birchplot <- plot(split(urkiola.ppp)$birch, "Birch Trees")
Now make plots of the kernel density of each species, and compare these plots.
oak.k <- split(urkiola.ppp)$oak
birch.k <- split(urkiola.ppp)$birch
plot(density(oak.k, sigma = 30))
plot(density(birch.k, sigma = 30))
Do they suggest that the two species co-occur within the park?
This suggests that the two species do minimally co-occur, but make some kind of an effort to stay away from each other. The most overlap is seen in the pink areas. I am not entirely sure how significant this is, given that legends are scaled differently.
Using Ripley’s K function, examine the individual distributions of the two species for non-random spatial organization. Use the envelope() function to test the obtained Ripley’s K against a hypothesis of Complete Spatial Randomness. Plot the results and state whether or not each species has a random distribution or not, and if not, whether the trees are clustered or have a regular distribution. Note that using summary() on the output of the envelope() function with give the significance level of the Monte Carlo test.
oak.kest <- Kest(oak.k)
birch.kest <- Kest(birch.k)
plot(oak.kest)
plot(birch.kest)
#envelope function oak
oak.kest.mc <- envelope(oak.k, fun = 'Kest', nsim = 99, verbose = FALSE)
plot(oak.kest.mc, shade = c("hi", "lo"))
summary(oak.kest.mc)
## Pointwise critical envelopes for K(r)
## and observed value for 'oak.k'
## Obtained from 99 simulations of CSR
## Alternative: two.sided
## Upper envelope: pointwise maximum of simulated curves
## Lower envelope: pointwise minimum of simulated curves
## Significance level of Monte Carlo test: 2/100 = 0.02
## Data: oak.k
#envelope function birch
birch.kest.mc <- envelope(birch.k, fun = 'Kest', nsim = 99, verbose = FALSE)
plot(birch.kest.mc, shade = c("hi", "lo"))
summary(birch.kest.mc)
## Pointwise critical envelopes for K(r)
## and observed value for 'birch.k'
## Obtained from 99 simulations of CSR
## Alternative: two.sided
## Upper envelope: pointwise maximum of simulated curves
## Lower envelope: pointwise minimum of simulated curves
## Significance level of Monte Carlo test: 2/100 = 0.02
## Data: birch.k
Both species are not random because their black lines are above the blue line. They are also both clustered, as they are above, not below, the other lines.
Finally, test the spatial dependence between the two distributions to test if the two species truly co-occur or not. Use the envelope() function again, but with the Kcross() function to estimate the cross-dependence. Plot the results and state whether the distributions of the two species show positive, negative or no correlation with each other
urkiola.ppp.kc <- envelope(urkiola.ppp, Kcross, i = "oak", j = "birch", nsim = 99, verbose = FALSE)
plot(urkiola.ppp.kc)
These trees seem to be randomly distributed, neither co-occurring or competing.