data(simdat)
 X <- simdat
 # Envelope of K function under CSR
 plot(envelope(X))
 <testonly>plot(envelope(X, nsim=4))</testonly>
 # Translation edge correction (this is also FASTER):
 plot(envelope(X, correction="translate"))
 <testonly>plot(envelope(X, nsim=4, correction="translate"))</testonly>
 # Envelope of K function for simulations from Gibbs model 
 data(cells)
 fit <- ppm(cells, ~1, Strauss(0.05))
 plot(envelope(fit))
 plot(envelope(fit), global=TRUE)
 <testonly>plot(envelope(fit, nsim=4))
  plot(envelope(fit, nsim=4, global=TRUE))</testonly>
 # Envelope of K function for simulations from cluster model 
 data(redwood)
 fit <- kppm(redwood, ~1, "Thomas")
 plot(envelope(fit, Gest))
 plot(envelope(fit, Gest, global=TRUE))
 <testonly>plot(envelope(fit, Gest, nsim=4))
  plot(envelope(fit, Gest, nsim=4, global=TRUE))</testonly>
 # Envelope of G function under CSR
 plot(envelope(X, Gest))
 <testonly>plot(envelope(X, Gest, nsim=4))</testonly>
 # Envelope of L function under CSR
 #  L(r) = sqrt(K(r)/pi)
 E <- envelope(X, Kest)
  plot(E, sqrt(./pi) ~ r)
 <testonly>E <- envelope(X, Kest, nsim=4)
  plot(E, sqrt(./pi) ~ r)</testonly>
 # Simultaneous critical envelope for L function
 # (alternatively, use Lest)
 plot(envelope(X, Kest, transform=expression(sqrt(./pi)), global=TRUE))
 <testonly>plot(envelope(X, Kest, nsim=4,transform=expression(sqrt(./pi)), global=TRUE))</testonly>
 # How to pass arguments needed to compute the summary functions:
 # We want envelopes for Jcross(X, "A", "B") 
 # where "A" and "B" are types of points in the dataset 'demopat'
 data(demopat)
 plot(envelope(demopat, Jcross, i="A", j="B"))
 <testonly>plot(envelope(demopat, Jcross, i="A", j="B", nsim=4))</testonly>
 
 # Use of `simulate'
 plot(envelope(cells, Gest, simulate=expression(runifpoint(42))))
 plot(envelope(cells, Gest, simulate=expression(rMaternI(100,0.02))))
 <testonly>plot(envelope(cells, Gest, simulate=expression(runifpoint(42)), nsim=4))
  plot(envelope(cells, Gest, simulate=expression(rMaternI(100, 0.02)), nsim=4))
  plot(envelope(cells, Gest, simulate=expression(runifpoint(42)),
nsim=4, global=TRUE))
  plot(envelope(cells, Gest, simulate=expression(rMaternI(100, 0.02)),
nsim=4, global=TRUE))</testonly>
 # Envelope under random toroidal shifts
 data(amacrine)
 plot(envelope(amacrine, Kcross, i="on", j="off",
               simulate=expression(rshift(amacrine, radius=0.25))))
 # Envelope under random shifts with erosion
 plot(envelope(amacrine, Kcross, i="on", j="off",
              simulate=expression(rshift(amacrine, radius=0.1, edge="erode"))))
  
 # Envelope of INHOMOGENEOUS K-function with fitted trend
trend <- density.ppp(X, 1.5)
 plot(envelope(X, Kinhom, lambda=trend,
         simulate=expression(rpoispp(trend))))
 # Precomputed list of point patterns
 X <- rpoispp(50)
 PatList <- list()
 for(i in 1:20) PatList[[i]] <- runifpoint(X$n)
 plot(envelope(X, Kest, nsim=20, simulate=PatList))
# re-using the same point patterns
 EK <- envelope(X, Kest, nsim=10, savepatterns=TRUE)
 EG <- envelope(X, Kest, nsim=10, simulate=EK)Run the code above in your browser using DataLab