```
X <- simdat
online <- interactive()
Nsim <- if(online) 19 else 3
# Envelope of K function under CSR
plot(envelope(X, nsim=Nsim))
# Translation edge correction (this is also FASTER):
if(online) {
plot(envelope(X, correction="translate"))
} else {
E <- envelope(X, nsim=Nsim, correction="translate")
}
# Global envelopes
if(online) {
plot(envelope(X, Lest, global=TRUE))
plot(envelope(X, Kest, global=TRUE, scale=function(r) { r }))
} else {
E <- envelope(X, Lest, nsim=Nsim, global=TRUE)
E <- envelope(X, Kest, nsim=Nsim, global=TRUE, scale=function(r) { r })
E
summary(E)
}
# Envelope of G function under CSR
if(online) {
plot(envelope(X, Gest))
} else {
E <- envelope(X, Gest, correction="rs", nsim=Nsim)
}
# Envelope of L function under CSR
# L(r) = sqrt(K(r)/pi)
if(online) {
E <- envelope(X, Kest)
} else {
E <- envelope(X, Kest, correction="border", nsim=Nsim)
}
plot(E, sqrt(./pi) ~ r)
# Simultaneous critical envelope for L function
# (alternatively, use Lest)
if(online) {
plot(envelope(X, Kest, transform=expression(sqrt(./pi)), global=TRUE))
} else {
E <- envelope(X, Kest, nsim=Nsim, correction="border",
transform=expression(sqrt(./pi)), global=TRUE)
}
## One-sided envelope
if(online) {
plot(envelope(X, Lest, alternative="less"))
} else {
E <- envelope(X, Lest, nsim=Nsim, alternative="less")
}
# 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'
if(online) {
plot(envelope(demopat, Jcross, i="A", j="B"))
} else {
plot(envelope(demopat, Jcross, correction="rs", i="A", j="B", nsim=Nsim))
}
# Use of `simulate' expression
if(online) {
plot(envelope(cells, Gest, simulate=expression(runifpoint(42))))
plot(envelope(cells, Gest, simulate=expression(rMaternI(100,0.02))))
} else {
plot(envelope(cells, Gest, correction="rs", simulate=expression(runifpoint(42)), nsim=Nsim))
plot(envelope(cells, Gest, correction="rs", simulate=expression(rMaternI(100, 0.02)),
nsim=Nsim, global=TRUE))
}
# Use of `simulate' function
if(online) {
plot(envelope(amacrine, Kcross, simulate=rlabel))
} else {
plot(envelope(amacrine, Kcross, simulate=rlabel, nsim=Nsim))
}
# Envelope under random toroidal shifts
if(online) {
plot(envelope(amacrine, Kcross, i="on", j="off",
simulate=expression(rshift(amacrine, radius=0.25))))
}
# Envelope under random shifts with erosion
if(online) {
plot(envelope(amacrine, Kcross, i="on", j="off",
simulate=expression(rshift(amacrine, radius=0.1, edge="erode"))))
}
# Note that the principle of symmetry, essential to the validity of
# simulation envelopes, requires that both the observed and
# simulated patterns be subjected to the same method of intensity
# estimation. In the following example it would be incorrect to set the
# argument 'lambda=red.dens' in the envelope command, because this
# would mean that the inhomogeneous K functions of the simulated
# patterns would be computed using the intensity function estimated
# from the original redwood data, violating the symmetry. There is
# still a concern about the fact that the simulations are generated
# from a model that was fitted to the data; this is only a problem in
# small datasets.
if(online) {
red.dens <- density(redwood, sigma=bw.diggle, positive=TRUE)
plot(envelope(redwood, Kinhom, sigma=bw.diggle,
simulate=expression(rpoispp(red.dens))))
}
# Precomputed list of point patterns
if(online) {
nX <- npoints(X)
PatList <- list()
for(i in 1:Nsim) PatList[[i]] <- runifpoint(nX)
E <- envelope(X, Kest, nsim=19, simulate=PatList)
} else {
PatList <- list()
for(i in 1:Nsim) PatList[[i]] <- runifpoint(10)
}
E <- envelope(X, Kest, nsim=Nsim, simulate=PatList)
# re-using the same point patterns
EK <- envelope(X, Kest, nsim=Nsim, savepatterns=TRUE)
EG <- envelope(X, Gest, nsim=Nsim, simulate=EK)
```

Run the code above in your browser using DataLab