[R-sig-Geo] Kcross and envelope

Rolf Turner r.turner at auckland.ac.nz
Tue Mar 5 03:19:24 CET 2013


Thank you for your interest in "spatstat" and for your clearly expressed
questions.

Please see in-line below.

On 03/05/2013 01:18 PM, Brigitte Hogan wrote:
> Hi All,
>
> I have run into an unexpected outcome using Kcross() and envelope()
> that  I hope someone can explain.  My question is, why does envelope()
> produce different curves when no edge correction is specified and when
> correction is set as "none"? I would expect these curves to be closely
> the same, if not identical.
     See below.
> For example:
>
> library(spatstat)
> data(lansing)
> x <- lansing
> Kx.en1 <- envelope(unique(x), fun=Kcross, nsim=99, nrank=2)
> Kx.en2 <- envelope(unique(x), fun=Kcross, nsim=99, nrank=2, correction="none")
> par(mfrow=c(1,2))
> plot(Kx.en1)
> plot(Kx.en2)
>
> I am also puzzled why the red theoretical line leaves the envelope in
> the second plot. I thought that the hi and lo values always bound the
> theoretical.
     Well, that's not *quite* correct.  It depends on the nature of the
     "simulate" argument.  Here however, with simulate unspecified,
     the simulations are done under CSR so the estimates of Kcross
     used to form the envelope all have expected value pi*r^2.

     What you are seeing is simply the strong biasing effect of failing
     to make an edge correction.  You can observe the same phenomenon
     with a simple K function estimate.  E.g.:

     set.seed(42)
     X <- rpoispp(800)
     E <- envelope(X,correction="none")
     plot(E)
> The help file (?envelope) does not give a default for
> 'correction', but says a border correction can be passed to the
> function fun using ... . That makes me think there is no 'default' for
> border correction in envelope - am I  mistaken?
     Well, yes.  The envelope() function actually uses the "best" edge 
correction by
     default, although this fact is not explicitly stated in the help 
for envelope().  The
     "best" edge correction (to quote from the help for Kest())
> Selects the best edge correction that is available for the geometry of 
> the window. Currently this is Ripley's isotropic correction for a 
> rectangular or polygonal window, and the translation correction for 
> masks. 
     Since the lansing data set has a rectangular window, envelope() 
will use the isotropic
     edge correction by default in the example you use.

     We will try to clarify this issue in the help for envelope() in a 
future release
     of spatstat.
> A related question is why using envelope to calculate Kcross does not
> give the same result for the 'obs' line as using a simple Kcross with
> 'correction="none"'.
>
> Kx.data <- Kcross(x, correction=c("none", "border"))
> Kx.en <- envelope(x, fun=Kcross, nrank=2, nsim=99)
> par(mfrow=c(1,1))
> plot(Kx.en, legend=NULL, main="")
> plot(Kx.data, cbind(border,un)~r, col=c("blue","black"), lty=c(1,1),
> 	lwd=2, legend=TRUE, legendmath=FALSE, add=TRUE)
>
> With these two plots. I was expecting the 'un' line in the second plot
> (thick black line) to be the same as the 'obs' line in the first (thin
> black line).
     The answer is the same; envelope() is using the isotropic edge 
correction
     here, since no correction was specified.

         cheers,

             Rolf Turner



More information about the R-sig-Geo mailing list