envelope {spatstat} | R Documentation |
Computes simulation envelopes of a summary function.
envelope(Y, fun=Kest, nsim=99, nrank=1, ..., simulate=NULL, verbose=TRUE, clipdata=TRUE, start=NULL,control=list(nrep=1e5,expand=1.5), transform=NULL,global=FALSE,ginterval=NULL, saveall=FALSE)
Y |
Either a point pattern (object of class
"ppp" ) or a fitted point process model
(object of class "ppm" ).
|
fun |
Function that computes the desired summary statistic for a point pattern. |
nsim |
Number of simulated point patterns to be generated when computing the envelopes. |
nrank |
Integer. Rank of the envelope value amongst the nsim simulated
values. A rank of 1 means that the minimum and maximum
simulated values will be used.
|
... |
Extra arguments passed to fun .
|
simulate |
Optional. An expression. If this is present, then the simulated
point patterns will be generated by evaluating this expression
nsim times.
|
verbose |
Logical flag indicating whether to print progress reports during the simulations. |
clipdata |
Logical flag indicating whether the data point pattern should be
clipped to the same window as the simulated patterns,
before the summary function for the data is computed.
This should usually be TRUE to ensure that the
data and simulations are properly comparable.
|
start,control |
Optional. These specify the arguments start and control
of rmh , giving complete control over the
simulation algorithm.
|
transform |
Optional. A transformation to be applied to the function values, before the envelopes are computed. An expression object (see Details). |
global |
Logical flag indicating whether envelopes should be pointwise
(global=FALSE ) or simultaneous (global=TRUE ).
|
ginterval |
Optional.
A vector of length 2 specifying
the interval of r values for the simultaneous critical
envelopes. Only relevant if global=TRUE .
|
saveall |
Logical flag indicating whether to save all the simulated curves. |
Simulation envelopes can be used to assess the goodness-of-fit of a point process model to point pattern data. See the References.
This function first generates nsim
random point patterns
in one of the following ways.
Y
is a point pattern (an object of class "ppp"
)
and simulate=NULL
,
then this routine generates nsim
simulations of
Complete Spatial Randomness (i.e. nsim
simulated point patterns
each being a realisation of the uniform Poisson point process)
with the same intensity as the pattern Y
.
(If Y
is a multitype point pattern, then the simulated patterns
are also given independent random marks; the probability
distribution of the random marks is determined by the
relative frequencies of marks in Y
.)
Y
is a fitted point process model (an object of class
"ppm"
) and simulate=NULL
,
then this routine generates nsim
simulated
realisations of that model.
simulate
is supplied, then it must be
an expression. It will be evaluated nsim
times to
yield nsim
point patterns.
The summary statistic fun
is applied to each of these simulated
patterns. Typically fun
is one of the functions
Kest
, Gest
, Fest
, Jest
, pcf
,
Kcross
, Kdot
, Gcross
, Gdot
,
Jcross
, Jdot
, Kmulti
, Gmulti
,
Jmulti
or Kinhom
. It may also be a character string
containing the name of one of these functions.
The statistic fun
can also be a user-supplied function;
if so, then it must have arguments X
and r
like those in the functions listed above, and it must return an object
of class "fv"
.
Upper and lower critical envelopes are computed in one of the following ways:
nsim
simulated values, and taking the m
-th lowest
and m
-th highest values, where m = nrank
.
For example if nrank=1
, the upper and lower envelopes
are the pointwise maximum and minimum of the simulated values.
The pointwise envelopes are not “confidence bands”
for the true value of the function! Rather,
they specify the critical points for a Monte Carlo test
(Ripley, 1981). The test is constructed by choosing a
fixed value of r, and rejecting the null hypothesis if the
observed function value
lies outside the envelope at this value of r.
This test has exact significance level
alpha = 2 * nrank/(1 + nsim)
.
global=TRUE
, then the envelopes are
determined as follows. First we calculate the theoretical mean value of
the summary statistic (if we are testing CSR, the theoretical
value is supplied by fun
; otherwise we compute the
average of all the simulated values and take this as an estimate
of the theoretical mean value). Then, for each simulation,
we compare the simulated curve to the theoretical curve, and compute the
maximum absolute difference between them (over the interval
of r values specified by ginterval
). This gives a
deviation value d[i] for each of the nsim
simulations. Finally we take the m
-th largest of the
deviation values, where m=nrank
, and call this
dcrit
. Then the simultaneous envelopes are of the form
lo = theo - dcrit
and hi = theo + dcrit
where
theo
is the theoretical mean value. Simultaneous critical
envelopes have constant width 2 * dcrit
.
The simultaneous critical envelopes allow us to perform a different
Monte Carlo test (Ripley, 1981). The test rejects the null
hypothesis if the graph of the observed function
lies outside the envelope at any value of r.
This test has exact significance level
alpha = nrank/(1 + nsim)
.
The return value is an object of class "fv"
containing
the summary function for the data point pattern
and the upper and lower simulation envelopes. It can be plotted
using plot.fv
.
Arguments can be passed to the function fun
through
...
. This makes it possible to select the edge correction
used to calculate the summary statistic. See the Examples.
Selecting only a single edge
correction will make the code run much faster.
If Y
is a fitted point process model, and simulate=NULL
,
then the model is simulated
by running the Metropolis-Hastings algorithm rmh
.
Complete control over this algorithm is provided by the
arguments start
and control
which are passed
to rmh
.
For simultaneous critical envelopes (global=TRUE
)
the following options are also useful:
ginterval
fun(X)
).
transform
fun
that will be carried out before the
deviations are computed. It must be an expression object
using the symbol .
to represent the function value.
For example,
the conventional way to normalise the K function
(Ripley, 1981) is to transform it to the L function
L(r) = sqrt(K(r)/pi)
and this is implemented by setting
transform=expression(sqrt(./pi))
.
Such transforms are only useful if global=TRUE
.
It is also possible to extract the summary functions for each of the
individual simulated point patterns, by setting saveall=TRUE
.
Then the return value also
has an attribute "savedata"
containing all the
summary functions for the individual simulated patterns.
It is an "fv"
object containing
functions named sim1, sim2, ...
representing the nsim
summary functions.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Essentially a data frame containing columns
r |
the vector of values of the argument r
at which the summary function fun has been estimated
|
obs |
values of the summary function for the data point pattern |
lo |
lower envelope of simulations |
hi |
upper envelope of simulations |
If saveall=TRUE
, the return value also has an attribute
"savedata"
which contains the summary functions
computed for each of the nsim
simulated patterns.
Adrian Baddeley adrian@maths.uwa.edu.au http://www.maths.uwa.edu.au/~adrian/ and Rolf Turner rolf@math.unb.ca http://www.math.unb.ca/~rolf
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Arnold, 2003.
Ripley, B.D. (1981) Spatial statistics. John Wiley and Sons.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
fv.object
,
plot.fv
,
Kest
,
Gest
,
Fest
,
Jest
,
pcf
,
ppp
,
ppm
data(simdat) X <- simdat # Envelope of K function under CSR ## Not run: plot(envelope(X)) ## End(Not run) # Translation edge correction (this is also FASTER): ## Not run: plot(envelope(X, correction="translate")) ## End(Not run) # Envelope of K function for simulations from model data(cells) fit <- ppm(cells, ~1, Strauss(0.05)) ## Not run: plot(envelope(fit)) ## End(Not run) # Envelope of G function under CSR ## Not run: plot(envelope(X, Gest)) ## End(Not run) # Envelope of L function under CSR # L(r) = sqrt(K(r)/pi) ## Not run: E <- envelope(X, Kest) plot(E, sqrt(./pi) ~ r) ## End(Not run) # Simultaneous critical envelope for L function ## Not run: plot(envelope(X, Kest, transform=expression(sqrt(./pi)), global=TRUE)) ## End(Not run) # 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) ## Not run: plot(envelope(demopat, Jcross, i="A", j="B")) ## End(Not run) # Use of `simulate' ## Not run: plot(envelope(cells, Gest, simulate=expression(runifpoint(42)))) plot(envelope(cells, Gest, simulate=expression(rMaternI(100,0.02)))) ## End(Not run) # Envelope under random toroidal shifts data(amacrine) ## Not run: plot(envelope(amacrine, Kcross, i="on", j="off", simulate=expression(rshift(amacrine, radius=0.25)))) ## End(Not run) # Envelope under random shifts with erosion ## Not run: plot(envelope(amacrine, Kcross, i="on", j="off", simulate=expression(rshift(amacrine, radius=0.1, edge="erode")))) ## End(Not run) # Envelope of INHOMOGENEOUS K-function with fitted trend ## Not run: trend <- density.ppp(X, 1.5) plot(envelope(X, Kinhom, lambda=trend, simulate=expression(rpoispp(trend)))) ## End(Not run)