Skip to content

Comparing distance among point pattern events

1 message · ASANTOS

#
Dear R-Sig-Geo Members,

I have the three hypothetical point process situation (A, B and C) and my question is: What point distribution (B or C) is more close to A?

For this problem, I make a simple example:

library(spatstat)
set.seed(2023)
A <- rpoispp(30) ## First event
B <- rpoispp(30) ## Second event
C <- rThomas(10,0.02,5) ## Third event with Thomas cluster process
plot(A, pch=16)
plot(B, col="red", add=T)
plot(C, col="blue", add=T)

First, I takesthe distances between pairs of events:

ABd<-crossdist(A, B)
ACd<-crossdist(A, C)

mean(ABd)
# 0.4846027
mean(ACd)
# 0.5848766



# test the hypothesis that ABd is equal to ACd courtesy of Sarah Goslee

nperm <- 999

permout <- data.frame(ABd = rep(NA, nperm), ACd = rep(NA, nperm))

# create framework for a random assignment of B and C to the existing points

BC <- superimpose(B, C)
B.len <- npoints(B)
C.len <- npoints(C)
B.sampvect <- c(rep(TRUE, B.len), rep(FALSE, C.len))

set.seed(2023)
for(i in seq_len(nperm)) {
 ??? B.sampvect <- sample(B.sampvect)
 ??? B.perm <- BC[B.sampvect]
 ??? C.perm <- BC[!B.sampvect]

 ??? permout[i, ] <- c(mean(crossdist(A, B.perm)), mean(crossdist(A, C.perm)))
}


boxplot(permout$ABd - permout$ACd)
points(1, mean(ABd) - mean(ACd), col="red")

table(abs(mean(ABd) - mean(ACd)) >= abs(permout$ABd - permout$ACd))
#TRUE
# 999

sum(abs(mean(ABd) - mean(ACd)) >= abs(permout$ABd - permout$ACd)) / nperm
# [1] 1


The difference between ACd and ABd is distinguishable from that obtained by a random resampling of B and C.
Then B (0.4846027) is more close to A, that C (0.5848766).


But, now I comparing the distance to mean nearest neighbour and minimum distance between each pair of types:

marks(A)<-as.factor("A")
marks(B)<-as.factor("B")
marks(C)<-as.factor("C")

# distance to nearest neighbour A to B
nnda <- nncross(A,B, by=marks(A,B))

# mean nearest neighbour distances
mean(nnda[,1])
#[1] 0.09847543

# distance to nearest neighbour A to C
nndb <- nncross(A,C, by=marks(A,C))

# mean nearest neighbour distances
mean(nndb[,1])
#[1] 0.151127

# test again the hypothesis that ABd is equal to ACd

nperm <- 999

permout <- data.frame(ABd = rep(NA, nperm), ACd = rep(NA, nperm))

# create framework for a random assignment of B and C to the existing points

BC <- superimpose(B, C)
B.len <- npoints(B)
C.len <- npoints(C)
B.sampvect <- c(rep(TRUE, B.len), rep(FALSE, C.len))

set.seed(2023)
for(i in seq_len(nperm)) {
     B.sampvect <- sample(B.sampvect)
     B.perm <- BC[B.sampvect]
     C.perm <- BC[!B.sampvect]
     ab<-nncross(A, B.perm)
     ac<-nncross(A, C.perm)

     permout[i, ] <- c(mean(ab[,1]), mean(ac[,1]))
}


boxplot(permout$ABd - permout$ACd)
points(1, mean(nnda[,1]) - mean(nndb[,1]), col="red")

table(abs(mean(nnda[,1]) - mean(nndb[,1])) >= abs(permout$ABd - permout$ACd))
#FALSE  TRUE
#   91   908

sum(abs(mean(nnda[,1]) - mean(nndb[,1])) >= abs(permout$ABd - permout$ACd)) / nperm
#[1] 0.9089089


Now, the same conclusion or the mean nearest neighbour distances of A to B (0.10887343) is smaller than A to C (0.151127),
but is not so clear for me, what is the better approach if a comparing crossdist() and nndist () results for a good answer to my question?

Any conceptual tips?

Thanks in advance,