library(spatstat)
## Warning: package 'spatstat' was built under R version 4.1.2
## Loading required package: spatstat.data
## Warning: package 'spatstat.data' was built under R version 4.1.2
## Loading required package: spatstat.geom
## Warning: package 'spatstat.geom' was built under R version 4.1.2
## spatstat.geom 2.3-0
## Loading required package: spatstat.core
## Warning: package 'spatstat.core' was built under R version 4.1.2
## Loading required package: nlme
## Loading required package: rpart
## spatstat.core 2.3-2
## Loading required package: spatstat.linnet
## Warning: package 'spatstat.linnet' was built under R version 4.1.2
## spatstat.linnet 2.3-0
##
## spatstat 2.2-0 (nickname: 'That's not important right now')
## For an introduction to spatstat, type 'beginner'
library(sf)
## Warning: package 'sf' was built under R version 4.1.2
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1
# Tree Locations
urkiola.sf <- st_read("C:/Users/taylu/OneDrive/Documents/Geog6000/Datafiles/urkiola/urkiola/urkiola.shp")
## Reading layer `urkiola' from data source
## `C:\Users\taylu\OneDrive\Documents\Geog6000\Datafiles\urkiola\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("C:/Users/taylu/OneDrive/Documents/Geog6000/Datafiles/urkiola/urkiola/urkiolaWindow.shp")
## Reading layer `urkiolaWindow' from data source
## `C:\Users\taylu\OneDrive\Documents\Geog6000\Datafiles\urkiola\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 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
The average intensity is 0.06564029 poinyd per square unit
Plot the distribution of the two tree species
plot(split(urkiola.ppp), main = "All marks")

oak <- plot(split(urkiola.ppp)$oak, main = "Distribution of Oak Trees")

birch <- plot(split(urkiola.ppp)$birch, main = "Distribution of Birch Trees")

Make the kernal density of each species
plot(density(split(urkiola.ppp)))

After observing the density plots, I noticed that they do not suggest these two species co-occur within the park.
Use Ripley’s K function (Oak Tree)
urkiola.oak <- split(urkiola.ppp)$oak
urkiola.birch <- split(urkiola.ppp)$birch
oak.ktest <- Kest(urkiola.oak)
plot(oak.ktest)

Use the envelope function to test the obtained Ripley’s K against a hypothesis of Complete Spatial Randomness
oakkest.mc = envelope(urkiola.oak, fun='Kest', nsim=99, verbose=FALSE)
plot(oakkest.mc, shade=c("hi", "lo"))

summary(oakkest.mc)
## Pointwise critical envelopes for K(r)
## and observed value for 'urkiola.oak'
## 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: urkiola.oak
Using the Monte Carlo test, it is understood that the significance level is 2/100 = 0.02. The observed line shown in the figure above indicates that the oak species is clustered because the observed line is above the theoretical line.
Ripley’s K Function (Birch Tree)
birch.ktest <- Kest(urkiola.birch)
plot(birch.ktest)

Envelope function for Birch
birchkest.mc <- envelope(urkiola.birch, fun = 'Kest', nsim = 99, verbose = FALSE)
plot(birchkest.mc, shade = c("hi", "lo"))

summary(birchkest.mc)
## Pointwise critical envelopes for K(r)
## and observed value for 'urkiola.birch'
## 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: urkiola.birch
The birch species also shows the observed line above the theoretical line, meaning this species also has a clustered pattern. Again, after using the Monte Carlo test, we see a significance level of 2/100 = 0.02.
Envelope with KCross function
urkiola.kcross <- envelope(urkiola.ppp,
Kcross,
i = "oak",
j = "birch",
nsim = 99,
verbose = FALSE)
plot(urkiola.kcross)

summary(urkiola.kcross)
## Pointwise critical envelopes for "K"["oak", "birch"](r)
## and observed value for 'urkiola.ppp'
## 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: urkiola.ppp
According to the figure and summary above, the combined distribution of both species are random because the observed curve is following the theoretical line within the envelope.