1

I have a two-dimensional point pattern (no marks) and I am trying to test for clustering in the presence of spatial inhomogeneity using envelopes and the inhomogenous pair correlation function. I am estimating an inhomogenous intensity function for the data using the density.ppp function. Here is some sample data:

           x       y
1     533.03  411.58
2     468.39  622.92
3     402.86  530.94
4     427.13  616.81
5     495.20  680.62
6     566.61  598.99
7     799.03  585.16
8    1060.09  544.23
9     144.66  747.40
10    138.14  752.92
11    449.49  839.15
12    756.45  713.72
13    741.01  728.41
14    760.22  740.28
15    802.34  756.21
16    799.04  764.89
17    773.81  771.97
18    768.41  720.07
19    746.14  754.11
20    815.40  765.14

There are ~1700 data points overall

Here is my code:

library("spatstat")

WT <- read.csv("Test.csv")

colnames(WT) <- c("x","y")

#determine bounding window
win <- ripras(WT)
unitname(win) <- c("micrometer")

#convert to ppp data class
WT.ppp <- as.ppp(WT, win)
plot(WT.ppp)

#estimate intensity function using cross validation
I <- density.ppp(WT.ppp,sigma=bw.diggle(WT.ppp),adjust=0.3,kernal="epanechnikov")
plot(I)

#predetermined r values for PCF 
radius <- seq(from = 0, to = 50, by = 0.5)

#use envelopes to test the null hypothesis (ie. inhomogenous poisson process)
PCF_envelopes <- envelope(WT.ppp,divisor="d", pcfinhom,r = radius,nsim=10,simulate=expression(rpoispp(I)) )

When I run rpoisspp(I), I get the following error:

Error in sample.int(npix, size = ni, replace = TRUE, prob = lpix) : 
   negative probability

I can't seem to figure out what the issue is....any suggestions?

Thanks for your help!

1 Answers1

2

This is happening because the image I contains some negative values, probably very small values but negative. You can check that by computing range(I) or min(I) or any(I < 0).

The help for density.ppp says that the result may contain negative values (very small ones) due to numerical error. To remove these, you need to set positive=TRUE in the call to density.ppp.

By the way, the argument kernel has been mis-spelt in the code above. Also the vector r is too coarsely spaced - you would be better to leave this argument un-specified. Also you don't need to type density.ppp, just density.

Adrian Baddeley
  • 1,956
  • 1
  • 8
  • 7