I am using spatial point pattern analysis (in spatstat v.3.3.3/ R version 4.4.1) on a dataset that consists of several video transects done in two years, covering the same general area. First year transects were done in a N-S orientation, the next year they were done at a roughly 45 angle. When it came to analysing the secondary summary statistics (K & pcf functions) I noticed that the x axis is much longer in the transects from the second year (45 degree angle) than the ones from the first year. I am afraid the issue is more fundamental than simply limiting the x axis to the desirable length, but I haven’t found an explanation why K and pcf functions don't focus only on the irregular polygon no matter the orientation. I am also wondering if other functions in spatstat would behave in a similar way, like the nearest neighbour distances? I started studying spatial point pattern recently and I may have missed the reason behind this behaviour, but I would appreciate guidance in that case.
Here is a simplified example consisting of 2 polygons of different orientation and size, each consisting of 80 points.
library(spatstat)
library(dplyr)
library(sf)
#generate points for the polygons
d1_pts <- matrix(c(
777651.3,5653762,
777652.1,5653742,
777648.4,5653741,
777647.3,5653762,
777650.1,5653824,
777654.0,5653795,
777651.3,5653762), ncol = 2, byrow = TRUE)
d2_pts <- matrix(c(
777674.0,5653805,
777669.7,5653800,
777643.0,5653814,
777648.1,5653819,
777657.3,5653809,
777674.0,5653805
), ncol = 2, byrow = TRUE)
#create polygons
d1_poly <- st_polygon(list(d1_pts))
d2_poly <- st_polygon(list(d2_pts))
#set the number of points
set.seed(123)
num_points <- 80
#create points within polygons
d1<- st_sample(d1_poly, size = num_points, type = "random")
d1_coords <- st_coordinates(d1)
d2<- st_sample(d2_poly, size = num_points, type = "random")
d2_coords <- st_coordinates(d2)
#create point patterns
pp_d1<-ppp(x=d1_coords[,"X"],
y=d1_coords[,"Y"],
window = as.owin(d1_poly),
unitname = c("meter", "meters"))
pp_d2<-ppp(x=d2_coords[,"X"],
y=d2_coords[,"Y"],
window = as.owin(d2_poly),
unitname = c("meter", "meters"))
#pcf function
pcf_d1<-pcf(pp_d1)
plot(pcf_d1)
pcf_d2<-pcf(pp_d2)
plot(pcf_d2)
#K function
K_d1<-Kest(pp_d1)
plot(K_d1)
K_d2<-Kest(pp_d2)
plot(K_d2)
The default maximum value of distance r is determined by "Ripley's rule of thumb" which states that it should be one-quarter of the length of the shortest side of the enclosing rectangle. When you rotate a window, the enclosing rectangle changes size and shape, causing the rule to give a different maximum value of r. This rule is unsatisfactory in your case; it is used as the default because it is conventional and it is quick to compute.
You can specify your desired sequence of distance values as the argument r when you call pcf. It must be an evenly-spaced sequence of values, increasing, starting from 0. For example pcf(X, r=seq(0, rmax, length=1024)) where rmax is your desired maximum distance. If you have already computed another estimate of pcf from another dataset, you can use the $r component of the result as the r argument to the next call to pcf.