[R-sig-Geo] Comparing distance among point pattern events

Sarah Goslee @@r@h@go@|ee @end|ng |rom gm@||@com
Fri Nov 22 15:09:19 CET 2019


Hi,

Great question, and clear example.

The first problem:
ACd<-pairdist(A) instead of ACd <- pairdist(AC)

BUT

pairdist() is the wrong function: that calculates the mean distance
between ALL points, A to A and C to C as well as A to C.

You need crossdist() instead.

The most flexible approach is to roll your own permutation test. That
will work even if B and C are different sizes, etc. If you specify the
problem more exactly, there are probably parametric tests, but I like
permutation tests.


library(spatstat)
set.seed(2019)
A <- rpoispp(100) ## First event
B <- rpoispp(50) ## Second event
C <- rpoispp(50) ## Third event
plot(A, pch=16)
plot(B, col="red", add=T)
plot(C, col="blue", add=T)

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

mean(ABd)
# 0.5168865
mean(ACd)
# 0.5070118


# test 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(2019)
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))
# FALSE  TRUE
#  573   426

sum(abs(mean(ABd) - mean(ACd)) >= abs(permout$ABd - permout$ACd)) / nperm
# 0.4264264

The difference between ACd and ABd is indistinguishable from that
obtained by a random resampling of B and C.


Sarah

On Fri, Nov 22, 2019 at 8:26 AM ASANTOS via R-sig-Geo
<r-sig-geo using r-project.org> wrote:
>
> Dear R-Sig-Geo Members,
>
> I have the hypothetical point process situation:
>
> library(spatstat)
> set.seed(2019)
> A <- rpoispp(100) ## First event
> B <- rpoispp(50) ## Second event
> C <- rpoispp(50) ## Third event
> plot(A, pch=16)
> plot(B, col="red", add=T)
> plot(C, col="blue", add=T)
>
> I've like to know an adequate spatial approach for comparing if on
> average the event B or C is more close to A. For this, I try to make:
>
> AB<-superimpose(A,B)
> ABd<-pairdist(AB)
> AC<-superimpose(A,C)
> ACd<-pairdist(A)
> mean(ABd)
> #[1] 0.5112954
> mean(ACd)
> #[1] 0.5035042
>
> With this naive approach, I concluded that event C is more close of A
> that B. This sounds enough for a final conclusion or more robust
> analysis is possible?
>
> Thanks in advance,
>
> Alexandre
>

-- 
Sarah Goslee (she/her)
http://www.numberwright.com



More information about the R-sig-Geo mailing list