Title: | Exploratory Data Analysis for the 'spatstat' Family |
---|---|
Description: | Functionality for exploratory data analysis and nonparametric analysis of spatial data, mainly spatial point patterns, in the 'spatstat' family of packages. (Excludes analysis of spatial data on a linear network, which is covered by the separate package 'spatstat.linnet'.) Methods include quadrat counts, K-functions and their simulation envelopes, nearest neighbour distance and empty space statistics, Fry plots, pair correlation function, kernel smoothed intensity, relative risk estimation with cross-validated bandwidth selection, mark correlation functions, segregation indices, mark dependence diagnostics, and kernel estimates of covariate effects. Formal hypothesis tests of random pattern (chi-squared, Kolmogorov-Smirnov, Monte Carlo, Diggle-Cressie-Loosmore-Ford, Dao-Genton, two-stage Monte Carlo) and tests for covariate effects (Cox-Berman-Waller-Lawson, Kolmogorov-Smirnov, ANOVA) are also supported. |
Authors: | Adrian Baddeley [aut, cre, cph] , Rolf Turner [aut, cph] , Ege Rubak [aut, cph] , Kasper Klitgaard Berthelsen [ctb], Warick Brown [cph], Achmad Choiruddin [ctb], Jean-Francois Coeurjolly [ctb], Ottmar Cronie [ctb], Tilman Davies [ctb, cph], Julian Gilbey [ctb], Jonatan Gonzalez [ctb], Yongtao Guan [ctb], Ute Hahn [ctb], Kassel Hingee [ctb, cph], Abdollah Jalilian [ctb], Frederic Lavancier [ctb], Marie-Colette van Lieshout [ctb, cph], Greg McSwiggan [ctb], Robin K Milne [cph], Tuomas Rajala [ctb], Suman Rakshit [ctb, cph], Dominic Schuhmacher [ctb], Rasmus Plenge Waagepetersen [ctb], Hangsheng Wang [ctb] |
Maintainer: | Adrian Baddeley <[email protected]> |
License: | GPL (>= 2) |
Version: | 3.3-3 |
Built: | 2024-11-21 05:35:56 UTC |
Source: | https://github.com/spatstat/spatstat.explore |
The spatstat.explore package belongs to the spatstat family of packages. It contains the core functionality for statistical analysis and modelling of spatial data.
spatstat is a family of R packages for the statistical analysis of spatial data. Its main focus is the analysis of spatial patterns of points in two-dimensional space.
The original spatstat package has now been split into several sub-packages.
This sub-package spatstat.explore contains the user-level functions that perform exploratory data analysis and nonparametric data analysis of spatial data.
(The main exception is that functions for linear networks are in the separate sub-package spatstat.linnet.)
The orginal spatstat package grew to be very large. It has now been divided into several sub-packages:
spatstat.utils containing basic utilities
spatstat.sparse containing linear algebra utilities
spatstat.data containing datasets
spatstat.univar containing functions for estimating probability distributions of random variables
spatstat.geom containing geometrical objects and geometrical operations
spatstat.explore containing the functionality for exploratory data analysis and nonparametric analysis of spatial data.
spatstat.model containing the functionality for statistical modelling, model-fitting, formal statistical inference and informal model diagnostics.
spatstat.linnet containing functions for spatial data on a linear network
spatstat, which simply loads the other sub-packages listed above, and provides documentation.
When you install spatstat, these sub-packages are also
installed. Then if you load the spatstat package by typing
library(spatstat)
, the other sub-packages listed above will
automatically be loaded or imported.
For an overview of all the functions available in
the sub-packages of spatstat,
see the help file for "spatstat-package"
in the spatstat package.
Additionally there are several extension packages:
spatstat.gui for interactive graphics
spatstat.local for local likelihood (including geographically weighted regression)
spatstat.Knet for additional, computationally efficient code for linear networks
spatstat.sphere (under development) for spatial data on a sphere, including spatial data on the earth's surface
The extension packages must be installed separately and loaded explicitly if needed. They also have separate documentation.
The spatstat family of packages is designed to support a complete statistical analysis of spatial data. It supports
creation, manipulation and plotting of point patterns;
exploratory data analysis;
spatial random sampling;
simulation of point process models;
parametric model-fitting;
non-parametric smoothing and regression;
formal inference (hypothesis tests, confidence intervals);
model diagnostics.
For an overview, see the help file for "spatstat-package"
in the spatstat package.
Following is a list of the functionality provided in the spatstat.explore package only.
To simulate a random point pattern:
Functions for generating random point patterns are now contained in the spatstat.random package.
To interrogate a point pattern:
density.ppp |
kernel estimation of point pattern intensity |
densityHeat.ppp |
diffusion kernel estimation of point pattern intensity |
Smooth.ppp |
kernel smoothing of marks of point pattern |
sharpen.ppp |
data sharpening |
Manipulation of pixel images:
An object of class "im"
represents a pixel image.
blur |
apply Gaussian blur to image |
Smooth.im |
apply Gaussian blur to image |
transect.im |
line transect of image |
pixelcentres |
extract centres of pixels |
rnoise |
random pixel noise |
Line segment patterns
An object of class "psp"
represents a pattern of straight line
segments.
density.psp |
kernel smoothing of line segments |
rpoisline |
generate a realisation of the Poisson line process inside a window |
Tessellations
An object of class "tess"
represents a tessellation.
rpoislinetess |
generate tessellation using Poisson line process |
Three-dimensional point patterns
An object of class "pp3"
represents a three-dimensional
point pattern in a rectangular box. The box is represented by
an object of class "box3"
.
runifpoint3 |
generate uniform random points in 3-D |
rpoispp3 |
generate Poisson random points in 3-D |
envelope.pp3 |
generate simulation envelopes for 3-D pattern |
Multi-dimensional space-time point patterns
An object of class "ppx"
represents a
point pattern in multi-dimensional space and/or time.
runifpointx |
generate uniform random points |
rpoisppx |
generate Poisson random points |
Classical exploratory tools:
clarkevans |
Clark and Evans aggregation index |
fryplot |
Fry plot |
miplot |
Morisita Index plot |
Smoothing:
density.ppp |
kernel smoothed density/intensity |
relrisk |
kernel estimate of relative risk |
Smooth.ppp |
spatial interpolation of marks |
bw.diggle |
cross-validated bandwidth selection
for density.ppp
|
bw.ppl |
likelihood cross-validated bandwidth selection
for density.ppp
|
bw.CvL |
Cronie-Van Lieshout bandwidth selection for density estimation |
bw.scott |
Scott's rule of thumb for density estimation |
bw.abram.ppp |
Abramson's rule for adaptive bandwidths |
bw.relrisk |
cross-validated bandwidth selection
for relrisk |
bw.smoothppp |
cross-validated bandwidth selection
for Smooth.ppp |
bw.frac |
bandwidth selection using window geometry |
bw.stoyan |
Stoyan's rule of thumb for bandwidth
for pcf
|
Modern exploratory tools:
clusterset |
Allard-Fraley feature detection |
nnclean |
Byers-Raftery feature detection |
sharpen.ppp |
Choi-Hall data sharpening |
rhohat |
Kernel estimate of covariate effect |
rho2hat |
Kernel estimate of effect of two covariates |
spatialcdf |
Spatial cumulative distribution function |
roc |
Receiver operating characteristic curve |
sdr |
Sufficient Data Reduction |
thresholdSelect |
optimal thresholding of a predictor |
Summary statistics for a point pattern:
Fest |
empty space function |
Gest |
nearest neighbour distribution function |
Jest |
-function |
Kest |
Ripley's -function |
Lest |
Besag -function |
Tstat |
Third order -function |
allstats |
all four functions , , , |
pcf |
pair correlation function |
Kinhom |
for inhomogeneous point patterns |
Linhom |
for inhomogeneous point patterns |
pcfinhom |
pair correlation for inhomogeneous patterns |
Finhom |
for inhomogeneous point patterns |
Ginhom |
for inhomogeneous point patterns |
Jinhom |
for inhomogeneous point patterns |
localL |
Getis-Franklin neighbourhood density function |
localK |
neighbourhood K-function |
localpcf |
local pair correlation function |
localKinhom |
local for inhomogeneous point patterns |
localLinhom |
local for inhomogeneous point patterns |
localpcfinhom |
local pair correlation for inhomogeneous patterns |
Ksector |
Directional -function |
Kscaled |
locally scaled -function |
Kest.fft |
fast -function using FFT for large datasets |
Kmeasure |
reduced second moment measure |
envelope |
simulation envelopes for a summary function |
varblock |
variances and confidence intervals |
for a summary function | |
lohboot |
bootstrap for a summary function |
Related facilities:
plot.fv |
plot a summary function |
eval.fv |
evaluate any expression involving summary functions |
harmonise.fv |
make functions compatible |
eval.fasp |
evaluate any expression involving an array of functions |
with.fv |
evaluate an expression for a summary function |
Smooth.fv |
apply smoothing to a summary function |
deriv.fv |
calculate derivative of a summary function |
pool.fv |
pool several estimates of a summary function |
density.ppp |
kernel smoothed density |
densityHeat.ppp |
diffusion kernel smoothed density |
Smooth.ppp |
spatial interpolation of marks |
relrisk |
kernel estimate of relative risk |
sharpen.ppp |
data sharpening |
rknn |
theoretical distribution of nearest neighbour distance |
Summary statistics for a multitype point pattern:
A multitype point pattern is represented by an object X
of class "ppp"
such that marks(X)
is a factor.
relrisk |
kernel estimation of relative risk |
scan.test |
spatial scan test of elevated risk |
Gcross,Gdot,Gmulti |
multitype nearest neighbour distributions
|
Kcross,Kdot, Kmulti |
multitype -functions
|
Lcross,Ldot |
multitype -functions
|
Jcross,Jdot,Jmulti |
multitype -functions
|
pcfcross |
multitype pair correlation function |
pcfdot |
multitype pair correlation function |
pcfmulti |
general pair correlation function |
markconnect |
marked connection function |
alltypes |
estimates of the above
for all pairs |
Iest |
multitype -function |
Kcross.inhom,Kdot.inhom |
inhomogeneous counterparts of Kcross , Kdot |
Lcross.inhom,Ldot.inhom |
inhomogeneous counterparts of Lcross , Ldot |
pcfcross.inhom,pcfdot.inhom |
inhomogeneous counterparts of pcfcross , pcfdot |
localKcross,localKdot |
local counterparts of Kcross , Kdot |
localLcross,localLdot |
local counterparts of Lcross , Ldot |
localKcross.inhom,localLcross.inhom |
local counterparts of Kcross.inhom , Lcross.inhom
|
Summary statistics for a marked point pattern:
A marked point pattern is represented by an object X
of class "ppp"
with a component X$marks
.
The entries in the vector X$marks
may be numeric, complex,
string or any other atomic type. For numeric marks, there are the
following functions:
markmean |
smoothed local average of marks |
markvar |
smoothed local variance of marks |
markcorr |
mark correlation function |
markcrosscorr |
mark cross-correlation function |
markvario |
mark variogram |
markmarkscatter |
mark-mark scatterplot |
Kmark |
mark-weighted function |
Emark |
mark independence diagnostic |
Vmark |
mark independence diagnostic |
nnmean |
nearest neighbour mean index |
nnvario |
nearest neighbour mark variance index |
For marks of any type, there are the following:
Gmulti |
multitype nearest neighbour distribution |
Kmulti |
multitype -function |
Jmulti |
multitype -function
|
Alternatively use cut.ppp
to convert a marked point pattern
to a multitype point pattern.
Programming tools:
marktable |
tabulate the marks of neighbours in a point pattern |
Summary statistics for a three-dimensional point pattern:
These are for 3-dimensional point pattern objects (class pp3
).
F3est |
empty space function |
G3est |
nearest neighbour function |
K3est |
-function |
pcf3est |
pair correlation function |
Related facilities:
envelope.pp3 |
simulation envelopes |
Summary statistics for random sets:
These work for point patterns (class ppp
),
line segment patterns (class psp
)
or windows (class owin
).
Hest |
spherical contact distribution |
Gfox |
Foxall -function |
Jfox |
Foxall -function
|
Model fitting
Functions for fitting point process models are now contained in the spatstat.model package.
Simulation
There are many ways to generate a random point pattern, line segment pattern, pixel image or tessellation in spatstat.
Random point patterns: Functions for random generation are now contained in the spatstat.random package.
See also varblock
for estimating the variance
of a summary statistic by block resampling, and
lohboot
for another bootstrap technique.
Fitted point process models:
If you have fitted a point process model to a point pattern dataset, the fitted model can be simulated.
Methods for simulating a fitted model are now contained in the spatstat.model package.
Other random patterns: Functions for random generation are now contained in the spatstat.random package.
Simulation-based inference
envelope |
critical envelope for Monte Carlo test of goodness-of-fit |
bits.envelope |
critical envelope for balanced two-stage Monte Carlo test |
qqplot.ppm |
diagnostic plot for interpoint interaction |
scan.test |
spatial scan statistic/test |
studpermu.test |
studentised permutation test |
segregation.test |
test of segregation of types |
Hypothesis tests:
quadrat.test |
goodness-of-fit
test on quadrat counts |
clarkevans.test |
Clark and Evans test |
cdf.test |
Spatial distribution goodness-of-fit test |
berman.test |
Berman's goodness-of-fit tests |
envelope |
critical envelope for Monte Carlo test of goodness-of-fit |
scan.test |
spatial scan statistic/test |
dclf.test |
Diggle-Cressie-Loosmore-Ford test |
mad.test |
Mean Absolute Deviation test |
anova.ppm |
Analysis of Deviance for point process models |
More recently-developed tests:
dg.test |
Dao-Genton test |
bits.test |
Balanced independent two-stage test |
dclf.progress |
Progress plot for DCLF test |
mad.progress |
Progress plot for MAD test |
Model diagnostics:
Classical measures of model sensitivity such as leverage and influence, and classical model diagnostic tools such as residuals, partial residuals, and effect estimates, have been adapted to point process models. These capabilities are now provided in the spatstat.model package.
Resampling and randomisation procedures
You can build your own tests based on randomisation and resampling using the following capabilities:
quadratresample |
block resampling |
rshift |
random shifting of (subsets of) points |
rthin |
random thinning |
This library and its documentation are usable under the terms of the "GNU General Public License", a copy of which is distributed with the package.
Kasper Klitgaard Berthelsen, Ottmar Cronie, Tilman Davies, Julian Gilbey, Yongtao Guan, Ute Hahn, Kassel Hingee, Abdollah Jalilian, Marie-Colette van Lieshout, Greg McSwiggan, Tuomas Rajala, Suman Rakshit, Dominic Schuhmacher, Rasmus Waagepetersen and Hangsheng Wang made substantial contributions of code.
For comments, corrections, bug alerts and suggestions, we thank Monsuru Adepeju, Corey Anderson, Ang Qi Wei, Ryan Arellano, Jens Astrom, Robert Aue, Marcel Austenfeld, Sandro Azaele, Malissa Baddeley, Guy Bayegnak, Colin Beale, Melanie Bell, Thomas Bendtsen, Ricardo Bernhardt, Andrew Bevan, Brad Biggerstaff, Anders Bilgrau, Leanne Bischof, Christophe Biscio, Roger Bivand, Jose M. Blanco Moreno, Florent Bonneu, Jordan Brown, Ian Buller, Julian Burgos, Simon Byers, Ya-Mei Chang, Jianbao Chen, Igor Chernayavsky, Y.C. Chin, Bjarke Christensen, Lucia Cobo Sanchez, Jean-Francois Coeurjolly, Kim Colyvas, Hadrien Commenges, Rochelle Constantine, Robin Corria Ainslie, Richard Cotton, Marcelino de la Cruz, Peter Dalgaard, Mario D'Antuono, Sourav Das, Peter Diggle, Patrick Donnelly, Ian Dryden, Stephen Eglen, Ahmed El-Gabbas, Belarmain Fandohan, Olivier Flores, David Ford, Peter Forbes, Shane Frank, Janet Franklin, Funwi-Gabga Neba, Oscar Garcia, Agnes Gault, Jonas Geldmann, Marc Genton, Shaaban Ghalandarayeshi, Jason Goldstick, Pavel Grabarnik, C. Graf, Ute Hahn, Andrew Hardegen, Martin Bogsted Hansen, Martin Hazelton, Juha Heikkinen, Mandy Hering, Markus Herrmann, Maximilian Hesselbarth, Paul Hewson, Hamidreza Heydarian, Kurt Hornik, Philipp Hunziker, Jack Hywood, Ross Ihaka, Cenk Icos, Aruna Jammalamadaka, Robert John-Chandran, Devin Johnson, Mahdieh Khanmohammadi, Bob Klaver, Lily Kozmian-Ledward, Peter Kovesi, Mike Kuhn, Jeff Laake, Robert Lamb, Frederic Lavancier, Tom Lawrence, Tomas Lazauskas, Jonathan Lee, George Leser, Angela Li, Li Haitao, George Limitsios, Andrew Lister, Nestor Luambua, Ben Madin, Martin Maechler, Kiran Marchikanti, Jeff Marcus, Robert Mark, Peter McCullagh, Monia Mahling, Jorge Mateu Mahiques, Ulf Mehlig, Frederico Mestre, Sebastian Wastl Meyer, Mi Xiangcheng, Lore De Middeleer, Robin Milne, Enrique Miranda, Jesper Moller, Annie Mollie, Ines Moncada, Mehdi Moradi, Virginia Morera Pujol, Erika Mudrak, Gopalan Nair, Nader Najari, Nicoletta Nava, Linda Stougaard Nielsen, Felipe Nunes, Jens Randel Nyengaard, Jens Oehlschlaegel, Thierry Onkelinx, Sean O'Riordan, Evgeni Parilov, Jeff Picka, Nicolas Picard, Tim Pollington, Mike Porter, Sergiy Protsiv, Adrian Raftery, Ben Ramage, Pablo Ramon, Xavier Raynaud, Nicholas Read, Matt Reiter, Ian Renner, Tom Richardson, Brian Ripley, Ted Rosenbaum, Barry Rowlingson, Jason Rudokas, Tyler Rudolph, John Rudge, Christopher Ryan, Farzaneh Safavimanesh, Aila Sarkka, Cody Schank, Katja Schladitz, Sebastian Schutte, Bryan Scott, Olivia Semboli, Francois Semecurbe, Vadim Shcherbakov, Shen Guochun, Shi Peijian, Harold-Jeffrey Ship, Tammy L Silva, Ida-Maria Sintorn, Yong Song, Malte Spiess, Mark Stevenson, Kaspar Stucki, Jan Sulavik, Michael Sumner, P. Surovy, Ben Taylor, Thordis Linda Thorarinsdottir, Leigh Torres, Berwin Turlach, Torben Tvedebrink, Kevin Ummer, Medha Uppala, Andrew van Burgel, Tobias Verbeke, Mikko Vihtakari, Alexendre Villers, Fabrice Vinatier, Maximilian Vogtland, Sasha Voss, Sven Wagner, Hao Wang, H. Wendrock, Jan Wild, Carl G. Witthoft, Selene Wong, Maxime Woringer, Luke Yates, Mike Zamboni and Achim Zeileis.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Extract a subset of the data for a spatially sampled function.
## S3 method for class 'ssf' x[i, j, ..., drop]
## S3 method for class 'ssf' x[i, j, ..., drop]
x |
Object of class |
i |
Subset index applying to the locations where the function is sampled. |
j |
Subset index applying to the columns (variables) measured at each location. |
... , drop
|
Ignored. |
This is the subset operator for the class "ssf"
.
Another object of class "ssf"
.
Adrian Baddeley [email protected].
f <- ssf(cells, data.frame(d=nndist(cells), i=1:42)) f f[1:10,] f[ ,1]
f <- ssf(cells, data.frame(d=nndist(cells), i=1:42)) f f[1:10,] f[ ,1]
Computes an adaptive estimate of the intensity function of a point pattern.
adaptive.density(X, ..., method=c("voronoi","kernel", "nearest"))
adaptive.density(X, ..., method=c("voronoi","kernel", "nearest"))
X |
Point pattern (object of class |
method |
Character string specifying the estimation method |
... |
Additional arguments passed to
|
This function is an alternative to density.ppp
and density.lpp
. It
computes an estimate of the intensity function of a point pattern
dataset. The result is a pixel image giving the estimated intensity.
If method="voronoi"
the data are passed to the function
densityVoronoi
which estimates the intensity using
the Voronoi-Dirichlet tessellation.
If method="kernel"
the data are passed to the function
densityAdaptiveKernel.ppp
which estimates the intensity
using a variable-bandwidth kernel estimator. (This is not yet supported
when X
has class "lpp"
.)
If method="nearest"
the data are passed to the function
nndensity.ppp
which estimates the intensity using the
distance to the k
-th nearest data point. (This is not yet supported
when X
has class "lpp"
.)
A pixel image (object of class "im"
or "linim"
)
whose values are estimates of the intensity of X
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected] and Mehdi Moradi [email protected].
density.ppp
,
densityVoronoi
,
densityAdaptiveKernel.ppp
,
nndensity.ppp
,
im.object
.
plot(adaptive.density(nztrees, 1), main="Voronoi estimate")
plot(adaptive.density(nztrees, 1), main="Voronoi estimate")
Calculates the ,
,
, and
summary functions for an unmarked point pattern.
Returns them as a function array (of class
"fasp"
, see
fasp.object
).
allstats(pp, ..., dataname=NULL, verb=FALSE)
allstats(pp, ..., dataname=NULL, verb=FALSE)
pp |
The observed point pattern, for which summary function
estimates are required. An object of class |
... |
Optional arguments passed to the summary functions
|
dataname |
A character string giving an optional (alternative) name for the point pattern. |
verb |
A logical value meaning “verbose”. If |
This computes four standard summary statistics for a
point pattern: the empty space function ,
nearest neighbour distance distribution function
,
van Lieshout-Baddeley function
and Ripley's function
.
The real work is done by
Fest
, Gest
, Jest
and
Kest
respectively. Consult the help files for these functions
for further information about the statistical interpretation
of ,
,
and
.
If verb
is TRUE
, then “progress reports”
(just indications of completion) are printed out when the
calculations are finished for each of the four function types.
The overall title of the array of four functions
(for plotting by plot.fasp
)
will be formed from the argument dataname
.
If this is not given, it defaults to the expression
for pp
given in the call to allstats
.
A list of length 4 containing the ,
,
and
functions respectively.
The list can be plotted directly using plot
(which dispatches to
plot.anylist
).
Each list entry retains the format
of the output of the relevant estimating routine
Fest
, Gest
, Jest
or
Kest
. Thus each entry in the list is
a function value table (object of class "fv"
,
see fv.object
).
The default formulae for plotting these functions are
cbind(km,theo) ~ r
for F, G, and J, and
cbind(trans,theo) ~ r
for K.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
plot.anylist
,
plot.fv
,
fv.object
,
Fest
,
Gest
,
Jest
,
Kest
a <- allstats(swedishpines,dataname="Swedish Pines") if(interactive()) { plot(a) plot(a, subset=list("r<=15","r<=15","r<=15","r<=50")) }
a <- allstats(swedishpines,dataname="Swedish Pines") if(interactive()) { plot(a) plot(a, subset=list("r<=15","r<=15","r<=15","r<=50")) }
Given a marked point pattern, this computes the estimates of
a selected summary function (,
,
,
etc)
of the pattern, for all possible combinations of marks,
and returns these functions in an array.
alltypes(X, fun="K", ..., dataname=NULL,verb=FALSE,envelope=FALSE,reuse=TRUE)
alltypes(X, fun="K", ..., dataname=NULL,verb=FALSE,envelope=FALSE,reuse=TRUE)
X |
The observed point pattern, for which summary function
estimates are required. An object of class |
fun |
The summary function. Either an R function,
or a character string indicating the summary function
required. Options for strings are
|
... |
Arguments passed to the summary function
(and to the function |
dataname |
Character string giving an optional (alternative)
name to the point pattern, different from what is given
in the call. This name, if supplied, may be used by
|
verb |
Logical value. If |
envelope |
Logical value. If |
reuse |
Logical value indicating whether the envelopes in each panel
should be based on the same set of simulated patterns
( |
This routine is a convenient way to analyse the dependence between
types in a multitype point pattern.
It computes the estimates of a selected summary function of the
pattern, for all possible combinations of marks.
It returns these functions in an array
(an object of class "fasp"
) amenable to plotting
by plot.fasp()
.
The argument fun
specifies the summary function that will
be evaluated for each type of point, or for each pair of types.
It may be either an R function or a character string.
Suppose that the points have possible types
and let
denote the pattern of points of type
only.
If fun="F"
then this routine
calculates, for each possible type ,
an estimate of the Empty Space Function
of
. See
Fest
for explanation of the empty space function.
The estimate is computed by applying Fest
to with the optional arguments
...
.
If fun
is
"Gcross"
, "Jcross"
, "Kcross"
or "Lcross"
,
the routine calculates, for each pair of types ,
an estimate of the “
i
-toj
” cross-type function
,
,
or
respectively describing the
dependence between
and
.
See
Gcross
, Jcross
, Kcross
or Lcross
respectively for explanation of these
functions.
The estimate is computed by applying the relevant function
(Gcross
etc)
to X
using each possible value of the arguments i,j
,
together with the optional arguments ...
.
If fun
is "pcf"
the routine calculates
the cross-type pair correlation function pcfcross
between each pair of types.
If fun
is
"Gdot"
, "Jdot"
, "Kdot"
or "Ldot"
,
the routine calculates, for each type ,
an estimate of the “
i
-to-any” dot-type function
,
or
or
respectively describing the
dependence between
and
.
See
Gdot
, Jdot
, Kdot
or Ldot
respectively for explanation of these functions.
The estimate is computed by applying the relevant function
(Gdot
etc)
to X
using each possible value of the argument i
,
together with the optional arguments ...
.
The letters "G"
, "J"
, "K"
and "L"
are interpreted as abbreviations for Gcross
,
Jcross
, Kcross
and Lcross
respectively, assuming the point pattern is
marked. If the point pattern is unmarked, the appropriate
function Fest
, Jest
,
Kest
or Lest
is invoked instead.
If envelope=TRUE
, then as well as computing the value of the
summary function for each combination of types, the algorithm also
computes simulation envelopes of the summary function for each
combination of types. The arguments ...
are passed to the function
envelope
to control the number of
simulations, the random process generating the simulations,
the construction of envelopes, and so on.
When envelope=TRUE
it is possible that errors could occur
because the simulated point patterns do not satisfy the requirements
of the summary function (for example, because the simulated pattern
is empty and fun
requires at least one point). If the number
of such errors exceeds the maximum permitted number maxnerr
,
then the envelope algorithm will give up, and will return
the empirical summary function for the data point pattern,
fun(X)
, in place of the envelope.
A function array (an object of class "fasp"
,
see fasp.object
). This can be plotted
using plot.fasp
.
If the pattern is not marked, the resulting “array” has dimensions
. Otherwise the following is true:
If fun="F"
,
the function array has dimensions
where
is the number of different marks in the point pattern.
The entry at position
[i,1]
in this array
is the result of applying Fest
to the
points of type i
only.
If fun
is "Gdot"
, "Jdot"
, "Kdot"
or "Ldot"
, the function array
again has dimensions .
The entry at position
[i,1]
in this array
is the result of Gdot(X, i)
, Jdot(X, i)
Kdot(X, i)
or Ldot(X, i)
respectively.
If fun
is "Gcross"
, "Jcross"
, "Kcross"
or "Lcross"
(or their abbreviations "G"
, "J"
, "K"
or "L"
),
the function array has dimensions .
The
[i,j]
entry of the function array
(for ) is the
result of applying the function
Gcross
,
Jcross
, Kcross
orLcross
to
the pair of types (i,j)
. The diagonal
[i,i]
entry of the function array is the result of
applying the univariate function Gest
,
Jest
, Kest
or Lest
to the
points of type i
only.
If envelope=FALSE
, then
each function entry fns[[i]]
retains the format
of the output of the relevant estimating routine
Fest
, Gest
, Jest
,
Kest
, Lest
, Gcross
,
Jcross
,Kcross
, Lcross
,
Gdot
, Jdot
, Kdot
or
Ldot
The default formulae for plotting these functions are
cbind(km,theo) ~ r
for F, G, and J functions, and
cbind(trans,theo) ~ r
for K and L functions.
If envelope=TRUE
, then each function entry fns[[i]]
has the same format as the output of the envelope
command.
Sizeable amounts of memory may be needed during the calculation.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
plot.fasp
,
fasp.object
,
Fest
,
Gest
,
Jest
,
Kest
,
Lest
,
Gcross
,
Jcross
,
Kcross
,
Lcross
,
Gdot
,
Jdot
,
Kdot
,
envelope
.
# bramblecanes (3 marks). bram <- bramblecanes bF <- alltypes(bram,"F",verb=TRUE) plot(bF) if(interactive()) { plot(alltypes(bram,"G")) plot(alltypes(bram,"Gdot")) } # Swedishpines (unmarked). swed <- swedishpines plot(alltypes(swed,"K")) plot(alltypes(amacrine, "pcf"), ylim=c(0,1.3)) # envelopes bKE <- alltypes(bram,"K",envelope=TRUE,nsim=19) # global version: bFE <- alltypes(bram,"F",envelope=TRUE,nsim=19,global=TRUE) # extract one entry as.fv(bKE[1,1])
# bramblecanes (3 marks). bram <- bramblecanes bF <- alltypes(bram,"F",verb=TRUE) plot(bF) if(interactive()) { plot(alltypes(bram,"G")) plot(alltypes(bram,"Gdot")) } # Swedishpines (unmarked). swed <- swedishpines plot(alltypes(swed,"K")) plot(alltypes(amacrine, "pcf"), ylim=c(0,1.3)) # envelopes bKE <- alltypes(bram,"K",envelope=TRUE,nsim=19) # global version: bFE <- alltypes(bram,"F",envelope=TRUE,nsim=19,global=TRUE) # extract one entry as.fv(bKE[1,1])
Converts an envelope object to a data frame.
## S3 method for class 'envelope' as.data.frame(x, ..., simfuns=FALSE)
## S3 method for class 'envelope' as.data.frame(x, ..., simfuns=FALSE)
x |
Envelope object (class |
... |
Ignored. |
simfuns |
Logical value indicating whether the result should include the values of the simulated functions that were used to build the envelope. |
This is a method for the generic function as.data.frame
for the class of envelopes (see envelope
.
The result is a data frame with columns
containing the values of the function argument
(usually named r
), the function estimate for the original
point pattern data (obs
),
the upper and lower envelope limits (hi
and lo
),
and possibly additional columns.
If simfuns=TRUE
, the result also includes columns of values
of the simulated functions that were used to compute the envelope.
This is possible only when the envelope was computed with the
argument savefuns=TRUE
in the call to envelope
.
A data frame.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
E <- envelope(cells, nsim=5, savefuns=TRUE) tail(as.data.frame(E)) tail(as.data.frame(E, simfuns=TRUE))
E <- envelope(cells, nsim=5, savefuns=TRUE) tail(as.data.frame(E)) tail(as.data.frame(E, simfuns=TRUE))
Converts an object of class "fv"
to an R language function.
## S3 method for class 'fv' as.function(x, ..., value=".y", extrapolate=FALSE)
## S3 method for class 'fv' as.function(x, ..., value=".y", extrapolate=FALSE)
x |
Object of class |
... |
Ignored. |
value |
Optional. Character string or character vector selecting
one or more of the columns of |
extrapolate |
Logical, indicating whether to extrapolate the function
outside the domain of |
A function value table (object of class "fv"
)
is a convenient way of storing and plotting
several different estimates of the same function.
Objects of this class are returned
by many commands in spatstat,
such as Kest
,
which returns an estimate of Ripley's -function
for a point pattern dataset.
Sometimes it is useful to convert the function value table
to a function
in the R language. This is done by
as.function.fv
. It converts an object x
of class "fv"
to an R function f
.
If f <- as.function(x)
then f
is an R function
that accepts a numeric argument and returns a corresponding value
for the summary function by linear interpolation between the values
in the table x
.
Argument values lying outside the range of the table
yield an NA
value (if extrapolate=FALSE
)
or the function value at the nearest endpoint of the range
(if extrapolate = TRUE
).
To apply different rules to the left and right extremes,
use extrapolate=c(TRUE,FALSE)
and so on.
Typically the table x
contains several columns of
function values corresponding to different edge corrections.
Auxiliary information for the table identifies one of these
columns as the recommended value.
By default, the values of the function f <- as.function(x)
are taken from this column of recommended values.
This default can be changed using the argument value
,
which can be a character string or character vector of names of
columns of x
. Alternatively value
can be one of
the abbreviations used by fvnames
.
If value
specifies a single column of the table,
then the result is a function f(r)
with a single numeric
argument r
(with the same name as the orginal argument
of the function table).
If value
specifies several columns of the table,
then the result is a function f(r,what)
where r
is the numeric argument and
what
is a character string identifying the column of values
to be used.
The formal arguments of the resulting function
are f(r, what=value)
, which
means that in a call to this function f
, the permissible values
of what
are the entries of the original vector value
;
the default value of what
is the first entry of value
.
The command as.function.fv
is a method for the generic command
as.function
.
A function(r)
or function(r,what)
where r
is the name of the original argument of the function table.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
as.function.rhohat
,
fv
,
fv.object
,
fvnames
,
plot.fv
,
Kest
K <- Kest(cells) f <- as.function(K) f f(0.1) g <- as.function(K, value=c("iso", "trans")) g g(0.1, "trans")
K <- Kest(cells) f <- as.function(K) f f(0.1) g <- as.function(K, value=c("iso", "trans")) g g(0.1, "trans")
Converts an object of class "rhohat"
to an R language function.
## S3 method for class 'rhohat' as.function(x, ..., value=".y", extrapolate=TRUE)
## S3 method for class 'rhohat' as.function(x, ..., value=".y", extrapolate=TRUE)
x |
Object of class |
... |
Ignored. |
value |
Optional. Character string or character vector selecting
one or more of the columns of |
extrapolate |
Logical, indicating whether to extrapolate the function
outside the domain of |
An object of class "rhohat"
is essentially a data frame
of estimated values of the function
as described in the help file for
rhohat
.
Sometimes it is useful to convert the function value table
to a function
in the R language. This is done by
as.function.rhohat
. It converts an object x
of class "rhohat"
to an R function f
.
The command as.function.rhohat
is a method for the generic command
as.function
for the class "rhohat"
.
If f <- as.function(x)
then f
is an R function
that accepts a numeric argument and returns a corresponding value
for the summary function by linear interpolation between the values
in the table x
.
Argument values lying outside the range of the table
yield an NA
value (if extrapolate=FALSE
)
or the function value at the nearest endpoint of the range
(if extrapolate = TRUE
).
To apply different rules to the left and right extremes,
use extrapolate=c(TRUE,FALSE)
and so on.
Typically the table x
contains several columns of
function values corresponding to different edge corrections.
Auxiliary information for the table identifies one of these
columns as the recommended value.
By default, the values of the function f <- as.function(x)
are taken from this column of recommended values.
This default can be changed using the argument value
,
which can be a character string or character vector of names of
columns of x
. Alternatively value
can be one of
the abbreviations used by fvnames
.
If value
specifies a single column of the table,
then the result is a function f(r)
with a single numeric
argument r
(with the same name as the orginal argument
of the function table).
If value
specifies several columns of the table,
then the result is a function f(r,what)
where r
is the numeric argument and
what
is a character string identifying the column of values
to be used.
The formal arguments of the resulting function
are f(r, what=value)
, which
means that in a call to this function f
, the permissible values
of what
are the entries of the original vector value
;
the default value of what
is the first entry of value
.
A function(r)
or function(r,what)
where r
is the name of the original argument of the function table.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
rhohat
,
methods.rhohat
,
as.function.fv
.
g <- rhohat(cells, "x") f <- as.function(g) f f(0.1)
g <- rhohat(cells, "x") f <- as.function(g) f f(0.1)
Converts data into a function table (an object of class "fv"
).
as.fv(x) ## S3 method for class 'fv' as.fv(x) ## S3 method for class 'data.frame' as.fv(x) ## S3 method for class 'matrix' as.fv(x) ## S3 method for class 'fasp' as.fv(x) ## S3 method for class 'bw.optim' as.fv(x)
as.fv(x) ## S3 method for class 'fv' as.fv(x) ## S3 method for class 'data.frame' as.fv(x) ## S3 method for class 'matrix' as.fv(x) ## S3 method for class 'fasp' as.fv(x) ## S3 method for class 'bw.optim' as.fv(x)
x |
Data which will be converted into a function table |
This command converts data x
, that
could be interpreted as the values of a function,
into a function value table (object of the class "fv"
as described in fv.object
). This object can then
be plotted easily using plot.fv
.
The dataset x
may be any of the following:
an object of class "fv"
;
a matrix or data frame with at least two columns;
an object of class "fasp"
, representing an array of
"fv"
objects.
an object of class "minconfit"
, giving the results
of a minimum contrast fit by
the command mincontrast
.
The
an object of class "kppm"
, representing a fitted
Cox or cluster point process model, obtained from the
model-fitting command kppm
;
an object of class "dppm"
, representing a fitted
determinantal point process model, obtained from the
model-fitting command dppm
;
an object of class "bw.optim"
, representing an optimal
choice of smoothing bandwidth by a cross-validation method, obtained
from commands like bw.diggle
.
The function as.fv
is generic, with methods for each of the
classes listed above. The behaviour is as follows:
If x
is an object of class "fv"
, it is
returned unchanged.
If x
is a matrix or data frame,
the first column is interpreted
as the function argument, and subsequent columns are interpreted as
values of the function computed by different methods.
If x
is an object of class "fasp"
representing an array of "fv"
objects,
these are combined into a single "fv"
object.
If x
is an object of class "minconfit"
,
or an object of class "kppm"
or "dppm"
,
the result is a function table containing the
observed summary function and the best fit summary function.
If x
is an object of class "bw.optim"
,
the result is a function table of the optimisation criterion
as a function of the smoothing bandwidth.
An object of class "fv"
(see fv.object
).
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
r <- seq(0, 1, length=101) x <- data.frame(r=r, y=r^2) as.fv(x)
r <- seq(0, 1, length=101) x <- data.frame(r=r, y=r^2) as.fv(x)
Converts data specifying an observation window
in any of several formats, into an object of class "owin"
.
## S3 method for class 'quadrattest' as.owin(W, ..., fatal=TRUE)
## S3 method for class 'quadrattest' as.owin(W, ..., fatal=TRUE)
W |
Data specifying an observation window, in any of several formats described under Details below. |
fatal |
Logical value determining what to do if the data cannot be converted to an observation window. See Details. |
... |
Ignored. |
The class "owin"
is a way of specifying the observation window
for a point pattern. See owin.object
for an overview.
The generic function as.owin
converts data in any of several formats
into an object of class "owin"
for use by the spatstat
package. The function as.owin
is generic, with methods
for different classes of objects, and a default method.
The argument W
may be
an object of class "owin"
a structure with entries xrange
, yrange
specifying the
and
dimensions of a rectangle
a structure with entries named xmin
, xmax
, ymin
,
ymax
(in any order)
specifying the and
dimensions of a rectangle.
This will accept objects of class
bbox
in the sf
package.
a numeric vector of length 4
(interpreted as (xmin, xmax, ymin, ymax)
in that order)
specifying the and
dimensions of a rectangle
a structure with entries named xl
, xu
, yl
, yu
(in any order)
specifying the and
dimensions of a rectangle
as
(xmin, xmax) = (xl, xu)
and
(ymin, ymax) = (yl, yu)
. This will accept objects of
class spp
used in the Venables and Ripley spatial
package.
an object of class "ppp"
representing a point pattern.
In this case, the object's window
structure will be
extracted.
an object of class "psp"
representing a line segment pattern.
In this case, the object's window
structure will be
extracted.
an object of class "tess"
representing a tessellation.
In this case, the object's window
structure will be
extracted.
an object of class "quad"
representing a quadrature scheme.
In this case, the window of the data
component will be
extracted.
an object of class "im"
representing a pixel image.
In this case, a window of type "mask"
will be returned,
with the same pixel raster coordinates as the image.
An image pixel value of NA
, signifying that the pixel
lies outside the window, is transformed into the logical value
FALSE
, which is the corresponding convention for window masks.
an object of class "ppm"
, "kppm"
, "slrm"
or "dppm"
representing a fitted point process
model. In this case, if from="data"
(the default),
as.owin
extracts the original point
pattern data to which the model was fitted, and returns the
observation window of this point pattern. If
from="covariates"
then as.owin
extracts the
covariate images to which the model was fitted,
and returns a binary mask window that specifies the pixel locations.
an object of class "lpp"
representing a point pattern on a linear network.
In this case, as.owin
extracts the linear network
and returns a window containing this network.
an object of class "lppm"
representing a fitted point process model on a linear network.
In this case, as.owin
extracts the linear network
and returns a window containing this network.
A data.frame
with exactly three columns. Each row of the
data frame corresponds to one pixel. Each row contains the
and
coordinates of a pixel, and a logical value
indicating whether the pixel lies inside the window.
A data.frame
with exactly two columns. Each row of the
data frame contains the and
coordinates of a pixel
that lies inside the window.
an object of class "distfun"
, "nnfun"
or "funxy"
representing a function of spatial location,
defined on a spatial domain. The spatial domain of the function will be
extracted.
an object of class "rmhmodel"
representing a
point process model that can be simulated using rmh
.
The window (spatial domain) of the model will be extracted.
The window may be NULL
in some circumstances (indicating that the
simulation window has not yet been determined). This is not treated
as an error, because the argument fatal
defaults to
FALSE
for this method.
an object of class "layered"
representing a
list of spatial objects. See layered
.
In this case, as.owin
will be applied to each
of the objects in the list, and the union of these windows
will be returned.
An object of another suitable class from another package.
For full details, see vignette('shapefiles')
.
If the argument W
is not in one of these formats
and cannot be converted to a window, then an error will
be generated (if fatal=TRUE
) or a value of NULL
will be returned (if fatal=FALSE
).
When W
is a data frame, the argument step
can be used to specify the pixel grid spacing; otherwise, the spacing
will be guessed from the data.
An object of class "owin"
(see owin.object
)
specifying an observation window.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
as.owin
,
as.owin.rmhmodel
,
as.owin.lpp
.
Additional methods for as.owin
may be provided
by other packages outside the spatstat family.
te <- quadrat.test(redwood, nx=3) as.owin(te)
te <- quadrat.test(redwood, nx=3) as.owin(te)
Converts data specifying a tessellation,
in any of several formats, into an object of class "tess"
.
## S3 method for class 'quadrattest' as.tess(X)
## S3 method for class 'quadrattest' as.tess(X)
X |
Data to be converted to a tessellation. |
A tessellation is a collection of disjoint spatial regions
(called tiles) that fit together to form a larger spatial
region. This command creates an object of class "tess"
that
represents a tessellation.
This function converts data in any of several formats
into an object of class "tess"
for use by the spatstat
package. The argument X
may be
an object of class "tess"
.
The object will be stripped of any extraneous attributes
and returned.
a pixel image (object of class "im"
) with pixel values that
are logical or factor values. Each level of the factor will
determine a tile of the tessellation.
a window (object of class "owin"
). The result will be a
tessellation consisting of a single tile.
a set of quadrat counts (object of class "quadratcount"
)
returned by the command quadratcount
.
The quadrats
used to generate the counts will be extracted and returned as a
tessellation.
a quadrat test (object of class "quadrattest"
)
returned by the command quadrat.test
.
The quadrats
used to perform the test will be extracted and returned as a
tessellation.
a list of windows (objects of class "owin"
)
giving the tiles of the tessellation.
The function as.tess
is generic, with methods for
various classes, as listed above.
An object of class "tess"
specifying a tessellation.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
h <- quadrat.test(nztrees, nx=4, ny=3) as.tess(h)
h <- quadrat.test(nztrees, nx=4, ny=3) as.tess(h)
Compute the AUC (area under the Receiver Operating Characteristic curve) for an observed point pattern.
auc(X, ...) ## S3 method for class 'ppp' auc(X, covariate, ..., high = TRUE)
auc(X, ...) ## S3 method for class 'ppp' auc(X, covariate, ..., high = TRUE)
X |
Point pattern (object of class |
covariate |
Spatial covariate. Either a |
high |
Logical value indicating whether the threshold operation should favour high or low values of the covariate. |
... |
Arguments passed to |
This command computes the AUC, the area under the Receiver Operating
Characteristic curve. The ROC itself is computed by roc
.
For a point pattern X
and a covariate Z
, the
AUC is a numerical index that measures the ability of the
covariate to separate the spatial domain
into areas of high and low density of points.
Let be a randomly-chosen data point from
X
and a randomly-selected location in the study region.
The AUC is the probability that
assuming
high=TRUE
.
That is, AUC is the probability that a randomly-selected data point
has a higher value of the covariate Z
than does a
randomly-selected spatial location. The AUC is a number between 0 and 1.
A value of 0.5 indicates a complete lack of discriminatory power.
Numeric.
For auc.ppp
and auc.lpp
, the result is a single number
giving the AUC value.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Lobo, J.M., Jimenez-Valverde, A. and Real, R. (2007) AUC: a misleading measure of the performance of predictive distribution models. Global Ecology and Biogeography 17(2) 145–151.
Nam, B.-H. and D'Agostino, R. (2002) Discrimination index, the area under the ROC curve. Pages 267–279 in Huber-Carol, C., Balakrishnan, N., Nikulin, M.S. and Mesbah, M., Goodness-of-fit tests and model validity, Birkhauser, Basel.
auc(swedishpines, "x")
auc(swedishpines, "x")
Tests the goodness-of-fit of a Poisson point process model using methods of Berman (1986).
berman.test(...) ## S3 method for class 'ppp' berman.test(X, covariate, which = c("Z1", "Z2"), alternative = c("two.sided", "less", "greater"), ...)
berman.test(...) ## S3 method for class 'ppp' berman.test(X, covariate, which = c("Z1", "Z2"), alternative = c("two.sided", "less", "greater"), ...)
X |
A point pattern (object of class |
covariate |
The spatial covariate on which the test will be based.
An image (object of class |
which |
Character string specifying the choice of test. |
alternative |
Character string specifying the alternative hypothesis. |
... |
Additional arguments controlling the pixel resolution
(arguments |
These functions perform a goodness-of-fit test of a Poisson point
process model fitted to point pattern data. The observed distribution
of the values of a spatial covariate at the data points,
and the predicted distribution of the same values under the model,
are compared using either of two test statistics
and
proposed by Berman (1986).
The
test is also known as the
Lawson-Waller test.
The function berman.test
is generic, with methods for
point patterns ("ppp"
or "lpp"
)
and point process models ("ppm"
or "lppm"
).
If X
is a point pattern dataset (object of class
"ppp"
or "lpp"
), then
berman.test(X, ...)
performs a goodness-of-fit test of the
uniform Poisson point process (Complete Spatial Randomness, CSR)
for this dataset.
If model
is a fitted point process model
(object of class "ppm"
or "lppm"
)
then berman.test(model, ...)
performs
a test of goodness-of-fit for this fitted model. In this case,
model
should be a Poisson point process.
The test is performed by comparing the observed distribution of the values of a spatial covariate at the data points, and the predicted distribution of the same covariate under the model. Thus, you must nominate a spatial covariate for this test.
The argument covariate
should be either a function(x,y)
or a pixel image (object of class "im"
containing the values
of a spatial function.
If covariate
is an image, it should have numeric values,
and its domain should cover the observation window of the
model
. If covariate
is a function, it should expect
two arguments x
and y
which are vectors of coordinates,
and it should return a numeric vector of the same length
as x
and y
.
First the original data point pattern is extracted from model
.
The values of the covariate
at these data points are
collected.
Next the values of the covariate
at all locations in the
observation window are evaluated. The point process intensity
of the fitted model is also evaluated at all locations in the window.
If which="Z1"
,
the test statistic is computed as follows.
The sum
of the covariate values at all data
points is evaluated. The predicted mean
and variance
of
are computed
from the values of the covariate at all locations in the window.
Then we compute
.
Closely-related tests were proposed independently
by Waller et al (1993) and Lawson (1993)
so this test is often termed the
Lawson-Waller test in epidemiological literature.
If which="Z2"
,
the test statistic is computed as follows.
The values of the
covariate
at all locations in the
observation window, weighted by the point process intensity,
are compiled into a cumulative distribution function .
The probability integral transformation is then applied:
the values of the
covariate
at the original data points
are transformed by the predicted cumulative distribution function
into numbers between 0 and 1. If the model is correct,
these numbers are i.i.d. uniform random numbers.
The standardised sample mean of these numbers is the
statistic
.
In both cases the null distribution of the test statistic is the standard normal distribution, approximately.
The return value is an object of class "htest"
containing the
results of the hypothesis test. The print method for this class
gives an informative summary of the test outcome.
An object of class "htest"
(hypothesis test)
and also of class "bermantest"
,
containing the results of the test. The return value can be
plotted (by plot.bermantest
) or printed
to give an informative summary of the test.
The meaning of a one-sided test must be carefully scrutinised: see the printed output.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Berman, M. (1986) Testing for spatial association between a point process and another stochastic process. Applied Statistics 35, 54–62.
Lawson, A.B. (1993) On the analysis of mortality events around a prespecified fixed point. Journal of the Royal Statistical Society, Series A 156 (3) 363–377.
Waller, L., Turnbull, B., Clark, L.C. and Nasca, P. (1992) Chronic Disease Surveillance and testing of clustering of disease and exposure: Application to leukaemia incidence and TCE-contaminated dumpsites in upstate New York. Environmetrics 3, 281–300.
# Berman's data X <- copper$SouthPoints L <- copper$SouthLines D <- distmap(L, eps=1) # test of CSR berman.test(X, D) berman.test(X, D, "Z2")
# Berman's data X <- copper$SouthPoints L <- copper$SouthLines D <- distmap(L, eps=1) # test of CSR berman.test(X, D) berman.test(X, D, "Z2")
Advanced Use Only.
Combine objects of class "fv"
,
or glue extra columns of data onto an existing "fv"
object.
## S3 method for class 'fv' cbind(...) bind.fv(x, y, labl = NULL, desc = NULL, preferred = NULL, clip=FALSE)
## S3 method for class 'fv' cbind(...) bind.fv(x, y, labl = NULL, desc = NULL, preferred = NULL, clip=FALSE)
... |
Any number of arguments, which are objects of class |
x |
An object of class |
y |
Either an object of class |
labl |
Plot labels (see |
desc |
Descriptions (see |
preferred |
Character string specifying the column which is to be the new recommended value of the function. |
clip |
Logical value indicating whether each object must have exactly the
same domain, that is, the same sequence of values of the function argument
( |
This documentation is provided for experienced programmers who want to modify the internal behaviour of spatstat.
The function cbind.fv
is a method for the generic
R function cbind
. It combines any number of
objects of class "fv"
into a single object of
class "fv"
. The objects must be compatible, in the sense
that they have identical values of the function argument.
The function bind.fv
is a lower level
utility which glues additional columns onto an
existing object x
of class "fv"
.
It has three modes of use:
If the additional dataset y
is an object of class "fv"
, then
x
and y
must be compatible as described above.
Then the columns of y
that contain function values
will be appended to the object x
.
Alternatively if y
is a data frame, then y
must have the
same number of rows as x
. All columns of y
will be
appended to x
.
Alternatively if y
is a function in the R language, then
this function will be evaluated at the argument values stored
in the object x
, and these function values will be appended
as a new column to x
.
The arguments labl
and desc
provide
plot labels and description strings (as described in fv
)
for the new columns. If y
is an object of class
"fv"
then labl
and desc
are optional, and
default to the relevant entries in the object y
.
If y
is a data frame then
labl
and desc
should be provided, but there is a
default.
For additional flexibility, cbind.fv
also accepts arguments
which are data frames or functions.
An object of class "fv"
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
fv
for creating objects of class "fv"
from raw data.
collapse.fv
for combining several "fv"
objects
with similar columns.
with.fv
for evaluating expressions.
fvnames
for extracting and assigning the column names
of standard components of "fv"
objects.
Undocumented functions for modifying an "fv"
object
include tweak.fv.entry
and rebadge.fv
.
K1 <- Kest(cells, correction="border") K2 <- Kest(cells, correction="iso") # remove column 'theo' to avoid duplication K2 <- K2[, names(K2) != "theo"] cbind(K1, K2) bind.fv(K1, K2, preferred="iso") # constrain border estimate to be monotonically increasing bm <- cumsum(c(0, pmax(0, diff(K1$border)))) bind.fv(K1, data.frame(bmono=bm), "%s[bmo](r)", "monotone border-corrected estimate of %s", "bmono") # add a column of values defined by a function cbind(K1, upper=function(r) { pi * r^2 + 0.1 })
K1 <- Kest(cells, correction="border") K2 <- Kest(cells, correction="iso") # remove column 'theo' to avoid duplication K2 <- K2[, names(K2) != "theo"] cbind(K1, K2) bind.fv(K1, K2, preferred="iso") # constrain border estimate to be monotonically increasing bm <- cumsum(c(0, pmax(0, diff(K1$border)))) bind.fv(K1, data.frame(bmono=bm), "%s[bmo](r)", "monotone border-corrected estimate of %s", "bmono") # add a column of values defined by a function cbind(K1, upper=function(r) { pi * r^2 + 0.1 })
Computes the global envelopes corresponding to the balanced independent two-stage Monte Carlo test of goodness-of-fit.
bits.envelope(X, ..., nsim = 19, nrank = 1, alternative=c("two.sided", "less", "greater"), leaveout=1, interpolate = FALSE, savefuns=FALSE, savepatterns=FALSE, verbose = TRUE)
bits.envelope(X, ..., nsim = 19, nrank = 1, alternative=c("two.sided", "less", "greater"), leaveout=1, interpolate = FALSE, savefuns=FALSE, savepatterns=FALSE, verbose = TRUE)
X |
Either a point pattern dataset (object of class |
... |
Arguments passed to
|
nsim |
Number of simulated patterns to be generated in each stage.
Number of simulations in each basic test. There will be |
nrank |
Integer. Rank of the envelope value amongst the |
alternative |
Character string determining whether the envelope corresponds
to a two-sided test ( |
leaveout |
Optional integer 0, 1 or 2 indicating how to calculate the deviation between the observed summary function and the nominal reference value, when the reference value must be estimated by simulation. See Details. |
interpolate |
Logical value indicating whether to interpolate the distribution of the test statistic by kernel smoothing, as described in Dao and Genton (2014, Section 5). |
savefuns |
Logical flag indicating whether to save the simulated function values (from the first stage). |
savepatterns |
Logical flag indicating whether to save the simulated point patterns (from the first stage). |
verbose |
Logical value determining whether to print progress reports. |
Computes global simulation envelopes corresponding to the balanced independent two-stage Monte Carlo test of goodness-of-fit described by Baddeley et al (2017). The envelopes are described in Baddeley et al (2019).
If X
is a point pattern, the null hypothesis is CSR.
If X
is a fitted model, the null hypothesis is that model.
This command is similar to dg.envelope
which corresponds
to the Dao-Genton test of goodness-of-fit.
It was shown in Baddeley et al (2017) that
the Dao-Genton test is biased when the significance level is very small
(small -values are not reliable) and
we recommend
bits.envelope
in this case.
An object of class "fv"
.
Adrian Baddeley, Andrew Hardegen, Tom Lawrence, Robin Milne, Gopalan Nair and Suman Rakshit. Implemented by Adrian Baddeley [email protected].
Dao, N.A. and Genton, M. (2014) A Monte Carlo adjusted goodness-of-fit test for parametric models describing spatial point patterns. Journal of Graphical and Computational Statistics 23, 497–517.
Baddeley, A., Hardegen, A., Lawrence, T., Milne, R.K., Nair, G. and Rakshit, S. (2017) On two-stage Monte Carlo tests of composite hypotheses. Computational Statistics and Data Analysis 114, 75–87.
Baddeley, A., Hardegen, A., Lawrence, L., Milne, R.K., Nair, G.M. and Rakshit, S. (2019) Pushing the envelope: extensions of graphical Monte Carlo tests. In preparation.
dg.envelope
,
bits.test
,
mad.test
,
envelope
ns <- if(interactive()) 19 else 4 E <- bits.envelope(swedishpines, Lest, nsim=ns) E plot(E) Eo <- bits.envelope(swedishpines, Lest, alternative="less", nsim=ns) Ei <- bits.envelope(swedishpines, Lest, interpolate=TRUE, nsim=ns)
ns <- if(interactive()) 19 else 4 E <- bits.envelope(swedishpines, Lest, nsim=ns) E plot(E) Eo <- bits.envelope(swedishpines, Lest, alternative="less", nsim=ns) Ei <- bits.envelope(swedishpines, Lest, interpolate=TRUE, nsim=ns)
Performs a Balanced Independent Two-Stage Monte Carlo test of goodness-of-fit for spatial pattern.
bits.test(X, ..., exponent = 2, nsim=19, alternative=c("two.sided", "less", "greater"), leaveout=1, interpolate = FALSE, savefuns=FALSE, savepatterns=FALSE, verbose = TRUE)
bits.test(X, ..., exponent = 2, nsim=19, alternative=c("two.sided", "less", "greater"), leaveout=1, interpolate = FALSE, savefuns=FALSE, savepatterns=FALSE, verbose = TRUE)
X |
Either a point pattern dataset (object of class |
... |
Arguments passed to |
exponent |
Exponent used in the test statistic. Use |
nsim |
Number of replicates in each stage of the test.
A total of |
alternative |
Character string specifying the alternative hypothesis.
The default ( |
leaveout |
Optional integer 0, 1 or 2 indicating how to calculate the deviation between the observed summary function and the nominal reference value, when the reference value must be estimated by simulation. See Details. |
interpolate |
Logical value indicating whether to interpolate the distribution of the test statistic by kernel smoothing, as described in Dao and Genton (2014, Section 5). |
savefuns |
Logical flag indicating whether to save the simulated function values (from the first stage). |
savepatterns |
Logical flag indicating whether to save the simulated point patterns (from the first stage). |
verbose |
Logical value indicating whether to print progress reports. |
Performs the Balanced Independent Two-Stage Monte Carlo test proposed by Baddeley et al (2017), an improvement of the Dao-Genton (2014) test.
If X
is a point pattern, the null hypothesis is CSR.
If X
is a fitted model, the null hypothesis is that model.
The argument use.theory
passed to envelope
determines whether to compare the summary function for the data
to its theoretical value for CSR (use.theory=TRUE
)
or to the sample mean of simulations from CSR
(use.theory=FALSE
).
The argument leaveout
specifies how to calculate the
discrepancy between the summary function for the data and the
nominal reference value, when the reference value must be estimated
by simulation. The values leaveout=0
and
leaveout=1
are both algebraically equivalent (Baddeley et al, 2014,
Appendix) to computing the difference observed - reference
where the reference
is the mean of simulated values.
The value leaveout=2
gives the leave-two-out discrepancy
proposed by Dao and Genton (2014).
A hypothesis test (object of class "htest"
which can be printed to show the outcome of the test.
Adrian Baddeley, Andrew Hardegen, Tom Lawrence, Robin Milne, Gopalan Nair and Suman Rakshit. Implemented by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Dao, N.A. and Genton, M. (2014) A Monte Carlo adjusted goodness-of-fit test for parametric models describing spatial point patterns. Journal of Graphical and Computational Statistics 23, 497–517.
Baddeley, A., Diggle, P.J., Hardegen, A., Lawrence, T., Milne, R.K. and Nair, G. (2014) On tests of spatial pattern based on simulation envelopes. Ecological Monographs 84 (3) 477–489.
Baddeley, A., Hardegen, A., Lawrence, L., Milne, R.K., Nair, G.M. and Rakshit, S. (2017) On two-stage Monte Carlo tests of composite hypotheses. Computational Statistics and Data Analysis 114, 75–87.
Simulation envelopes: bits.envelope
.
Other tests:
dg.test
,
dclf.test
,
mad.test
.
ns <- if(interactive()) 19 else 4 bits.test(cells, nsim=ns) bits.test(cells, alternative="less", nsim=ns) bits.test(cells, nsim=ns, interpolate=TRUE)
ns <- if(interactive()) 19 else 4 bits.test(cells, nsim=ns) bits.test(cells, alternative="less", nsim=ns) bits.test(cells, nsim=ns, interpolate=TRUE)
Applies a Gaussian blur to a pixel image.
blur(x, sigma = NULL, ..., kernel="gaussian", normalise=FALSE, bleed = TRUE, varcov=NULL) ## S3 method for class 'im' Smooth(X, sigma = NULL, ..., kernel="gaussian", normalise=FALSE, bleed = TRUE, varcov=NULL)
blur(x, sigma = NULL, ..., kernel="gaussian", normalise=FALSE, bleed = TRUE, varcov=NULL) ## S3 method for class 'im' Smooth(X, sigma = NULL, ..., kernel="gaussian", normalise=FALSE, bleed = TRUE, varcov=NULL)
x , X
|
The pixel image. An object of class |
sigma |
Standard deviation of isotropic Gaussian smoothing kernel. |
... |
Ignored. |
kernel |
String (partially matched) specifying the smoothing kernel.
Current options are |
normalise |
Logical flag indicating whether the output values should be divided by the corresponding blurred image of the window itself. See Details. |
bleed |
Logical flag indicating whether to allow blur to extend outside the original domain of the image. See Details. |
varcov |
Variance-covariance matrix of anisotropic Gaussian kernel.
Incompatible with |
This command applies a Gaussian blur to the pixel image x
.
Smooth.im
is a method for the generic Smooth
for pixel images. It is currently identical to blur
,
apart from the name of the first argument.
The blurring kernel is the isotropic Gaussian kernel with standard
deviation sigma
, or the anisotropic Gaussian kernel with
variance-covariance matrix varcov
.
The arguments sigma
and varcov
are incompatible.
Also sigma
may be a vector of length 2 giving the
standard deviations of two independent Gaussian coordinates,
thus equivalent to varcov = diag(sigma^2)
.
If the pixel values of x
include some NA
values
(meaning that the image domain does not completely fill
the rectangular frame) then these NA
values are first reset to zero.
The algorithm then computes the convolution
of the (zero-padded) pixel
image
with the specified Gaussian kernel
.
If normalise=FALSE
, then this convolution
is returned.
If
normalise=TRUE
, then the convolution
is normalised by
dividing it by the convolution
of the image
domain
w
with the same Gaussian kernel. Normalisation ensures that the result
can be interpreted as a weighted average of input pixel values,
without edge effects due to the shape of the domain.
If bleed=FALSE
, then pixel values outside the original image
domain are set to NA
. Thus the output is a pixel image with the
same domain as the input. If bleed=TRUE
, then no such
alteration is performed, and the result is a pixel image defined
everywhere in the rectangular frame containing the input image.
Computation is performed using the Fast Fourier Transform.
A pixel image with the same pixel array as the input image x
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
interp.im
for interpolating a pixel image to a finer resolution,
density.ppp
for blurring a point pattern,
Smooth.ppp
for interpolating marks attached to points.
Z <- as.im(function(x,y) { 4 * x^2 + 3 * y }, letterR) opa <- par(mfrow=c(1,3)) plot(Z) plot(letterR, add=TRUE) plot(blur(Z, 0.3, bleed=TRUE)) plot(letterR, add=TRUE) plot(blur(Z, 0.3, bleed=FALSE)) plot(letterR, add=TRUE) par(opa)
Z <- as.im(function(x,y) { 4 * x^2 + 3 * y }, letterR) opa <- par(mfrow=c(1,3)) plot(Z) plot(letterR, add=TRUE) plot(blur(Z, 0.3, bleed=TRUE)) plot(letterR, add=TRUE) plot(blur(Z, 0.3, bleed=FALSE)) plot(letterR, add=TRUE) par(opa)
Blur a Pixel Image by Applying Diffusion
blurHeat(X, ...) ## S3 method for class 'im' blurHeat(X, sigma, ..., connect = 8, symmetric = FALSE, k= 1, show = FALSE) ## S3 method for class 'im' SmoothHeat(X, sigma, ...)
blurHeat(X, ...) ## S3 method for class 'im' blurHeat(X, sigma, ..., connect = 8, symmetric = FALSE, k= 1, show = FALSE) ## S3 method for class 'im' SmoothHeat(X, sigma, ...)
X |
Pixel image (object of class |
sigma |
Smoothing bandwidth. A numeric value, a pixel image or
a |
... |
Ignored by |
connect |
Grid connectivity: either 4 or 8. |
symmetric |
Logical value indicating whether to force the algorithm to use a symmetric random walk. |
k |
Integer. Calculations will be performed by repeatedly multiplying
the current state by the |
show |
Logical value indicating whether to plot successive iterations. |
The function blurHeat
is generic.
This help file documents the method blurHeat.im
for pixel images
(objects of class "im"
). This is currently equivalent
to SmoothHeat.im
, which is also documented here.
If sigma
is a numeric value, then
the classical time-dependent heat equation is solved
up to time t = sigma^2
starting with the initial
condition given by the image X
. This has the effect
of blurring the input image X
.
If sigma
is a function or a pixel image, then
it is treated as a spatially-variable diffusion rate,
and the corresponding heat equation is solved.
This command can be used to calculate the expected value
of the diffusion estimator of intensity (densityHeat
)
when the true intensity is known.
A pixel image on the same raster as X
.
Adrian Baddeley [email protected].
Z <- as.im(function(x,y) { sin(10*x) + sin(9*y) }, letterR) ZZ <- blurHeat(Z, 0.2) plot(solist(original=Z, blurred=ZZ), main="")
Z <- as.im(function(x,y) { sin(10*x) + sin(9*y) }, letterR) ZZ <- blurHeat(Z, 0.2) plot(solist(original=Z, blurred=ZZ), main="")
Calculate the discrete or continuous Boyce index for a spatial point pattern dataset.
boyce(X, Z, ..., breaks = NULL, halfwidth = NULL)
boyce(X, Z, ..., breaks = NULL, halfwidth = NULL)
X |
A spatial point pattern (object of class |
Z |
Habitat suitability classes or habitat suitability index.
Either a tessellation (object of class |
... |
Additional arguments passed to |
breaks |
The breakpoint values defining discrete bands of values
of the covariate |
halfwidth |
The half-width |
Given a spatial point pattern X
and some kind of explanatory
information Z
, this function computes either the
index originally defined by Boyce et al (2002)
or the ‘continuous Boyce index’ defined by Hirzel et al (2006).
Boyce et al (2002) defined an index of habitat suitability in which
the study region is first divided into separate subregions
based on appropriate scientific
considerations. Then we count the number
of data
points of
X
that fall in each subregion ,
measure the area
of each subregion
,
and calculate the index
where is the total area and
is the total number of
points in
X
.
Hirzel et al (2006) defined another version of this index which is
based on a continuous spatial covariate. For each possible value
of the covariate
,
consider the region
where the value of the covariate
lies between
and
, where
is the
chosen ‘halfwidth’. The ‘continuous Boyce index’ is
where is the number of points of
X
falling in , and
is the area of
.
If Z
is a tessellation (object of class "tess"
),
the algorithm calculates the original (‘discrete’) Boyce index
(Boyce et al, 2002)
for each tile of the tessellation. The result is another tessellation,
identical to Z
except that the mark values are the
values of the discrete Boyce index.
If Z
is a pixel image whose values are categorical (i.e. factor
values), then Z
is treated as a tessellation, with one tile
for each level of the factor. The discrete Boyce index is then
calculated. The result is a tessellation with marks that are the
values of the discrete Boyce index.
Otherwise, if Z
is a spatial covariate such as a pixel image,
a function(x,y)
or one of the characters "x"
or
"y"
, then exactly one of the arguments breaks
or
halfwidth
must be given.
if halfwidth
is given, it should be a single positive
number. The continuous Boyce index (Hirzel et al, 2006)
is computed using the specified halfwidth .
The result is an object of class
"fv"
that can be plotted
to show as a function of
.
if breaks
is given, it can be either a numeric vector
of possible values of Z
defining the breakpoints for the
bands of values of Z
, or a single integer specifying the
number of evenly-spaced breakpoints that should be created.
The discrete Boyce index (Boyce et al, 2002) is computed.
The result is an object of class "fv"
that can be plotted
to show the discrete Boyce index as a function of .
When Z
is a spatial covariate (not factor-valued), the calculation is performed
using rhohat.ppp
(since the Boyce index is a special case
of rhohat
). Arguments ...
passed to
rhohat.ppp
control the accuracy of the spatial discretisation
and other parameters of the algorithm.
A tessellation (object of class "tess"
)
or a function value table (object of class "fv"
)
as explained above.
Adrian Baddeley [email protected]
Boyce, M.S., Vernier, P.R., Nielsen, S.E. and Schmiegelow, F.K.A. (2002) Evaluating resource selection functions. Ecological modelling 157, 281–300.
Hirzel, A.H., Le Lay, V., Helfer, V., Randin, C. and Guisan, A. (2006) Evaluating the ability of habitat suitability models to predict species presences. Ecological Modelling 199, 142–152.
online <- interactive() ## a simple tessellation V <- quadrats(Window(bei), 4, 3) if(online) plot(V) ## discrete Boyce index for a simple tessellation A <- boyce(bei, V) if(online) { plot(A, do.col=TRUE) marks(A) tilenames(A) } ## spatial covariate: terrain elevation Z <- bei.extra$elev ## continuous Boyce index for terrain elevation BC <- boyce(bei, Z, halfwidth=10) if(online) plot(BC) ## discrete Boyce index for terrain elevation steps of height 5 metres bk <- c(seq(min(Z), max(Z), by=5), Inf) BD <- boyce(bei, Z, breaks=bk) if(online) plot(BD)
online <- interactive() ## a simple tessellation V <- quadrats(Window(bei), 4, 3) if(online) plot(V) ## discrete Boyce index for a simple tessellation A <- boyce(bei, V) if(online) { plot(A, do.col=TRUE) marks(A) tilenames(A) } ## spatial covariate: terrain elevation Z <- bei.extra$elev ## continuous Boyce index for terrain elevation BC <- boyce(bei, Z, halfwidth=10) if(online) plot(BC) ## discrete Boyce index for terrain elevation steps of height 5 metres bk <- c(seq(min(Z), max(Z), by=5), Inf) BD <- boyce(bei, Z, breaks=bk) if(online) plot(BD)
Computes adaptive smoothing bandwidths for a spatial point pattern, according to the inverse-square-root rule of Abramson (1982).
## S3 method for class 'ppp' bw.abram(X, h0, ..., at=c("points", "pixels"), hp = h0, pilot = NULL, trim=5, smoother=density.ppp)
## S3 method for class 'ppp' bw.abram(X, h0, ..., at=c("points", "pixels"), hp = h0, pilot = NULL, trim=5, smoother=density.ppp)
X |
A point pattern (object of class |
h0 |
A scalar value giving the global smoothing bandwidth
in the same units as the coordinates of |
... |
Additional arguments passed to
|
at |
Character string (partially matched) specifying whether
to compute bandwidth values at the points of |
hp |
Optional. A scalar pilot bandwidth, used for estimation
of the pilot density if required. Ignored if |
pilot |
Optional. Specification of a pilot density
(possibly unnormalised).
If |
trim |
A trimming value required to curb excessively large bandwidths. See Details. The default is sensible in most cases. |
smoother |
Smoother for the pilot.
A function or character string, specifying the function
to be used to compute the pilot estimate when
|
This function computes adaptive smoothing bandwidths using the methods of Abramson (1982) and Hall and Marron (1988).
The function bw.abram
is generic. The function
bw.abram.ppp
documented here is the method
for spatial point patterns (objects of class "ppp"
).
If at="points"
(the default) a smoothing bandwidth is
computed for each point in the pattern X
. Alternatively if
at="pixels"
a smoothing bandwidth is computed for
each spatial location in a pixel grid.
Under the Abramson-Hall-Marron rule, the bandwidth at location is
where is a pilot estimate of the spatially varying
probability density. The variable bandwidths are rescaled by
, the
geometric mean of the
terms evaluated at the
data; this allows the global bandwidth
h0
to be considered on
the same scale as a corresponding fixed bandwidth. The trimming value
trim
has the same interpretation as the required ‘clipping’ of
the pilot density at some small nominal value (see Hall and Marron,
1988), to necessarily prevent extreme bandwidths (which
can occur at very isolated observations).
The pilot density or intensity is determined as follows:
If pilot
is a pixel image, this is taken as the
pilot density or intensity.
If pilot
is NULL
, then the pilot intensity is
computed as a fixed-bandwidth kernel
intensity estimate using density.ppp
applied to
the data pattern X
using
the pilot bandwidth hp
.
If pilot
is a different point pattern on the same spatial
domain as X
, then the pilot intensity is
computed as a fixed-bandwidth kernel
intensity estimate using density.ppp
applied to
pilot
using the pilot bandwidth hp
.
In each case the pilot density or intensity is renormalised to become a probability density, and then the Abramson rule is applied.
Instead of calculating the pilot as a fixed-bandwidth density
estimate, the user can specify another density estimation procedure
using the argument smoother
. This should be either a function
or the character string name of a function. It will replace
density.ppp
as the function used to calculate the
pilot estimate. The pilot estimate will be computed as
smoother(X, sigma=hp, ...)
if pilot
is NULL
,
or smoother(pilot, sigma=hp, ...)
if pilot
is a point
pattern. If smoother
does not recognise the argument name
sigma
for the smoothing bandwidth, then hp
is effectively
ignored, as shown in the Examples.
Either a numeric vector of length npoints(X)
giving the Abramson bandwidth for each point
(when at = "points"
, the default),
or the entire pixel im
age
of the Abramson bandwidths over the relevant spatial domain
(when at = "pixels"
).
Tilman Davies [email protected]. Adapted by Adrian Baddeley [email protected].
Abramson, I. (1982) On bandwidth variation in kernel estimates — a square root law. Annals of Statistics, 10(4), 1217-1223.
Davies, T.M. and Baddeley, A. (2018) Fast computation of spatially adaptive kernel estimates. Statistics and Computing, 28(4), 937-956.
Davies, T.M., Marshall, J.C., and Hazelton, M.L. (2018) Tutorial on kernel estimation of continuous spatial and spatiotemporal relative risk. Statistics in Medicine, 37(7), 1191-1221.
Hall, P. and Marron, J.S. (1988) Variable window width kernel density estimates of probability densities. Probability Theory and Related Fields, 80, 37-49.
Silverman, B.W. (1986) Density Estimation for Statistics and Data Analysis. Chapman and Hall, New York.
# 'ch' just 58 laryngeal cancer cases ch <- split(chorley)[[1]] h <- bw.abram(ch,h0=1,hp=0.7) length(h) summary(h) if(interactive()) hist(h) # calculate pilot based on all 1036 observations h.pool <- bw.abram(ch,h0=1,hp=0.7,pilot=chorley) length(h.pool) summary(h.pool) if(interactive()) hist(h.pool) # get full image used for 'h' above him <- bw.abram(ch,h0=1,hp=0.7,at="pixels") plot(him);points(ch,col="grey") # use Voronoi-Dirichlet pilot ('hp' is ignored) hvo <- bw.abram(ch, h0=1, smoother=densityVoronoi)
# 'ch' just 58 laryngeal cancer cases ch <- split(chorley)[[1]] h <- bw.abram(ch,h0=1,hp=0.7) length(h) summary(h) if(interactive()) hist(h) # calculate pilot based on all 1036 observations h.pool <- bw.abram(ch,h0=1,hp=0.7,pilot=chorley) length(h.pool) summary(h.pool) if(interactive()) hist(h.pool) # get full image used for 'h' above him <- bw.abram(ch,h0=1,hp=0.7,at="pixels") plot(him);points(ch,col="grey") # use Voronoi-Dirichlet pilot ('hp' is ignored) hvo <- bw.abram(ch, h0=1, smoother=densityVoronoi)
Uses Cronie and van Lieshout's criterion based on Cambell's formula to select a smoothing bandwidth for the kernel estimation of point process intensity.
bw.CvL(X, ..., srange = NULL, ns = 16, sigma = NULL, warn=TRUE)
bw.CvL(X, ..., srange = NULL, ns = 16, sigma = NULL, warn=TRUE)
X |
A point pattern (object of class |
... |
Ignored. |
srange |
Optional numeric vector of length 2 giving the range of values of bandwidth to be searched. |
ns |
Optional integer giving the number of values of bandwidth to search. |
sigma |
Optional. Vector of values of the bandwidth to be searched.
Overrides the values of |
warn |
Logical. If |
This function selects an appropriate bandwidth sigma
for the kernel estimator of point process intensity
computed by density.ppp
.
The bandwidth is chosen to
minimise the discrepancy between the area of the observation window and the
sum of reciprocal estimated intensity values at the points of the point process
where the sum is taken over all the data points ,
and where
is the
kernel-smoothing estimate of the intensity at
with smoothing bandwidth
.
The value of is computed
directly, using
density.ppp
,
for ns
different values of
between
srange[1]
and srange[2]
.
A single numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
(see bw.optim.object
)
which can be plotted to show the bandwidth selection criterion
as a function of sigma
.
Ottmar Cronie [email protected] and Marie-Colette van Lieshout [email protected]. Adapted for spatstat by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Cronie, O and Van Lieshout, M N M (2018) A non-model-based approach to bandwidth selection for kernel estimators of spatial intensity functions, Biometrika, 105, 455-462.
Alternative methods:
bw.diggle
,
bw.scott
,
bw.ppl
,
bw.frac
.
For adaptive smoothing bandwidths, use bw.CvL.adaptive
.
if(interactive()) { b <- bw.CvL(redwood) b plot(b, main="Cronie and van Lieshout bandwidth criterion for redwoods") plot(density(redwood, b)) plot(density(redwood, bw.CvL)) }
if(interactive()) { b <- bw.CvL(redwood) b plot(b, main="Cronie and van Lieshout bandwidth criterion for redwoods") plot(density(redwood, b)) plot(density(redwood, bw.CvL)) }
Uses the Cronie-Van Lieshout criterion to select the global smoothing bandwidth for adaptive kernel estimation of point process intensity.
bw.CvL.adaptive(X, ..., hrange = NULL, nh = 16, h=NULL, bwPilot = bw.scott.iso(X), edge = FALSE, diggle = TRUE)
bw.CvL.adaptive(X, ..., hrange = NULL, nh = 16, h=NULL, bwPilot = bw.scott.iso(X), edge = FALSE, diggle = TRUE)
X |
A point pattern (object of class |
... |
Additional arguments passed to
|
hrange |
Optional numeric vector of length 2 giving the
range of values of global bandwidth |
nh |
Optional integer giving the number of values of
bandwidth |
h |
Optional. Vector of values of the bandwidth to be searched.
Overrides the values of |
bwPilot |
Pilot bandwidth. A scalar value in the same units as the
coordinates of |
edge |
Logical value indicating whether to apply edge correction. |
diggle |
Logical. If |
This function selects an appropriate value of global bandwidth
h0
for adaptive kernel estimation of the intensity function
for the point pattern X
.
In adaptive estimation, each point in the point pattern is
subjected to a different amount of smoothing, controlled by
data-dependent or spatially-varying bandwidths.
The global bandwidth h0
is a scale factor
which is used to adjust all of the data-dependent bandwidths
according to the Abramson (1982) square-root rule.
This function considers each candidate value of bandwidth ,
performs the smoothing steps described above, extracts the
adaptively-estimated intensity values
at each data point
,
and calculates the Cronie-Van Lieshout criterion
The value of which minimises the squared difference
(where |W|
is the area of the window of X
)
is selected as the optimal global bandwidth.
Bandwidths h
are physical distance values
expressed in the same units as the coordinates of X
.
A single numerical value giving the selected global bandwidth.
The result also belongs to the class "bw.optim"
(see bw.optim.object
)
which can be plotted to show the bandwidth selection criterion
as a function of sigma
.
Marie-Colette Van Lieshout. Modified by Adrian Baddeley [email protected].
Abramson, I. (1982)
On bandwidth variation in kernel estimates — a square root law.
Annals of Statistics, 10(4), 1217-1223.
Cronie, O and Van Lieshout, M N M (2018) A non-model-based approach to bandwidth selection for kernel estimators of spatial intensity functions, Biometrika, 105, 455-462.
Van Lieshout, M.N.M. (2021) Infill asymptotics for adaptive kernel estimators of spatial intensity. Australian and New Zealand Journal of Statistics 63 (1) 159–181.
adaptive.density
,
densityAdaptiveKernel.ppp
,
bw.abram.ppp
,
density.ppp
.
To select a fixed smoothing bandwidth
using the Cronie-Van Lieshout criterion, use bw.CvL
.
online <- interactive() if(online) { h0 <- bw.CvL.adaptive(redwood3) } else { ## faster computation for package checker h0 <- bw.CvL.adaptive(redwood3, nh=8, hrange=c(1/4, 4) * bw.diggle(redwood3)) } plot(h0) plot(as.fv(h0), CvL ~ h) if(online) { Z <- densityAdaptiveKernel(redwood3, h0) plot(Z) }
online <- interactive() if(online) { h0 <- bw.CvL.adaptive(redwood3) } else { ## faster computation for package checker h0 <- bw.CvL.adaptive(redwood3, nh=8, hrange=c(1/4, 4) * bw.diggle(redwood3)) } plot(h0) plot(as.fv(h0), CvL ~ h) if(online) { Z <- densityAdaptiveKernel(redwood3, h0) plot(Z) }
Selects an optimal bandwidth for diffusion smoothing using the Cronie-van Lieshout rule.
bw.CvLHeat(X, ..., srange=NULL, ns=16, sigma=NULL, leaveoneout=TRUE, verbose = TRUE)
bw.CvLHeat(X, ..., srange=NULL, ns=16, sigma=NULL, leaveoneout=TRUE, verbose = TRUE)
X |
Point pattern (object of class |
... |
Arguments passed to |
srange |
Numeric vector of length 2 specifying a range of bandwidths to be considered. |
ns |
Integer. Number of candidate bandwidths to be considered. |
sigma |
Maximum smoothing bandwidth.
A numeric value, or a pixel image, or a |
leaveoneout |
Logical value specifying whether intensity values at data points should be estimated using the leave-one-out rule. |
verbose |
Logical value specifying whether to print progress reports. |
This algorithm selects the optimal global bandwidth for
kernel estimation of intensity for the dataset X
using diffusion smoothing densityHeat.ppp
.
If sigma
is a numeric value, the algorithm finds the
optimal bandwidth tau <= sigma
.
If sigma
is a pixel image or function, the algorithm
finds the optimal fraction 0 < f <= 1
such that
smoothing with f * sigma
would be optimal.
A numerical value giving the selected bandwidth
(if sigma
was a numeric value)
or the selected fraction of the maximum bandwidth
(if sigma
was a pixel image or function).
The result also belongs to the class "bw.optim"
which can be
plotted.
Adrian Baddeley.
bw.pplHeat
for an alternative method.
online <- interactive() if(!online) op <- spatstat.options(npixel=32) f <- function(x,y) { dnorm(x, 2.3, 0.1) * dnorm(y, 2.0, 0.2) } X <- rpoint(15, f, win=letterR) plot(X) b <- bw.CvLHeat(X, sigma=0.25) b plot(b) if(!online) spatstat.options(op)
online <- interactive() if(!online) op <- spatstat.options(npixel=32) f <- function(x,y) { dnorm(x, 2.3, 0.1) * dnorm(y, 2.0, 0.2) } X <- rpoint(15, f, win=letterR) plot(X) b <- bw.CvLHeat(X, sigma=0.25) b plot(b) if(!online) spatstat.options(op)
Uses cross-validation to select a smoothing bandwidth for the kernel estimation of point process intensity.
bw.diggle(X, ..., correction="good", hmax=NULL, nr=512, warn=TRUE)
bw.diggle(X, ..., correction="good", hmax=NULL, nr=512, warn=TRUE)
X |
A point pattern (object of class |
... |
Ignored. |
correction |
Character string passed to |
hmax |
Numeric. Maximum value of bandwidth that should be considered. |
nr |
Integer. Number of steps in the distance value |
warn |
Logical. If |
This function selects an appropriate bandwidth sigma
for the kernel estimator of point process intensity
computed by density.ppp
.
The bandwidth is chosen to
minimise the mean-square error criterion defined by Diggle (1985).
The algorithm uses the method of Berman and Diggle (1989) to
compute the quantity
as a function of bandwidth ,
where
is the
mean squared error at bandwidth
,
while
is the mean intensity,
and
is the pair correlation function.
See Diggle (2003, pages 115-118) for a summary of this method.
The result is a numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
which can be plotted to show the (rescaled) mean-square error
as a function of sigma
.
A single numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
(see bw.optim.object
)
which can be plotted to show the bandwidth selection criterion
as a function of sigma
.
The smoothing parameter sigma
returned by bw.diggle
(and displayed on the horizontal axis of the plot)
corresponds to h/2
, where h
is the smoothing
parameter described in Diggle (2003, pages 116-118) and
Berman and Diggle (1989).
In those references, the smoothing kernel
is the uniform density on the disc of radius h
. In
density.ppp
, the smoothing kernel is the
isotropic Gaussian density with standard deviation sigma
.
When replacing one kernel by another, the usual
practice is to adjust the bandwidths so that the kernels have equal
variance (cf. Diggle 2003, page 118). This implies that sigma = h/2
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Berman, M. and Diggle, P. (1989) Estimating weighted integrals of the second-order intensity of a spatial point process. Journal of the Royal Statistical Society, series B 51, 81–92.
Diggle, P.J. (1985) A kernel method for smoothing point process data. Applied Statistics (Journal of the Royal Statistical Society, Series C) 34 (1985) 138–147.
Diggle, P.J. (2003) Statistical analysis of spatial point patterns, Second edition. Arnold.
Alternative methods:
bw.ppl
,
bw.scott
,
bw.CvL
,
bw.frac
.
attach(split(lansing)) b <- bw.diggle(hickory) plot(b, ylim=c(-2, 0), main="Cross validation for hickories") if(interactive()) { plot(density(hickory, b)) }
attach(split(lansing)) b <- bw.diggle(hickory) plot(b, ylim=c(-2, 0), main="Cross validation for hickories") if(interactive()) { plot(density(hickory, b)) }
Select a smoothing bandwidth for smoothing a point pattern, based only on the geometry of the spatial window. The bandwidth is a specified quantile of the distance between two independent random points in the window.
bw.frac(X, ..., f=1/4)
bw.frac(X, ..., f=1/4)
X |
A window (object of class |
... |
Arguments passed to |
f |
Probability value (between 0 and 1) determining the quantile of the distribution. |
This function selects an appropriate bandwidth sigma
for the kernel estimator of point process intensity
computed by density.ppp
.
The bandwidth is computed as a
quantile of the distance between two independent random points
in the window. The default is the lower quartile of this
distribution.
If is the cumulative distribution function of the
distance between two independent random points uniformly distributed
in the window, then the value returned is the quantile
with probability
. That is, the bandwidth is
the value
such that
.
The cumulative distribution function is
computed using
distcdf
. We then
we compute the smallest number
such that
.
A numerical value giving the selected bandwidth.
The result also belongs to the class "bw.frac"
which can be plotted to show the cumulative distribution function
and the selected quantile.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
For estimating point process intensity, see
density.ppp
,
bw.diggle
,
bw.ppl
,
bw.scott
,
bw.CvL
.
For other smoothing purposes, see
bw.stoyan
,
bw.smoothppp
,
bw.relrisk
.
h <- bw.frac(letterR) h plot(h, main="bw.frac(letterR)")
h <- bw.frac(letterR) h plot(h, main="bw.frac(letterR)")
An object of the class "bw.optim"
represents
a tuning parameter (usually a smoothing bandwidth)
that has been selected automatically.
The object can be used as if it were a numerical value,
but it can also be plotted to show the optimality criterion.
An object of the class "bw.optim"
represents the numerical
value of a smoothing bandwidth, a threshold, or a similar
tuning parameter, that has been selected by optimising
a criterion such as cross-validation.
The object is a numerical value, with some attributes that retain information about how the value was selected.
Attributes include the vector of candidate values that were examined, the corresponding values of the optimality criterion, the name of the parameter, the name of the optimality criterion, and the units in which the parameter is measured.
There are methods for print
, plot
,
summary
, as.data.frame
and as.fv
for the class "bw.optim"
.
The print
method simply prints the numerical value of the
parameter.
The summary
method prints this value, and states how
this value was selected.
The plot
method produces a plot of the optimisation criterion
against the candidate value of the parameter. The as.data.frame
and as.fv
methods extract this graphical information as a data
frame or function table, respectively.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Functions which produce objects of class bw.optim
include
bw.CvL
,
bw.CvL.adaptive
,
bw.diggle
,
bw.lppl
,
bw.pcf
,
bw.ppl
,
bw.relrisk
,
bw.relrisk.lpp
,
bw.smoothppp
and
bw.voronoi
Ns <- if(interactive()) 32 else 3 b <- bw.ppl(redwood, srange=c(0.02, 0.07), ns=Ns) b summary(b) plot(b)
Ns <- if(interactive()) 32 else 3 b <- bw.ppl(redwood, srange=c(0.02, 0.07), ns=Ns) b summary(b) plot(b)
Uses composite likelihood or generalized least squares cross-validation to select a smoothing bandwidth for the kernel estimation of pair correlation function.
bw.pcf(X, rmax=NULL, lambda=NULL, divisor="r", kernel="epanechnikov", nr=10000, bias.correct=TRUE, cv.method=c("compLik", "leastSQ"), simple=TRUE, srange=NULL, ..., verbose=FALSE, warn=TRUE)
bw.pcf(X, rmax=NULL, lambda=NULL, divisor="r", kernel="epanechnikov", nr=10000, bias.correct=TRUE, cv.method=c("compLik", "leastSQ"), simple=TRUE, srange=NULL, ..., verbose=FALSE, warn=TRUE)
X |
A point pattern (object of class |
rmax |
Numeric. Maximum value of the spatial lag distance |
lambda |
Optional.
Values of the estimated intensity function.
A vector giving the intensity values
at the points of the pattern |
divisor |
Choice of divisor in the estimation formula:
either |
kernel |
Choice of smoothing kernel, passed to |
nr |
Integer. Number of subintervals for discretization of [0, rmax] to use in computing numerical integrals. |
bias.correct |
Logical. Whether to use bias corrected version of the kernel estimate. See Details. |
cv.method |
Choice of cross validation method: either
|
simple |
Logical. Whether to use simple removal of spatial lag distances. See Details. |
srange |
Optional. Numeric vector of length 2 giving the range of bandwidth values that should be searched to find the optimum bandwidth. |
... |
|
verbose |
Logical value indicating whether to print progress reports during the optimization procedure. |
warn |
Logical. If |
This function selects an appropriate bandwidth bw
for the kernel estimator of the pair correlation function
of a point process intensity computed by pcf.ppp
(homogeneous case) or pcfinhom
(inhomogeneous case).
With cv.method="leastSQ"
, the bandwidth
is chosen to minimise an unbiased
estimate of the integrated mean-square error criterion
defined in equation (4) in Guan (2007a).
The code implements the fast algorithm of Jalilian and Waagepetersen
(2018).
With cv.method="compLik"
, the bandwidth
is chosen to maximise a likelihood
cross-validation criterion
defined in
equation (6) of Guan (2007b).
The result is a numerical value giving the selected bandwidth.
A single numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
(see bw.optim.object
)
which can be plotted to show the bandwidth selection criterion
as a function of sigma
.
The bandwidth bw
returned by bw.pcf
is the standard deviation of the smoothing kernel,
following the standard convention in R.
As mentioned in the documentation for
density.default
and pcf.ppp
,
this differs from other definitions of bandwidth that can be
found in the literature. The scale parameter
h
, which is called the bandwidth in some literature,
is defined differently.
For example for the Epanechnikov kernel, h
is the half-width
of the kernel, and bw=h/sqrt(5)
.
Rasmus Waagepetersen and Abdollah Jalilian. Adapted for spatstat by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Guan, Y. (2007a). A composite likelihood cross-validation approach in selecting bandwidth for the estimation of the pair correlation function. Scandinavian Journal of Statistics, 34(2), 336–346.
Guan, Y. (2007b). A least-squares cross-validation bandwidth selection approach in pair correlation function estimations. Statistics & Probability Letters, 77(18), 1722–1729.
Jalilian, A. and Waagepetersen, R. (2018) Fast bandwidth selection for estimation of the pair correlation function. Journal of Statistical Computation and Simulation, 88(10), 2001–2011. https://www.tandfonline.com/doi/full/10.1080/00949655.2018.1428606
pcf.ppp
,
pcfinhom
,
bw.optim.object
b <- bw.pcf(redwood) plot(pcf(redwood, bw=b))
b <- bw.pcf(redwood) plot(pcf(redwood, bw=b))
Uses likelihood cross-validation to select a smoothing bandwidth for the kernel estimation of point process intensity.
bw.ppl(X, ..., srange=NULL, ns=16, sigma=NULL, varcov1=NULL, weights=NULL, shortcut=TRUE, warn=TRUE)
bw.ppl(X, ..., srange=NULL, ns=16, sigma=NULL, varcov1=NULL, weights=NULL, shortcut=TRUE, warn=TRUE)
X |
A point pattern (object of class |
srange |
Optional numeric vector of length 2 giving the range of values of bandwidth to be searched. |
ns |
Optional integer giving the number of values of bandwidth to search. |
sigma |
Optional. Vector of values of the bandwidth to be searched.
Overrides the values of |
varcov1 |
Optional. Variance-covariance matrix matrix of the kernel with
bandwidth |
weights |
Optional. Numeric vector of weights for the points of |
... |
Additional arguments passed to
|
shortcut |
Logical value indicating whether to speed up the calculation by omitting the integral term in the cross-validation criterion. |
warn |
Logical. If |
This function selects an appropriate bandwidth sigma
for the kernel estimator of point process intensity
computed by density.ppp
.
The bandwidth is chosen to
maximise the point process likelihood cross-validation criterion
where the sum is taken over all the data points ,
where
is the
leave-one-out kernel-smoothing estimate of the intensity at
with smoothing bandwidth
,
and
is the kernel-smoothing estimate
of the intensity at a spatial location
with smoothing
bandwidth
.
See Loader(1999, Section 5.3).
The value of is computed
directly, using
density.ppp
,
for ns
different values of
between
srange[1]
and srange[2]
.
The result is a numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
which can be plotted to show the (rescaled) mean-square error
as a function of sigma
.
If shortcut=TRUE
(the default), the computation is accelerated by
omitting the integral term in the equation above. This is valid
because the integral is approximately constant.
A numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
which can be plotted.
Anisotropic kernel smoothing is available in density.ppp
using
the argument varcov
to specify the variance-covariance
matrix of the anisotropic kernel. In order to choose the matrix
varcov
, the user can call bw.ppl
using the argument varcov1
to specify a ‘template’
matrix. Scalar multiples of varcov1
will be
considered and the optimal scale factor will be determined.
That is, bw.ppl
will try
smoothing the data using varcov = h^2 * varcov1
for different
values of h
.
The result of bw.ppl
will be the optimal value of h
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Loader, C. (1999) Local Regression and Likelihood. Springer, New York.
density.ppp
,
bw.diggle
,
bw.scott
,
bw.CvL
,
bw.frac
.
if(interactive()) { b <- bw.ppl(redwood) plot(b, main="Likelihood cross validation for redwoods") plot(density(redwood, b)) }
if(interactive()) { b <- bw.ppl(redwood) plot(b, main="Likelihood cross validation for redwoods") plot(density(redwood, b)) }
Selects an optimal bandwidth for diffusion smoothing by point process likelihood cross-validation.
bw.pplHeat(X, ..., srange=NULL, ns=16, sigma=NULL, leaveoneout=TRUE, verbose = TRUE)
bw.pplHeat(X, ..., srange=NULL, ns=16, sigma=NULL, leaveoneout=TRUE, verbose = TRUE)
X |
Point pattern (object of class |
... |
Arguments passed to |
srange |
Numeric vector of length 2 specifying a range of bandwidths to be considered. |
ns |
Integer. Number of candidate bandwidths to be considered. |
sigma |
Maximum smoothing bandwidth.
A numeric value, or a pixel image, or a |
leaveoneout |
Logical value specifying whether intensity values at data points should be estimated using the leave-one-out rule. |
verbose |
Logical value specifying whether to print progress reports. |
This algorithm selects the optimal global bandwidth for
kernel estimation of intensity for the dataset X
using diffusion smoothing densityHeat.ppp
.
If sigma
is a numeric value, the algorithm finds the
optimal bandwidth tau <= sigma
.
If sigma
is a pixel image or function, the algorithm
finds the optimal fraction 0 < f <= 1
such that
smoothing with f * sigma
would be optimal.
A numerical value giving the selected bandwidth
(if sigma
was a numeric value)
or the selected fraction of the maximum bandwidth
(if sigma
was a pixel image or function).
The result also belongs to the class "bw.optim"
which can be
plotted.
Adrian Baddeley and Tilman Davies.
bw.CvLHeat
for an alternative method.
online <- interactive() if(!online) op <- spatstat.options(npixel=32) f <- function(x,y) { dnorm(x, 2.3, 0.1) * dnorm(y, 2.0, 0.2) } X <- rpoint(15, f, win=letterR) plot(X) b <- bw.pplHeat(X, sigma=0.25) b plot(b) if(!online) spatstat.options(op)
online <- interactive() if(!online) op <- spatstat.options(npixel=32) f <- function(x,y) { dnorm(x, 2.3, 0.1) * dnorm(y, 2.0, 0.2) } X <- rpoint(15, f, win=letterR) plot(X) b <- bw.pplHeat(X, sigma=0.25) b plot(b) if(!online) spatstat.options(op)
Uses cross-validation to select a smoothing bandwidth for the estimation of relative risk.
bw.relrisk(X, ...) ## S3 method for class 'ppp' bw.relrisk(X, method = "likelihood", ..., nh = spatstat.options("n.bandwidth"), hmin=NULL, hmax=NULL, warn=TRUE)
bw.relrisk(X, ...) ## S3 method for class 'ppp' bw.relrisk(X, method = "likelihood", ..., nh = spatstat.options("n.bandwidth"), hmin=NULL, hmax=NULL, warn=TRUE)
X |
A multitype point pattern (object of class |
method |
Character string determining the cross-validation method.
Current options are |
nh |
Number of trial values of smoothing bandwith |
hmin , hmax
|
Optional. Numeric values.
Range of trial values of smoothing bandwith |
warn |
Logical. If |
... |
Additional arguments passed to |
This function selects an appropriate bandwidth for the nonparametric
estimation of relative risk using relrisk
.
Consider the indicators which equal
when
data point
belongs to type
, and equal
otherwise.
For a particular value of smoothing bandwidth,
let
be the estimated
probabilities that a point at location
will belong to
type
.
Then the bandwidth is chosen to minimise either the negative likelihood,
the squared error, or the approximately standardised squared error, of the
indicators
relative to the fitted
values
. See Diggle (2003)
or Baddeley et al (2015).
The result is a numerical value giving the selected bandwidth sigma
.
The result also belongs to the class "bw.optim"
allowing it to be printed and plotted. The plot shows the cross-validation
criterion as a function of bandwidth.
The range of values for the smoothing bandwidth sigma
is set by the arguments hmin, hmax
. There is a sensible default,
based on multiples of Stoyan's rule of thumb bw.stoyan
.
If the optimal bandwidth is achieved at an endpoint of the
interval [hmin, hmax]
, the algorithm will issue a warning
(unless warn=FALSE
). If this occurs, then it is probably advisable
to expand the interval by changing the arguments hmin, hmax
.
Computation time depends on the number nh
of trial values
considered, and also on the range [hmin, hmax]
of values
considered, because larger values of sigma
require
calculations involving more pairs of data points.
A single numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
(see bw.optim.object
)
which can be plotted to show the bandwidth selection criterion
as a function of sigma
.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Diggle, P.J. (2003) Statistical analysis of spatial point patterns, Second edition. Arnold.
Kelsall, J.E. and Diggle, P.J. (1995) Kernel estimation of relative risk. Bernoulli 1, 3–16.
b <- bw.relrisk(urkiola) b plot(b) b <- bw.relrisk(urkiola, hmax=20) plot(b)
b <- bw.relrisk(urkiola) b plot(b) b <- bw.relrisk(urkiola, hmax=20) plot(b)
Performs data-based bandwidth selection for
the diffusion estimate of relative risk relriskHeat.ppp
using either likelihood cross-validation or least squares
bw.relriskHeatppp(X, ..., method = c("likelihood", "leastsquares"), weights = NULL, srange = NULL, ns = 16, sigma = NULL, leaveoneout = TRUE, verbose = TRUE)
bw.relriskHeatppp(X, ..., method = c("likelihood", "leastsquares"), weights = NULL, srange = NULL, ns = 16, sigma = NULL, leaveoneout = TRUE, verbose = TRUE)
X |
A multitype point pattern (object of class |
... |
Arguments passed to |
method |
Character string specifying the cross-validation method.
Partially matched to |
weights |
Optional numeric vector of weights associated with each point of |
srange |
Numeric vector of length 2 specifying a range of bandwidths to be considered. |
ns |
Integer. Number of candidate bandwidths to be considered. |
sigma |
Maximum smoothing bandwidth.
A numeric value, or a pixel image, or a |
leaveoneout |
Logical value specifying whether intensity values at data points should be estimated using the leave-one-out rule. |
verbose |
Logical value specifying whether to print progress reports. |
This algorithm selects the optimal global bandwidth for
kernel estimation of relative risk for the dataset X
using diffusion smoothing relriskHeat
.
If sigma
is a numeric value, the algorithm finds the
optimal bandwidth tau <= sigma
.
If sigma
is a pixel image or function, the algorithm
finds the optimal fraction 0 < f <= 1
such that
smoothing with f * sigma
would be optimal.
A numerical value giving the selected bandwidth
(if sigma
was a numeric value)
or the selected fraction of the maximum bandwidth
(if sigma
was a pixel image or function).
The result also belongs to the class "bw.optim"
which can be
plotted.
Adrian Baddeley [email protected], Tilman Davies [email protected] and Suman Rakshit.
## bovine tuberculosis data X <- subset(btb, select=spoligotype) if(interactive()) { smax <- 40 ns <- 16 dimyx <- NULL } else { ## reduce data and resolution to speed up X <- X[c(TRUE, rep(FALSE, 7))] smax <- 9 ns <- 8 dimyx <- 32 } b <- bw.relriskHeatppp(X, sigma=smax, ns=ns, dimyx=dimyx) b plot(b)
## bovine tuberculosis data X <- subset(btb, select=spoligotype) if(interactive()) { smax <- 40 ns <- 16 dimyx <- NULL } else { ## reduce data and resolution to speed up X <- X[c(TRUE, rep(FALSE, 7))] smax <- 9 ns <- 8 dimyx <- 32 } b <- bw.relriskHeatppp(X, sigma=smax, ns=ns, dimyx=dimyx) b plot(b)
Use Scott's rule of thumb to determine the smoothing bandwidth for the kernel estimation of point process intensity.
bw.scott(X, isotropic=FALSE, d=NULL) bw.scott.iso(X)
bw.scott(X, isotropic=FALSE, d=NULL) bw.scott.iso(X)
X |
A point pattern (object of class |
isotropic |
Logical value indicating whether to compute a single
bandwidth for an isotropic Gaussian kernel ( |
d |
Advanced use only. An integer value that should be used in Scott's formula instead of the true number of spatial dimensions. |
These functions select a bandwidth sigma
for the kernel estimator of point process intensity
computed by density.ppp
or other appropriate functions.
They can be applied to a point pattern
belonging to any class "ppp"
, "lpp"
, "pp3"
or "ppx"
.
The bandwidth is computed by the rule of thumb
of Scott (1992, page 152, equation 6.42).
The bandwidth is proportional to
where
is the number of points and
is the number of
spatial dimensions.
This rule is very fast to compute. It typically produces a larger bandwidth
than bw.diggle
. It is useful for estimating
gradual trend.
If isotropic=FALSE
(the default), bw.scott
provides a
separate bandwidth for each coordinate axis, and the result of the
function is a vector, of length equal to the number of coordinates.
If isotropic=TRUE
, a single bandwidth value is computed
and the result is a single numeric value.
bw.scott.iso(X)
is equivalent to
bw.scott(X, isotropic=TRUE)
.
The default value of is as follows:
class | dimension |
"ppp" |
2 |
"lpp" |
1 |
"pp3" |
3 |
"ppx" |
number of spatial coordinates |
The use of d=1
for point patterns on a linear network
(class "lpp"
) was proposed by McSwiggan et al (2016)
and Rakshit et al (2019).
A numerical value giving the selected bandwidth, or a numerical vector giving the selected bandwidths for each coordinate.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Scott, D.W. (1992) Multivariate Density Estimation. Theory, Practice and Visualization. New York: Wiley.
density.ppp
,
bw.diggle
,
bw.ppl
,
bw.CvL
,
bw.frac
.
hickory <- split(lansing)[["hickory"]] b <- bw.scott(hickory) b if(interactive()) { plot(density(hickory, b)) } bw.scott.iso(hickory) bw.scott(osteo$pts[[1]])
hickory <- split(lansing)[["hickory"]] b <- bw.scott(hickory) b if(interactive()) { plot(density(hickory, b)) } bw.scott.iso(hickory) bw.scott(osteo$pts[[1]])
Uses least-squares cross-validation to select a smoothing bandwidth for spatial smoothing of marks.
bw.smoothppp(X, nh = spatstat.options("n.bandwidth"), hmin=NULL, hmax=NULL, warn=TRUE, kernel="gaussian", varcov1=NULL)
bw.smoothppp(X, nh = spatstat.options("n.bandwidth"), hmin=NULL, hmax=NULL, warn=TRUE, kernel="gaussian", varcov1=NULL)
X |
A marked point pattern with numeric marks. |
nh |
Number of trial values of smoothing bandwith |
hmin , hmax
|
Optional. Numeric values.
Range of trial values of smoothing bandwith |
warn |
Logical. If |
kernel |
The smoothing kernel.
A character string specifying the smoothing kernel
(current options are |
varcov1 |
Optional. Variance-covariance matrix matrix of the kernel with
bandwidth |
This function selects an appropriate bandwidth for the nonparametric
smoothing of mark values using Smooth.ppp
.
The argument X
must be a marked point pattern
with a vector or data frame of marks. All mark values must be numeric.
The bandwidth is selected by least-squares cross-validation.
Let be the mark value at the
th data point.
For a particular choice of smoothing bandwidth,
let
be the smoothed value at the
th data point.
Then the bandwidth is chosen to minimise
the squared error of the smoothed values
.
The result of bw.smoothppp
is a numerical value giving the selected bandwidth sigma
.
The result also belongs to the class "bw.optim"
allowing it to be printed and plotted. The plot shows the cross-validation
criterion as a function of bandwidth.
The range of values for the smoothing bandwidth sigma
is set by the arguments hmin, hmax
. There is a sensible default,
based on the nearest neighbour distances.
If the optimal bandwidth is achieved at an endpoint of the
interval [hmin, hmax]
, the algorithm will issue a warning
(unless warn=FALSE
). If this occurs, then it is probably advisable
to expand the interval by changing the arguments hmin, hmax
.
Computation time depends on the number nh
of trial values
considered, and also on the range [hmin, hmax]
of values
considered, because larger values of sigma
require
calculations involving more pairs of data points.
A single numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
(see bw.optim.object
)
which can be plotted to show the bandwidth selection criterion
as a function of sigma
.
Anisotropic smoothing is available in Smooth.ppp
using
the argument varcov
to specify the variance-covariance
matrix of the anisotropic kernel. In order to choose the matrix
varcov
, the user can call bw.smoothppp
using the argument varcov1
to specify a ‘template’
matrix. Scalar multiples of varcov1
will be
considered and the optimal scale factor will be determined.
That is, bw.smoothppp
will try
smoothing the data using varcov = h^2 * varcov1
for different
values of h
ranging from hmin
to hmax
.
The result of bw.smoothppp
will be the optimal value
of the standard deviation scale factor h
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
b <- bw.smoothppp(longleaf) b plot(b)
b <- bw.smoothppp(longleaf) b plot(b)
Computes a rough estimate of the appropriate bandwidth for kernel smoothing estimators of the pair correlation function and other quantities.
bw.stoyan(X, co=0.15)
bw.stoyan(X, co=0.15)
X |
A point pattern (object of class |
co |
Coefficient appearing in the rule of thumb. See Details. |
Estimation of the pair correlation function and other quantities by smoothing methods requires a choice of the smoothing bandwidth. Stoyan and Stoyan (1995, equation (15.16), page 285) proposed a rule of thumb for choosing the smoothing bandwidth.
For the Epanechnikov kernel, the rule of thumb is to set
the kernel's half-width to
where
is the estimated intensity of the point pattern,
typically computed as the number of points of
X
divided by the
area of the window containing X
.
For a general kernel, the corresponding rule is to set the
standard deviation of the kernel to
.
The coefficient can be tweaked using the
argument
co
.
To ensure the bandwidth is finite, an empty point pattern is treated as if it contained 1 point.
A finite positive numerical value giving the selected bandwidth (the standard deviation of the smoothing kernel).
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Stoyan, D. and Stoyan, H. (1995) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
bw.stoyan(shapley)
bw.stoyan(shapley)
Performs a test of goodness-of-fit of a point process model. The observed and predicted distributions of the values of a spatial covariate are compared using either the Kolmogorov-Smirnov test, Cramer-von Mises test or Anderson-Darling test. For non-Poisson models, a Monte Carlo test is used.
cdf.test(...) ## S3 method for class 'ppp' cdf.test(X, covariate, test=c("ks", "cvm", "ad"), ..., interpolate=TRUE, jitter=TRUE)
cdf.test(...) ## S3 method for class 'ppp' cdf.test(X, covariate, test=c("ks", "cvm", "ad"), ..., interpolate=TRUE, jitter=TRUE)
X |
A point pattern (object of class |
covariate |
The spatial covariate on which the test will be based.
A function, a pixel image (object of class |
test |
Character string identifying the test to be performed:
|
... |
Arguments passed to |
interpolate |
Logical flag indicating whether to interpolate pixel images.
If |
jitter |
Logical flag. If |
These functions perform a goodness-of-fit test of a Poisson or Gibbs point process model fitted to point pattern data. The observed distribution of the values of a spatial covariate at the data points, and the predicted distribution of the same values under the model, are compared using the Kolmogorov-Smirnov test, the Cramer-von Mises test or the Anderson-Darling test. For Gibbs models, a Monte Carlo test is performed using these test statistics.
The function cdf.test
is generic, with methods for
point patterns ("ppp"
or "lpp"
),
point process models ("ppm"
or "lppm"
)
and spatial logistic regression models ("slrm"
).
If X
is a point pattern dataset (object of class
"ppp"
), then cdf.test(X, ...)
performs a goodness-of-fit test of the
uniform Poisson point process (Complete Spatial Randomness, CSR)
for this dataset.
For a multitype point pattern, the uniform intensity
is assumed to depend on the type of point (sometimes called
Complete Spatial Randomness and Independence, CSRI).
If model
is a fitted point process model
(object of class "ppm"
or "lppm"
)
then cdf.test(model, ...)
performs
a test of goodness-of-fit for this fitted model.
If model
is a fitted spatial logistic regression
(object of class "slrm"
) then cdf.test(model, ...)
performs
a test of goodness-of-fit for this fitted model.
The test is performed by comparing the observed distribution of the values of a spatial covariate at the data points, and the predicted distribution of the same covariate under the model, using a classical goodness-of-fit test. Thus, you must nominate a spatial covariate for this test.
If X
is a point pattern that does not have marks,
the argument covariate
should be either a function(x,y)
or a pixel image (object of class "im"
containing the values
of a spatial function, or one of the characters "x"
or
"y"
indicating the Cartesian coordinates.
If covariate
is an image, it should have numeric values,
and its domain should cover the observation window of the
model
. If covariate
is a function, it should expect
two arguments x
and y
which are vectors of coordinates,
and it should return a numeric vector of the same length
as x
and y
.
If X
is a multitype point pattern, the argument covariate
can be either a function(x,y,marks)
,
or a pixel image, or a list of pixel images corresponding to
each possible mark value, or one of the characters "x"
or
"y"
indicating the Cartesian coordinates.
First the original data point pattern is extracted from model
.
The values of the covariate
at these data points are
collected.
The predicted distribution of the values of the covariate
under the fitted model
is computed as follows.
The values of the covariate
at all locations in the
observation window are evaluated,
weighted according to the point process intensity of the fitted model,
and compiled into a cumulative distribution function using
ewcdf
.
The probability integral transformation is then applied:
the values of the covariate
at the original data points
are transformed by the predicted cumulative distribution function
into numbers between 0 and 1. If the model is correct,
these numbers are i.i.d. uniform random numbers. The
A goodness-of-fit test of the uniform distribution is applied
to these numbers using
stats::ks.test
,
goftest::cvm.test
or
goftest::ad.test
.
This test was apparently first described (in the context of spatial data, and using Kolmogorov-Smirnov) by Berman (1986). See also Baddeley et al (2005).
If model
is not a Poisson process, then
a Monte Carlo test is performed, by generating nsim
point patterns which are simulated realisations of the model
,
re-fitting the model to each simulated point pattern,
and calculating the test statistic for each fitted model.
The Monte Carlo value is determined by comparing
the simulated values of the test statistic
with the value for the original data.
The return value is an object of class "htest"
containing the
results of the hypothesis test. The print method for this class
gives an informative summary of the test outcome.
The return value also belongs to the class "cdftest"
for which there is a plot method plot.cdftest
.
The plot method displays the empirical cumulative distribution
function of the covariate at the data points, and the predicted
cumulative distribution function of the covariate under the model,
plotted against the value of the covariate.
The argument jitter
controls whether covariate values are
randomly perturbed, in order to avoid ties.
If the original data contains any ties in the covariate (i.e. points
with equal values of the covariate), and if jitter=FALSE
, then
the Kolmogorov-Smirnov test implemented in ks.test
will issue a warning that it cannot calculate the exact -value.
To avoid this, if
jitter=TRUE
each value of the covariate will
be perturbed by adding a small random value. The perturbations are
normally distributed with standard deviation equal to one hundredth of
the range of values of the covariate. This prevents ties,
and the -value is still correct. There is
a very slight loss of power.
An object of class "htest"
containing the results of the
test. See ks.test
for details. The return value can be
printed to give an informative summary of the test.
The value also belongs to the class "cdftest"
for which there is
a plot method.
The outcome of the test involves a small amount of random variability,
because (by default) the coordinates are randomly perturbed to
avoid tied values. Hence, if cdf.test
is executed twice, the
-values will not be exactly the same. To avoid this behaviour,
set
jitter=FALSE
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Baddeley, A., Turner, R., Moller, J. and Hazelton, M. (2005) Residual analysis for spatial point processes. Journal of the Royal Statistical Society, Series B 67, 617–666.
Berman, M. (1986) Testing for spatial association between a point process and another stochastic process. Applied Statistics 35, 54–62.
plot.cdftest
,
quadrat.test
,
berman.test
,
ks.test
,
cvm.test
,
ad.test
,
ppm
op <- options(useFancyQuotes=FALSE) # test of CSR using x coordinate cdf.test(nztrees, "x") cdf.test(nztrees, "x", "cvm") cdf.test(nztrees, "x", "ad") # test of CSR using a function of x and y fun <- function(x,y){2* x + y} cdf.test(nztrees, fun) # test of CSR using an image covariate funimage <- as.im(fun, W=Window(nztrees)) cdf.test(nztrees, funimage) # multitype point pattern cdf.test(amacrine, "x") options(op)
op <- options(useFancyQuotes=FALSE) # test of CSR using x coordinate cdf.test(nztrees, "x") cdf.test(nztrees, "x", "cvm") cdf.test(nztrees, "x", "ad") # test of CSR using a function of x and y fun <- function(x,y){2* x + y} cdf.test(nztrees, fun) # test of CSR using an image covariate funimage <- as.im(fun, W=Window(nztrees)) cdf.test(nztrees, funimage) # multitype point pattern cdf.test(amacrine, "x") options(op)
Computes a kernel smoothed estimate of the probability density for angular data.
circdensity(x, sigma = "nrd0", ..., bw = NULL, weights=NULL, unit = c("degree", "radian"))
circdensity(x, sigma = "nrd0", ..., bw = NULL, weights=NULL, unit = c("degree", "radian"))
x |
Numeric vector, containing angular data. |
sigma |
Smoothing bandwidth, or bandwidth selection rule, passed to
|
bw |
Alternative to |
... |
Additional arguments passed to
|
weights |
Optional numeric vector of weights for the data in |
unit |
The unit of angle in which |
The angular values x
are smoothed using
(by default) the wrapped Gaussian kernel with standard deviation sigma
.
An object of class "density"
(produced by
density.default
) which can be plotted
by plot
or by rose
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
ang <- runif(1000, max=360) rose(circdensity(ang, 12))
ang <- runif(1000, max=360) rose(circdensity(ang, 12))
Computes the Clark and Evans aggregation index
for a spatial point pattern.
clarkevans(X, correction=c("none", "Donnelly", "cdf"), clipregion=NULL)
clarkevans(X, correction=c("none", "Donnelly", "cdf"), clipregion=NULL)
X |
A spatial point pattern (object of class |
correction |
Character vector. The type of edge correction(s) to be applied. |
clipregion |
Clipping region for the guard area correction.
A window (object of class |
The Clark and Evans (1954) aggregation index is a crude
measure of clustering or ordering of a point pattern.
It is the ratio of the observed mean nearest neighbour distance
in the pattern to that expected for a Poisson point process
of the same intensity.
A value
suggests ordering, while
suggests
clustering.
Without correction for edge effects, the value of R
will be
positively biased. Edge effects arise because, for a point of X
close to the edge of the window, the true nearest neighbour may
actually lie outside the window. Hence observed nearest neighbour
distances tend to be larger than the true nearest neighbour distances.
The argument correction
specifies an edge correction
or several edge corrections to be applied. It is a character vector
containing one or more of the options
"none"
, "Donnelly"
, "guard"
and "cdf"
(which are recognised by partial matching).
These edge corrections are:
No edge correction is applied.
Edge correction of Donnelly (1978), available for rectangular
windows only.
The theoretical expected value of mean nearest neighbour distance
under a Poisson process is adjusted for edge effects by the
edge correction of Donnelly (1978). The value of is the
ratio of the observed mean nearest neighbour distance to this
adjusted theoretical mean.
Guard region or buffer area method.
The observed mean nearest neighbour distance
for the point pattern X
is re-defined by averaging only over those points of X
that fall inside the sub-window clipregion
.
Cumulative Distribution Function method.
The nearest neighbour distance distribution function
of the stationary point process is estimated by
Gest
using the Kaplan-Meier type edge correction. Then the mean of the
distribution is calculated from the cdf.
Alternatively correction="all"
selects all options.
If the argument clipregion
is given, then the selected
edge corrections will be assumed to include correction="guard"
.
To perform a test based on the Clark-Evans index,
see clarkevans.test
.
A numeric value, or a numeric vector with named components
naive |
|
Donnelly |
|
guard |
|
cdf |
|
(as selected by correction
). The value of the Donnelly
component will be NA
if the window of X
is not a rectangle.
John Rudge [email protected] with modifications by Adrian Baddeley [email protected]
Clark, P.J. and Evans, F.C. (1954) Distance to nearest neighbour as a measure of spatial relationships in populations Ecology 35, 445–453.
Donnelly, K. (1978) Simulations to determine the variance and edge-effect of total nearest neighbour distance. In I. Hodder (ed.) Simulation studies in archaeology, Cambridge/New York: Cambridge University Press, pp 91–95.
clarkevans.test
,
hopskel
,
nndist
,
Gest
# Example of a clustered pattern clarkevans(redwood) # Example of an ordered pattern clarkevans(cells) # Random pattern X <- rpoispp(100) clarkevans(X) # How to specify a clipping region clip1 <- owin(c(0.1,0.9),c(0.1,0.9)) clip2 <- erosion(Window(cells), 0.1) clarkevans(cells, clipregion=clip1) clarkevans(cells, clipregion=clip2)
# Example of a clustered pattern clarkevans(redwood) # Example of an ordered pattern clarkevans(cells) # Random pattern X <- rpoispp(100) clarkevans(X) # How to specify a clipping region clip1 <- owin(c(0.1,0.9),c(0.1,0.9)) clip2 <- erosion(Window(cells), 0.1) clarkevans(cells, clipregion=clip1) clarkevans(cells, clipregion=clip2)
Performs the Clark-Evans test of aggregation for a spatial point pattern.
clarkevans.test(X, ..., correction, clipregion=NULL, alternative=c("two.sided", "less", "greater", "clustered", "regular"), method=c("asymptotic", "MonteCarlo"), nsim=999)
clarkevans.test(X, ..., correction, clipregion=NULL, alternative=c("two.sided", "less", "greater", "clustered", "regular"), method=c("asymptotic", "MonteCarlo"), nsim=999)
X |
A spatial point pattern (object of class |
... |
Ignored. |
correction |
Character string.
The type of edge correction to be applied.
See |
clipregion |
Clipping region for the guard area correction.
A window (object of class |
alternative |
String indicating the type of alternative for the hypothesis test. Partially matched. |
method |
Character string (partially matched) specifying how to calculate
the |
nsim |
Number of Monte Carlo simulations to perform, if a Monte Carlo
|
This command uses the Clark and Evans (1954) aggregation index
as the basis for a crude test of clustering or ordering of a point pattern.
The Clark-Evans aggregation index is computed by the separate
function
clarkevans
.
This command clarkevans.text
performs a hypothesis test of clustering or ordering of
the point pattern X
based on the Clark-Evans index .
The null hypothesis is Complete
Spatial Randomness, i.e.\ a uniform Poisson process. The alternative
hypothesis is specified by the argument
alternative
:
alternative="less"
or alternative="clustered"
:
the alternative hypothesis
is that corresponding to a clustered point pattern;
alternative="greater"
or alternative="regular"
:
the alternative hypothesis
is that corresponding to a regular or ordered point pattern;
alternative="two.sided"
:
the alternative hypothesis is that
corresponding to a clustered or regular pattern.
The Clark-Evans index is first computed for the point pattern
dataset
X
using the edge correction determined by
the arguments correction
and clipregion
. These arguments
are documented in the help file for clarkevans
.
If method="asymptotic"
(the default),
the -value for the test is computed by standardising
as proposed by Clark and Evans (1954) and referring the
standardised statistic to the standard Normal distribution.
For this asymptotic test, the default edge correction is
correction="Donnelly"
if the window of X
is a rectangle,
and correction="cdf"
otherwise. It is strongly recommended
to avoid using correction="none"
which would lead to a severely
biased test.
If method="MonteCarlo"
, the -value for the test is computed
by comparing the observed value of
to the
results obtained from
nsim
simulated realisations of
Complete Spatial Randomness conditional on the
observed number of points. This test is theoretically exact
for any choice of edge correction, but may have lower power
than the asymptotic test.
For this Monte Carlo test, the default edge correction
is correction="none"
for computational efficiency.
An object of class "htest"
representing the result of the test.
Adrian Baddeley [email protected]
Clark, P.J. and Evans, F.C. (1954) Distance to nearest neighbour as a measure of spatial relationships in populations. Ecology 35, 445–453.
Donnelly, K. (1978) Simulations to determine the variance and edge-effect of total nearest neighbour distance. In Simulation methods in archaeology, Cambridge University Press, pp 91–95.
# Redwood data - clustered clarkevans.test(redwood) clarkevans.test(redwood, alternative="clustered") clarkevans.test(redwood, correction="cdf", method="MonteCarlo", nsim=39)
# Redwood data - clustered clarkevans.test(redwood) clarkevans.test(redwood, alternative="clustered") clarkevans.test(redwood, correction="cdf", method="MonteCarlo", nsim=39)
Detect high-density features in a spatial point pattern using the (unrestricted) Allard-Fraley estimator.
clusterset(X, what=c("marks", "domain"), ..., verbose=TRUE, fast=FALSE, exact=!fast)
clusterset(X, what=c("marks", "domain"), ..., verbose=TRUE, fast=FALSE, exact=!fast)
X |
A dimensional spatial point pattern (object of class
|
what |
Character string or character vector specifying the type of result. See Details. |
verbose |
Logical value indicating whether to print progress reports. |
fast |
Logical. If |
exact |
Logical. If |
... |
Optional arguments passed to |
Allard and Fraley (1997) developed a technique for recognising features of high density in a spatial point pattern in the presence of random clutter.
This algorithm computes the unrestricted Allard-Fraley estimator.
The Dirichlet (Voronoi) tessellation of the point pattern X
is
computed. The smallest m
Dirichlet cells are selected,
where the number m
is determined by a maximum likelihood
criterion.
If fast=FALSE
(the default), the areas of the tiles
of the Dirichlet tessellation will be computed exactly
using polygonal geometry. This ensures that the optimal selection of
tiles is computed exactly.
If fast=TRUE
, the Dirichlet tile areas
will be approximated by counting pixels.
This is faster, and is usually correct (depending on the pixel
resolution, which is controlled by the arguments ...
).
The type of result depends on the character vector what
.
If what="marks"
the result is the point pattern X
with a vector of marks labelling each point with a value yes
or
no
depending on whether the corresponding Dirichlet cell is
selected by the Allard-Fraley estimator. In other words each point of
X
is labelled as either a cluster point or a non-cluster point.
If what="domain"
, the result is the Allard-Fraley estimator
of the cluster feature set, which is the union of all the
selected Dirichlet cells, represented as a window (object of class
"owin"
).
If what=c("marks", "domain")
the result is a list
containing both of the results described above.
Computation of the Allard-Fraley set estimator depends on
the argument exact
.
If exact=TRUE
(the default), the Allard-Fraley set estimator
will be computed exactly using polygonal geometry.
The result is a polygonal window.
If exact=FALSE
, the Allard-Fraley set estimator
will be approximated by a binary pixel mask.
This is faster than the exact computation.
The result is a binary mask.
If what="marks"
, a multitype point pattern (object of class
"ppp"
).
If what="domain"
, a window (object of class
"owin"
).
If what=c("marks", "domain")
(the default),
a list consisting of a multitype point pattern and a window.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Allard, D. and Fraley, C. (1997) Nonparametric maximum likelihood estimation of features in spatial point processes using Voronoi tessellation. Journal of the American Statistical Association 92, 1485–1493.
opa <- par(mfrow=c(1,2)) W <- grow.rectangle(as.rectangle(letterR), 1) X <- superimpose(runifpoint(300, letterR), runifpoint(50, W), W=W) plot(W, main="clusterset(X, 'm')") plot(clusterset(X, "marks", fast=TRUE), add=TRUE, chars=c(1, 3), cols=1:2) plot(letterR, add=TRUE) plot(W, main="clusterset(X, 'd')") plot(clusterset(X, "domain", exact=FALSE), add=TRUE) plot(letterR, add=TRUE) par(opa)
opa <- par(mfrow=c(1,2)) W <- grow.rectangle(as.rectangle(letterR), 1) X <- superimpose(runifpoint(300, letterR), runifpoint(50, W), W=W) plot(W, main="clusterset(X, 'm')") plot(clusterset(X, "marks", fast=TRUE), add=TRUE, chars=c(1, 3), cols=1:2) plot(letterR, add=TRUE) plot(W, main="clusterset(X, 'd')") plot(clusterset(X, "domain", exact=FALSE), add=TRUE) plot(letterR, add=TRUE) par(opa)
Combines several function tables (objects of class "fv"
)
into a single function table, merging columns that are identical
and relabelling columns that are different.
## S3 method for class 'fv' collapse(object, ..., same = NULL, different = NULL) ## S3 method for class 'anylist' collapse(object, ..., same = NULL, different = NULL)
## S3 method for class 'fv' collapse(object, ..., same = NULL, different = NULL) ## S3 method for class 'anylist' collapse(object, ..., same = NULL, different = NULL)
object |
An object of class |
... |
Additional objects of class |
same |
Character string or character vector specifying a column or columns
of function values that are identical in different |
different |
Character string or character vector specifying a column or columns
of function values, that are different in different |
This is a method for the generic function
collapse
.
It combines the data in several function tables
(objects of class "fv"
, see fv.object
)
to make a single function table.
It is essentially a smart wrapper for
cbind.fv
.
A typical application is to calculate the same summary statistic
(such as the function) for different point patterns,
and then to use
collapse.fv
to combine the results into a
single object that can easily be plotted. See the Examples.
The arguments object
and ...
should be function tables
(objects of class "fv"
, see fv.object
)
that are compatible in the sense that they
have the same values of the function argument.
(This can be ensured by applying harmonise.fv
to them.)
The argument same
identifies any columns that are present
in some or all of the function tables, and
which are known to contain exactly the same values in each table
that includes them. This column or columns will be
included only once in the result.
The argument different
identifies any columns that are present
in some or all of the function tables, and which may contain
different numerical values in different tables.
Each of these columns will be included, with labels
to distinguish them.
Columns that are not named in same
or different
will not
be included.
The function argument is always included and does not need to be specified.
The arguments same
and different
can be NULL
,
or they can be character vectors containing the names
of columns of object
. The argument different
can be
one of the abbreviations recognised by fvnames
.
Object of class "fv"
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
# generate simulated data X <- replicate(3, rpoispp(100), simplify=FALSE) names(X) <- paste("Simulation", 1:3) # compute K function estimates Klist <- anylapply(X, Kest) # collapse K <- collapse(Klist, same="theo", different="iso") K
# generate simulated data X <- replicate(3, rpoispp(100), simplify=FALSE) names(X) <- paste("Simulation", 1:3) # compute K function estimates Klist <- anylapply(X, Kest) # collapse K <- collapse(Klist, same="theo", different="iso") K
Tests whether two or more function arrays (class "fasp"
)
are compatible.
## S3 method for class 'fasp' compatible(A, B, ...)
## S3 method for class 'fasp' compatible(A, B, ...)
A , B , ...
|
Two or more function arrays (object of class |
An object of class "fasp"
can be regarded as an array
of functions. Such objects are returned by the
command alltypes
.
This command tests whether such objects are compatible
(so that, for example, they could be added or subtracted).
It is a method for the generic command compatible
.
The function arrays are compatible if the arrays have the same dimensions,
and the corresponding elements in each cell of the array
are compatible as defined by compatible.fv
.
Logical value: TRUE
if the objects are compatible, and FALSE
if they are not.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Tests whether two or more function objects (class "fv"
)
are compatible.
## S3 method for class 'fv' compatible(A, B, ..., samenames=TRUE)
## S3 method for class 'fv' compatible(A, B, ..., samenames=TRUE)
A , B , ...
|
Two or more function value objects (class
|
samenames |
Logical value indicating whether to check for complete agreement
between the column names of the objects ( |
An object of class "fv"
is essentially a data frame
containing several different statistical estimates of the same
function. Such objects are returned by Kest
and its
relatives.
This command tests whether such objects are compatible
(so that, for example, they could be added or subtracted).
It is a method for the generic command compatible
.
The functions are compatible if they have been evaluated at the
same sequence of values of the argument r
, and if the
statistical estimates have the same names.
Logical value: TRUE
if the objects are compatible, and FALSE
if they are not.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
A low-level function which calculates the estimated cumulative distribution function of a distance variable.
compileCDF(D, B, r, ..., han.denom=NULL, check=TRUE)
compileCDF(D, B, r, ..., han.denom=NULL, check=TRUE)
D |
A vector giving the distances from each data point to the target. |
B |
A vector giving the distances from each data point to the window boundary, or censoring distances. |
r |
An equally spaced, finely spaced sequence of distance values at which the CDF should be estimated. |
... |
Ignored. |
han.denom |
Denominator for the Hanisch-Chiu-Stoyan estimator.
A single number, or a numeric vector with the same length
as |
check |
Logical value specifying whether to check validity of the data,
for example, that the vectors |
This low-level function calculates estimates of the cumulative distribution function
of a distance variable , given a vector of observed values of
and other information.
Examples of this concept include the empty space distance function
computed by
Fest
and the nearest-neighbour distance
distribution function Gest
.
This function compileCDF
and its siblings compileK
and compilepcf
are useful for code development and for teaching,
because they perform a common task, and do the housekeeping required to
make an object of class "fv"
that represents the estimated
function. However, they are not very efficient.
The argument D
should be a numeric vector of shortest distances
measured from each ‘query’ point to the ‘target’ set.
The argument B
should be a numeric vector of shortest distances
measured from each ‘query’ point to the boundary of the window
of observation.
All entries of D
and B
should be non-negative.
compileCDF
calculates estimates of the cumulative distribution
function using the border method (reduced sample
estimator), the Kaplan-Meier estimator and, if
han.denom
is
given, the Hanisch-Chiu-Stoyan estimator.
See Chapter 8 of Baddeley, Rubak and Turner (2015).
The result is an object of class "fv"
representing the
estimated function.
Additional columns (such as a column giving the theoretical
value) must be added by the user, with the aid of
bind.fv
.
An object of class "fv"
representing the estimated function.
Adrian Baddeley [email protected]
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
bind.fv
to add more columns.
## Equivalent to Gest(japanesepines) X <- japanesepines D <- nndist(X) B <- bdist.points(X) r <- seq(0, 0.25, by=0.01) H <- eroded.areas(Window(X), r) G <- compileCDF(D=D, B=B, r=r, han.denom=H) G <- rebadge.fv(G, new.fname="G", new.ylab=quote(G(r))) plot(G)
## Equivalent to Gest(japanesepines) X <- japanesepines D <- nndist(X) B <- bdist.points(X) r <- seq(0, 0.25, by=0.01) H <- eroded.areas(Window(X), r) G <- compileCDF(D=D, B=B, r=r, han.denom=H) G <- rebadge.fv(G, new.fname="G", new.ylab=quote(G(r))) plot(G)
Low-level functions which
calculate the estimated function
and estimated pair correlation function
(or any similar functions)
from a matrix of pairwise distances and optional weights.
compileK(D, r, weights = NULL, denom = 1, check = TRUE, ratio = FALSE, fname = "K", samplesize=denom) compilepcf(D, r, weights = NULL, denom = 1, check = TRUE, endcorrect = TRUE, ratio=FALSE, ..., fname = "g", samplesize=denom)
compileK(D, r, weights = NULL, denom = 1, check = TRUE, ratio = FALSE, fname = "K", samplesize=denom) compilepcf(D, r, weights = NULL, denom = 1, check = TRUE, endcorrect = TRUE, ratio=FALSE, ..., fname = "g", samplesize=denom)
D |
A square matrix giving the distances between all pairs of points. |
r |
An equally spaced, finely spaced sequence of distance values. |
weights |
Optional numerical weights for the pairwise distances.
A numeric matrix with the same dimensions as |
denom |
Denominator for the estimator.
A single number, or a numeric vector with the same length
as |
check |
Logical value specifying whether to check that |
ratio |
Logical value indicating whether to store ratio information. See Details. |
... |
Optional arguments passed to |
endcorrect |
Logical value indicating whether to apply End Correction of
the pair correlation estimate at |
fname |
Character string giving the name of the function being estimated. |
samplesize |
The sample size that should be used as the denominator when
|
These low-level functions construct estimates of
the function or pair correlation function,
or any similar functions, given only the matrix of pairwise
distances and optional weights associated with these distances.
These functions are useful for code development and for teaching,
because they perform a common task, and do the housekeeping required to
make an object of class "fv"
that represents the estimated
function. However, they are not very efficient.
compileK
calculates the weighted estimate
of the function,
and compilepcf
calculates the weighted estimate of the
pair correlation function,
where is the distance between spatial points
and
, with corresponding weight
,
and
is a specified denominator. Here
is a fixed-bandwidth smoothing kernel.
For a point pattern in two dimensions, the usual denominator
is constant for the
function, and proportional to
for the pair correlation function. See the Examples.
The result is an object of class "fv"
representing the
estimated function. This object has only one column of function
values. Additional columns (such as a column giving the theoretical
value) must be added by the user, with the aid of
bind.fv
.
If ratio=TRUE
, the result also belongs to class "rat"
and has attributes containing the numerator and denominator
of the function estimate.
(If samplesize
is given, the numerator and denominator are
rescaled by a common factor so that the denominator is
equal to samplesize
.)
This allows function estimates from
several datasets to be pooled using pool
.
An object of class "fv"
representing the estimated function.
Adrian Baddeley [email protected]
Kest
,
pcf
for definitions of the function
and pair correlation function.
bind.fv
to add more columns.
compileCDF
for the corresponding low-level utility
for estimating a cumulative distribution function.
## Equivalent to Kest(japanesepines) and pcf(japanesepines) X <- japanesepines D <- pairdist(X) Wt <- edge.Ripley(X, D) lambda <- intensity(X) a <- (npoints(X)-1) * lambda r <- seq(0, 0.25, by=0.01) K <- compileK(D=D, r=r, weights=Wt, denom=a) g <- compilepcf(D=D, r=r, weights=Wt, denom= a * 2 * pi * r)
## Equivalent to Kest(japanesepines) and pcf(japanesepines) X <- japanesepines D <- pairdist(X) Wt <- edge.Ripley(X, D) lambda <- intensity(X) a <- (npoints(X)-1) * lambda r <- seq(0, 0.25, by=0.01) K <- compileK(D=D, r=r, weights=Wt, denom=a) g <- compilepcf(D=D, r=r, weights=Wt, denom= a * 2 * pi * r)
Compute the covariance or correlation between (the corresponding pixel values in) several images.
cov.im(..., use = "everything", method = c("pearson", "kendall", "spearman"))
cov.im(..., use = "everything", method = c("pearson", "kendall", "spearman"))
... |
Any number of arguments, each of which is
a pixel image (object of class |
use |
Argument passed to |
method |
Argument passed to |
The arguments ...
should be pixel images (objects of class "im"
).
Their spatial domains must overlap, but need not have the same
pixel dimensions.
These functions compute the covariance or correlation between the corresponding pixel values in the images given.
The pixel image domains are intersected, and converted to a common pixel resolution. Then the corresponding pixel values of each image are extracted. Finally the correlation or covariance between the pixel values of each pair of images, at corresponding pixels, is computed.
The result is a symmetric matrix with one row and column for each image.
The [i,j]
entry is the correlation or covariance between
the i
th and j
th images in the argument list.
The row names and column names of the matrix are copied from the
argument names if they were given (i.e. if the arguments were given
as name=value
).
Note that cor
and cov
are not generic, so you have to type cor.im
, cov.im
.
A symmetric matrix.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
cor.im(bei.extra)
cor.im(bei.extra)
Generates a progress plot (envelope representation) of the Diggle-Cressie-Loosmore-Ford test or the Maximum Absolute Deviation test for a spatial point pattern.
dclf.progress(X, ...) mad.progress(X, ...) mctest.progress(X, fun = Lest, ..., exponent = 1, nrank = 1, interpolate = FALSE, alpha, rmin=0)
dclf.progress(X, ...) mad.progress(X, ...) mctest.progress(X, fun = Lest, ..., exponent = 1, nrank = 1, interpolate = FALSE, alpha, rmin=0)
X |
Either a point pattern (object of class |
... |
Arguments passed to |
fun |
Function that computes the desired summary statistic for a point pattern. |
exponent |
Positive number. The exponent of the |
nrank |
Integer. The rank of the critical value of the Monte Carlo test,
amongst the |
interpolate |
Logical value indicating how to compute the critical value.
If |
alpha |
Optional. The significance level of the test.
Equivalent to |
rmin |
Optional. Left endpoint for the interval of |
The Diggle-Cressie-Loosmore-Ford test and the
Maximum Absolute Deviation test for a spatial point pattern
are described in dclf.test
.
These tests depend on the choice of an interval of
distance values (the argument rinterval
).
A progress plot or envelope representation
of the test (Baddeley et al, 2014) is a plot of the
test statistic (and the corresponding critical value) against the length of
the interval rinterval
.
The command dclf.progress
performs
dclf.test
on X
using all possible intervals
of the form , and returns the resulting values of the test
statistic, and the corresponding critical values of the test,
as a function of
.
Similarly mad.progress
performs
mad.test
using all possible intervals
and returns the test statistic and critical value.
More generally, mctest.progress
performs a test based on the
discrepancy between the curves. The deviation between two
curves is measured by the
th root of the integral of
the
th power of the absolute value of the difference
between the two curves. The exponent
is
given by the argument
exponent
. The case exponent=2
is the Cressie-Loosmore-Ford test, while exponent=Inf
is the
MAD test.
If the argument rmin
is given, it specifies the left endpoint
of the interval defining the test statistic: the tests are
performed using intervals
where
.
The result of each command is an object of class "fv"
that can be plotted to obtain the progress plot. The display shows
the test statistic (solid black line) and the Monte Carlo
acceptance region (grey shading).
The significance level for the Monte Carlo test is
nrank/(nsim+1)
. Note that nsim
defaults to 99,
so if the values of nrank
and nsim
are not given,
the default is a test with significance level 0.01.
If X
is an envelope object, then some of the data stored
in X
may be re-used:
If X
is an envelope object containing simulated functions,
and fun=NULL
, then
the code will re-use the simulated functions stored in X
.
If X
is an envelope object containing
simulated point patterns,
then fun
will be applied to the stored point patterns
to obtain the simulated functions.
If fun
is not specified, it defaults to Lest
.
Otherwise, new simulations will be performed,
and fun
defaults to Lest
.
An object of class "fv"
that can be plotted to
obtain the progress plot.
Adrian Baddeley [email protected]
, Andrew Hardegen, Tom Lawrence, Gopal Nair and Robin Milne.
Baddeley, A., Diggle, P., Hardegen, A., Lawrence, T., Milne, R. and Nair, G. (2014) On tests of spatial pattern based on simulation envelopes. Ecological Monographs 84 (3) 477–489.
dclf.test
and
mad.test
for the tests.
See plot.fv
for information on plotting
objects of class "fv"
.
plot(dclf.progress(cells, nsim=19))
plot(dclf.progress(cells, nsim=19))
Generates a Significance Trace of the Diggle(1986)/ Cressie (1991)/ Loosmore and Ford (2006) test or the Maximum Absolute Deviation test for a spatial point pattern.
dclf.sigtrace(X, ...) mad.sigtrace(X, ...) mctest.sigtrace(X, fun=Lest, ..., exponent=1, interpolate=FALSE, alpha=0.05, confint=TRUE, rmin=0)
dclf.sigtrace(X, ...) mad.sigtrace(X, ...) mctest.sigtrace(X, fun=Lest, ..., exponent=1, interpolate=FALSE, alpha=0.05, confint=TRUE, rmin=0)
X |
Either a point pattern (object of class |
... |
Arguments passed to |
fun |
Function that computes the desired summary statistic for a point pattern. |
exponent |
Positive number. The exponent of the |
interpolate |
Logical value specifying whether to calculate the |
alpha |
Significance level to be plotted (this has no effect on the calculation but is simply plotted as a reference value). |
confint |
Logical value indicating whether to compute a confidence interval
for the ‘true’ |
rmin |
Optional. Left endpoint for the interval of |
The Diggle (1986)/ Cressie (1991)/Loosmore and Ford (2006) test and the
Maximum Absolute Deviation test for a spatial point pattern
are described in dclf.test
.
These tests depend on the choice of an interval of
distance values (the argument rinterval
).
A significance trace (Bowman and Azzalini, 1997;
Baddeley et al, 2014, 2015; Baddeley, Rubak and Turner, 2015)
of the test is a plot of the -value
obtained from the test against the length of
the interval
rinterval
.
The command dclf.sigtrace
performs
dclf.test
on X
using all possible intervals
of the form , and returns the resulting
-values
as a function of
.
Similarly mad.sigtrace
performs
mad.test
using all possible intervals
and returns the -values.
More generally, mctest.sigtrace
performs a test based on the
discrepancy between the curves. The deviation between two
curves is measured by the
th root of the integral of
the
th power of the absolute value of the difference
between the two curves. The exponent
is
given by the argument
exponent
. The case exponent=2
is the Cressie-Loosmore-Ford test, while exponent=Inf
is the
MAD test.
If the argument rmin
is given, it specifies the left endpoint
of the interval defining the test statistic: the tests are
performed using intervals
where
.
The result of each command
is an object of class "fv"
that can be plotted to
obtain the significance trace. The plot shows the Monte Carlo
-value (solid black line),
the critical value
0.05
(dashed red line),
and a pointwise 95% confidence band (grey shading)
for the ‘true’ (Neyman-Pearson) -value.
The confidence band is based on the Agresti-Coull (1998)
confidence interval for a binomial proportion (when
interpolate=FALSE
) or the delta method
and normal approximation (when interpolate=TRUE
).
If X
is an envelope object and fun=NULL
then
the code will re-use the simulated functions stored in X
.
An object of class "fv"
that can be plotted to
obtain the significance trace.
Adrian Baddeley, Andrew Hardegen, Tom Lawrence, Robin Milne, Gopalan Nair and Suman Rakshit. Implemented by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Agresti, A. and Coull, B.A. (1998) Approximate is better than “Exact” for interval estimation of binomial proportions. American Statistician 52, 119–126.
Baddeley, A., Diggle, P., Hardegen, A., Lawrence, T., Milne, R. and Nair, G. (2014) On tests of spatial pattern based on simulation envelopes. Ecological Monographs 84(3) 477–489.
Baddeley, A., Hardegen, A., Lawrence, L., Milne, R.K., Nair, G.M. and Rakshit, S. (2015) Pushing the envelope: extensions of graphical Monte Carlo tests. Unpublished manuscript.
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Bowman, A.W. and Azzalini, A. (1997) Applied smoothing techniques for data analysis: the kernel approach with S-Plus illustrations. Oxford University Press, Oxford.
dclf.test
for the tests;
dclf.progress
for progress plots.
See plot.fv
for information on plotting
objects of class "fv"
.
See also dg.sigtrace
.
plot(dclf.sigtrace(cells, Lest, nsim=19))
plot(dclf.sigtrace(cells, Lest, nsim=19))
Perform the Diggle (1986) / Cressie (1991) / Loosmore and Ford (2006) test or the Maximum Absolute Deviation test for a spatial point pattern.
dclf.test(X, ..., alternative=c("two.sided", "less", "greater"), rinterval = NULL, leaveout=1, scale=NULL, clamp=FALSE, interpolate=FALSE) mad.test(X, ..., alternative=c("two.sided", "less", "greater"), rinterval = NULL, leaveout=1, scale=NULL, clamp=FALSE, interpolate=FALSE)
dclf.test(X, ..., alternative=c("two.sided", "less", "greater"), rinterval = NULL, leaveout=1, scale=NULL, clamp=FALSE, interpolate=FALSE) mad.test(X, ..., alternative=c("two.sided", "less", "greater"), rinterval = NULL, leaveout=1, scale=NULL, clamp=FALSE, interpolate=FALSE)
X |
Data for the test.
Either a point pattern (object of class |
... |
Arguments passed to |
alternative |
The alternative hypothesis. A character string. The default is a two-sided alternative. See Details. |
rinterval |
Interval of values of the summary function argument |
leaveout |
Optional integer 0, 1 or 2 indicating how to calculate the deviation between the observed summary function and the nominal reference value, when the reference value must be estimated by simulation. See Details. |
scale |
Optional. A function in the R language which determines the
relative scale of deviations, as a function of
distance |
clamp |
Logical value indicating how to compute deviations
in a one-sided test. Deviations of the observed
summary function from the theoretical summary function are initially
evaluated as signed real numbers, with large positive values indicating
consistency with the alternative hypothesis.
If |
interpolate |
Logical value specifying whether to calculate the |
These functions perform hypothesis tests for goodness-of-fit of a point pattern dataset to a point process model, based on Monte Carlo simulation from the model.
dclf.test
performs the test advocated by Loosmore and Ford (2006)
which is also described in Diggle (1986), Cressie (1991, page 667, equation
(8.5.42)) and Diggle (2003, page 14). See Baddeley et al (2014) for
detailed discussion.
mad.test
performs the ‘global’ or
‘Maximum Absolute Deviation’ test described by Ripley (1977, 1981).
See Baddeley et al (2014).
The type of test depends on the type of argument X
.
If X
is some kind of point pattern, then a test of Complete
Spatial Randomness (CSR) will be performed. That is,
the null hypothesis is that the point pattern is completely random.
If X
is a fitted point process model, then a test of
goodness-of-fit for the fitted model will be performed. The model object
contains the data point pattern to which it was originally fitted.
The null hypothesis is that the data point pattern is a realisation
of the model.
If X
is an envelope object generated by envelope
,
then it should have been generated with savefuns=TRUE
or
savepatterns=TRUE
so that it contains simulation results.
These simulations will be treated as realisations from the null
hypothesis.
Alternatively X
could be a previously-performed
test of the same kind (i.e. the result of calling
dclf.test
or mad.test
).
The simulations used to perform the original test
will be re-used to perform the new test (provided these simulations
were saved in the original test, by setting savefuns=TRUE
or
savepatterns=TRUE
).
The argument alternative
specifies the alternative hypothesis,
that is, the direction of deviation that will be considered
statistically significant. If alternative="two.sided"
(the
default), both positive and negative deviations (between
the observed summary function and the theoretical function)
are significant. If alternative="less"
, then only negative
deviations (where the observed summary function is lower than the
theoretical function) are considered. If alternative="greater"
,
then only positive deviations (where the observed summary function is
higher than the theoretical function) are considered.
In all cases, the algorithm will first call envelope
to
generate or extract the simulated summary functions.
The number of simulations that will be generated or extracted,
is determined by the argument nsim
, and defaults to 99.
The summary function that will be computed is determined by the
argument fun
(or the first unnamed argument in the list
...
) and defaults to Kest
(except when
X
is an envelope object generated with savefuns=TRUE
,
when these functions will be taken).
The choice of summary function fun
affects the power of the
test. It is normally recommended to apply a variance-stabilising
transformation (Ripley, 1981). If you are using the function,
the normal practice is to replace this by the
function
(Besag, 1977) computed by
Lest
. If you are using
the or
functions, the recommended practice is to apply
Fisher's variance-stabilising transformation
using the argument
transform
. See the Examples.
The argument rinterval
specifies the interval of
distance values which will contribute to the
test statistic (either maximising over this range of values
for
mad.test
, or integrating over this range of values
for dclf.test
). This affects the power of the test.
General advice and experiments in Baddeley et al (2014) suggest
that the maximum value should be slightly larger than
the maximum possible range of interaction between points. The
dclf.test
is quite sensitive to this choice, while the
mad.test
is relatively insensitive.
It is also possible to specify a pointwise test (i.e. taking
a single, fixed value of distance ) by specifing
rinterval = c(r,r)
.
The argument use.theory
passed to envelope
determines whether to compare the summary function for the data
to its theoretical value for CSR (use.theory=TRUE
)
or to the sample mean of simulations from CSR
(use.theory=FALSE
). The test statistic is defined in
equations (10.21) and (10.22) respectively on page 394 of Baddeley,
Rubak and Turner (2015).
The argument leaveout
specifies how to calculate the
discrepancy between the summary function for the data and the
nominal reference value, when the reference value must be estimated
by simulation. The values leaveout=0
and
leaveout=1
are both algebraically equivalent (Baddeley et al, 2014,
Appendix) to computing the difference observed - reference
where the reference
is the mean of simulated values.
The value leaveout=2
gives the leave-two-out discrepancy
proposed by Dao and Genton (2014).
An object of class "htest"
.
Printing this object gives a report on the result of the test.
The -value is contained in the component
p.value
.
If the observed value of the test statistic is equal to one or more of the simulated values (called a tied value), then the tied values will be assigned a random ordering, and a message will be printed.
Adrian Baddeley [email protected], Andrew Hardegen and Suman Rakshit.
Baddeley, A., Diggle, P.J., Hardegen, A., Lawrence, T., Milne, R.K. and Nair, G. (2014) On tests of spatial pattern based on simulation envelopes. Ecological Monographs 84(3) 477–489.
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Besag, J. (1977) Discussion of Dr Ripley's paper. Journal of the Royal Statistical Society, Series B, 39, 193–195.
Cressie, N.A.C. (1991) Statistics for spatial data. John Wiley and Sons, 1991.
Dao, N.A. and Genton, M. (2014) A Monte Carlo adjusted goodness-of-fit test for parametric models describing spatial point patterns. Journal of Graphical and Computational Statistics 23, 497–517.
Diggle, P. J. (1986). Displaced amacrine cells in the retina of a rabbit : analysis of a bivariate spatial point pattern. J. Neuroscience Methods 18, 115–125.
Diggle, P.J. (2003) Statistical analysis of spatial point patterns, Second edition. Arnold.
Loosmore, N.B. and Ford, E.D. (2006) Statistical inference using the G or K point pattern spatial statistics. Ecology 87, 1925–1931.
Ripley, B.D. (1977) Modelling spatial patterns (with discussion). Journal of the Royal Statistical Society, Series B, 39, 172 – 212.
Ripley, B.D. (1981) Spatial statistics. John Wiley and Sons.
dclf.test(cells, Lest, nsim=39) m <- mad.test(cells, Lest, verbose=FALSE, rinterval=c(0, 0.1), nsim=19) m # extract the p-value m$p.value # variance stabilised G function dclf.test(cells, Gest, transform=expression(asin(sqrt(.))), verbose=FALSE, nsim=19) ## one-sided test ml <- mad.test(cells, Lest, verbose=FALSE, nsim=19, alternative="less") ## scaled mad.test(cells, Kest, verbose=FALSE, nsim=19, rinterval=c(0.05, 0.2), scale=function(r) { r })
dclf.test(cells, Lest, nsim=39) m <- mad.test(cells, Lest, verbose=FALSE, rinterval=c(0, 0.1), nsim=19) m # extract the p-value m$p.value # variance stabilised G function dclf.test(cells, Gest, transform=expression(asin(sqrt(.))), verbose=FALSE, nsim=19) ## one-sided test ml <- mad.test(cells, Lest, verbose=FALSE, nsim=19, alternative="less") ## scaled mad.test(cells, Kest, verbose=FALSE, nsim=19, rinterval=c(0.05, 0.2), scale=function(r) { r })
Compute a kernel smoothed intensity function from a point pattern.
## S3 method for class 'ppp' density(x, sigma=NULL, ..., weights=NULL, edge=TRUE, varcov=NULL, at="pixels", leaveoneout=TRUE, adjust=1, diggle=FALSE, se=FALSE, wtype=c("value", "multiplicity"), kernel="gaussian", scalekernel=is.character(kernel), positive=FALSE, verbose=TRUE, sameas)
## S3 method for class 'ppp' density(x, sigma=NULL, ..., weights=NULL, edge=TRUE, varcov=NULL, at="pixels", leaveoneout=TRUE, adjust=1, diggle=FALSE, se=FALSE, wtype=c("value", "multiplicity"), kernel="gaussian", scalekernel=is.character(kernel), positive=FALSE, verbose=TRUE, sameas)
x |
Point pattern (object of class |
sigma |
The smoothing bandwidth (the amount of smoothing).
The standard deviation of the isotropic smoothing kernel.
Either a numerical value,
or a function that computes an appropriate value of |
weights |
Optional weights to be attached to the points.
A numeric vector, numeric matrix, an |
... |
Additional arguments passed to |
edge |
Logical value indicating whether to apply edge correction. |
varcov |
Variance-covariance matrix of anisotropic smoothing kernel.
Incompatible with |
at |
String specifying whether to compute the intensity values
at a grid of pixel locations ( |
leaveoneout |
Logical value indicating whether to compute a leave-one-out
estimator. Applicable only when |
adjust |
Optional. Adjustment factor for the smoothing parameter. |
diggle |
Logical. If |
kernel |
The smoothing kernel.
A character string specifying the smoothing kernel
(current options are |
scalekernel |
Logical value.
If |
se |
Logical value indicating whether to compute standard errors as well. |
wtype |
Character string (partially matched) specifying how the weights should be interpreted for the calculation of standard error. See Details. |
positive |
Logical value indicating whether to force all density values to
be positive numbers. Default is |
verbose |
Logical value indicating whether to issue warnings about numerical problems and conditions. |
sameas |
Optional. The result of a previous evaluation of |
This is a method for the generic function density
.
It computes a fixed-bandwidth kernel estimate
(Diggle, 1985) of the intensity function of the point process
that generated the point pattern x
.
The amount of smoothing is controlled by sigma
if it is specified.
By default, smoothing is performed using a Gaussian kernel.
The resulting density estimate is the convolution of the
isotropic Gaussian kernel, of standard deviation sigma
,
with point masses at each of the data points in x
.
Anisotropic kernels, and non-Gaussian kernels, are also supported.
Each point has unit weight, unless the argument weights
is
given.
If edge=TRUE
(the default), the intensity estimate is corrected
for edge effect bias.
If at="pixels"
(the default), the result is a pixel image
giving the estimated intensity at each pixel in a grid.
If at="points"
, the result is a numeric vector giving the
estimated intensity at each of the original data points in x
.
By default, the result is
a pixel image (object of class "im"
).
Pixel values are estimated intensity values,
expressed in “points per unit area”.
If at="points"
, the result is a numeric vector
of length equal to the number of points in x
.
Values are estimated intensity values at the points of x
.
In either case, the return value has attributes
"sigma"
and "varcov"
which report the smoothing
bandwidth that was used.
If weights
is a matrix with more than one column, then the
result is a list of images (if at="pixels"
) or a matrix of
numerical values (if at="points"
).
If se=TRUE
, the result is a list with two elements named
estimate
and SE
, each of the format described above.
The amount of smoothing is determined by the arguments
sigma
, varcov
and adjust
.
if sigma
is a single numerical value,
this is taken as the standard deviation of the isotropic Gaussian
kernel.
alternatively sigma
may be a function that computes
an appropriate bandwidth
from the data point pattern by calling sigma(x)
.
To perform automatic bandwidth selection using cross-validation,
it is recommended to use the functions
bw.diggle
,
bw.CvL
,
bw.scott
or
bw.ppl
.
The smoothing kernel may be made anisotropic
by giving the variance-covariance matrix varcov
.
The arguments sigma
and varcov
are incompatible.
Alternatively sigma
may be a vector of length 2 giving the
standard deviations of the and
coordinates,
thus equivalent to
varcov = diag(rep(sigma^2, 2))
.
if neither sigma
nor varcov
is specified,
an isotropic Gaussian kernel will be used,
with a default value of sigma
calculated by a simple rule of thumb
that depends only on the size of the window.
The argument adjust
makes it easy for the user to change the
bandwidth specified by any of the rules above.
The value of sigma
will be multiplied by
the factor adjust
. The matrix varcov
will be
multiplied by adjust^2
. To double the smoothing bandwidth, set
adjust=2
.
An infinite bandwidth, sigma=Inf
or adjust=Inf
,
is permitted, and yields an intensity estimate which is constant
over the spatial domain.
If edge=TRUE
, the intensity estimate is corrected for
edge effect bias in one of two ways:
If diggle=FALSE
(the default) the intensity estimate is
correted by dividing it by the convolution of the
Gaussian kernel with the window of observation.
This is the approach originally described in Diggle (1985).
Thus the intensity value at a point is
where is the Gaussian smoothing kernel,
is an edge correction factor,
and
are the weights.
If diggle=TRUE
then the code uses the improved edge correction
described by Jones (1993) and Diggle (2010, equation 18.9).
This has been shown to have better performance (Jones, 1993)
but is slightly slower to compute.
The intensity value at a point is
where again is the Gaussian smoothing kernel,
is an edge correction factor,
and
are the weights.
In both cases, the edge correction term is the reciprocal of the
kernel mass inside the window:
where is the observation window.
By default, smoothing is performed using a Gaussian kernel.
The choice of smoothing kernel is determined by the argument kernel
.
This should be a character string giving the name of a recognised
two-dimensional kernel
(current options are "gaussian"
, "epanechnikov"
,
"quartic"
or "disc"
),
or a pixel image (object of class "im"
)
containing values of the kernel, or a function(x,y)
which
yields values of the kernel. The default is a Gaussian kernel.
If scalekernel=TRUE
then the kernel values will be rescaled
according to the arguments sigma
, varcov
and
adjust
as explained above, effectively treating
kernel
as the template kernel with standard deviation equal to 1.
This is the default behaviour when kernel
is a character string.
If scalekernel=FALSE
, the kernel values will not be altered,
and the arguments sigma
, varcov
and adjust
are ignored. This is the default behaviour when kernel
is a
pixel image or a function.
If at="pixels"
(the default), intensity values are
computed at every location in a fine grid,
and are returned as a pixel image. The point pattern is first discretised
using
pixellate.ppp
, then the intensity is
computed using the Fast Fourier Transform.
Accuracy depends on the pixel resolution and the discretisation rule.
The pixel resolution is controlled by the arguments
...
passed to as.mask
(specify the number of
pixels by dimyx
or the pixel size by eps
).
The discretisation rule is controlled by the arguments
...
passed to pixellate.ppp
(the default rule is that each point is allocated to the nearest
pixel centre; this can be modified using the arguments
fractional
and preserve
).
If at="points"
, the intensity values are computed
to high accuracy at the points of x
only. Computation is
performed by directly evaluating and summing the kernel
contributions without discretising the data. The result is a numeric
vector giving the density values.
The intensity value at a point is (if
diggle=FALSE
)
or (if diggle=TRUE
)
If leaveoneout=TRUE
(the default), then the sum in the equation
is taken over all not equal to
,
so that the intensity value at a
data point is the sum of kernel contributions from
all other data points.
If
leaveoneout=FALSE
then the sum is taken over all ,
so that the intensity value at a data point includes a contribution
from the same point.
If weights
is a matrix with more than one column, then the
calculation is effectively repeated for each column of weights. The
result is a list of images (if at="pixels"
) or a matrix of
numerical values (if at="points"
).
The argument weights
can also be an expression
.
It will be evaluated in the data frame as.data.frame(x)
to obtain a vector or matrix of weights. The expression may involve
the symbols x
and y
representing the Cartesian
coordinates, the symbol marks
representing the mark values
if there is only one column of marks, and the names of the columns of
marks if there are several columns.
The argument weights
can also be a pixel image
(object of class "im"
). numerical weights for the data points
will be extracted from this image (by looking up the pixel values
at the locations of the data points in x
).
If se=TRUE
, the standard error of the estimate will also be
calculated. The calculation assumes a Poisson point process.
If weights
are given, then the calculation of standard error
depends on the interpretation of the weights. This is controlled by
the argument wtype
.
If wtype="value"
(the default),
the weights are interpreted as numerical values observed
at the data locations. Roughly speaking,
standard errors are proportional to the absolute
values of the weights.
If wtype="multiplicity"
the weights are interpreted as
multiplicities so that a weight of 2 is equivalent to having a pair
of duplicated points at the data location. Roughly speaking,
standard errors are proportional
to the square roots of the weights. Negative weights are not
permitted.
The default rule is now wtype="value"
but previous versions
of density.ppp
(in spatstat.explore versions
3.1-0
and earlier) effectively used wtype="multiplicity"
.
density.ppp
This function is often misunderstood.
The result of density.ppp
is not a spatial smoothing
of the marks or weights attached to the point pattern.
To perform spatial interpolation of values that were observed
at the points of a point pattern, use Smooth.ppp
.
The result of density.ppp
is not a probability density.
It is an estimate of the intensity function of the
point process that generated the point pattern data.
Intensity is the expected number of random points
per unit area.
The units of intensity are “points per unit area”.
Intensity is usually a function of spatial location,
and it is this function which is estimated by density.ppp
.
The integral of the intensity function over a spatial region gives the
expected number of points falling in this region.
Inspecting an estimate of the intensity function is usually the first step in exploring a spatial point pattern dataset. For more explanation, see Baddeley, Rubak and Turner (2015) or Diggle (2003, 2010).
If you have two (or more) types of points, and you want a
probability map or relative risk surface (the spatially-varying
probability of a given type), use relrisk
.
Negative and zero values of the density estimate are possible
when at="pixels"
because of numerical errors in finite-precision
arithmetic.
By default, density.ppp
does not try to repair such errors.
This would take more computation time and is not always needed.
(Also it would not be appropriate if weights
include negative values.)
To ensure that the resulting density values are always positive,
set positive=TRUE
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Diggle, P.J. (1985) A kernel method for smoothing point process data. Applied Statistics (Journal of the Royal Statistical Society, Series C) 34 (1985) 138–147.
Diggle, P.J. (2003) Statistical analysis of spatial point patterns, Second edition. Arnold.
Diggle, P.J. (2010) Nonparametric methods. Chapter 18, pp. 299–316 in A.E. Gelfand, P.J. Diggle, M. Fuentes and P. Guttorp (eds.) Handbook of Spatial Statistics, CRC Press, Boca Raton, FL.
Jones, M.C. (1993) Simple boundary corrections for kernel density estimation. Statistics and Computing 3, 135–146.
To select the bandwidth sigma
automatically by
cross-validation, use
bw.diggle
,
bw.CvL
,
bw.scott
or
bw.ppl
.
To perform spatial interpolation of values that were observed
at the points of a point pattern, use Smooth.ppp
.
For adaptive nonparametric estimation, see
adaptive.density
.
For data sharpening, see sharpen.ppp
.
To compute a relative risk surface or probability map for
two (or more) types of points, use relrisk
.
For information about the data structures, see
ppp.object
,
im.object
.
if(interactive()) { opa <- par(mfrow=c(1,2)) plot(density(cells, 0.05)) plot(density(cells, 0.05, diggle=TRUE)) par(opa) v <- diag(c(0.05, 0.07)^2) plot(density(cells, varcov=v)) } # automatic bandwidth selection plot(density(cells, sigma=bw.diggle(cells))) # equivalent: plot(density(cells, bw.diggle)) # evaluate intensity at points density(cells, 0.05, at="points") # non-Gaussian kernel plot(density(cells, sigma=0.4, kernel="epanechnikov")) if(interactive()) { # see effect of changing pixel resolution opa <- par(mfrow=c(1,2)) plot(density(cells, sigma=0.4)) plot(density(cells, sigma=0.4, eps=0.05)) par(opa) } # relative risk calculation by hand (see relrisk.ppp) lung <- split(chorley)$lung larynx <- split(chorley)$larynx D <- density(lung, sigma=2) plot(density(larynx, sigma=2, weights=1/D))
if(interactive()) { opa <- par(mfrow=c(1,2)) plot(density(cells, 0.05)) plot(density(cells, 0.05, diggle=TRUE)) par(opa) v <- diag(c(0.05, 0.07)^2) plot(density(cells, varcov=v)) } # automatic bandwidth selection plot(density(cells, sigma=bw.diggle(cells))) # equivalent: plot(density(cells, bw.diggle)) # evaluate intensity at points density(cells, 0.05, at="points") # non-Gaussian kernel plot(density(cells, sigma=0.4, kernel="epanechnikov")) if(interactive()) { # see effect of changing pixel resolution opa <- par(mfrow=c(1,2)) plot(density(cells, sigma=0.4)) plot(density(cells, sigma=0.4, eps=0.05)) par(opa) } # relative risk calculation by hand (see relrisk.ppp) lung <- split(chorley)$lung larynx <- split(chorley)$larynx D <- density(lung, sigma=2) plot(density(larynx, sigma=2, weights=1/D))
Compute a kernel smoothed intensity function from a line segment pattern.
## S3 method for class 'psp' density(x, sigma, ..., weights=NULL, edge=TRUE, method=c("FFT", "C", "interpreted"), at=NULL)
## S3 method for class 'psp' density(x, sigma, ..., weights=NULL, edge=TRUE, method=c("FFT", "C", "interpreted"), at=NULL)
x |
Line segment pattern (object of class |
sigma |
Standard deviation of isotropic Gaussian smoothing kernel. |
... |
Extra arguments, including arguments passed to |
weights |
Optional. Numerical weights for each line segment.
A numeric vector, of length equal to the number of segments in
|
edge |
Logical flag indicating whether to apply edge correction. |
method |
Character string (partially matched) specifying the method of
computation. Option |
at |
Optional. An object specifying the locations where density values
should be computed. Either a window (object of class |
This is the method for the generic function density
for the class "psp"
(line segment patterns).
A kernel estimate of the intensity of the line segment pattern
is computed. The result is
the convolution of the isotropic Gaussian kernel, of
standard deviation sigma
, with the line segments.
The result is computed as follows:
if method="FFT"
(the default),
the line segments are discretised
using pixellate.psp
, then the Fast Fourier Transform
is used to calculate the convolution. This method is the fastest,
but is slightly less accurate. Accuracy can be improved by
increasing pixel resolution.
if method="C"
the exact value of the convolution at the
centre of each pixel is computed analytically using C
code;
if method="interpreted"
,
the exact value of the convolution at the
centre of each pixel is computed analytically using R
code.
This method is the slowest.
If edge=TRUE
this result is adjusted for edge effects
by dividing it by the convolution of the same Gaussian kernel
with the observation window.
If weights
are given, then the contribution from line segment
i
is multiplied by the value of weights[i]
.
If the argument at
is given, then it specifies the locations
where density values should be computed.
If at
is a window,
then the window is converted to a binary mask
using the arguments ...
, and density values are computed at
the centre of each pixel in this mask. The result is a pixel image.
If at
is a point pattern, then density values are computed at
each point location, and the result is a numeric vector.
A pixel image (object of class "im"
)
or a numeric vector.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
psp.object
,
im.object
,
density
L <- psp(runif(20),runif(20),runif(20),runif(20), window=owin()) D <- density(L, sigma=0.03) plot(D, main="density(L)") plot(L, add=TRUE)
L <- psp(runif(20),runif(20),runif(20),runif(20), window=owin()) D <- density(L, sigma=0.03) plot(D, main="density(L)") plot(L, add=TRUE)
Compute a kernel smoothed intensity function for each of the components of a split point pattern, or each of the point patterns in a list.
## S3 method for class 'splitppp' density(x, ..., weights=NULL, se=FALSE) ## S3 method for class 'ppplist' density(x, ..., weights=NULL, se=FALSE)
## S3 method for class 'splitppp' density(x, ..., weights=NULL, se=FALSE) ## S3 method for class 'ppplist' density(x, ..., weights=NULL, se=FALSE)
x |
Split point pattern (object of class |
... |
Arguments passed to |
weights |
Numerical weights for the points. See Details. |
se |
Logical value indicating whether to compute standard errors as well. |
This is a method for the generic function density
.
The argument x
should be a list of point patterns,
and should belong to one of the classes
"ppplist"
or "splitppp"
.
Typically x
is obtained by applying
the function split.ppp
to a point pattern y
by calling split(y)
. This splits the points of y
into several
sub-patterns.
A kernel estimate of the intensity function of each of the
point patterns is computed using density.ppp
.
The return value is usually a list, each of whose entries is a
pixel image (object of class "im"
). The return value
also belongs to the class "solist"
and can be plotted
or printed.
If the argument at="points"
is given, the result is a list
of numeric vectors giving the intensity values at the data points.
If se=TRUE
, the result is a list with two elements named
estimate
and SE
, each of the format described above.
The argument weights
specifies numerical case weights
for the data points.
Normally it should be a list, with the same length as
x
. The entry weights[[i]]
will determine the
case weights for the pattern x[[i]]
, and may be given in
any format acceptable to density.ppp
.
For example, weights[[i]]
can be
a numeric vector of length equal to npoints(x[[i]])
,
a single numeric value, a numeric matrix,
a pixel image (object of class "im"
),
an expression
, or a function of class "funxy"
.
For convenience, weights
can also be a single expression
,
or a single pixel image (object of class "im"
),
or a single function of class "funxy"
.
A list of pixel images (objects of class "im"
)
which can be plotted or printed;
or a list of numeric vectors giving the values at specified points.
If se=TRUE
, the result is a list with two elements named
estimate
and SE
, each of the format described above.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Z <- density(split(amacrine), 0.05) plot(Z)
Z <- density(split(amacrine), 0.05) plot(Z)
Computes an adaptive estimate of the intensity function of a point pattern using a variable-bandwidth smoothing kernel.
## S3 method for class 'ppp' densityAdaptiveKernel(X, bw, ..., weights=NULL, at=c("pixels", "points"), edge=TRUE, ngroups)
## S3 method for class 'ppp' densityAdaptiveKernel(X, bw, ..., weights=NULL, at=c("pixels", "points"), edge=TRUE, ngroups)
X |
Point pattern (object of class |
bw |
Numeric vector of smoothing bandwidths for each point in |
... |
Arguments passed to
|
weights |
Optional vector of numeric weights for the points of |
at |
String specifying whether to compute the intensity values
at a grid of pixel locations ( |
edge |
Logical value indicating whether to perform edge correction. |
ngroups |
Number of groups into which the bandwidth values should be partitioned and discretised. |
This function computes a spatially-adaptive kernel estimate of the
spatially-varying intensity from the point pattern X
using the partitioning technique of Davies and Baddeley (2018).
The function densityAdaptiveKernel
is generic.
This file documents the method for point patterns,
densityAdaptiveKernel.ppp
.
The argument bw
specifies the smoothing bandwidths to be
applied to each of the points in X
. It may be a numeric vector
of bandwidth values, or a pixel image or function yielding the
bandwidth values.
If the points of X
are
and the corresponding bandwidths are
then the adaptive kernel estimate of intensity at a location
is
where is the value at
of the (possibly edge-corrected) smoothing kernel with bandwidth
induced by a data point at
.
Exact computation of the estimate above can be time-consuming:
it takes times longer than fixed-bandwidth smoothing.
The partitioning method of Davies and Baddeley (2018)
accelerates this computation by partitioning the range of
bandwidths into ngroups
intervals,
correspondingly subdividing the points of the pattern X
into
ngroups
sub-patterns according to bandwidth,
and applying fixed-bandwidth smoothing to each sub-pattern.
The default value of ngroups
is the integer part of the square root of
the number of points in X
, so that the computation time is
only about times slower than fixed-bandwidth
smoothing. Any positive value of
ngroups
can be specified by the user. Specifying ngroups=Inf
enforces exact
computation of the estimate without partitioning. Specifying
ngroups=1
is the same as fixed-bandwidth smoothing with
bandwidth sigma=median(bw)
.
If at="pixels"
(the default), the result is a pixel image.
If at="points"
, the result is a numeric vector with one entry
for each data point in X
.
The function densityAdaptiveKernel
computes one adaptive estimate of the intensity,
determined by the smoothing bandwidth values bw
.
Typically the bandwidth values are computed by first computing
a pilot estimate of the intensity, then using bw.abram.ppp
to compute the vector of bandwidths according to Abramson's rule.
This involves specifying a global bandwidth h0
.
The default bandwidths may work well in many contexts, but for optimal
bandwidth selection, this calculation should be performed repeatedly with
different values of h0
to optimise the value of h0
.
This can be computationally demanding; we recommend
the function multiscale.density
in the sparr package
which supports much faster bandwidth selection, using the FFT
method of Davies and Baddeley (2018).
Adrian Baddeley [email protected] and Tilman Davies.
Davies, T.M. and Baddeley, A. (2018) Fast computation of spatially adaptive kernel estimates. Statistics and Computing, 28(4), 937-956.
Hall, P. and Marron, J.S. (1988) Variable window width kernel density estimates of probability densities. Probability Theory and Related Fields, 80, 37-49.
Silverman, B.W. (1986) Density Estimation for Statistics and Data Analysis. Chapman and Hall, New York.
bw.abram.ppp
,
density.ppp
,
adaptive.density
,
densityVoronoi
,
im.object
.
See the function bivariate.density
in the sparr package
for a more flexible implementation, and
multiscale.density
for an implementation that is more
efficient for bandwidth selection.
Z <- densityAdaptiveKernel(redwood, h0=0.1) plot(Z, main="Adaptive kernel estimate") points(redwood, col="white")
Z <- densityAdaptiveKernel(redwood, h0=0.1) plot(Z, main="Adaptive kernel estimate") points(redwood, col="white")
Computes an adaptive estimate of the intensity function (using a variable-bandwidth smoothing kernel) for each of the components of a split point pattern, or each of the point patterns in a list.
## S3 method for class 'splitppp' densityAdaptiveKernel(X, bw=NULL, ..., weights=NULL) ## S3 method for class 'ppplist' densityAdaptiveKernel(X, bw=NULL, ..., weights=NULL)
## S3 method for class 'splitppp' densityAdaptiveKernel(X, bw=NULL, ..., weights=NULL) ## S3 method for class 'ppplist' densityAdaptiveKernel(X, bw=NULL, ..., weights=NULL)
X |
Split point pattern (object of class |
bw |
Smoothing bandwidths. See Details. |
... |
Additional arguments passed to
|
weights |
Numerical weights for the points. See Details. |
This function computes a spatially-adaptive kernel estimate of the
spatially-varying intensity for each of the point patterns
in the list X
, using densityAdaptiveKernel.ppp
.
The argument bw
specifies smoothing bandwidths
for the data points.
Normally it should be a list, with the same length as
x
. The entry bw[[i]]
will determine the
smoothing bandwidths for the pattern x[[i]]
, and may be given in
any format acceptable to densityAdaptiveKernel.ppp
.
For example, bw[[i]]
can be
a numeric vector of length equal to npoints(x[[i]])
,
a single numeric value,
a pixel image (object of class "im"
),
an expression
, or a function of class "funxy"
.
For convenience, bw
can also be a single expression
,
or a single pixel image, or a single function.
If bw
is missing or NULL
, the default is to compute
bandwidths using bw.abram.ppp
.
The argument weights
specifies numerical case weights
for the data points.
Normally it should be a list, with the same length as
x
. The entry weights[[i]]
will determine the
case weights for the pattern x[[i]]
, and may be given in
any format acceptable to density.ppp
.
For example, weights[[i]]
can be
a numeric vector of length equal to npoints(x[[i]])
,
a single numeric value, a numeric matrix,
a pixel image (object of class "im"
),
an expression
, or a function of class "funxy"
.
For convenience, weights
can also be a single expression
,
or a single pixel image (object of class "im"
),
or a single function of class "funxy"
.
If weights
is missing or NULL
, all weights are assumed
to be equal to 1.
A list of pixel images (objects of class "im"
)
which can be plotted or printed;
or a list of numeric vectors giving the values at specified points.
Adrian Baddeley [email protected].
densityAdaptiveKernel.ppp
,
bw.abram.ppp
.
X <- amacrine if(!interactive()) X <- X[c(TRUE,FALSE,FALSE,FALSE)] Z <- densityAdaptiveKernel(split(X), h0=0.15) plot(Z, main="Adaptive kernel estimate")
X <- amacrine if(!interactive()) X <- X[c(TRUE,FALSE,FALSE,FALSE)] Z <- densityAdaptiveKernel(split(X), h0=0.15) plot(Z, main="Adaptive kernel estimate")
Compute a kernel estimate of intensity for a point pattern, and return the result as a function of spatial location.
densityfun(X, ...) ## S3 method for class 'ppp' densityfun(X, sigma = NULL, ..., weights = NULL, edge = TRUE, diggle = FALSE)
densityfun(X, ...) ## S3 method for class 'ppp' densityfun(X, sigma = NULL, ..., weights = NULL, edge = TRUE, diggle = FALSE)
X |
Point pattern (object of class |
sigma |
Smoothing bandwidth, or bandwidth selection function,
passed to |
... |
Additional arguments passed to |
weights |
Optional vector of weights associated with the points of |
edge , diggle
|
Logical arguments controlling the edge correction.
Arguments passed to |
The commands densityfun
and density
both perform kernel estimation of the intensity of a point pattern.
The difference is that density
returns a pixel image,
containing the estimated intensity values at a grid of locations, while
densityfun
returns a function(x,y)
which can be used
to compute the intensity estimate at any spatial locations
with coordinates x,y
.
For purposes such as model-fitting it is more accurate to
use densityfun
.
A function
with arguments x,y,drop
.
The function also belongs to the class "densityfun"
which has
methods for print
and as.im
.
It also belongs to the class "funxy"
which has methods
for plot
, contour
and persp
.
densityfun
If f <- densityfun(X)
, where X
is a two-dimensional
point pattern, the resulting object f
is a function
in the R language.
By calling this function, the user can evaluate the estimated intensity at any desired spatial locations.
Additionally f
belongs to other
classes which allow it to be printed and plotted easily.
The function f
has arguments x,y,drop
.
The arguments x,y
of f
specify the query locations. They can be numeric vectors
of coordinates. Alternatively x
can be a point pattern
(or data acceptable to as.ppp
) and y
is omitted.
The result of f(x,y)
is a numeric vector giving the values of
the intensity.
The argument drop
of f
specifies how to handle query locations
which are outside the window of the original data.
If drop=TRUE
(the default), such locations are ignored.
If drop=FALSE
, a value of NA
is returned
for each such location.
Note that the smoothing parameters, such as the bandwidth
sigma
, are assigned when densityfun
is executed.
Smoothing parameters are fixed inside the function f
and cannot be changed by arguments of f
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
To interpolate values observed at the points, use Smoothfun
.
f <- densityfun(swedishpines) f f(42, 60) X <- runifpoint(2, Window(swedishpines)) f(X) plot(f)
f <- densityfun(swedishpines) f f(42, 60) X <- runifpoint(2, Window(swedishpines)) f(X) plot(f)
Computes a diffusion estimate of intensity for a point pattern.
densityHeat(x, sigma, ...)
densityHeat(x, sigma, ...)
x |
Point pattern (object of class |
sigma |
Smoothing bandwidth. Usually a single number giving the equivalent standard deviation of the smoother. |
... |
Additional arguments depending on the method. |
The generic function densityHeat
computes an
estimate of point process intensity using a diffusion kernel method.
Further details depend on the class of point pattern x
.
See the help file for the appropriate method.
Depends on the class of x
.
Adrian Baddeley and Tilman Davies.
For two-dimensional point patterns (objects of class "ppp"
),
the diffusion kernel estimator is densityHeat.ppp
.
The usual kernel estimator is density.ppp
,
and the tessellation-based estimator is
adaptive.density
.
Computes the diffusion estimate of the intensity of a point pattern.
## S3 method for class 'ppp' densityHeat(x, sigma, ..., weights=NULL, connect=8, symmetric=FALSE, sigmaX=NULL, k=1, show=FALSE, se=FALSE, at=c("pixels", "points"), leaveoneout = TRUE, extrapolate = FALSE, coarsen = TRUE, verbose=TRUE, internal=NULL)
## S3 method for class 'ppp' densityHeat(x, sigma, ..., weights=NULL, connect=8, symmetric=FALSE, sigmaX=NULL, k=1, show=FALSE, se=FALSE, at=c("pixels", "points"), leaveoneout = TRUE, extrapolate = FALSE, coarsen = TRUE, verbose=TRUE, internal=NULL)
x |
Point pattern (object of class |
sigma |
Smoothing bandwidth. A single number giving the equivalent
standard deviation of the smoother.
Alternatively, a pixel image (class |
... |
Arguments passed to |
weights |
Optional numeric vector of weights associated with each point of
|
connect |
Grid connectivity: either 4 or 8. |
symmetric |
Logical value indicating whether to force the algorithm to use a symmetric random walk. |
sigmaX |
Numeric vector of bandwidths, one associated with each data point in
|
k |
Integer. Calculations will be performed by repeatedly multiplying
the current state by the |
show |
Logical value indicating whether to plot successive iterations. |
se |
Logical value indicating whether to compute standard errors. |
at |
Character string specifying whether to compute values
at a grid of pixels ( |
leaveoneout |
Logical value specifying whether to compute a leave-one-out
estimate at each data point, when |
extrapolate |
Logical value specifying whether to use Richardson extrapolation to improve the accuracy of the computation. |
coarsen |
Logical value, controlling the calculation performed when
|
verbose |
Logical value specifying whether to print progress reports. |
internal |
Developer use only. |
This command computes a diffusion kernel estimate
of point process intensity from the observed point pattern x
.
The function densityHeat
is generic,
with methods for point patterns in two dimensions
(class "ppp"
) and point patterns on a linear network
(class "lpp"
). The function densityHeat.ppp
described
here is the method for class "ppp"
. Given a two-dimensional
point pattern x
, it computes a diffusion kernel estimate
of the intensity of the point process which generated x
.
Diffusion kernel estimates were developed by Botev et al (2010), Barry and McIntyre (2011) and Baddeley et al (2022).
Barry and McIntyre (2011) proposed an estimator for point process intensity based on a random walk on the pixel grid inside the observation window. Baddeley et al (2022) showed that the Barry-McIntyre method is a special case of the diffusion estimator proposed by Botev et al (2010).
The original Barry-McIntyre algorithm assumes a symmetric random walk
(i.e. each possible transition has the same probability )
and requires a square pixel grid (i.e. equal
spacing in the
and
directions). Their original
algorithm is used if
symmetric=TRUE
. Use the ...
arguments to ensure a square grid: for example, the argument
eps
specifies a square grid with spacing eps
units.
The more general algorithm used here (Baddeley et al, 2022)
does not require a square grid of pixels.
If the pixel grid is not square, and if symmetric=FALSE
(the default), then the random walk is not symmetric,
in the sense that the probabilities of different jumps will be
different, in order to ensure that the smoothing is isotropic.
This implementation also includes two generalizations to the case of adaptive smoothing (Baddeley et al, 2022).
In the first version of adaptive smoothing, the bandwidth is
spatially-varying.
The argument sigma
should be a pixel image (class "im"
)
or a function(x,y)
specifying the bandwidth at each spatial
location. The smoothing is performed by solving the
heat equation with spatially-varying parameters.
In the second version of adaptive smoothing, each data point in
x
is smoothed using a separate bandwidth.
The argument sigmaX
should be a numeric vector
specifying the bandwidth for each point of x
.
The smoothing is performed using the lagged arrival algorithm.
The argument sigma
can be omitted.
If extrapolate=FALSE
(the default), calculations are performed
using the Euler scheme for the heat equation.
If extrapolate=TRUE
, the accuracy of the result will be
improved by applying Richardson extrapolation (Baddeley et al, 2022, Section
4). After computing the intensity estimate using the Euler scheme
on the desired pixel grid, another estimate is computed using the same
method on another pixel grid, and the two estimates are combined by
Richardson extrapolation to obtain a more accurate result.
The second grid is coarser than the original grid if
coarsen=TRUE
(the default), and finer than the original grid
if coarsen=FALSE
. Setting extrapolate=TRUE
increases
computation time by 35% if coarsen=TRUE
and by 400% if
coarsen=FALSE
.
Pixel image (object of class "im"
) giving the estimated
intensity of the point process.
If se=TRUE
, the result has an attribute "se"
which is another pixel image giving the estimated standard error.
If at="points"
then the result is a numeric vector
with one entry for each point of x
.
Adrian Baddeley and Tilman Davies.
Baddeley, A., Davies, T., Rakshit, S., Nair, G. and McSwiggan, G. (2022) Diffusion smoothing for spatial point patterns. Statistical Science 37 (1) 123–142.
Barry, R.P. and McIntyre, J. (2011) Estimating animal densities and home range in regions with irregular boundaries and holes: a lattice-based alternative to the kernel density estimator. Ecological Modelling 222, 1666–1672.
Botev, Z.I., Grotowski, J.F. and Kroese, D.P. (2010) Kernel density estimation via diffusion. Annals of Statistics 38, 2916–2957.
density.ppp
for the usual kernel estimator,
and adaptive.density
for the
tessellation-based estimator.
online <- interactive() if(!online) op <- spatstat.options(npixel=32) X <- runifpoint(25, letterR) Z <- densityHeat(X, 0.2) if(online) { plot(Z, main="Diffusion estimator") plot(X, add=TRUE, pch=16) integral(Z) # should equal 25 } Z <- densityHeat(X, 0.2, se=TRUE) Zse <- attr(Z, "se") if(online) plot(solist(estimate=Z, SE=Zse), main="") Zex <- densityHeat(X, 0.2, extrapolate=TRUE) ZS <- densityHeat(X, 0.2, symmetric=TRUE, eps=0.125) if(online) { plot(ZS, main="fixed bandwidth") plot(X, add=TRUE, pch=16) } sig <- function(x,y) { (x-1.5)/10 } ZZ <- densityHeat(X, sig) if(online) { plot(ZZ, main="adaptive (I)") plot(X, add=TRUE, pch=16) } sigX <- sig(X$x, X$y) AA <- densityHeat(X, sigmaX=sigX) if(online) { plot(AA, main="adaptive (II)") plot(X, add=TRUE, pch=16) } if(!online) spatstat.options(op)
online <- interactive() if(!online) op <- spatstat.options(npixel=32) X <- runifpoint(25, letterR) Z <- densityHeat(X, 0.2) if(online) { plot(Z, main="Diffusion estimator") plot(X, add=TRUE, pch=16) integral(Z) # should equal 25 } Z <- densityHeat(X, 0.2, se=TRUE) Zse <- attr(Z, "se") if(online) plot(solist(estimate=Z, SE=Zse), main="") Zex <- densityHeat(X, 0.2, extrapolate=TRUE) ZS <- densityHeat(X, 0.2, symmetric=TRUE, eps=0.125) if(online) { plot(ZS, main="fixed bandwidth") plot(X, add=TRUE, pch=16) } sig <- function(x,y) { (x-1.5)/10 } ZZ <- densityHeat(X, sig) if(online) { plot(ZZ, main="adaptive (I)") plot(X, add=TRUE, pch=16) } sigX <- sig(X$x, X$y) AA <- densityHeat(X, sigmaX=sigX) if(online) { plot(AA, main="adaptive (II)") plot(X, add=TRUE, pch=16) } if(!online) spatstat.options(op)
Computes an adaptive estimate of the intensity function of a point pattern using the Dirichlet-Voronoi tessellation.
densityVoronoi(X, ...) ## S3 method for class 'ppp' densityVoronoi(X, f = 1, ..., counting=FALSE, fixed=FALSE, nrep = 1, verbose=TRUE)
densityVoronoi(X, ...) ## S3 method for class 'ppp' densityVoronoi(X, f = 1, ..., counting=FALSE, fixed=FALSE, nrep = 1, verbose=TRUE)
X |
Point pattern dataset (object of class |
f |
Fraction (between 0 and 1 inclusive) of the data points that will be used to build a tessellation for the intensity estimate. |
... |
Arguments passed to |
counting |
Logical value specifying the choice of estimation method. See Details. |
fixed |
Logical. If |
nrep |
Number of independent repetitions of the randomised procedure. |
verbose |
Logical value indicating whether to print progress reports. |
This function is an alternative to density.ppp
. It
computes an estimate of the intensity function of a point pattern
dataset. The result is a pixel image giving the estimated intensity.
If f=1
(the default), the Voronoi estimate (Barr and Schoenberg, 2010)
is computed: the point pattern X
is used to construct
a Voronoi/Dirichlet tessellation (see dirichlet
);
the areas of the Dirichlet tiles are computed; the estimated intensity
in each tile is the reciprocal of the tile area.
The result is a pixel image
of intensity estimates which are constant on each tile of the tessellation.
If f=0
, the intensity estimate at every location is
equal to the average intensity (number of points divided by window area).
The result is a pixel image
of intensity estimates which are constant.
If f
is strictly between 0 and 1,
the estimation method is applied to a random subset of X
.
This randomised procedure is repeated nrep
times,
and the results are averaged.
The subset is selected as follows:
if fixed=FALSE
,
the dataset X
is randomly
thinned by deleting or retaining each point independently, with
probability f
of retaining a point.
if fixed=TRUE
,
a random sample of fixed size m
is taken from
the dataset X
, where m
is the largest integer
less than or equal to f*n
and n
is the number of
points in X
.
Then the intensity estimate is calculated as follows:
if counting = FALSE
(the default), the thinned pattern
is used to construct a Dirichlet tessellation and form the
Voronoi estimate (Barr and Schoenberg, 2010) which is then
adjusted by a factor 1/f
or n/m
as appropriate.
to obtain an estimate
of the intensity of X
in the tile.
if counting = TRUE
,
the randomly selected subset A
is used to construct a Dirichlet tessellation, while the
complementary subset B
(consisting of points that were not
selected in the sample) is used for counting
to calculate a quadrat count estimate of intensity.
For each tile of the Dirichlet tessellation formed by A
,
we count the number of points of B
falling in the
tile, and divide by the area of the same tile, to obtain an estimate
of the intensity of the pattern B
in the tile.
This estimate is adjusted by 1/(1-f)
or n/(n-m)
as appropriate
to obtain an estimate of the intensity of X
in the tile.
Ogata et al. (2003) and Ogata (2004) estimated intensity using the
Dirichlet-Voronoi tessellation in a modelling context.
Baddeley (2007) proposed intensity estimation by subsampling
with 0 < f < 1
, and used the technique described above
with fixed=TRUE
and counting=TRUE
.
Barr and Schoenberg (2010) described and analysed the
Voronoi estimator (corresponding to f=1
).
Moradi et al (2019) developed the subsampling technique with
fixed=FALSE
and counting=FALSE
and called it the
smoothed Voronoi estimator.
A pixel image (object of class "im"
) whose values are
estimates of the intensity of X
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected] and Mehdi Moradi [email protected].
Baddeley, A. (2007) Validation of statistical models for spatial point patterns. In J.G. Babu and E.D. Feigelson (eds.) SCMA IV: Statistical Challenges in Modern Astronomy IV, volume 317 of Astronomical Society of the Pacific Conference Series, San Francisco, California USA, 2007. Pages 22–38.
Barr, C., and Schoenberg, F.P. (2010). On the Voronoi estimator for the intensity of an inhomogeneous planar Poisson process. Biometrika 97 (4), 977–984.
Moradi, M., Cronie, 0., Rubak, E., Lachieze-Rey, R., Mateu, J. and Baddeley, A. (2019) Resample-smoothing of Voronoi intensity estimators. Statistics and Computing 29 (5) 995–1010.
Ogata, Y. (2004) Space-time model for regional seismicity and detection of crustal stress changes. Journal of Geophysical Research, 109, 2004.
Ogata, Y., Katsura, K. and Tanemura, M. (2003). Modelling heterogeneous space-time occurrences of earthquakes and its residual analysis. Applied Statistics 52 499–509.
adaptive.density
,
density.ppp
,
dirichlet
,
im.object
.
plot(densityVoronoi(nztrees, 1, f=1), main="Voronoi estimate") nr <- if(interactive()) 100 else 5 plot(densityVoronoi(nztrees, f=0.5, nrep=nr), main="smoothed Voronoi estimate")
plot(densityVoronoi(nztrees, 1, f=1), main="Voronoi estimate") nr <- if(interactive()) 100 else 5 plot(densityVoronoi(nztrees, f=0.5, nrep=nr), main="smoothed Voronoi estimate")
Applies numerical differentiation to the values in selected columns of a function value table.
## S3 method for class 'fv' deriv(expr, which = "*", ..., method=c("spline", "numeric"), kinks=NULL, periodic=FALSE, Dperiodic=periodic)
## S3 method for class 'fv' deriv(expr, which = "*", ..., method=c("spline", "numeric"), kinks=NULL, periodic=FALSE, Dperiodic=periodic)
expr |
Function values to be differentiated.
A function value table (object of class |
which |
Character vector identifying which columns of the table
should be differentiated. Either a vector containing names
of columns, or one of the wildcard strings |
... |
Extra arguments passed to |
method |
Differentiation method. A character string, partially matched
to either |
kinks |
Optional vector of |
periodic |
Logical value indicating whether the function |
Dperiodic |
Logical value indicating whether the resulting derivative should be a periodic function. |
This command performs numerical differentiation on the function values in
a function value table (object of class "fv"
).
The differentiation is performed either by
smooth.spline
or by
a naive numerical difference algorithm.
The command deriv
is generic. This is the
method for objects of class "fv"
.
Differentiation is applied to every column
(or to each of the selected columns) of function values in turn,
using the function argument as the coordinate
and the selected column as the
coordinate.
The original function values are then replaced by the corresponding
derivatives.
The optional argument which
specifies which of the
columns of function values in expr
will be differentiated.
The default (indicated by the wildcard which="*"
)
is to differentiate all function values, i.e.\ all columns except the
function argument. Alternatively which="."
designates
the subset of function values that are displayed in the default plot.
Alternatively which
can be a character vector containing the
names of columns of expr
.
If the argument kinks
is given, it should be a numeric vector
giving the discontinuity points of the function: the value or values
of the function argument at which the function is
not differentiable. Differentiation will be performed separately on
intervals between the discontinuity points.
If periodic=TRUE
then the function expr
is taken to be
periodic, with period equal to the range of the function
argument in expr
. The resulting derivative is periodic.
If periodic=FALSE
but Dperiodic=TRUE
, then the
derivative is assumed to be periodic. This would be
appropriate if expr
is the cumulative distribution function
of an angular variable, for example.
Another function value table (object of class "fv"
)
of the same format.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
with.fv
,
fv.object
,
smooth.spline
G <- Gest(cells) plot(deriv(G, which=".", spar=0.5)) A <- pairorient(redwood, 0.05, 0.15) DA <- deriv(A, spar=0.6, Dperiodic=TRUE)
G <- Gest(cells) plot(deriv(G, which=".", spar=0.5)) A <- pairorient(redwood, 0.05, 0.15) DA <- deriv(A, spar=0.6, Dperiodic=TRUE)
Computes the global envelopes corresponding to the Dao-Genton test of goodness-of-fit.
dg.envelope(X, ..., nsim = 19, nsimsub=nsim-1, nrank = 1, alternative=c("two.sided", "less", "greater"), leaveout=1, interpolate = FALSE, savefuns=FALSE, savepatterns=FALSE, verbose = TRUE)
dg.envelope(X, ..., nsim = 19, nsimsub=nsim-1, nrank = 1, alternative=c("two.sided", "less", "greater"), leaveout=1, interpolate = FALSE, savefuns=FALSE, savepatterns=FALSE, verbose = TRUE)
X |
Either a point pattern dataset (object of class |
... |
Arguments passed to
|
nsim |
Number of simulated patterns to be generated in the primary experiment. |
nsimsub |
Number of simulations in each basic test. There will be |
nrank |
Integer. Rank of the envelope value amongst the |
alternative |
Character string determining whether the envelope corresponds
to a two-sided test ( |
leaveout |
Optional integer 0, 1 or 2 indicating how to calculate the deviation between the observed summary function and the nominal reference value, when the reference value must be estimated by simulation. See Details. |
interpolate |
Logical value indicating whether to interpolate the distribution of the test statistic by kernel smoothing, as described in Dao and Genton (2014, Section 5). |
savefuns |
Logical flag indicating whether to save the simulated function values (from the first stage). |
savepatterns |
Logical flag indicating whether to save the simulated point patterns (from the first stage). |
verbose |
Logical value determining whether to print progress reports. |
Computes global simulation envelopes corresponding to the Dao-Genton (2014) adjusted Monte Carlo goodness-of-fit test. The envelopes were developed in Baddeley et al (2015) and described in Baddeley, Rubak and Turner (2015).
If X
is a point pattern, the null hypothesis is CSR.
If X
is a fitted model, the null hypothesis is that model.
The Dao-Genton test is biased when the significance level is very small
(small -values are not reliable) and
we recommend
bits.envelope
in this case.
An object of class "fv"
.
Adrian Baddeley, Andrew Hardegen, Tom Lawrence, Robin Milne, Gopalan Nair and Suman Rakshit. Implemented by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Dao, N.A. and Genton, M. (2014) A Monte Carlo adjusted goodness-of-fit test for parametric models describing spatial point patterns. Journal of Graphical and Computational Statistics 23, 497–517.
Baddeley, A., Hardegen, A., Lawrence, L., Milne, R.K., Nair, G.M. and Rakshit, S. (2015) Pushing the envelope: extensions of graphical Monte Carlo tests. Unpublished manuscript.
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
ns <- if(interactive()) 19 else 4 E <- dg.envelope(swedishpines, Lest, nsim=ns) E plot(E) Eo <- dg.envelope(swedishpines, Lest, alternative="less", nsim=ns) Ei <- dg.envelope(swedishpines, Lest, interpolate=TRUE, nsim=ns)
ns <- if(interactive()) 19 else 4 E <- dg.envelope(swedishpines, Lest, nsim=ns) E plot(E) Eo <- dg.envelope(swedishpines, Lest, alternative="less", nsim=ns) Ei <- dg.envelope(swedishpines, Lest, interpolate=TRUE, nsim=ns)
Generates a progress plot (envelope representation) of the Dao-Genton test for a spatial point pattern.
dg.progress(X, fun = Lest, ..., exponent = 2, nsim = 19, nsimsub = nsim - 1, nrank = 1, alpha, leaveout=1, interpolate = FALSE, rmin=0, savefuns = FALSE, savepatterns = FALSE, verbose=TRUE)
dg.progress(X, fun = Lest, ..., exponent = 2, nsim = 19, nsimsub = nsim - 1, nrank = 1, alpha, leaveout=1, interpolate = FALSE, rmin=0, savefuns = FALSE, savepatterns = FALSE, verbose=TRUE)
X |
Either a point pattern (object of class |
fun |
Function that computes the desired summary statistic for a point pattern. |
... |
Arguments passed to |
exponent |
Positive number. The exponent of the |
nsim |
Number of repetitions of the basic test. |
nsimsub |
Number of simulations in each basic test. There will be |
nrank |
Integer. The rank of the critical value of the Monte Carlo test,
amongst the |
alpha |
Optional. The significance level of the test.
Equivalent to |
leaveout |
Optional integer 0, 1 or 2 indicating how to calculate the deviation between the observed summary function and the nominal reference value, when the reference value must be estimated by simulation. See Details. |
interpolate |
Logical value indicating how to compute the critical value.
If |
rmin |
Optional. Left endpoint for the interval of |
savefuns |
Logical value indicating whether to save the simulated function values (from the first stage). |
savepatterns |
Logical value indicating whether to save the simulated point patterns (from the first stage). |
verbose |
Logical value indicating whether to print progress reports. |
The Dao and Genton (2014) test for a spatial point pattern
is described in dg.test
.
This test depends on the choice of an interval of
distance values (the argument rinterval
).
A progress plot or envelope representation
of the test (Baddeley et al, 2014, 2015; Baddeley, Rubak and Turner, 2015) is a plot of the
test statistic (and the corresponding critical value) against the length of
the interval rinterval
.
The command dg.progress
effectively performs
dg.test
on X
using all possible intervals
of the form , and returns the resulting values of the test
statistic, and the corresponding critical values of the test,
as a function of
.
The result is an object of class "fv"
that can be plotted to obtain the progress plot. The display shows
the test statistic (solid black line) and the test
acceptance region (grey shading).
If X
is an envelope object, then some of the data stored
in X
may be re-used:
If X
is an envelope object containing simulated functions,
and fun=NULL
, then
the code will re-use the simulated functions stored in X
.
If X
is an envelope object containing
simulated point patterns,
then fun
will be applied to the stored point patterns
to obtain the simulated functions.
If fun
is not specified, it defaults to Lest
.
Otherwise, new simulations will be performed,
and fun
defaults to Lest
.
If the argument rmin
is given, it specifies the left endpoint
of the interval defining the test statistic: the tests are
performed using intervals
where
.
The argument leaveout
specifies how to calculate the
discrepancy between the summary function for the data and the
nominal reference value, when the reference value must be estimated
by simulation. The values leaveout=0
and
leaveout=1
are both algebraically equivalent (Baddeley et al, 2014,
Appendix) to computing the difference observed - reference
where the reference
is the mean of simulated values.
The value leaveout=2
gives the leave-two-out discrepancy
proposed by Dao and Genton (2014).
An object of class "fv"
that can be plotted to
obtain the progress plot.
Adrian Baddeley, Andrew Hardegen, Tom Lawrence, Robin Milne, Gopalan Nair and Suman Rakshit. Implemented by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Baddeley, A., Diggle, P., Hardegen, A., Lawrence, T., Milne, R. and Nair, G. (2014) On tests of spatial pattern based on simulation envelopes. Ecological Monographs 84 (3) 477–489.
Baddeley, A., Hardegen, A., Lawrence, L., Milne, R.K., Nair, G.M. and Rakshit, S. (2015) Pushing the envelope: extensions of graphical Monte Carlo tests. Unpublished manuscript.
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Dao, N.A. and Genton, M. (2014) A Monte Carlo adjusted goodness-of-fit test for parametric models describing spatial point patterns. Journal of Graphical and Computational Statistics 23, 497–517.
ns <- if(interactive()) 19 else 5 plot(dg.progress(cells, nsim=ns))
ns <- if(interactive()) 19 else 5 plot(dg.progress(cells, nsim=ns))
Generates a Significance Trace of the Dao and Genton (2014) test for a spatial point pattern.
dg.sigtrace(X, fun = Lest, ..., exponent = 2, nsim = 19, nsimsub = nsim - 1, alternative = c("two.sided", "less", "greater"), rmin=0, leaveout=1, interpolate = FALSE, confint = TRUE, alpha = 0.05, savefuns=FALSE, savepatterns=FALSE, verbose=FALSE)
dg.sigtrace(X, fun = Lest, ..., exponent = 2, nsim = 19, nsimsub = nsim - 1, alternative = c("two.sided", "less", "greater"), rmin=0, leaveout=1, interpolate = FALSE, confint = TRUE, alpha = 0.05, savefuns=FALSE, savepatterns=FALSE, verbose=FALSE)
X |
Either a point pattern (object of class |
fun |
Function that computes the desired summary statistic for a point pattern. |
... |
Arguments passed to |
exponent |
Positive number. Exponent used in the test statistic. Use |
nsim |
Number of repetitions of the basic test. |
nsimsub |
Number of simulations in each basic test. There will be |
alternative |
Character string specifying the alternative hypothesis.
The default ( |
rmin |
Optional. Left endpoint for the interval of |
leaveout |
Optional integer 0, 1 or 2 indicating how to calculate the deviation between the observed summary function and the nominal reference value, when the reference value must be estimated by simulation. See Details. |
interpolate |
Logical value indicating whether to interpolate the distribution of the test statistic by kernel smoothing, as described in Dao and Genton (2014, Section 5). |
confint |
Logical value indicating whether to compute a confidence interval
for the ‘true’ |
alpha |
Significance level to be plotted (this has no effect on the calculation but is simply plotted as a reference value). |
savefuns |
Logical flag indicating whether to save the simulated function values (from the first stage). |
savepatterns |
Logical flag indicating whether to save the simulated point patterns (from the first stage). |
verbose |
Logical flag indicating whether to print progress reports. |
The Dao and Genton (2014) test for a spatial point pattern
is described in dg.test
.
This test depends on the choice of an interval of
distance values (the argument rinterval
).
A significance trace (Bowman and Azzalini, 1997;
Baddeley et al, 2014, 2015; Baddeley, Rubak and Turner, 2015)
of the test is a plot of the -value
obtained from the test against the length of
the interval
rinterval
.
The command dg.sigtrace
effectively performs
dg.test
on X
using all possible intervals
of the form , and returns the resulting
-values
as a function of
.
The result is an object of class "fv"
that can be plotted to
obtain the significance trace. The plot shows the
Dao-Genton adjusted
-value (solid black line),
the critical value
0.05
(dashed red line),
and a pointwise 95% confidence band (grey shading)
for the ‘true’ (Neyman-Pearson) -value.
The confidence band is based on the Agresti-Coull (1998)
confidence interval for a binomial proportion.
If X
is an envelope object and fun=NULL
then
the code will re-use the simulated functions stored in X
.
If the argument rmin
is given, it specifies the left endpoint
of the interval defining the test statistic: the tests are
performed using intervals
where
.
The argument leaveout
specifies how to calculate the
discrepancy between the summary function for the data and the
nominal reference value, when the reference value must be estimated
by simulation. The values leaveout=0
and
leaveout=1
are both algebraically equivalent (Baddeley et al, 2014,
Appendix) to computing the difference observed - reference
where the reference
is the mean of simulated values.
The value leaveout=2
gives the leave-two-out discrepancy
proposed by Dao and Genton (2014).
An object of class "fv"
that can be plotted to
obtain the significance trace.
Adrian Baddeley, Andrew Hardegen, Tom Lawrence, Robin Milne, Gopalan Nair and Suman Rakshit. Implemented by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Agresti, A. and Coull, B.A. (1998) Approximate is better than “Exact” for interval estimation of binomial proportions. American Statistician 52, 119–126.
Baddeley, A., Diggle, P., Hardegen, A., Lawrence, T., Milne, R. and Nair, G. (2014) On tests of spatial pattern based on simulation envelopes. Ecological Monographs 84(3) 477–489.
Baddeley, A., Hardegen, A., Lawrence, L., Milne, R.K., Nair, G.M. and Rakshit, S. (2015) Pushing the envelope: extensions of graphical Monte Carlo tests. Unpublished manuscript.
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Bowman, A.W. and Azzalini, A. (1997) Applied smoothing techniques for data analysis: the kernel approach with S-Plus illustrations. Oxford University Press, Oxford.
Dao, N.A. and Genton, M. (2014) A Monte Carlo adjusted goodness-of-fit test for parametric models describing spatial point patterns. Journal of Graphical and Computational Statistics 23, 497–517.
dg.test
for the Dao-Genton test,
dclf.sigtrace
for significance traces of other tests.
ns <- if(interactive()) 19 else 5 plot(dg.sigtrace(cells, nsim=ns))
ns <- if(interactive()) 19 else 5 plot(dg.sigtrace(cells, nsim=ns))
Performs the Dao and Genton (2014) adjusted goodness-of-fit test of spatial pattern.
dg.test(X, ..., exponent = 2, nsim=19, nsimsub=nsim-1, alternative=c("two.sided", "less", "greater"), reuse = TRUE, leaveout=1, interpolate = FALSE, savefuns=FALSE, savepatterns=FALSE, verbose = TRUE)
dg.test(X, ..., exponent = 2, nsim=19, nsimsub=nsim-1, alternative=c("two.sided", "less", "greater"), reuse = TRUE, leaveout=1, interpolate = FALSE, savefuns=FALSE, savepatterns=FALSE, verbose = TRUE)
X |
Either a point pattern dataset (object of class |
... |
Arguments passed to |
exponent |
Exponent used in the test statistic. Use |
nsim |
Number of repetitions of the basic test. |
nsimsub |
Number of simulations in each basic test. There will be |
alternative |
Character string specifying the alternative hypothesis.
The default ( |
reuse |
Logical value indicating whether to re-use the first stage simulations at the second stage, as described by Dao and Genton (2014). |
leaveout |
Optional integer 0, 1 or 2 indicating how to calculate the deviation between the observed summary function and the nominal reference value, when the reference value must be estimated by simulation. See Details. |
interpolate |
Logical value indicating whether to interpolate the distribution of the test statistic by kernel smoothing, as described in Dao and Genton (2014, Section 5). |
savefuns |
Logical flag indicating whether to save the simulated function values (from the first stage). |
savepatterns |
Logical flag indicating whether to save the simulated point patterns (from the first stage). |
verbose |
Logical value indicating whether to print progress reports. |
Performs the Dao-Genton (2014) adjusted Monte Carlo goodness-of-fit test, in the equivalent form described by Baddeley et al (2014).
If X
is a point pattern, the null hypothesis is CSR.
If X
is a fitted model, the null hypothesis is that model.
The argument use.theory
passed to envelope
determines whether to compare the summary function for the data
to its theoretical value for CSR (use.theory=TRUE
)
or to the sample mean of simulations from CSR
(use.theory=FALSE
).
The argument leaveout
specifies how to calculate the
discrepancy between the summary function for the data and the
nominal reference value, when the reference value must be estimated
by simulation. The values leaveout=0
and
leaveout=1
are both algebraically equivalent (Baddeley et al, 2014,
Appendix) to computing the difference observed - reference
where the reference
is the mean of simulated values.
The value leaveout=2
gives the leave-two-out discrepancy
proposed by Dao and Genton (2014).
The Dao-Genton test is biased when the significance level is very small
(small -values are not reliable) and
we recommend
bits.test
in this case.
A hypothesis test (object of class "htest"
which can be printed to show the outcome of the test.
Adrian Baddeley, Andrew Hardegen, Tom Lawrence, Robin Milne, Gopalan Nair and Suman Rakshit. Implemented by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Dao, N.A. and Genton, M. (2014) A Monte Carlo adjusted goodness-of-fit test for parametric models describing spatial point patterns. Journal of Graphical and Computational Statistics 23, 497–517.
Baddeley, A., Diggle, P.J., Hardegen, A., Lawrence, T., Milne, R.K. and Nair, G. (2014) On tests of spatial pattern based on simulation envelopes. Ecological Monographs 84 (3) 477–489.
Baddeley, A., Hardegen, A., Lawrence, L., Milne, R.K., Nair, G.M. and Rakshit, S. (2017) On two-stage Monte Carlo tests of composite hypotheses. Computational Statistics and Data Analysis 114, 75–87.
bits.test
,
dclf.test
,
mad.test
ns <- if(interactive()) 19 else 4 dg.test(cells, nsim=ns) dg.test(cells, alternative="less", nsim=ns) dg.test(cells, nsim=ns, interpolate=TRUE)
ns <- if(interactive()) 19 else 4 dg.test(cells, nsim=ns) dg.test(cells, alternative="less", nsim=ns) dg.test(cells, nsim=ns, interpolate=TRUE)
Given the kernel matrix that characterises a central subspace, this function estimates the dimension of the subspace.
dimhat(M)
dimhat(M)
M |
Kernel of subspace. A symmetric, non-negative definite, numeric
matrix, typically obtained from |
This function computes the maximum descent estimate of
the dimension of the central subspace with a given kernel matrix M
.
The matrix M
should be the kernel matrix of a central subspace,
which can be obtained from sdr
. It must be a symmetric,
non-negative-definite, numeric matrix.
The algorithm finds the eigenvalues
of
,
and then determines the index
for which
is greatest.
A single integer giving the estimated dimension.
Matlab original by Yongtao Guan, translated to R by Suman Rakshit.
Guan, Y. and Wang, H. (2010) Sufficient dimension reduction for spatial point processes directed by Gaussian random fields. Journal of the Royal Statistical Society, Series B, 72, 367–387.
Computes the cumulative distribution function of the distance between two independent random points in a given window or windows.
distcdf(W, V=W, ..., dW=1, dV=dW, nr=1024, regularise=TRUE, savedenom=FALSE, delta=NULL)
distcdf(W, V=W, ..., dW=1, dV=dW, nr=1024, regularise=TRUE, savedenom=FALSE, delta=NULL)
W |
A window (object of class |
V |
Optional. Another window containing the second random point.
Defaults to |
... |
Arguments passed to |
dV , dW
|
Optional. Probability densities (not necessarily normalised)
for the first and second random points respectively.
Data in any format acceptable
to |
nr |
Integer. The number of values of interpoint distance |
regularise |
Logical value indicating whether to smooth the results for very small distances, to avoid discretisation artefacts. |
savedenom |
Logical value indicating whether to save the denominator of the double integral as an attribute of the result. |
delta |
Optional. A positive number. The maximum permitted spacing between values of the function argument. |
This command computes the Cumulative Distribution Function
of the Euclidean distance
between two independent random points
and
.
In the simplest case, the command distcdf(W)
, the random points are
assumed to be uniformly distributed in the same
window W
.
Alternatively the two random points may be
uniformly distributed in two different windows W
and V
.
In the most general case the first point is random
in the window
W
with a probability density proportional to
dW
, and the second point is random in
a different window
V
with probability density proportional
to dV
. The values of dW
and dV
must be
finite and nonnegative.
The calculation is performed by numerical integration of the set covariance
function setcov
for uniformly distributed points, and
by computing the covariance function imcov
in the
general case. The accuracy of the result depends on
the pixel resolution used to represent the windows: this is controlled
by the arguments ...
which are passed to as.mask
.
For example use eps=0.1
to specify pixels of size 0.1 units.
The arguments W
or V
may also be point patterns
(objects of class "ppp"
).
The result is the cumulative distribution function
of the distance from a randomly selected point in the point pattern,
to a randomly selected point in the other point pattern or window.
If regularise=TRUE
(the default), values of the cumulative
distribution function for very short distances are smoothed to avoid
discretisation artefacts. Smoothing is applied to all distances
shorter than the width of 10 pixels.
Numerical accuracy of some calculations requires
very fine spacing of the values of the function argument r
.
If the argument delta
is given, then
after the cumulative distribution function
has been calculated, it will be interpolated onto a finer grid of r
values with spacing less than or equal to delta
.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
# The unit disc B <- disc() plot(distcdf(B))
# The unit disc B <- disc() plot(distcdf(B))
Given a spatial object such as a point pattern, in any number of dimensions, this function extracts the spatial domain in which the object is defined.
## S3 method for class 'quadrattest' domain(X, ...)
## S3 method for class 'quadrattest' domain(X, ...)
X |
A spatial object such as a point pattern (in any number of dimensions), line segment pattern or pixel image. |
... |
Extra arguments. They are ignored by all the methods listed here. |
The function domain
is generic.
For a spatial object X
in any number of dimensions,
domain(X)
extracts the spatial domain in which X
is
defined.
For a two-dimensional object X
, typically domain(X)
is the same as Window(X)
.
Exceptions occur for methods related to linear networks.
A spatial object representing the domain of X
.
Typically a window (object of class "owin"
),
a three-dimensional box ("box3"
), a multidimensional
box ("boxx"
) or a linear network ("linnet"
).
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
domain
,
domain.quadratcount
,
domain.ppm
,
domain.rmhmodel
,
domain.lpp
.
Window
,
Frame
.
domain(quadrat.test(redwood, 2, 2))
domain(quadrat.test(redwood, 2, 2))
Computes Ripley's isotropic edge correction weights for a point pattern.
edge.Ripley(X, r, W = Window(X), method = c("C", "interpreted"), maxweight = 100, internal=list()) rmax.Ripley(W)
edge.Ripley(X, r, W = Window(X), method = c("C", "interpreted"), maxweight = 100, internal=list()) rmax.Ripley(W)
X |
Point pattern (object of class |
W |
Window for which the edge correction is required. |
r |
Vector or matrix of interpoint distances for which the edge correction should be computed. |
method |
Choice of algorithm. Either |
maxweight |
Maximum permitted value of the edge correction weight. |
internal |
For developer use only. |
The function edge.Ripley
computes Ripley's (1977) isotropic edge correction
weight, which is used in estimating the function and in many
other contexts.
The function rmax.Ripley
computes the maximum value of
distance for which the isotropic edge correction
estimate of
is valid.
For a single point in a window
,
and a distance
, the isotropic edge correction weight
is
where is the circle of radius
centred at the
point
. The denominator is the length of the overlap between
this circle and the window
.
The function edge.Ripley
computes this edge correction weight
for each point in the point pattern X
and for each
corresponding distance value in the vector or matrix r
.
If r
is a vector, with one entry for each point in
X
, then the result is a vector containing the
edge correction weights e(X[i], r[i])
for each i
.
If r
is a matrix, with one row for each point in X
,
then the result is a matrix whose i,j
entry gives the
edge correction weight e(X[i], r[i,j])
.
For example edge.Ripley(X, pairdist(X))
computes all the
edge corrections required for the -function.
If any value of the edge correction weight exceeds maxwt
,
it is set to maxwt
.
The function rmax.Ripley
computes the smallest distance
such that it is possible to draw a circle of radius
, centred
at a point of
W
, such that the circle does not intersect the
interior of W
.
A numeric vector or matrix.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Ripley, B.D. (1977) Modelling spatial patterns (with discussion). Journal of the Royal Statistical Society, Series B, 39, 172 – 212.
v <- edge.Ripley(cells, pairdist(cells)) rmax.Ripley(Window(cells))
v <- edge.Ripley(cells, pairdist(cells)) rmax.Ripley(Window(cells))
Computes Ohser and Stoyan's translation edge correction weights for a point pattern.
edge.Trans(X, Y = X, W = Window(X), exact = FALSE, paired = FALSE, ..., trim = spatstat.options("maxedgewt"), dx=NULL, dy=NULL, give.rmax=FALSE, gW=NULL) rmax.Trans(W, g=setcov(W))
edge.Trans(X, Y = X, W = Window(X), exact = FALSE, paired = FALSE, ..., trim = spatstat.options("maxedgewt"), dx=NULL, dy=NULL, give.rmax=FALSE, gW=NULL) rmax.Trans(W, g=setcov(W))
X , Y
|
Point patterns (objects of class |
W |
Window for which the edge correction is required. |
exact |
Logical. If |
paired |
Logical value indicating whether |
... |
Ignored. |
trim |
Maximum permitted value of the edge correction weight. |
dx , dy
|
Alternative data giving the |
give.rmax |
Logical. If |
g , gW
|
Optional. Set covariance of |
The function edge.Trans
computes Ohser and Stoyan's translation edge correction
weight, which is used in estimating the function and in many
other contexts.
The function rmax.Trans
computes the maximum value of
distance for which the translation edge correction
estimate of
is valid.
For a pair of points and
in a window
,
the translation edge correction weight
is
where is the result of shifting the window
by the vector
. The denominator is the area of the overlap between
this shifted window and the original window.
The function edge.Trans
computes this edge correction weight.
If paired=TRUE
, then X
and Y
should contain the
same number of points. The result is a vector containing the
edge correction weights e(X[i], Y[i])
for each i
.
If paired=FALSE
,
then the result is a matrix whose i,j
entry gives the
edge correction weight e(X[i], Y[j])
.
Computation is exact if the window is a rectangle. Otherwise,
if exact=TRUE
, the edge
correction weights are computed exactly using
overlap.owin
, which can be quite slow.
if exact=FALSE
(the default),
the weights are computed rapidly by evaluating the
set covariance function setcov
using the Fast Fourier Transform.
If any value of the edge correction weight exceeds trim
,
it is set to trim
.
The arguments dx
and dy
can be provided as
an alternative to X
and Y
.
If paired=TRUE
then dx,dy
should be vectors of equal length
such that the vector difference of the th pair is
c(dx[i], dy[i])
. If paired=FALSE
then
dx,dy
should be matrices of the same dimensions,
such that the vector difference between X[i]
and Y[j]
is
c(dx[i,j], dy[i,j])
. The argument W
is needed.
The value of rmax.Trans
is the shortest distance from the
origin to the boundary of the support of
the set covariance function of
W
. It is computed by pixel
approximation using setcov
, unless W
is a
rectangle, when rmax.Trans(W)
is the length of the
shortest side of the rectangle.
Numeric vector or matrix.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Ohser, J. (1983) On estimators for the reduced second moment measure of point processes. Mathematische Operationsforschung und Statistik, series Statistics, 14, 63 – 71.
rmax.Trans
,
edge.Ripley
,
setcov
,
Kest
v <- edge.Trans(cells) rmax.Trans(Window(cells))
v <- edge.Trans(cells) rmax.Trans(Window(cells))
Estimate the summary functions and
for
a marked point pattern, proposed by Schlather et al (2004) as diagnostics
for dependence between the points and the marks.
Emark(X, r=NULL, correction=c("isotropic", "Ripley", "translate"), method="density", ..., normalise=FALSE) Vmark(X, r=NULL, correction=c("isotropic", "Ripley", "translate"), method="density", ..., normalise=FALSE)
Emark(X, r=NULL, correction=c("isotropic", "Ripley", "translate"), method="density", ..., normalise=FALSE) Vmark(X, r=NULL, correction=c("isotropic", "Ripley", "translate"), method="density", ..., normalise=FALSE)
X |
The observed point pattern.
An object of class |
r |
Optional. Numeric vector. The values of the argument |
correction |
A character vector containing any selection of the
options |
method |
A character vector indicating the user's choice of
density estimation technique to be used. Options are
|
... |
Arguments passed to the density estimation routine
( |
normalise |
If |
For a marked point process,
Schlather et al (2004) defined the functions
and
to be the conditional mean
and conditional variance of the mark attached to a
typical random point, given that there exists another random
point at a distance
away from it.
More formally,
and
where denotes the conditional expectation
given that there are points of the process at the locations
and
separated by a distance
,
and where
denotes the mark attached to the point
.
These functions may serve as diagnostics for dependence
between the points and the marks. If the points and marks are
independent, then and
should be
constant (not depending on
). See Schlather et al (2004).
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern with numeric marks.
The argument r
is the vector of values for the
distance at which
is estimated.
This algorithm assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Kest
.
The edge corrections implemented here are
Ripley's isotropic correction (see Ripley, 1988; Ohser, 1983). This is implemented only for rectangular and polygonal windows (not for binary masks).
Translation correction (Ohser, 1983). Implemented for all window geometries, but slow for complex windows.
Note that the estimator assumes the process is stationary (spatially homogeneous).
The numerator and denominator of the mark correlation function (in the expression above) are estimated using density estimation techniques. The user can choose between
"density"
which uses the standard kernel
density estimation routine density
, and
works only for evenly-spaced r
values;
"loess"
which uses the function loess
in the
package modreg;
"sm"
which uses the function sm.density
in the
package sm and is extremely slow;
"smrep"
which uses the function sm.density
in the
package sm and is relatively fast, but may require manual
control of the smoothing parameter hmult
.
If marks(X)
is a numeric vector, the result is
an object of class "fv"
(see fv.object
).
If marks(X)
is a data frame, the result is
a list of objects of class "fv"
, one for each column of marks.
An object of class "fv"
is essentially
a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical, constant value of |
together with a column or columns named
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function or
obtained by the edge corrections named.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Schlather, M. and Ribeiro, P. and Diggle, P. (2004) Detecting dependence between marks and locations of marked point processes. Journal of the Royal Statistical Society, series B 66 (2004) 79-83.
Mark correlation markcorr
,
mark variogram markvario
for numeric marks.
Mark connection function markconnect
and
multitype K-functions Kcross
, Kdot
for factor-valued marks.
plot(Emark(spruces)) E <- Emark(spruces, method="density", kernel="epanechnikov") plot(Vmark(spruces)) plot(Emark(finpines)) V <- Vmark(finpines)
plot(Emark(spruces)) E <- Emark(spruces, method="density", kernel="epanechnikov") plot(Vmark(spruces)) plot(Emark(finpines)) V <- Vmark(finpines)
Computes simulation envelopes of a summary function.
envelope(Y, fun, ...) ## S3 method for class 'ppp' envelope(Y, fun=Kest, nsim=99, nrank=1, ..., funargs=list(), funYargs=funargs, simulate=NULL, fix.n=FALSE, fix.marks=FALSE, verbose=TRUE, clipdata=TRUE, transform=NULL, global=FALSE, ginterval=NULL, use.theory=NULL, alternative=c("two.sided", "less", "greater"), scale=NULL, clamp=FALSE, savefuns=FALSE, savepatterns=FALSE, nsim2=nsim, VARIANCE=FALSE, nSD=2, Yname=NULL, maxnerr=nsim, rejectNA=FALSE, silent=FALSE, do.pwrong=FALSE, envir.simul=NULL)
envelope(Y, fun, ...) ## S3 method for class 'ppp' envelope(Y, fun=Kest, nsim=99, nrank=1, ..., funargs=list(), funYargs=funargs, simulate=NULL, fix.n=FALSE, fix.marks=FALSE, verbose=TRUE, clipdata=TRUE, transform=NULL, global=FALSE, ginterval=NULL, use.theory=NULL, alternative=c("two.sided", "less", "greater"), scale=NULL, clamp=FALSE, savefuns=FALSE, savepatterns=FALSE, nsim2=nsim, VARIANCE=FALSE, nSD=2, Yname=NULL, maxnerr=nsim, rejectNA=FALSE, silent=FALSE, do.pwrong=FALSE, envir.simul=NULL)
Y |
Object containing point pattern data.
A point pattern (object of class
|
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 |
... |
Extra arguments passed to |
funargs |
A list, containing extra arguments to be passed to |
funYargs |
Optional. A list, containing extra arguments to be passed to
|
simulate |
Optional. Specifies how to generate the simulated point patterns.
If |
fix.n |
Logical. If |
fix.marks |
Logical. If |
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 |
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
( |
ginterval |
Optional.
A vector of length 2 specifying
the interval of |
use.theory |
Logical value indicating whether to use the theoretical value,
computed by |
alternative |
Character string determining whether the envelope corresponds
to a two-sided test ( |
scale |
Optional. Scaling function for global envelopes.
A function in the R language which determines the
relative scale of deviations, as a function of
distance |
clamp |
Logical value indicating how to compute envelopes when
|
savefuns |
Logical flag indicating whether to save all the simulated function values. |
savepatterns |
Logical flag indicating whether to save all the simulated point patterns. |
nsim2 |
Number of extra simulated point patterns to be generated
if it is necessary to use simulation to estimate the theoretical
mean of the summary function. Only relevant when |
VARIANCE |
Logical. If |
nSD |
Number of estimated standard deviations used to determine
the critical envelopes, if |
Yname |
Character string that should be used as the name of the
data point pattern |
maxnerr |
Maximum number of rejected patterns.
If |
rejectNA |
Logical value specifying whether to reject a simulated pattern
if the resulting values of |
silent |
Logical value specifying whether to print a report each time a simulated pattern is rejected. |
do.pwrong |
Logical. If |
envir.simul |
Environment in which to evaluate the expression |
The envelope
command performs simulations and
computes envelopes of a summary statistic based on the simulations.
The result is an object that can be plotted to display the envelopes.
The envelopes can be used to assess the goodness-of-fit of
a point process model to point pattern data.
For the most basic use, if you have a point pattern X
and
you want to test Complete Spatial Randomness (CSR), type
plot(envelope(X, Kest,nsim=39))
to see the function
for
X
plotted together with the envelopes of the
function for 39 simulations of CSR.
The envelope
function is generic, with methods for
the classes "ppp"
, "ppm"
, "kppm"
and "slrm"
described here. There are also methods for the classes "pp3"
,
"lpp"
and "lppm"
which are described separately
under envelope.pp3
and envelope.lpp
.
Envelopes can also be computed from other envelopes, using
envelope.envelope
.
To create simulation envelopes, the command envelope(Y, ...)
first generates nsim
random point patterns
in one of the following ways.
If Y
is a point pattern (an object of class "ppp"
)
and simulate=NULL
,
then we generate 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
.)
If Y
is a fitted point process model (an object of class
"ppm"
or "kppm"
or "slrm"
) and simulate=NULL
,
then this routine generates nsim
simulated
realisations of that model.
If simulate
is supplied, then it determines how the
simulated point patterns are generated. It may be either
an expression in the R language, typically containing a call
to a random generator. This expression will be evaluated
nsim
times to yield nsim
point patterns. For example
if simulate=expression(runifpoint(100))
then each simulated
pattern consists of exactly 100 independent uniform random points.
a function in the R language, typically containing a call to a
random generator. This function will be applied repeatedly
to the original data pattern Y
to yield nsim
point
patterns. For example if simulate=rlabel
then each
simulated pattern was generated by evaluating rlabel(Y)
and consists of a randomly-relabelled version of Y
.
a list of point patterns. The entries in this list will be taken as the simulated patterns.
an object of class "envelope"
. This should have been
produced by calling envelope
with the
argument savepatterns=TRUE
.
The simulated point patterns that were saved in this object
will be extracted and used as the simulated patterns for the
new envelope computation. This makes it possible to plot envelopes
for two different summary functions based on exactly the same set of
simulated 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:
by default, envelopes are calculated pointwise
(i.e. for each value of the distance argument ), by sorting the
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 , and rejecting the null hypothesis if the
observed function value
lies outside the envelope at this value of
.
This test has exact significance level
alpha = 2 * nrank/(1 + nsim)
.
if 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 perform a separate
set of nsim2
simulations, compute the
average of all these simulated values, and take this average
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 values specified by
ginterval
). This gives a
deviation value 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 = expected - dcrit
and hi = expected + dcrit
where
expected
is either the theoretical mean value theo
(if we are testing CSR) or the estimated theoretical value
mmean
(if we are testing another model). The 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 .
This test has exact significance level
alpha = nrank/(1 + nsim)
.
This test can also be performed using mad.test
.
if VARIANCE=TRUE
,
the algorithm calculates the
(pointwise) sample mean and sample variance of
the simulated functions. Then the envelopes are computed
as mean plus or minus nSD
standard deviations.
These envelopes do not have an exact significance interpretation.
They are a naive approximation to
the critical points of the Neyman-Pearson test
assuming the summary statistic is approximately Normally
distributed.
The return value is an object of class "fv"
containing
the summary function for the data point pattern,
the upper and lower simulation envelopes, and
the theoretical expected value (exact or estimated) of the summary function
for the model being tested. It can be plotted
using plot.envelope
.
If VARIANCE=TRUE
then the return value also includes the
sample mean, sample variance and other quantities.
Arguments can be passed to the function fun
through
...
. This means that you simply specify these arguments in the call to
envelope
, and they will be passed to fun
.
In particular, the argument correction
determines the edge correction to be used to calculate the summary
statistic. See the section on Edge Corrections, and the Examples.
Arguments can also be passed to the function fun
through the list funargs
. This mechanism is typically used if
an argument of fun
has the same name as an argument of
envelope
. The list funargs
should contain
entries of the form name=value
, where each name
is the name
of an argument of fun
.
There is also an option, rarely used, in which different function
arguments are used when computing the summary function
for the data Y
and for the simulated patterns.
If funYargs
is given, it will be used
when the summary function for the data Y
is computed,
while funargs
will be used when computing the summary function
for the simulated patterns.
This option is only needed in rare cases: usually the basic principle
requires that the data and simulated patterns must be treated
equally, so that funargs
and funYargs
should be identical.
If Y
is a fitted cluster point process model (object of
class "kppm"
), and simulate=NULL
,
then the model is simulated directly
using simulate.kppm
.
If Y
is a fitted Gibbs point process model (object of
class "ppm"
), 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
determines the interval of values
over which the deviation between curves is calculated.
It should be a numeric vector of length 2.
There is a sensible default (namely, the recommended plotting
interval for
fun(X)
, or the range of r
values if
r
is explicitly specified).
transform
specifies a transformation of the
summary function fun
that will be carried out before the
deviations are computed.
Such transforms are useful if global=TRUE
or
VARIANCE=TRUE
.
The transform
must be an expression object
using the symbol .
to represent the function value
(and possibly other symbols recognised by with.fv
).
For example,
the conventional way to normalise the function
(Ripley, 1981) is to transform it to the
function
and this is implemented by setting
transform=expression(sqrt(./pi))
.
It is also possible to extract the summary functions for each of the
individual simulated point patterns, by setting savefuns=TRUE
.
Then the return value also
has an attribute "simfuns"
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.
It is also possible to save the simulated point patterns themselves,
by setting savepatterns=TRUE
. Then the return value also has
an attribute "simpatterns"
which is a list of length
nsim
containing all the simulated point patterns.
See plot.envelope
and plot.fv
for information about how to plot the envelopes.
Different envelopes can be recomputed from the same data
using envelope.envelope
.
Envelopes can be combined using pool.envelope
.
An object of class "envelope"
and "fv"
, see fv.object
,
which can be printed and plotted directly.
Essentially a data frame containing columns
r |
the vector of values of the argument |
obs |
values of the summary function for the data point pattern |
lo |
lower envelope of simulations |
hi |
upper envelope of simulations |
and either
theo |
theoretical value of the summary function under CSR (Complete Spatial Randomness, a uniform Poisson point process) if the simulations were generated according to CSR |
mmean |
estimated theoretical value of the summary function, computed by averaging simulated values, if the simulations were not generated according to CSR. |
Additionally, if savepatterns=TRUE
, the return value has an attribute
"simpatterns"
which is a list containing the nsim
simulated patterns. If savefuns=TRUE
, the return value
has an attribute "simfuns"
which is an object of class
"fv"
containing the summary functions
computed for each of the nsim
simulated patterns.
An error may be generated if one of the simulations produces a
point pattern that is empty, or is otherwise unacceptable to the
function fun
.
The upper envelope may be NA
(plotted as plus or minus
infinity) if some of the function values
computed for the simulated point patterns are NA
.
Whether this occurs will depend on the function fun
,
but it usually happens when the simulated point pattern does not contain
enough points to compute a meaningful value.
Simulation envelopes do not compute confidence intervals;
they generate significance bands.
If you really need a confidence interval for the true summary function
of the point process, use lohboot
.
See also varblock
.
It is common to apply a correction for edge effects when
calculating a summary function such as the function.
Typically the user has a choice between several possible edge
corrections.
In a call to
envelope
, the user can specify the edge correction
to be applied in fun
, using the argument correction
.
See the Examples below.
Summary functions that are available in spatstat, such as
Kest
, Gest
and pcf
,
have a standard argument called correction
which specifies
the name of one or more edge corrections.
The list of available edge
corrections is different for each summary function,
and may also depend on the kind of window in which the point pattern is
recorded.
In the
case of Kest
(the default and most frequently used value of
fun
) the best edge correction is Ripley's isotropic
correction if the window is rectangular or polygonal,
and the translation correction if the window is a binary mask.
See the help files for the individual
functions for more information.
All the summary functions in spatstat
recognise the option correction="best"
which gives the “best” (most accurate) available edge correction
for that function.
In a call to envelope
, if fun
is one of the
summary functions provided in spatstat, then the default
is correction="best"
. This means that
by default, the envelope will be computed
using the “best” available edge correction.
The user can override this default by specifying the argument
correction
. For example the computation can be accelerated
by choosing another edge correction which is less accurate
than the “best” one, but faster to compute.
If fun
is a function written by the user,
then envelope
has to guess what to do.
If fun
has an argument
called correction
, or has ...
arguments,
then envelope
assumes that the function
can handle a correction argument. To compute the envelope,
fun
will be called with a correction
argument.
The default is correction="best"
, unless
overridden in the call to envelope
.
Otherwise, if fun
does not have an argument
called correction
and does not have ...
arguments,
then envelope
assumes that the function
cannot handle a correction argument. To compute the
envelope, fun
is called without a correction argument.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Baddeley, A., Diggle, P.J., Hardegen, A., Lawrence, T., Milne, R.K. and Nair, G. (2014) On tests of spatial pattern based on simulation envelopes. Ecological Monographs 84 (3) 477–489.
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.
dclf.test
,
mad.test
for envelope-based tests.
fv.object
,
plot.envelope
,
plot.fv
,
envelope.envelope
,
pool.envelope
for handling envelopes.
There are also methods for print
and summary
.
Kest
,
Gest
,
Fest
,
Jest
,
pcf
,
ppp
,
ppm
,
default.expand
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)
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)
Given a simulation envelope (object of class "envelope"
),
compute another envelope from the same simulation data
using different parameters.
## S3 method for class 'envelope' envelope(Y, fun = NULL, ..., transform=NULL, global=FALSE, VARIANCE=FALSE)
## S3 method for class 'envelope' envelope(Y, fun = NULL, ..., transform=NULL, global=FALSE, VARIANCE=FALSE)
Y |
A simulation envelope (object of class |
fun |
Optional. Summary function to be applied to the simulated point patterns. |
... , transform , global , VARIANCE
|
Parameters controlling the type of envelope that is re-computed.
See |
This function can be used to re-compute a simulation envelope from previously simulated data, using different parameter settings for the envelope: for example, a different significance level, or a global envelope instead of a pointwise envelope.
The function envelope
is generic. This is the method for
the class "envelope"
.
The argument Y
should be a simulation envelope (object of
class "envelope"
) produced by any of the methods for
envelope
. Additionally, Y
must contain either
the simulated point patterns that were used to create
the original envelope (so Y
should have been created by calling
envelope
with savepatterns=TRUE
);
the summary functions of the simulated point patterns
that were used to create
the original envelope (so Y
should have been created by calling
envelope
with savefuns=TRUE
).
If the argument fun
is given, it should be a summary function
that can be applied to the simulated point patterns that were
used to create Y
. The envelope of
the summary function fun
for these point patterns
will be computed using the parameters specified in ...
.
If fun
is not given, then:
If Y
contains the summary functions that were used to
compute the original envelope, then the new envelope will be
computed from these original summary functions.
Otherwise, if Y
contains the simulated point patterns.
then the function
Kest
will be applied to
each of these simulated point patterns, and the new envelope will
be based on the functions.
The new envelope
will be computed using the parameters specified in ...
.
See envelope
for a full list of envelope parameters.
Frequently-used parameters include nrank
and nsim
(to change the
number of simulations used and the significance level of the
envelope), global
(to change from pointwise to global
envelopes) and VARIANCE
(to compute the envelopes from the sample
moments instead of the ranks).
An envelope (object of class "envelope"
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
E <- envelope(cells, Kest, nsim=19, savefuns=TRUE, savepatterns=TRUE) E2 <- envelope(E, nrank=2) Eg <- envelope(E, global=TRUE) EG <- envelope(E, Gest) EL <- envelope(E, transform=expression(sqrt(./pi)))
E <- envelope(cells, Kest, nsim=19, savefuns=TRUE, savepatterns=TRUE) E2 <- envelope(E, nrank=2) Eg <- envelope(E, global=TRUE) EG <- envelope(E, Gest) EL <- envelope(E, transform=expression(sqrt(./pi)))
Computes simulation envelopes of a summary function for a three-dimensional point pattern.
## S3 method for class 'pp3' envelope(Y, fun=K3est, nsim=99, nrank=1, ..., funargs=list(), funYargs=funargs, simulate=NULL, verbose=TRUE, transform=NULL,global=FALSE,ginterval=NULL,use.theory=NULL, alternative=c("two.sided", "less", "greater"), scale=NULL, clamp=FALSE, savefuns=FALSE, savepatterns=FALSE, nsim2=nsim, VARIANCE=FALSE, nSD=2, Yname=NULL, maxnerr=nsim, rejectNA=FALSE, silent=FALSE, do.pwrong=FALSE, envir.simul=NULL)
## S3 method for class 'pp3' envelope(Y, fun=K3est, nsim=99, nrank=1, ..., funargs=list(), funYargs=funargs, simulate=NULL, verbose=TRUE, transform=NULL,global=FALSE,ginterval=NULL,use.theory=NULL, alternative=c("two.sided", "less", "greater"), scale=NULL, clamp=FALSE, savefuns=FALSE, savepatterns=FALSE, nsim2=nsim, VARIANCE=FALSE, nSD=2, Yname=NULL, maxnerr=nsim, rejectNA=FALSE, silent=FALSE, do.pwrong=FALSE, envir.simul=NULL)
Y |
A three-dimensional point pattern (object of class
|
fun |
Function that computes the desired summary statistic for a 3D point pattern. |
nsim |
Number of simulated point patterns to be generated when computing the envelopes. |
nrank |
Integer. Rank of the envelope value amongst the |
... |
Extra arguments passed to |
funargs |
A list, containing extra arguments to be passed to |
funYargs |
Optional. A list, containing extra arguments to be passed to
|
simulate |
Optional. Specifies how to generate the simulated point patterns.
If |
verbose |
Logical flag indicating whether to print progress reports during the simulations. |
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
( |
ginterval |
Optional.
A vector of length 2 specifying
the interval of |
use.theory |
Logical value indicating whether to use the theoretical value,
computed by |
alternative |
Character string determining whether the envelope corresponds
to a two-sided test ( |
scale |
Optional. Scaling function for global envelopes.
A function in the R language which determines the
relative scale of deviations, as a function of
distance |
clamp |
Logical value indicating how to compute envelopes when
|
savefuns |
Logical flag indicating whether to save all the simulated function values. |
savepatterns |
Logical flag indicating whether to save all the simulated point patterns. |
nsim2 |
Number of extra simulated point patterns to be generated
if it is necessary to use simulation to estimate the theoretical
mean of the summary function. Only relevant when |
VARIANCE |
Logical. If |
nSD |
Number of estimated standard deviations used to determine
the critical envelopes, if |
Yname |
Character string that should be used as the name of the
data point pattern |
maxnerr |
Maximum number of rejected patterns.
If |
rejectNA |
Logical value specifying whether to reject a simulated pattern
if the resulting values of |
silent |
Logical value specifying whether to print a report each time a simulated pattern is rejected. |
do.pwrong |
Logical. If |
envir.simul |
Environment in which to evaluate the expression |
The envelope
command performs simulations and
computes envelopes of a summary statistic based on the simulations.
The result is an object that can be plotted to display the envelopes.
The envelopes can be used to assess the goodness-of-fit of
a point process model to point pattern data.
The envelope
function is generic, with methods for
the classes "ppp"
, "ppm"
and "kppm"
described in the help file for envelope
.
This function envelope.pp3
is the method for
three-dimensional point patterns (objects of class "pp3"
).
For the most basic use, if you have a 3D point pattern X
and
you want to test Complete Spatial Randomness (CSR), type
plot(envelope(X, K3est,nsim=39))
to see the three-dimensional
function for
X
plotted together with the envelopes of
the three-dimensional function for 39 simulations of CSR.
To create simulation envelopes, the command envelope(Y, ...)
first generates nsim
random point patterns
in one of the following ways.
If simulate=NULL
,
then we generate 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 simulate
is supplied, then it determines how the
simulated point patterns are generated.
See envelope
for details.
The summary statistic fun
is applied to each of these simulated
patterns. Typically fun
is one of the functions
K3est
, G3est
, F3est
or pcf3est
.
It may also be a character string
containing the name of one of these functions.
For further information, see the documentation for
envelope
.
A function value table (object of class "fv"
)
which can be plotted directly.
See envelope
for further details.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Baddeley, A.J, Moyeed, R.A., Howard, C.V. and Boyde, A. (1993) Analysis of a three-dimensional point pattern with replication. Applied Statistics 42, 641–668.
pp3
,
rpoispp3
,
K3est
,
G3est
,
F3est
,
pcf3est
.
X <- rpoispp3(20, box3()) if(interactive()) { plot(envelope(X, nsim=39)) }
X <- rpoispp3(20, box3()) if(interactive()) { plot(envelope(X, nsim=39)) }
Compute an array of simulation envelopes using a summary function that returns an array of curves.
envelopeArray(X, fun, ..., dataname = NULL, verb = FALSE, reuse = TRUE)
envelopeArray(X, fun, ..., dataname = NULL, verb = FALSE, reuse = TRUE)
X |
Object containing point pattern data.
A point pattern (object of class
|
fun |
Function that computes the desired summary statistic
for a point pattern. The result of |
... |
Arguments passed to |
dataname |
Optional character string name for the data. |
verb |
Logical value indicating whether to print progress reports. |
reuse |
Logical value indicating whether the envelopes in each panel
should be based on the same set of simulated patterns
( |
This command is the counterpart of envelope
when the function fun
that is evaluated on each simulated point pattern
will return an object of class "fasp"
representing an array of
summary functions.
Simulated point patterns are generated according to the
rules described for envelope
. In brief,
if X
is a point pattern, the algorithm generates
simulated point patterns of the same kind, according to complete
spatial randomness. If X
is a fitted model, the algorithm
generates simulated point patterns according to this model.
For each simulated point pattern Y
, the function fun
is invoked. The result Z <- fun(Y, ...)
should be an object of
class "fasp"
representing an array of summary functions.
The dimensions of the array Z
should be the same
for each simulated pattern Y
.
This algorithm finds the simulation envelope of the summary functions in each cell of the array.
An object of class "fasp"
representing
an array of envelopes.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
if(interactive()) { Nsim <- 19 X <- finpines co <- "best" } else { ## smaller task to reduce check time Nsim <- 3 X <- finpines[c(FALSE, TRUE)] co <- "none" } A <- envelopeArray(X, markcrosscorr, nsim=Nsim, correction=co) plot(A)
if(interactive()) { Nsim <- 19 X <- finpines co <- "best" } else { ## smaller task to reduce check time Nsim <- 3 X <- finpines[c(FALSE, TRUE)] co <- "none" } A <- envelopeArray(X, markcrosscorr, nsim=Nsim, correction=co) plot(A)
Evaluates any expression involving one or more function arrays
(fasp
objects) and returns another function array.
eval.fasp(expr, envir, dotonly=TRUE)
eval.fasp(expr, envir, dotonly=TRUE)
expr |
An expression involving the names of objects of class |
envir |
Optional. The environment in which to evaluate the expression,
or a named list containing |
dotonly |
Logical. Passed to |
This is a wrapper to make it easier to perform pointwise calculations with the arrays of summary functions used in spatial statistics.
A function array (object of class "fasp"
) can be regarded as a matrix
whose entries are functions. Objects of this kind
are returned by the command alltypes
.
Suppose X
is an object of class "fasp"
.
Then eval.fasp(X+3)
effectively adds 3 to the value of
every function in the array X
, and returns
the resulting object.
Suppose X
and Y
are two objects of class "fasp"
which are compatible (for example the arrays
must have the same dimensions). Then
eval.fasp(X + Y)
will add the corresponding functions in
each cell of the arrays X
and Y
,
and return the resulting array of functions.
Suppose X
is an object of class "fasp"
and f
is an object of class "fv"
.
Then eval.fasp(X + f)
will add the function f
to the functions in each cell of the array X
,
and return the resulting array of functions.
In general, expr
can be any expression involving
(a) the names of objects of class "fasp"
or "fv"
,
(b) scalar constants, and (c) functions which are vectorised.
See the Examples.
First eval.fasp
determines which of the variable names
in the expression expr
refer to objects of class "fasp"
.
The expression is then evaluated for each cell of the array
using eval.fv
.
The expression expr
must be vectorised.
There must be at least one object of class "fasp"
in the expression.
All such objects must be compatible.
Another object of class "fasp"
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
K <- alltypes(amacrine, "K") # expressions involving a fasp object eval.fasp(K + 3) L <- eval.fasp(sqrt(K/pi)) # expression involving two fasp objects D <- eval.fasp(K - L) # subtracting the unmarked K function from the cross-type K functions K0 <- Kest(unmark(amacrine)) DK <- eval.fasp(K - K0) ## Use of 'envir' S <- eval.fasp(1-G, list(G=alltypes(amacrine, 'G')))
K <- alltypes(amacrine, "K") # expressions involving a fasp object eval.fasp(K + 3) L <- eval.fasp(sqrt(K/pi)) # expression involving two fasp objects D <- eval.fasp(K - L) # subtracting the unmarked K function from the cross-type K functions K0 <- Kest(unmark(amacrine)) DK <- eval.fasp(K - K0) ## Use of 'envir' S <- eval.fasp(1-G, list(G=alltypes(amacrine, 'G')))
Evaluates any expression involving one or more function value (fv) objects, and returns another object of the same kind.
eval.fv(expr, envir, dotonly=TRUE, equiv=NULL, relabel=TRUE)
eval.fv(expr, envir, dotonly=TRUE, equiv=NULL, relabel=TRUE)
expr |
An expression. |
envir |
Optional. The environment in which to evaluate the
expression, or a named list containing |
dotonly |
Logical. See Details. |
equiv |
Mapping between column names of different objects that are deemed to be equivalent. See Details. |
relabel |
Logical value indicating whether to
compute appropriate labels for the resulting function.
This should normally be |
This is a wrapper to make it easier to perform pointwise calculations with the summary functions used in spatial statistics.
An object of class "fv"
is essentially a data frame
containing several different statistical estimates of the same
function. Such objects are returned by Kest
and its
relatives.
For example, suppose X
is an object of class "fv"
containing several different estimates of the Ripley's K function ,
evaluated at a sequence of values of
.
Then
eval.fv(X+3)
effectively adds 3 to
each function estimate in X
, and returns
the resulting object.
Suppose X
and Y
are two objects of class "fv"
which are compatible (in particular they have the same vector
of values). Then
eval.im(X + Y)
will add the corresponding function values in
X
and Y
, and return the resulting function.
In general, expr
can be any expression involving
(a) the names of objects of class "fv"
, (b) scalar
constants, and (c) functions which are vectorised.
See the Examples.
First eval.fv
determines which of the variable names
in the expression expr
refer to objects of class "fv"
.
Each such name is replaced by a vector containing the function values.
The expression is then evaluated. The result should be a vector;
it is taken as the new vector of function values.
The expression expr
must be vectorised.
There must be at least one object of class "fv"
in the expression.
If the objects are not compatible, they will be made compatible
by harmonise.fv
.
If dotonly=TRUE
(the default), the expression will be
evaluated only for those columns of an "fv"
object
that contain values of the function itself (rather than
values of the derivative of the function, the hazard rate, etc).
If dotonly=FALSE
, the expression will be evaluated for all columns.
For example the result of Fest
includes several columns
containing estimates of the empty space function ,
but also includes an estimate of the
hazard
of
. Transformations that are valid
for
may not be valid for
. Accordingly,
would
normally be omitted from the calculation.
The columns of an object x
that represent the function itself
are identified by its “dot” names, fvnames(x, ".")
.
They are the columns normally plotted by plot.fv
and identified by the symbol "."
in plot formulas
in plot.fv
.
The argument equiv
can be used to specify that
two different column names in different function objects
are mathematically equivalent or cognate.
It should be a list of name=value
pairs, or a named vector of
character strings, indicating the pairing of equivalent names.
(Without this argument, these columns would be discarded.)
See the Examples.
The argument relabel
should normally be TRUE
(the default).
It determines whether to compute appropriate mathematical labels and
descriptions for the resulting function object
(used when the object is printed or plotted).
If relabel=FALSE
then this does not occur,
and the mathematical labels and descriptions
in the result are taken from the function object
that appears first in the expression. This reduces computation time
slightly (for advanced use only).
Another object of class "fv"
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
# manipulating the K function X <- runifrect(42) Ks <- Kest(X) eval.fv(Ks + 3) Ls <- eval.fv(sqrt(Ks/pi)) # manipulating two K functions Y <- runifrect(20) Kr <- Kest(Y) Kdif <- eval.fv(Ks - Kr) Z <- eval.fv(sqrt(Ks/pi) - sqrt(Kr/pi)) ## Use of 'envir' U <- eval.fv(sqrt(K), list(K=Ks)) ## Use of 'equiv' Fc <- Fest(cells) Gc <- Gest(cells) # Hanisch and Chiu-Stoyan estimators are cognate Dc <- eval.fv(Fc - Gc, equiv=list(cs="han"))
# manipulating the K function X <- runifrect(42) Ks <- Kest(X) eval.fv(Ks + 3) Ls <- eval.fv(sqrt(Ks/pi)) # manipulating two K functions Y <- runifrect(20) Kr <- Kest(Y) Kdif <- eval.fv(Ks - Kr) Z <- eval.fv(sqrt(Ks/pi) - sqrt(Kr/pi)) ## Use of 'envir' U <- eval.fv(sqrt(K), list(K=Ks)) ## Use of 'equiv' Fc <- Fest(cells) Gc <- Gest(cells) # Hanisch and Chiu-Stoyan estimators are cognate Dc <- eval.fv(Fc - Gc, equiv=list(cs="han"))
Extract a subset of a function array (an object of class
"fasp"
).
## S3 method for class 'fasp' x[I, J, drop=TRUE,...]
## S3 method for class 'fasp' x[I, J, drop=TRUE,...]
x |
A function array. An object of class |
I |
any valid expression for a subset of the row indices of the array. |
J |
any valid expression for a subset of the column indices of the array. |
drop |
Logical.
When the selected subset consists of only one cell of the array,
if |
... |
Ignored. |
A function array can be regarded as a matrix whose entries
are functions. See fasp.object
for an explanation of
function arrays.
This routine extracts a sub-array according to the usual conventions for matrix indexing.
A function array (of class "fasp"
).
Exceptionally, if the array has only one cell, and
if drop=TRUE
, then the result is a function value table
(class "fv"
).
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
online <- interactive() # Lansing woods data - multitype points with 6 types X <- lansing if(!online) { # subsample data (from 2251 to 450 points) to shorten check time X <- X[c(FALSE,FALSE,FALSE,FALSE,TRUE)] } a <- alltypes(X, 'K') # extract first three marks only b <- a[1:3,1:3] if(online) {plot(b)} # subset of array pertaining to hickories h <- a["hickory", ] if(online) {plot(h)}
online <- interactive() # Lansing woods data - multitype points with 6 types X <- lansing if(!online) { # subsample data (from 2251 to 450 points) to shorten check time X <- X[c(FALSE,FALSE,FALSE,FALSE,TRUE)] } a <- alltypes(X, 'K') # extract first three marks only b <- a[1:3,1:3] if(online) {plot(b)} # subset of array pertaining to hickories h <- a["hickory", ] if(online) {plot(h)}
Extract or replace a subset of an object of class "fv"
.
## S3 method for class 'fv' x[i, j, ..., drop=FALSE] ## S3 replacement method for class 'fv' x[i, j] <- value ## S3 replacement method for class 'fv' x$name <- value
## S3 method for class 'fv' x[i, j, ..., drop=FALSE] ## S3 replacement method for class 'fv' x[i, j] <- value ## S3 replacement method for class 'fv' x$name <- value
x |
a function value object,
of class |
i |
any appropriate subset index.
Selects a subset of the rows of the data frame, i.e.
a subset of the domain of the function(s) represented by |
j |
any appropriate subset index for the columns of the data frame.
Selects some of the functions present in |
name |
the name of a column of the data frame. |
... |
Ignored. |
drop |
Logical. If |
value |
Replacement value for the column or columns selected by
|
These functions extract a designated subset of an object of class
"fv"
, or replace the designated subset with other data,
or delete the designated subset.
The subset is specified by the
row index i
and column index j
, or
by the column name name
. Either i
or j
may be missing, or both may be missing.
The function [.fv
is a method for the generic operator
[
for the class "fv"
. It extracts the
designated subset of x
, and returns it as
another object of class "fv"
(if drop=FALSE
)
or as a data frame or vector (if drop=TRUE
).
The function [<-.fv
is a method for the generic operator
[<-
for the class "fv"
.
If value
is NULL
, the designated subset of x
will be
deleted from x
.
Otherwise, the designated subset of x
will be
replaced by the data contained in value
.
The return value is the modified object x
.
The function $<-.fv
is a method for the generic operator
$<-
for the class "fv"
.
If value
is NULL
, the designated column of x
will be
deleted from x
.
Otherwise, the designated column of x
will be
replaced by the data contained in value
.
The return value is the modified object x
.
The result of [.fv
with drop=TRUE
is a data frame or vector.
Otherwise, the result is another object of class "fv"
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
K <- Kest(cells) # discard the estimates of K(r) for r > 0.1 Ksub <- K[K$r <= 0.1, ] # extract the border method estimates bor <- K[ , "border", drop=TRUE] # or equivalently bor <- K$border # remove the border-method estimates K$border <- NULL K
K <- Kest(cells) # discard the estimates of K(r) for r > 0.1 Ksub <- K[K$r <= 0.1, ] # extract the border method estimates bor <- K[ , "border", drop=TRUE] # or equivalently bor <- K$border # remove the border-method estimates K$border <- NULL K
Estimates the empty space function from
a three-dimensional point pattern.
F3est(X, ..., rmax = NULL, nrval = 128, vside = NULL, correction = c("rs", "km", "cs"), sphere = c("fudge", "ideal", "digital"))
F3est(X, ..., rmax = NULL, nrval = 128, vside = NULL, correction = c("rs", "km", "cs"), sphere = c("fudge", "ideal", "digital"))
X |
Three-dimensional point pattern (object of class |
... |
Ignored. |
rmax |
Optional. Maximum value of argument |
nrval |
Optional. Number of values of |
vside |
Optional. Side length of the voxels in the discrete approximation. |
correction |
Optional. Character vector specifying the edge correction(s) to be applied. See Details. |
sphere |
Optional. Character string specifying how to calculate the
theoretical value of |
For a stationary point process in three-dimensional
space, the empty space function is
where denotes the distance from a fixed
origin
to the nearest point of
.
The three-dimensional point pattern X
is assumed to be a
partial realisation of a stationary point process .
The empty space function of
can then be estimated using
techniques described in the References.
The box containing the point
pattern is discretised into cubic voxels of side length vside
.
The distance function is computed for
every voxel centre point
using a three-dimensional version of the distance transform
algorithm (Borgefors, 1986). The empirical cumulative distribution
function of these values, with appropriate edge corrections, is the
estimate of
.
The available edge corrections are:
"rs"
:the reduced sample (aka minus sampling, border correction) estimator (Baddeley et al, 1993)
"km"
:the three-dimensional version of the Kaplan-Meier estimator (Baddeley and Gill, 1997)
"cs"
:the three-dimensional generalisation of the Chiu-Stoyan or Hanisch estimator (Chiu and Stoyan, 1998).
Alternatively correction="all"
selects all options.
The result includes a column theo
giving the
theoretical value of for
a uniform Poisson process (Complete Spatial Randomness).
This value depends on the volume of the sphere of radius
r
measured in the discretised distance metric.
The argument sphere
determines how this will be calculated.
If sphere="ideal"
the calculation will use the
volume of an ideal sphere of radius namely
. This is not recommended
because the theoretical values of
are inaccurate.
If sphere="fudge"
then the volume of the ideal sphere will
be multiplied by 0.78, which gives the approximate volume
of the sphere in the discretised distance metric.
If sphere="digital"
then the volume of the sphere in the
discretised distance metric is computed exactly using another
distance transform. This takes longer to compute, but is exact.
A function value table (object of class "fv"
) that can be
plotted, printed or coerced to a data frame containing the function values.
A small value of vside
and a large value of nrval
are required for reasonable accuracy.
The default value of vside
ensures that the total number of
voxels is 2^22
or about 4 million.
To change the default number of voxels, see
spatstat.options("nvoxel")
.
Adrian Baddeley [email protected]
and Rana Moyeed.
Baddeley, A.J, Moyeed, R.A., Howard, C.V. and Boyde, A. Analysis of a three-dimensional point pattern with replication. Applied Statistics 42 (1993) 641–668.
Baddeley, A.J. and Gill, R.D. (1997) Kaplan-Meier estimators of interpoint distance distributions for spatial point processes. Annals of Statistics 25, 263–292.
Borgefors, G. (1986) Distance transformations in digital images. Computer Vision, Graphics and Image Processing 34, 344–371.
Chiu, S.N. and Stoyan, D. (1998) Estimators of distance distributions for spatial patterns. Statistica Neerlandica 52, 239–246.
pp3
to create a three-dimensional point
pattern (object of class "pp3"
).
G3est
,
K3est
,
pcf3est
for other summary functions of
a three-dimensional point pattern.
Fest
to estimate the empty space function of
point patterns in two dimensions.
X <- rpoispp3(42) Z <- F3est(X) if(interactive()) plot(Z)
X <- rpoispp3(42) Z <- F3est(X) if(interactive()) plot(Z)
A class "fasp"
to represent a “matrix”
of functions, amenable to plotting as a matrix of plot panels.
An object of this class is a convenient way of storing
(and later plotting, editing, etc)
a set of functions of a real argument
,
defined for each possible pair
of indices
. We may think of this
as a matrix or array of functions
.
Function arrays are particularly useful in the
analysis of a multitype point pattern (a point pattern in which
the points are identified as belonging to separate types).
We may want to compute a summary function for the points
of type only, for each of the possible types
.
This produces a
array of functions.
Alternatively we may compute a summary function
for each possible pair of types
.
This produces an
array of functions.
For multitype point patterns the command alltypes
will compute arrays of summary functions for each possible
type or for each possible pair of types.
The function alltypes
returns an object of class "fasp"
.
An object of class "fasp"
is a list containing at least the
following components:
A list of data frames, each representing one of the functions.
A matrix representing the spatial arrangement of the
functions. If which[i,j] = k
then the function represented by fns[[k]]
should be plotted
in the panel at position . If
which[i,j] = NA
then nothing is plotted in that position.
A list of character strings, providing suitable plotting titles for the functions.
A list of default formulae for plotting each of the functions.
A character string, giving a default title for the array when it is plotted.
There are methods for plot
, print
and "["
for this class.
The plot method displays the entire array of functions.
The method [.fasp
selects a sub-array using the natural
indices i,j
.
The command eval.fasp
can be used to apply
a transformation to each function in the array,
and to combine two arrays.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
alltypes
,
plot.fasp
,
[.fasp
,
eval.fasp
GG <- alltypes(amacrine, 'G') plot(GG) # select the row corresponding to cells of type "on" Gon <- GG["on", ] plot(Gon) # extract the G function for i = "on", j = "off" Gonoff <- GG["on", "off", drop=TRUE] # Fisher variance stabilising transformation GGfish <- eval.fasp(asin(sqrt(GG))) plot(GGfish)
GG <- alltypes(amacrine, 'G') plot(GG) # select the row corresponding to cells of type "on" Gon <- GG["on", ] plot(Gon) # extract the G function for i = "on", j = "off" Gonoff <- GG["on", "off", drop=TRUE] # Fisher variance stabilising transformation GGfish <- eval.fasp(asin(sqrt(GG))) plot(GGfish)
Estimates the empty space function
or its hazard rate
from a point pattern in a
window of arbitrary shape.
Fest(X, ..., eps, r=NULL, breaks=NULL, correction=c("rs", "km", "cs"), domain=NULL) Fhazard(X, ...)
Fest(X, ..., eps, r=NULL, breaks=NULL, correction=c("rs", "km", "cs"), domain=NULL) Fhazard(X, ...)
X |
The observed point pattern,
from which an estimate of |
... |
Extra arguments, passed from |
eps |
Optional. A positive number. The resolution of the discrete approximation to Euclidean distance (see below). There is a sensible default. |
r |
Optional. Numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
correction |
Optional.
The edge correction(s) to be used to estimate |
domain |
Optional. Calculations will be restricted to this subset of the window. See Details. |
Fest
computes an estimate of the empty space function ,
and
Fhazard
computes an estimate of its hazard rate .
The empty space function
(also called the “spherical contact distribution”
or the “point-to-nearest-event” distribution)
of a stationary point process
is the cumulative distribution function
of the distance
from a fixed point in space to the nearest point of
.
An estimate of derived from a spatial point pattern dataset
can be used in exploratory data analysis and formal inference
about the pattern (Cressie, 1991; Diggle, 1983; Ripley, 1988).
In exploratory analyses, the estimate of
is a useful statistic
summarising the sizes of gaps in the pattern.
For inferential purposes, the estimate of
is usually compared to the
true value of
for a completely random (Poisson) point process,
which is
where
is the intensity (expected number of points per unit area).
Deviations between the empirical and theoretical
curves
may suggest spatial clustering or spatial regularity.
This algorithm estimates the empty space function
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
) may have arbitrary shape.
The argument X
is interpreted as a point pattern object
(of class "ppp"
, see ppp.object
) and can
be supplied in any of the formats recognised
by as.ppp
.
The algorithm uses two discrete approximations which are controlled
by the parameter eps
and by the spacing of values of r
respectively. (See below for details.)
First-time users are strongly advised not to specify these arguments.
The estimation of is hampered by edge effects arising from
the unobservability of points of the random pattern outside the window.
An edge correction is needed to reduce bias (Baddeley, 1998; Ripley, 1988).
The edge corrections implemented here are the border method or
"reduced sample" estimator, the spatial Kaplan-Meier estimator
(Baddeley and Gill, 1997) and the Chiu-Stoyan estimator (Chiu and
Stoyan, 1998).
Our implementation makes essential use of the distance transform algorithm
of image processing (Borgefors, 1986). A fine grid of pixels is
created in the observation window. The Euclidean distance between two pixels
is approximated by the length of the shortest path joining them in the grid,
where a path is a sequence of steps between adjacent pixels, and
horizontal, vertical and diagonal steps have length
,
and
respectively in pixel units. If the pixel grid is sufficiently fine then
this is an accurate approximation.
The parameter eps
is the pixel width of the rectangular raster
used to compute the distance transform (see below). It must not be too
large: the absolute error in distance values due to discretisation is bounded
by eps
.
If eps
is not specified, the function
checks whether the window Window(X)
contains pixel raster
information. If so, then eps
is set equal to the
pixel width of the raster; otherwise, eps
defaults to 1/100 of the width of the observation window.
The argument r
is the vector of values for the
distance at which
should be evaluated.
It is also used to determine the breakpoints
(in the sense of
hist
)
for the computation of histograms of distances. The
estimators are computed from histogram counts.
This introduces a discretisation
error which is controlled by the fineness of the breakpoints.
First-time users would be strongly advised not to specify r
.
However, if it is specified, r
must satisfy r[1] = 0
,
and max(r)
must be larger than the radius of the largest disc
contained in the window. Furthermore, the spacing of successive
r
values must be very fine (ideally not greater than eps/4
).
The algorithm also returns an estimate of the hazard rate function,
of
. The hazard rate is
defined by
The hazard rate of has been proposed as a useful
exploratory statistic (Baddeley and Gill, 1994).
The estimate of
given here
is a discrete approximation to the hazard rate of the
Kaplan-Meier estimator of
. Note that
is
absolutely continuous (for any stationary point process
),
so the hazard function always exists (Baddeley and Gill, 1997).
If the argument domain
is given, the estimate of
will be based only on the empty space distances
measured from locations inside
domain
(although their
nearest data points may lie outside domain
).
This is useful in bootstrap techniques. The argument domain
should be a window (object of class "owin"
) or something acceptable to
as.owin
. It must be a subset of the
window of the point pattern X
.
The naive empirical distribution of distances from each location
in the window to the nearest point of the data pattern, is a biased
estimate of . However this is also returned by the algorithm
(if
correction="none"
),
as it is sometimes useful in other contexts.
Care should be taken not to use the uncorrected
empirical as if it were an unbiased estimator of
.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
The result of Fest
is
essentially a data frame containing up to seven columns:
r |
the values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
km |
the spatial Kaplan-Meier estimator of |
hazard |
the hazard rate |
cs |
the Chiu-Stoyan estimator of |
raw |
the uncorrected estimate of |
theo |
the theoretical value of |
The result of Fhazard
contains only three columns
r |
the values of the argument |
hazard |
the spatial Kaplan-Meier estimate of the
hazard rate |
theo |
the theoretical value of |
The reduced sample (border method)
estimator of is pointwise approximately
unbiased, but need not be a valid distribution function; it may
not be a nondecreasing function of
. Its range is always
within
.
The spatial Kaplan-Meier estimator of is always nondecreasing
but its maximum value may be less than
.
The estimate of hazard rate
returned by the algorithm is an approximately
unbiased estimate for the integral of
over the corresponding histogram cell.
It may exhibit oscillations due to discretisation effects.
We recommend modest smoothing, such as kernel smoothing with
kernel width equal to the width of a histogram cell,
using
Smooth.fv
.
Sizeable amounts of memory may be needed during the calculation.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Baddeley, A.J. Spatial sampling and censoring. In O.E. Barndorff-Nielsen, W.S. Kendall and M.N.M. van Lieshout (eds) Stochastic Geometry: Likelihood and Computation. Chapman and Hall, 1998. Chapter 2, pages 37-78.
Baddeley, A.J. and Gill, R.D. The empty space hazard of a spatial pattern. Research Report 1994/3, Department of Mathematics, University of Western Australia, May 1994.
Baddeley, A.J. and Gill, R.D. Kaplan-Meier estimators of interpoint distance distributions for spatial point processes. Annals of Statistics 25 (1997) 263-292.
Borgefors, G. Distance transformations in digital images. Computer Vision, Graphics and Image Processing 34 (1986) 344-371.
Chiu, S.N. and Stoyan, D. (1998) Estimators of distance distributions for spatial patterns. Statistica Neerlandica 52, 239–246.
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
Gest
,
Jest
,
Kest
,
km.rs
,
reduced.sample
,
kaplan.meier
Fc <- Fest(cells, 0.01) # Tip: don't use F for the left hand side! # That's an abbreviation for FALSE plot(Fc) # P-P style plot plot(Fc, cbind(km, theo) ~ theo) # The empirical F is above the Poisson F # indicating an inhibited pattern if(interactive()) { plot(Fc, . ~ theo) plot(Fc, asin(sqrt(.)) ~ asin(sqrt(theo))) }
Fc <- Fest(cells, 0.01) # Tip: don't use F for the left hand side! # That's an abbreviation for FALSE plot(Fc) # P-P style plot plot(Fc, cbind(km, theo) ~ theo) # The empirical F is above the Poisson F # indicating an inhibited pattern if(interactive()) { plot(Fc, . ~ theo) plot(Fc, asin(sqrt(.)) ~ asin(sqrt(theo))) }
Estimates the inhomogeneous empty space function of a non-stationary point pattern.
Finhom(X, lambda = NULL, lmin = NULL, ..., sigma = NULL, varcov = NULL, r = NULL, breaks = NULL, ratio = FALSE, update = TRUE, warn.bias=TRUE, savelambda=FALSE)
Finhom(X, lambda = NULL, lmin = NULL, ..., sigma = NULL, varcov = NULL, r = NULL, breaks = NULL, ratio = FALSE, update = TRUE, warn.bias=TRUE, savelambda=FALSE)
X |
The observed data point pattern,
from which an estimate of the inhomogeneous |
lambda |
Optional.
Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern |
lmin |
Optional. The minimum possible value of the intensity over the spatial domain. A positive numerical value. |
sigma , varcov
|
Optional arguments passed to |
... |
Extra arguments passed to |
r |
vector of values for the argument |
breaks |
This argument is for internal use only. |
ratio |
Logical.
If |
update |
Logical. If |
warn.bias |
Logical value specifying whether to issue a warning when the inhomogeneity correction factor takes extreme values, which can often lead to biased results. This usually occurs when insufficient smoothing is used to estimate the intensity. |
savelambda |
Logical value specifying whether to save the values of
|
This command computes estimates of the
inhomogeneous -function (van Lieshout, 2010)
of a point pattern. It is the counterpart, for inhomogeneous
spatial point patterns, of the empty space function
for homogeneous point patterns computed by
Fest
.
The argument X
should be a point pattern
(object of class "ppp"
).
The inhomogeneous function is computed
using the border correction, equation (6) in Van Lieshout (2010).
The argument lambda
should supply the
(estimated) values of the intensity function
of the point process. It may be either
containing the values
of the intensity function at the points of the pattern X
.
(object of class "im"
)
assumed to contain the values of the intensity function
at all locations in the window.
(object of class "ppm"
or "kppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
which can be evaluated to give values of the intensity at any locations.
if lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
If lambda
is a numeric vector, then its length should
be equal to the number of points in the pattern X
.
The value lambda[i]
is assumed to be the
the (estimated) value of the intensity
for
the point
of the pattern
.
Each value must be a positive number;
NA
's are not allowed.
If lambda
is a pixel image, the domain of the image should
cover the entire window of the point pattern. If it does not (which
may occur near the boundary because of discretisation error),
then the missing pixel values
will be obtained by applying a Gaussian blur to lambda
using
blur
, then looking up the values of this blurred image
for the missing locations.
(A warning will be issued in this case.)
If lambda
is a function, then it will be evaluated in the
form lambda(x,y)
where x
and y
are vectors
of coordinates of the points of X
. It should return a numeric
vector with length equal to the number of points in X
.
If lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother. The estimate lambda[i]
for the
point X[i]
is computed by removing X[i]
from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point X[i]
. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Original code by Marie-Colette van Lieshout. C implementation and R adaptation by Adrian Baddeley [email protected] and Ege Rubak [email protected].
Van Lieshout, M.N.M. and Baddeley, A.J. (1996) A nonparametric measure of spatial interaction in point patterns. Statistica Neerlandica 50, 344–361.
Van Lieshout, M.N.M. (2010) A J-function for inhomogeneous point processes. Statistica Neerlandica 65, 183–201.
online <- interactive() if(online) { plot(Finhom(swedishpines, sigma=10)) plot(Finhom(swedishpines, sigma=bw.diggle, adjust=2)) } else { ## use a coarse grid for faster computation and package testing plot(Finhom(swedishpines, sigma=10, dimyx=32)) }
online <- interactive() if(online) { plot(Finhom(swedishpines, sigma=10)) plot(Finhom(swedishpines, sigma=bw.diggle, adjust=2)) } else { ## use a coarse grid for faster computation and package testing plot(Finhom(swedishpines, sigma=10, dimyx=32)) }
For a marked point pattern,
estimate the inhomogeneous version of the multitype function,
effectively the cumulative distribution function of the distance from
a fixed point to the nearest point in subset
,
adjusted for spatially varying intensity.
Fmulti.inhom(X, J, lambda = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL) FmultiInhom(X, J, lambda = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL)
Fmulti.inhom(X, J, lambda = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL) FmultiInhom(X, J, lambda = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL)
X |
A spatial point pattern (object of class |
J |
A subset index specifying the subset of points to which
distances are measured. Any kind of subset index acceptable
to |
lambda |
Intensity estimates for each point of |
lambdaJ |
Intensity estimates for each point of |
lambdamin |
A lower bound for the intensity,
or at least a lower bound for the values in |
... |
Extra arguments passed to |
r |
Vector of distance values at which the inhomogeneous |
See Cronie and Van Lieshout (2015).
The functions FmultiInhom
and Fmulti.inhom
are identical.
Object of class "fv"
containing the estimate of the
inhomogeneous multitype function.
Ottmar Cronie and Marie-Colette van Lieshout. Rewritten for spatstat by Adrian Baddeley [email protected].
Cronie, O. and Van Lieshout, M.N.M. (2015) Summary statistics for inhomogeneous marked point processes. Annals of the Institute of Statistical Mathematics DOI: 10.1007/s10463-015-0515-z
X <- amacrine J <- (marks(X) == "off") online <- interactive() eps <- if(online) NULL else 0.025 if(online && require(spatstat.model)) { mod <- ppm(X ~ marks * x, eps=eps) lambdaX <- fitted(mod, dataonly=TRUE) lambdaOff <- predict(mod, eps=eps)[["off"]] lmin <- min(lambdaOff) * 0.9 } else { ## faster computation for package checker only lambdaX <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 } plot(FmultiInhom(X, J, lambda=lambdaX, lambdamin=lmin, eps=eps))
X <- amacrine J <- (marks(X) == "off") online <- interactive() eps <- if(online) NULL else 0.025 if(online && require(spatstat.model)) { mod <- ppm(X ~ marks * x, eps=eps) lambdaX <- fitted(mod, dataonly=TRUE) lambdaOff <- predict(mod, eps=eps)[["off"]] lmin <- min(lambdaOff) * 0.9 } else { ## faster computation for package checker only lambdaX <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 } plot(FmultiInhom(X, J, lambda=lambdaX, lambdamin=lmin, eps=eps))
Extract or change the default plotting formula
for an object of class "fv"
(function value table).
## S3 method for class 'fv' formula(x, ...) formula(x, ...) <- value ## S3 replacement method for class 'fv' formula(x, ...) <- value
## S3 method for class 'fv' formula(x, ...) formula(x, ...) <- value ## S3 replacement method for class 'fv' formula(x, ...) <- value
x |
An object of class |
... |
Arguments passed to other methods. |
value |
New value of the formula. Either a |
A function value table
(object of class "fv"
, see fv.object
)
is a convenient way of storing and plotting
several different estimates of the same function.
The default behaviour of plot(x)
for a function value table
x
is determined by a formula
associated with x
called its plot formula.
See plot.fv
for explanation about these formulae.
The function formula.fv
is a method for the generic command
formula
. It extracts the plot formula associated with
the object.
The function formula<-
is generic. It changes the formula
associated with an object.
The function formula<-.fv
is the method for formula<-
for the class "fv"
. It changes the plot formula associated with
the object.
The result of formula.fv
is a character string containing the
plot formula. The result of formula<-.fv
is a new object of
class "fv"
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
K <- Kest(cells) formula(K) formula(K) <- (iso ~ r)
K <- Kest(cells) formula(K) formula(K) <- (iso ~ r)
Displays the Fry plot (Patterson plot) of a spatial point pattern.
fryplot(X, ..., width=NULL, from=NULL, to=NULL, axes=FALSE) frypoints(X, from=NULL, to=NULL, dmax=Inf)
fryplot(X, ..., width=NULL, from=NULL, to=NULL, axes=FALSE) frypoints(X, from=NULL, to=NULL, dmax=Inf)
X |
A point pattern (object of class |
... |
Optional arguments to control the appearance of the plot. |
width |
Optional parameter indicating the width of a box for a zoomed-in view of the Fry plot near the origin. |
from , to
|
Optional. Subset indices specifying which points of |
axes |
Logical value indicating whether to draw axes, crossing at the origin. |
dmax |
Maximum distance between points. Pairs at greater distances do not contribute to the result. The default means there is no maximum distance. |
The function fryplot
generates a Fry plot (or Patterson plot);
frypoints
returns the points of the Fry plot as a point pattern
dataset.
Fry (1979) and Hanna and Fry (1979) introduced a manual graphical method for
investigating features of a spatial point pattern of mineral deposits.
A transparent sheet, marked
with an origin or centre point, is placed over the point pattern.
The transparent sheet is shifted so that the origin lies over one of
the data points, and the positions of all the other data points
are copied onto the transparent sheet. This procedure is repeated for
each data point in turn. The resulting plot (the Fry plot)
is a pattern of points, where
is the original number
of data points. This procedure was previously proposed by
Patterson (1934, 1935) for studying inter-atomic distances in
crystals, and is also known as a Patterson plot.
The function fryplot
generates the Fry/Patterson plot.
Standard graphical parameters
such as main
, pch
,
lwd
, col
, bg
, cex
can be used to control
the appearance of the plot.
To zoom in (to view only a subset of the Fry plot at higher
magnification), use the argument width
to specify the width
of a rectangular field of view centred at the origin, or the standard
graphical arguments xlim
and ylim
to specify another
rectangular field of view. (The actual field of view may be slightly
larger, depending on the graphics device.)
The function frypoints
returns the points of the Fry
plot as a point pattern object. There may be a large number of points
in this pattern, so this function should be used only if further
analysis of the Fry plot is required.
Fry plots are particularly useful for recognising anisotropy in regular point patterns. A void around the origin in the Fry plot suggests regularity (inhibition between points) and the shape of the void gives a clue to anisotropy in the pattern. Fry plots are also useful for detecting periodicity or rounding of the spatial coordinates.
In mathematical terms, the Fry plot of a point pattern X
is simply a plot of the vectors X[i] - X[j]
connecting all
pairs of distinct points in X
.
The Fry plot is related to the function (see
Kest
) and the reduced second moment measure
(see Kmeasure
). For example, the number
of points in the Fry plot lying within a circle of given radius
is an unnormalised and uncorrected version of the function.
The Fry plot has a similar appearance to the plot of the
reduced second moment measure
Kmeasure
when the
smoothing parameter sigma
is very small.
The Fry plot does not adjust for the effect
of the size and shape of the sampling window.
The density of points in the Fry plot tapers off near the edges of the
plot. This is an edge effect, a consequence of the bounded sampling
window. In geological applications this is usually not
important, because interest is focused on the behaviour near the
origin where edge effects can be ignored.
To correct for the edge effect, use Kmeasure
or
Kest
or its relatives.
fryplot
returns NULL
.
frypoints
returns a point pattern (object of class "ppp"
).
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Fry, N. (1979) Random point distributions and strain measurement in rocks. Tectonophysics 60, 89–105.
Hanna, S.S. and Fry, N. (1979) A comparison of methods of strain determination in rocks from southwest Dyfed (Pembrokeshire) and adjacent areas. Journal of Structural Geology 1, 155–162.
Patterson, A.L. (1934) A Fourier series method for the determination of the component of inter-atomic distances in crystals. Physics Reviews 46, 372–376.
Patterson, A.L. (1935) A direct method for the determination of the components of inter-atomic distances in crystals. Zeitschrift fuer Krystallographie 90, 517–554.
## unmarked data fryplot(cells) Y <- frypoints(cells) ## numerical marks fryplot(longleaf, width=4, axes=TRUE) ## multitype points fryplot(amacrine, width=0.2, from=(marks(amacrine) == "on"), chars=c(3,16), cols=2:3, main="Fry plot centred at an On-cell") points(0,0)
## unmarked data fryplot(cells) Y <- frypoints(cells) ## numerical marks fryplot(longleaf, width=4, axes=TRUE) ## multitype points fryplot(amacrine, width=0.2, from=(marks(amacrine) == "on"), chars=c(3,16), cols=2:3, main="Fry plot centred at an On-cell") points(0,0)
Advanced Use Only.
This low-level function creates an object of class "fv"
from raw numerical data.
fv(x, argu = "r", ylab = NULL, valu, fmla = NULL, alim = NULL, labl = names(x), desc = NULL, unitname = NULL, fname = NULL, yexp = ylab)
fv(x, argu = "r", ylab = NULL, valu, fmla = NULL, alim = NULL, labl = names(x), desc = NULL, unitname = NULL, fname = NULL, yexp = ylab)
x |
A data frame with at least 2 columns containing the values of the function argument and the corresponding values of (one or more versions of) the function. |
argu |
String. The name of the column of |
ylab |
Either |
valu |
String. The name of the column of |
fmla |
Either |
alim |
Optional. The default range of values of the function argument for which the function will be plotted. Numeric vector of length 2. |
labl |
Optional. Plot labels for the columns of |
desc |
Optional. Descriptions of the columns of |
unitname |
Optional. Name of the unit (usually a unit of length) in which the function argument is expressed. Either a single character string, or a vector of two character strings giving the singular and plural forms, respectively. |
fname |
Optional. The name of the function itself. A character string. |
yexp |
Optional. Alternative form of |
This documentation is provided
for experienced programmers who want to modify the internal
behaviour of spatstat. Other users please see fv.object
.
The low-level function fv
is used to create an object of
class "fv"
from raw numerical data.
The data frame x
contains the numerical data.
It should have one column
(typically but not necessarily named "r"
)
giving the values of the function argument for which
the function has been evaluated; and at least one other column,
containing the corresponding values of the function.
Typically there is more than one column of function values.
These columns typically give the values of different versions or estimates
of the same function,
for example, different estimates of the function
obtained using different edge corrections.
However they may also contain the values of related functions
such as the derivative or hazard rate.
argu
specifies the name of the column of
x
that contains the values of the function argument
(typically argu="r"
but this is not compulsory).
valu
specifies the name of another column
that contains the ‘recommended’ estimate of the function.
It will be used to provide function values in those situations where
a single column of data is required. For example,
envelope
computes its simulation envelopes
using the recommended value of the summary function.
fmla
specifies the default plotting behaviour.
It should be a formula, or a string that can be converted to a
formula. Variables in the formula are names of columns of x
.
See plot.fv
for the interpretation of this
formula.
alim
specifies the recommended range of the
function argument. This is used in situations where statistical
theory or statistical practice indicates that the computed
estimates of the function are not trustworthy outside a certain
range of values of the function argument. By default,
plot.fv
will restrict the plot to this range.
fname
is a string giving the name of the function itself.
For example, the function would have
fname="K"
.
ylab
is a mathematical expression
for the function value, used when labelling an axis
of the plot, or when printing a description of the
function. It should be an R language object.
For example the function's mathematical name
is rendered
by
ylab=quote(K(r))
.
If yexp
is present, then ylab
will be
used only for printing, and yexp
will be used for
annotating axes in a plot. (Otherwise yexp
defaults to ylab
).
For example the cross-type function
is rendered by something like
ylab=quote(Kcross[1,2](r))
and
yexp=quote(Kcross[list(1,2)](r))
to get the most satisfactory behaviour.
(A useful tip: use substitute
instead of
quote
to insert values of variables into an expression,
e.g. substitute(Kcross[i,j](r), list(i=42,j=97))
yields the same as quote(Kcross[42, 97](r))
.)
labl
is a character vector specifying plot labels
for each column of x
. These labels will appear on the
plot axes (in non-default plots), legends and printed output.
Entries in labl
may contain the string "%s"
which will be replaced
by fname
. For example the border-corrected estimate
of the function has label
"%s[bord](r)"
which
becomes "K[bord](r)"
.
desc
is a character vector containing intelligible
explanations of each column of x
. Entries in
desc
may contain the string "%s"
which will be replaced
by ylab
. For example the border correction estimate of the
function has description
"border correction estimate of %s"
.
An object of class "fv"
, see fv.object
.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
See plot.fv
for plotting an "fv"
object.
See as.function.fv
to convert an "fv"
object
to an R function.
Use cbind.fv
to combine several "fv"
objects.
Use bind.fv
to glue additional columns onto an existing
"fv"
object.
Simple calculations such as arithmetic and mathematical operations
can be computed directly.
The range of values of a function
f
can be computed by
typing range(f)
. These operations are dispatched to
Summary.fv
, Math.fv
and Ops.fv
.
Use eval.fv
or with.fv
for more complicated
calculations.
The functions fvnames
, fvnames<-
allow the user to
use standard abbreviations to refer to columns of an "fv"
object.
Undocumented functions for modifying an "fv"
object
include tweak.fv.entry
and rebadge.fv
.
df <- data.frame(r=seq(0,5,by=0.1)) df <- transform(df, a=pi*r^2, b=3*r^2) X <- fv(df, "r", quote(A(r)), "a", cbind(a, b) ~ r, alim=c(0,4), labl=c("r", "%s[true](r)", "%s[approx](r)"), desc=c("radius of circle", "true area %s", "rough area %s"), fname="A") X
df <- data.frame(r=seq(0,5,by=0.1)) df <- transform(df, a=pi*r^2, b=3*r^2) X <- fv(df, "r", quote(A(r)), "a", cbind(a, b) ~ r, alim=c(0,4), labl=c("r", "%s[true](r)", "%s[approx](r)"), desc=c("radius of circle", "true area %s", "rough area %s"), fname="A") X
A class "fv"
to support the convenient plotting
of several estimates of the same function.
An object of this class is a convenient way of storing and plotting several different estimates of the same function.
It is a data frame with extra attributes indicating the recommended way of plotting the function, and other information.
There are methods for print
and plot
for
this class.
Objects of class "fv"
are returned by
Fest
, Gest
,Jest
,
and Kest
along with many other functions.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Objects of class "fv"
are returned by
Fest
, Gest
,Jest
,
and Kest
along with many other functions.
See plot.fv
for plotting an "fv"
object.
See as.function.fv
to convert an "fv"
object
to an R function.
Use cbind.fv
to combine several "fv"
objects.
Use bind.fv
to glue additional columns onto an existing
"fv"
object.
Undocumented functions for modifying an "fv"
object
include fvnames
, fvnames<-
,
tweak.fv.entry
and rebadge.fv
.
K <- Kest(cells) class(K) K # prints a sensible summary plot(K)
K <- Kest(cells) class(K) K # prints a sensible summary plot(K)
Groups of columns in a function value table (object
of class "fv"
) identified by standard abbreviations.
fvnames(X, a = ".") fvnames(X, a = ".") <- value
fvnames(X, a = ".") fvnames(X, a = ".") <- value
X |
Function value table (object of class |
a |
One of the standard abbreviations listed below. |
value |
Character vector containing names of columns of |
An object of class "fv"
represents a table of
values of a function, usually a summary function for spatial data
such as the -function, for which several different statistical
estimators may be available. The different estimates are stored
as columns of the table.
Auxiliary information carried in the object X
specifies some
columns or groups of columns of this table that should be
used for particular purposes.
For convenience these groups can be referred to by standard
abbreviations which are recognised by various functions
in the spatstat package, such as plot.fv
.
These abbreviations are:
".x" |
the function argument |
".y" |
the recommended value of the function |
"." |
all function values to be plotted by default |
(in order of plotting) | |
".s" |
the upper and lower limits of shading |
(for envelopes and confidence intervals) | |
".a" |
all function values (in column order) |
The command fvnames(X, a)
expands the abbreviation a
and returns
a character vector containing the names of the columns.
The assignment fvnames(X, a) <- value
changes the
definition of the abbreviation a
to the character string
value
(which should be the name of another column of X
).
The column names of X
are not changed.
Note that fvnames(x, ".")
lists the columns of values that will
be plotted by default, in the order that they would be plotted, not in
order of the column position. The order in which curves are plotted
affects the colours and line styles associated with the curves.
For fvnames
, a character vector.
For fvnames<-
, the updated object.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
K <- Kest(cells) fvnames(K, ".y") fvnames(K, ".y") <- "trans"
K <- Kest(cells) fvnames(K, ".y") fvnames(K, ".y") <- "trans"
Estimates the nearest-neighbour distance distribution function
from a three-dimensional point pattern.
G3est(X, ..., rmax = NULL, nrval = 128, correction = c("rs", "km", "Hanisch"))
G3est(X, ..., rmax = NULL, nrval = 128, correction = c("rs", "km", "Hanisch"))
X |
Three-dimensional point pattern (object of class |
... |
Ignored. |
rmax |
Optional. Maximum value of argument |
nrval |
Optional. Number of values of |
correction |
Optional. Character vector specifying the edge correction(s) to be applied. See Details. |
For a stationary point process in three-dimensional
space, the nearest-neighbour function
is
the cumulative distribution function of the distance
from a typical point
in
to its nearest neighbour, i.e.
to the nearest other point of
.
The three-dimensional point pattern X
is assumed to be a
partial realisation of a stationary point process .
The nearest neighbour function of
can then be estimated using
techniques described in the References. For each data point, the
distance to the nearest neighbour is computed.
The empirical cumulative distribution
function of these values, with appropriate edge corrections, is the
estimate of
.
The available edge corrections are:
"rs"
:the reduced sample (aka minus sampling, border correction) estimator (Baddeley et al, 1993)
"km"
:the three-dimensional version of the Kaplan-Meier estimator (Baddeley and Gill, 1997)
"Hanisch"
:the three-dimensional generalisation of the Hanisch estimator (Hanisch, 1984).
Alternatively correction="all"
selects all options.
A function value table (object of class "fv"
) that can be
plotted, printed or coerced to a data frame containing the function values.
A large value of nrval
is required in order to avoid
discretisation effects (due to the use of histograms in the
calculation).
Adrian Baddeley [email protected] and Rana Moyeed.
Baddeley, A.J, Moyeed, R.A., Howard, C.V. and Boyde, A. (1993) Analysis of a three-dimensional point pattern with replication. Applied Statistics 42, 641–668.
Baddeley, A.J. and Gill, R.D. (1997) Kaplan-Meier estimators of interpoint distance distributions for spatial point processes. Annals of Statistics 25, 263–292.
Hanisch, K.-H. (1984) Some remarks on estimators of the distribution function of nearest neighbour distance in stationary spatial point patterns. Mathematische Operationsforschung und Statistik, series Statistics 15, 409–412.
pp3
to create a three-dimensional point
pattern (object of class "pp3"
).
F3est
,
K3est
,
pcf3est
for other summary functions of
a three-dimensional point pattern.
Gest
to estimate the empty space function of
point patterns in two dimensions.
X <- rpoispp3(42) Z <- G3est(X) if(interactive()) plot(Z)
X <- rpoispp3(42) Z <- G3est(X) if(interactive()) plot(Z)
For a multitype point pattern,
estimate the distribution of the distance
from a point of type
to the nearest point of type
.
Gcross(X, i, j, r=NULL, breaks=NULL, ..., correction=c("rs", "km", "han"))
Gcross(X, i, j, r=NULL, breaks=NULL, ..., correction=c("rs", "km", "han"))
X |
The observed point pattern,
from which an estimate of the cross type distance distribution function
|
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
r |
Optional. Numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
... |
Ignored. |
correction |
Optional. Character string specifying the edge correction(s)
to be used. Options are |
This function Gcross
and its companions
Gdot
and Gmulti
are generalisations of the function Gest
to multitype point patterns.
A multitype point pattern is a spatial pattern of points classified into a finite number of possible “colours” or “types”. In the spatstat package, a multitype pattern is represented as a single point pattern object in which the points carry marks, and the mark value attached to each point determines the type of that point.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The arguments i
and j
will be interpreted as
levels of the factor X$marks
. (Warning: this means that
an integer value i=3
will be interpreted as
the number 3, not the 3rd smallest level).
The “cross-type” (type to type
)
nearest neighbour distance distribution function
of a multitype point process
is the cumulative distribution function
of the distance from a typical random point of the process with type
the nearest point of type
.
An estimate of
is a useful summary statistic in exploratory data analysis
of a multitype point pattern.
If the process of type
points
were independent of the process of type
points,
then
would equal
,
the empty space function of the type
points.
For a multitype Poisson point process where the type
points
have intensity
, we have
Deviations between the empirical and theoretical curves
may suggest dependence between the points of types
and
.
This algorithm estimates the distribution function
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Gest
.
The argument r
is the vector of values for the
distance at which
should be evaluated.
It is also used to determine the breakpoints
(in the sense of
hist
)
for the computation of histograms of distances. The reduced-sample and
Kaplan-Meier estimators are computed from histogram counts.
In the case of the Kaplan-Meier estimator this introduces a discretisation
error which is controlled by the fineness of the breakpoints.
First-time users would be strongly advised not to specify r
.
However, if it is specified, r
must satisfy r[1] = 0
,
and max(r)
must be larger than the radius of the largest disc
contained in the window. Furthermore, the successive entries of r
must be finely spaced.
The algorithm also returns an estimate of the hazard rate function,
, of
.
This estimate should be used with caution as
is not necessarily differentiable.
The naive empirical distribution of distances from each point of
the pattern X
to the nearest other point of the pattern,
is a biased estimate of .
However this is also returned by the algorithm, as it is sometimes
useful in other contexts. Care should be taken not to use the uncorrected
empirical
as if it were an unbiased estimator of
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing six numeric columns
r |
the values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
han |
the Hanisch-style estimator of |
km |
the spatial Kaplan-Meier estimator of |
hazard |
the hazard rate |
raw |
the uncorrected estimate of |
theo |
the theoretical value of |
The arguments i
and j
are always interpreted as
levels of the factor X$marks
. They are converted to character
strings if they are not already character strings.
The value i=1
does not
refer to the first level of the factor.
The function does not necessarily have a density.
The reduced sample estimator of is pointwise approximately
unbiased, but need not be a valid distribution function; it may
not be a nondecreasing function of
. Its range is always
within
.
The spatial Kaplan-Meier estimator of
is always nondecreasing
but its maximum value may be less than
.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Diggle, P. J. (1986). Displaced amacrine cells in the retina of a rabbit : analysis of a bivariate spatial point pattern. J. Neurosci. Meth. 18, 115–125.
Harkness, R.D and Isham, V. (1983) A bivariate spatial point pattern of ants' nests. Applied Statistics 32, 293–303
Lotwick, H. W. and Silverman, B. W. (1982). Methods for analysing spatial processes of several types of points. J. Royal Statist. Soc. Ser. B 44, 406–413.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
Van Lieshout, M.N.M. and Baddeley, A.J. (1999) Indices of dependence between types in multivariate point patterns. Scandinavian Journal of Statistics 26, 511–532.
# amacrine cells data G01 <- Gcross(amacrine) # equivalent to: G01 <- Gcross(amacrine, "off", "on") plot(G01) # empty space function of `on' points if(interactive()) { F1 <- Fest(split(amacrine)$on, r = G01$r) lines(F1$r, F1$km, lty=3) } # synthetic example pp <- runifpoispp(30) pp <- pp %mark% factor(sample(0:1, npoints(pp), replace=TRUE)) G <- Gcross(pp, "0", "1") # note: "0" not 0
# amacrine cells data G01 <- Gcross(amacrine) # equivalent to: G01 <- Gcross(amacrine, "off", "on") plot(G01) # empty space function of `on' points if(interactive()) { F1 <- Fest(split(amacrine)$on, r = G01$r) lines(F1$r, F1$km, lty=3) } # synthetic example pp <- runifpoispp(30) pp <- pp %mark% factor(sample(0:1, npoints(pp), replace=TRUE)) G <- Gcross(pp, "0", "1") # note: "0" not 0
For a multitype point pattern,
estimate the inhomogeneous version of the cross function,
which is the distribution of the distance
from a point of type
to the nearest point of type
,
adjusted for spatially varying intensity.
Gcross.inhom(X, i, j, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
Gcross.inhom(X, i, j, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
X |
The observed point pattern,
from which an estimate of the inhomogeneous cross type |
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
lambda |
Optional.
Values of the estimated intensity of the point process.
Either a pixel image (object of class |
lambdaI |
Optional.
Values of the estimated intensity of the sub-process of
points of type |
lambdaJ |
Optional.
Values of the the estimated intensity of the sub-process of
points of type |
lambdamin |
Optional. The minimum possible value of the intensity over the spatial domain. A positive numerical value. |
... |
Extra arguments passed to |
r |
vector of values for the argument |
ReferenceMeasureMarkSetI |
Optional. The total measure of the mark set. A positive number. |
ratio |
Logical value indicating whether to save ratio information. |
This is a generalisation of the function Gcross
to include an adjustment for spatially inhomogeneous intensity,
in a manner similar to the function Ginhom
.
The argument lambdaI
supplies the values
of the intensity of the sub-process of points of type i
.
It may be either
(object of class "im"
) which
gives the values of the type i
intensity
at all locations in the window containing X
;
containing the values of the
type i
intensity evaluated only
at the data points of type i
. The length of this vector
must equal the number of type i
points in X
.
of the form function(x,y)
which can be evaluated to give values of the intensity at
any locations.
(object of class "ppm"
, "kppm"
or "dppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
if lambdaI
is omitted then it will be estimated
using a leave-one-out kernel smoother.
If lambdaI
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
Similarly the argument lambdaJ
should contain
estimated values of the intensity of the points of type .
It may be either a pixel image, a numeric vector of length equal
to the number of points in
X
, a function, or omitted.
The argument r
is the vector of values for the
distance at which
should be evaluated.
The values of
must be increasing nonnegative numbers
and the maximum
value must not exceed the radius of the
largest disc contained in the window.
An object of class "fv"
(see fv.object
)
containing estimates of the inhomogeneous cross type function.
The argument i
is interpreted as
a level of the factor X$marks
. It is converted to a character
string if it is not already a character string.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected].
Cronie, O. and Van Lieshout, M.N.M. (2015) Summary statistics for inhomogeneous marked point processes. Annals of the Institute of Statistical Mathematics DOI: 10.1007/s10463-015-0515-z
Gcross
,
Ginhom
,
Gcross.inhom
,
Gmulti.inhom
.
X <- rescale(amacrine) if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 } GC <- Gcross.inhom(X, "on", "off", lambda=lam, lambdamin=lmin)
X <- rescale(amacrine) if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 } GC <- Gcross.inhom(X, "on", "off", lambda=lam, lambdamin=lmin)
For a multitype point pattern,
estimate the distribution of the distance
from a point of type
to the nearest other point of any type.
Gdot(X, i, r=NULL, breaks=NULL, ..., correction=c("km", "rs", "han"))
Gdot(X, i, r=NULL, breaks=NULL, ..., correction=c("km", "rs", "han"))
X |
The observed point pattern,
from which an estimate of the
distance distribution function
|
i |
The type (mark value)
of the points in |
r |
Optional. Numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
... |
Ignored. |
correction |
Optional. Character string specifying the edge correction(s)
to be used. Options are |
This function Gdot
and its companions
Gcross
and Gmulti
are generalisations of the function Gest
to multitype point patterns.
A multitype point pattern is a spatial pattern of points classified into a finite number of possible “colours” or “types”. In the spatstat package, a multitype pattern is represented as a single point pattern object in which the points carry marks, and the mark value attached to each point determines the type of that point.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The argument will be interpreted as a
level of the factor X$marks
. (Warning: this means that
an integer value i=3
will be interpreted as the number 3,
not the 3rd smallest level.)
The “dot-type” (type to any type)
nearest neighbour distance distribution function
of a multitype point process
is the cumulative distribution function
of the distance from a typical random point of the process with type
the nearest other point of the process, regardless of type.
An estimate of
is a useful summary statistic in exploratory data analysis
of a multitype point pattern.
If the type
points
were independent of all other points,
then
would equal
,
the nearest neighbour distance distribution function of the type
points alone.
For a multitype Poisson point process with total intensity
, we have
Deviations between the empirical and theoretical
curves
may suggest dependence of the type
points on the other points.
This algorithm estimates the distribution function
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Gest
.
The argument r
is the vector of values for the
distance at which
should be evaluated.
It is also used to determine the breakpoints
(in the sense of
hist
)
for the computation of histograms of distances. The reduced-sample and
Kaplan-Meier estimators are computed from histogram counts.
In the case of the Kaplan-Meier estimator this introduces a discretisation
error which is controlled by the fineness of the breakpoints.
First-time users would be strongly advised not to specify r
.
However, if it is specified, r
must satisfy r[1] = 0
,
and max(r)
must be larger than the radius of the largest disc
contained in the window. Furthermore, the successive entries of r
must be finely spaced.
The algorithm also returns an estimate of the hazard rate function,
, of
.
This estimate should be used with caution as
is not necessarily differentiable.
The naive empirical distribution of distances from each point of
the pattern X
to the nearest other point of the pattern,
is a biased estimate of .
However this is also returned by the algorithm, as it is sometimes
useful in other contexts. Care should be taken not to use the uncorrected
empirical
as if it were an unbiased estimator of
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing six numeric columns
r |
the values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
han |
the Hanisch-style estimator of |
km |
the spatial Kaplan-Meier estimator of |
hazard |
the hazard rate |
raw |
the uncorrected estimate of |
theo |
the theoretical value of |
The argument i
is interpreted as
a level of the factor X$marks
. It is converted to a character
string if it is not already a character string.
The value i=1
does not
refer to the first level of the factor.
The function does not necessarily have a density.
The reduced sample estimator of
is pointwise approximately
unbiased, but need not be a valid distribution function; it may
not be a nondecreasing function of
. Its range is always
within
.
The spatial Kaplan-Meier estimator of
is always nondecreasing
but its maximum value may be less than
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Diggle, P. J. (1986). Displaced amacrine cells in the retina of a rabbit : analysis of a bivariate spatial point pattern. J. Neurosci. Meth. 18, 115–125.
Harkness, R.D and Isham, V. (1983) A bivariate spatial point pattern of ants' nests. Applied Statistics 32, 293–303
Lotwick, H. W. and Silverman, B. W. (1982). Methods for analysing spatial processes of several types of points. J. Royal Statist. Soc. Ser. B 44, 406–413.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
Van Lieshout, M.N.M. and Baddeley, A.J. (1999) Indices of dependence between types in multivariate point patterns. Scandinavian Journal of Statistics 26, 511–532.
# amacrine cells data G0. <- Gdot(amacrine, "off") plot(G0.) # synthetic example pp <- runifpoispp(30) pp <- pp %mark% factor(sample(0:1, npoints(pp), replace=TRUE)) G <- Gdot(pp, "0") G <- Gdot(pp, 0) # equivalent
# amacrine cells data G0. <- Gdot(amacrine, "off") plot(G0.) # synthetic example pp <- runifpoispp(30) pp <- pp %mark% factor(sample(0:1, npoints(pp), replace=TRUE)) G <- Gdot(pp, "0") G <- Gdot(pp, 0) # equivalent
For a multitype point pattern,
estimate the inhomogeneous version of the dot function,
which is the distribution of the distance
from a point of type
to the nearest other point of any type,
adjusted for spatially varying intensity.
Gdot.inhom(X, i, lambdaI = NULL, lambdadot = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
Gdot.inhom(X, i, lambdaI = NULL, lambdadot = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
X |
The observed point pattern,
from which an estimate of the inhomogeneous dot type |
i |
The type (mark value)
of the points in |
lambdaI |
Optional.
Values of the estimated intensity of the sub-process of
points of type |
lambdadot |
Optional.
Values of the estimated intensity of the entire point process,
Either a pixel image (object of class |
lambdamin |
Optional. The minimum possible value of the intensity over the spatial domain. A positive numerical value. |
... |
Ignored. |
r |
vector of values for the argument |
ReferenceMeasureMarkSetI |
Optional. The total measure of the mark set. A positive number. |
ratio |
Logical value indicating whether to save ratio information. |
This is a generalisation of the function Gdot
to include an adjustment for spatially inhomogeneous intensity,
in a manner similar to the function Ginhom
.
The argument lambdaI
supplies the values
of the intensity of the sub-process of points of type i
.
It may be either
(object of class "im"
) which
gives the values of the type i
intensity
at all locations in the window containing X
;
containing the values of the
type i
intensity evaluated only
at the data points of type i
. The length of this vector
must equal the number of type i
points in X
.
of the form function(x,y)
which can be evaluated to give values of the intensity at
any locations.
(object of class "ppm"
, "kppm"
or "dppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
if lambdaI
is omitted then it will be estimated
using a leave-one-out kernel smoother.
If lambdaI
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
Similarly the argument lambdadot
should contain
estimated values of the intensity of the entire point process.
It may be either a pixel image, a numeric vector of length equal
to the number of points in X
, a function, or omitted.
The argument r
is the vector of values for the
distance at which
should be evaluated.
The values of
must be increasing nonnegative numbers
and the maximum
value must not exceed the radius of the
largest disc contained in the window.
An object of class "fv"
(see fv.object
)
containing estimates of the inhomogeneous dot type function.
The argument i
is interpreted as
a level of the factor X$marks
. It is converted to a character
string if it is not already a character string.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
Cronie, O. and Van Lieshout, M.N.M. (2015) Summary statistics for inhomogeneous marked point processes. Annals of the Institute of Statistical Mathematics DOI: 10.1007/s10463-015-0515-z
Gdot
,
Ginhom
,
Gcross.inhom
,
Gmulti.inhom
.
X <- rescale(amacrine) if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 } lamI <- lam[marks(X) == "on"] GD <- Gdot.inhom(X, "on", lambdaI=lamI, lambdadot=lam, lambdamin=lmin)
X <- rescale(amacrine) if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 } lamI <- lam[marks(X) == "on"] GD <- Gdot.inhom(X, "on", lambdaI=lamI, lambdadot=lam, lambdamin=lmin)
Estimates the nearest neighbour distance distribution
function from a point pattern in a
window of arbitrary shape.
Gest(X, r=NULL, breaks=NULL, ..., correction=c("rs", "km", "han"), domain=NULL)
Gest(X, r=NULL, breaks=NULL, ..., correction=c("rs", "km", "han"), domain=NULL)
X |
The observed point pattern,
from which an estimate of |
r |
Optional. Numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
... |
Ignored. |
correction |
Optional.
The edge correction(s) to be used to estimate |
domain |
Optional. Calculations will be restricted to this subset of the window. See Details. |
The nearest neighbour distance distribution function
(also called the “event-to-event” or
“inter-event” distribution)
of a point process
is the cumulative distribution function
of the distance
from a typical random point of
to
the nearest other point of
.
An estimate of derived from a spatial point pattern dataset
can be used in exploratory data analysis and formal inference
about the pattern (Cressie, 1991; Diggle, 1983; Ripley, 1988).
In exploratory analyses, the estimate of
is a useful statistic
summarising one aspect of the “clustering” of points.
For inferential purposes, the estimate of
is usually compared to the
true value of
for a completely random (Poisson) point process,
which is
where is the intensity
(expected number of points per unit area).
Deviations between the empirical and theoretical
curves
may suggest spatial clustering or spatial regularity.
This algorithm estimates the nearest neighbour distance distribution
function
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
The argument X
is interpreted as a point pattern object
(of class "ppp"
, see ppp.object
) and can
be supplied in any of the formats recognised
by as.ppp()
.
The estimation of is hampered by edge effects arising from
the unobservability of points of the random pattern outside the window.
An edge correction is needed to reduce bias (Baddeley, 1998; Ripley, 1988).
The edge corrections implemented here are the border method or
“reduced sample” estimator, the spatial Kaplan-Meier estimator
(Baddeley and Gill, 1997) and the Hanisch estimator (Hanisch, 1984).
The argument r
is the vector of values for the
distance at which
should be evaluated.
It is also used to determine the breakpoints
(in the sense of
hist
)
for the computation of histograms of distances. The
estimators are computed from histogram counts.
This introduces a discretisation
error which is controlled by the fineness of the breakpoints.
First-time users would be strongly advised not to specify r
.
However, if it is specified, r
must satisfy r[1] = 0
,
and max(r)
must be larger than the radius of the largest disc
contained in the window. Furthermore, the successive entries of r
must be finely spaced.
The algorithm also returns an estimate of the hazard rate function,
, of
. The hazard rate is
defined as the derivative
This estimate should be used with caution as is not necessarily
differentiable.
If the argument domain
is given, the estimate of
will be based only on the nearest neighbour distances
measured from points falling inside
domain
(although their
nearest neighbours may lie outside domain
).
This is useful in bootstrap techniques. The argument domain
should be a window (object of class "owin"
) or something acceptable to
as.owin
. It must be a subset of the
window of the point pattern X
.
The naive empirical distribution of distances from each point of
the pattern X
to the nearest other point of the pattern,
is a biased estimate of . However it is sometimes useful.
It can be returned by the algorithm, by selecting
correction="none"
.
Care should be taken not to use the uncorrected
empirical as if it were an unbiased estimator of
.
To simply compute the nearest neighbour distance for each point in the
pattern, use nndist
. To determine which point is the
nearest neighbour of a given point, use nnwhich
.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Essentially a data frame containing some or all of the following columns:
r |
the values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
km |
the spatial Kaplan-Meier estimator of |
hazard |
the hazard rate |
raw |
the uncorrected estimate of |
han |
the Hanisch correction estimator of |
theo |
the theoretical value of |
The function does not necessarily have a density.
Any valid c.d.f. may appear as the nearest neighbour distance
distribution function of a stationary point process.
The reduced sample estimator of is pointwise approximately
unbiased, but need not be a valid distribution function; it may
not be a nondecreasing function of
. Its range is always
within
.
The spatial Kaplan-Meier estimator of is always nondecreasing
but its maximum value may be less than
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Baddeley, A.J. Spatial sampling and censoring. In O.E. Barndorff-Nielsen, W.S. Kendall and M.N.M. van Lieshout (eds) Stochastic Geometry: Likelihood and Computation. Chapman and Hall, 1998. Chapter 2, pages 37-78.
Baddeley, A.J. and Gill, R.D. Kaplan-Meier estimators of interpoint distance distributions for spatial point processes. Annals of Statistics 25 (1997) 263-292.
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Hanisch, K.-H. (1984) Some remarks on estimators of the distribution function of nearest-neighbour distance in stationary spatial point patterns. Mathematische Operationsforschung und Statistik, series Statistics 15, 409–412.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
nndist
,
nnwhich
,
Fest
,
Jest
,
Kest
,
km.rs
,
reduced.sample
,
kaplan.meier
G <- Gest(cells) plot(G) # P-P style plot plot(G, cbind(km,theo) ~ theo) # the empirical G is below the Poisson G, # indicating an inhibited pattern if(interactive()) { plot(G, . ~ r) plot(G, . ~ theo) plot(G, asin(sqrt(.)) ~ asin(sqrt(theo))) }
G <- Gest(cells) plot(G) # P-P style plot plot(G, cbind(km,theo) ~ theo) # the empirical G is below the Poisson G, # indicating an inhibited pattern if(interactive()) { plot(G, . ~ r) plot(G, . ~ theo) plot(G, asin(sqrt(.)) ~ asin(sqrt(theo))) }
Given a point pattern X
and a spatial object Y
,
compute estimates of Foxall's and
functions.
Gfox(X, Y, r=NULL, breaks=NULL, correction=c("km", "rs", "han"), W, ...) Jfox(X, Y, r=NULL, breaks=NULL, correction=c("km", "rs", "han"), W, ..., warn.trim=TRUE)
Gfox(X, Y, r=NULL, breaks=NULL, correction=c("km", "rs", "han"), W, ...) Jfox(X, Y, r=NULL, breaks=NULL, correction=c("km", "rs", "han"), W, ..., warn.trim=TRUE)
X |
A point pattern (object of class |
Y |
An object of class |
r |
Optional. Numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
correction |
Optional.
The edge correction(s) to be used to estimate
|
W |
Optional. A window (object of class |
... |
Extra arguments affecting the discretisation of distances.
These arguments are ignored by |
warn.trim |
Logical value indicating whether a warning should be issued
by |
Given a point pattern X
and another spatial object Y
,
these functions compute two nonparametric measures of association
between X
and Y
, introduced by Foxall
(Foxall and Baddeley, 2002).
Let the random variable be the distance from a typical point
of
X
to the object Y
.
Foxall's -function is the cumulative distribution function
of
:
Let the random variable be the distance from a fixed point
in space to the object
Y
. The cumulative distribution function
of is the (unconditional) spherical contact distribution
function
which is computed by Hest
.
Foxall's -function is the ratio
For further interpretation, see Foxall and Baddeley (2002).
Accuracy of Jfox
depends on the pixel resolution,
which is controlled by the
arguments eps
, dimyx
and xy
passed to
as.mask
. For example, use eps=0.1
to specify
square pixels of side 0.1 units, and dimyx=256
to specify a
256 by 256 grid of pixels.
A function value table (object of class "fv"
)
which can be printed, plotted, or converted to a data frame of values.
Rob Foxall and Adrian Baddeley [email protected]
Foxall, R. and Baddeley, A. (2002) Nonparametric measures of association between a spatial point process and a random set, with geological applications. Applied Statistics 51, 165–182.
X <- copper$SouthPoints Y <- copper$SouthLines G <- Gfox(X,Y) J <- Jfox(X,Y, correction="km")
X <- copper$SouthPoints Y <- copper$SouthLines G <- Gfox(X,Y) J <- Jfox(X,Y, correction="km")
Estimates the inhomogeneous nearest neighbour function of
a non-stationary point pattern.
Ginhom(X, lambda = NULL, lmin = NULL, ..., sigma = NULL, varcov = NULL, r = NULL, breaks = NULL, ratio = FALSE, update = TRUE, warn.bias=TRUE, savelambda=FALSE)
Ginhom(X, lambda = NULL, lmin = NULL, ..., sigma = NULL, varcov = NULL, r = NULL, breaks = NULL, ratio = FALSE, update = TRUE, warn.bias=TRUE, savelambda=FALSE)
X |
The observed data point pattern,
from which an estimate of the inhomogeneous |
lambda |
Optional.
Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern |
lmin |
Optional. The minimum possible value of the intensity over the spatial domain. A positive numerical value. |
sigma , varcov
|
Optional arguments passed to |
... |
Extra arguments passed to |
r |
vector of values for the argument |
breaks |
This argument is for internal use only. |
ratio |
Logical.
If |
update |
Logical. If |
warn.bias |
Logical value specifying whether to issue a warning when the inhomogeneity correction factor takes extreme values, which can often lead to biased results. This usually occurs when insufficient smoothing is used to estimate the intensity. |
savelambda |
Logical value specifying whether to save the values of
|
This command computes estimates of the
inhomogeneous -function (van Lieshout, 2010)
of a point pattern. It is the counterpart, for inhomogeneous
spatial point patterns, of the nearest-neighbour distance
distribution function
for homogeneous point patterns computed by
Gest
.
The argument X
should be a point pattern
(object of class "ppp"
).
The inhomogeneous function is computed
using the border correction, equation (7) in Van Lieshout (2010).
The argument lambda
should supply the
(estimated) values of the intensity function
of the point process. It may be either
containing the values
of the intensity function at the points of the pattern X
.
(object of class "im"
)
assumed to contain the values of the intensity function
at all locations in the window.
(object of class "ppm"
or "kppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
which can be evaluated to give values of the intensity at any locations.
if lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
If lambda
is a numeric vector, then its length should
be equal to the number of points in the pattern X
.
The value lambda[i]
is assumed to be the
the (estimated) value of the intensity
for
the point
of the pattern
.
Each value must be a positive number;
NA
's are not allowed.
If lambda
is a pixel image, the domain of the image should
cover the entire window of the point pattern. If it does not (which
may occur near the boundary because of discretisation error),
then the missing pixel values
will be obtained by applying a Gaussian blur to lambda
using
blur
, then looking up the values of this blurred image
for the missing locations.
(A warning will be issued in this case.)
If lambda
is a function, then it will be evaluated in the
form lambda(x,y)
where x
and y
are vectors
of coordinates of the points of X
. It should return a numeric
vector with length equal to the number of points in X
.
If lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
The estimate lambda[i]
for the
point X[i]
is computed by removing X[i]
from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point X[i]
. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Original code by Marie-Colette van Lieshout. C implementation and R adaptation by Adrian Baddeley [email protected] and Ege Rubak [email protected].
Van Lieshout, M.N.M. and Baddeley, A.J. (1996) A nonparametric measure of spatial interaction in point patterns. Statistica Neerlandica 50, 344–361.
Van Lieshout, M.N.M. (2010) A J-function for inhomogeneous point processes. Statistica Neerlandica 65, 183–201.
plot(Ginhom(swedishpines, sigma=10)) plot(Ginhom(swedishpines, sigma=bw.diggle, adjust=2))
plot(Ginhom(swedishpines, sigma=10)) plot(Ginhom(swedishpines, sigma=bw.diggle, adjust=2))
For a marked point pattern,
estimate the distribution of the distance
from a typical point in subset I
to the nearest point of subset .
Gmulti(X, I, J, r=NULL, breaks=NULL, ..., disjoint=NULL, correction=c("rs", "km", "han"))
Gmulti(X, I, J, r=NULL, breaks=NULL, ..., disjoint=NULL, correction=c("rs", "km", "han"))
X |
The observed point pattern,
from which an estimate of the multitype distance distribution function
|
I |
Subset of points of |
J |
Subset of points in |
r |
Optional. Numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
... |
Ignored. |
disjoint |
Optional flag indicating whether
the subsets |
correction |
Optional. Character string specifying the edge correction(s)
to be used. Options are |
The function Gmulti
generalises Gest
(for unmarked point
patterns) and Gdot
and Gcross
(for
multitype point patterns) to arbitrary marked point patterns.
Suppose ,
are subsets, possibly
overlapping, of a marked point process. This function computes an
estimate of the cumulative
distribution function
of the distance
from a typical point of
to the nearest distinct point of
.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
The arguments I
and J
specify two subsets of the
point pattern. They may be any type of subset indices, for example,
logical vectors of length equal to npoints(X)
,
or integer vectors with entries in the range 1 to
npoints(X)
, or negative integer vectors.
Alternatively, I
and J
may be functions
that will be applied to the point pattern X
to obtain
index vectors. If I
is a function, then evaluating
I(X)
should yield a valid subset index. This option
is useful when generating simulation envelopes using
envelope
.
This algorithm estimates the distribution function
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Gest
.
The argument r
is the vector of values for the
distance at which
should be evaluated.
It is also used to determine the breakpoints
(in the sense of
hist
)
for the computation of histograms of distances. The reduced-sample and
Kaplan-Meier estimators are computed from histogram counts.
In the case of the Kaplan-Meier estimator this introduces a discretisation
error which is controlled by the fineness of the breakpoints.
First-time users would be strongly advised not to specify r
.
However, if it is specified, r
must satisfy r[1] = 0
,
and max(r)
must be larger than the radius of the largest disc
contained in the window. Furthermore, the successive entries of r
must be finely spaced.
The algorithm also returns an estimate of the hazard rate function,
, of
.
This estimate should be used with caution as
is not necessarily differentiable.
The naive empirical distribution of distances from each point of
the pattern X
to the nearest other point of the pattern,
is a biased estimate of .
However this is also returned by the algorithm, as it is sometimes
useful in other contexts. Care should be taken not to use the uncorrected
empirical
as if it were an unbiased estimator of
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing six numeric columns
r |
the values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
han |
the Hanisch-style estimator of |
km |
the spatial Kaplan-Meier estimator of |
hazard |
the hazard rate |
raw |
the uncorrected estimate of |
theo |
the theoretical value of |
The function does not necessarily have a density.
The reduced sample estimator of is pointwise approximately
unbiased, but need not be a valid distribution function; it may
not be a nondecreasing function of
. Its range is always
within
.
The spatial Kaplan-Meier estimator of
is always nondecreasing
but its maximum value may be less than
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Diggle, P. J. (1986). Displaced amacrine cells in the retina of a rabbit : analysis of a bivariate spatial point pattern. J. Neurosci. Meth. 18, 115–125.
Harkness, R.D and Isham, V. (1983) A bivariate spatial point pattern of ants' nests. Applied Statistics 32, 293–303
Lotwick, H. W. and Silverman, B. W. (1982). Methods for analysing spatial processes of several types of points. J. Royal Statist. Soc. Ser. B 44, 406–413.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
Van Lieshout, M.N.M. and Baddeley, A.J. (1999) Indices of dependence between types in multivariate point patterns. Scandinavian Journal of Statistics 26, 511–532.
trees <- longleaf # Longleaf Pine data: marks represent diameter Gm <- Gmulti(trees, marks(trees) <= 15, marks(trees) >= 25) plot(Gm)
trees <- longleaf # Longleaf Pine data: marks represent diameter Gm <- Gmulti(trees, marks(trees) <= 15, marks(trees) >= 25) plot(Gm)
For a marked point pattern,
estimate the inhomogeneous version of the multitype function,
effectively the cumulative distribution function of the distance from
a point in subset
to the nearest point in subset
,
adjusted for spatially varying intensity.
Gmulti.inhom(X, I, J, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE) GmultiInhom(X, I, J, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
Gmulti.inhom(X, I, J, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE) GmultiInhom(X, I, J, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
X |
A spatial point pattern (object of class |
I |
A subset index specifying the subset of points from which
distances are measured. Any kind of subset index acceptable
to |
J |
A subset index specifying the subset of points to which
distances are measured. Any kind of subset index acceptable
to |
lambda |
Intensity estimates for each point of |
lambdaI |
Intensity estimates for each point of |
lambdaJ |
Intensity estimates for each point of |
lambdamin |
A lower bound for the intensity,
or at least a lower bound for the values in |
... |
Ignored. |
r |
Vector of distance values at which the inhomogeneous |
ReferenceMeasureMarkSetI |
Optional. The total measure of the mark set. A positive number. |
ratio |
Logical value indicating whether to save ratio information. |
See Cronie and Van Lieshout (2015).
The functions GmultiInhom
and Gmulti.inhom
are identical.
Object of class "fv"
containing the estimate of the
inhomogeneous multitype function.
Ottmar Cronie and Marie-Colette van Lieshout. Rewritten for spatstat by Adrian Baddeley [email protected].
Cronie, O. and Van Lieshout, M.N.M. (2015) Summary statistics for inhomogeneous marked point processes. Annals of the Institute of Statistical Mathematics DOI: 10.1007/s10463-015-0515-z
X <- rescale(amacrine) I <- (marks(X) == "on") J <- (marks(X) == "off") if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 } plot(GmultiInhom(X, I, J, lambda=lam, lambdamin=lmin)) # equivalent plot(GmultiInhom(X, I, J, lambdaI=lam[I], lambdaJ=lam[J], lambdamin=lmin), main="")
X <- rescale(amacrine) I <- (marks(X) == "on") J <- (marks(X) == "off") if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 } plot(GmultiInhom(X, I, J, lambda=lam, lambdamin=lmin)) # equivalent plot(GmultiInhom(X, I, J, lambdaI=lam[I], lambdaJ=lam[J], lambdamin=lmin), main="")
Convert several objects of class "fv"
to the same values of the function argument.
## S3 method for class 'fv' harmonise(..., strict=FALSE) ## S3 method for class 'fv' harmonize(..., strict=FALSE)
## S3 method for class 'fv' harmonise(..., strict=FALSE) ## S3 method for class 'fv' harmonize(..., strict=FALSE)
... |
Any number of function tables (objects of class |
strict |
Logical. If |
A function value table (object of class "fv"
) is
essentially a data frame giving the values of a function
(or several alternative estimates of this value)
at equally-spaced values of the function argument
.
The command harmonise
is generic. This is the
method for objects of class "fv"
.
This command makes any number of "fv"
objects compatible,
in the loose sense that they have the same sequence of values of
. They can then be combined by
cbind.fv
,
but not necessarily by eval.fv
.
All arguments ...
must be function value tables
(objects of class "fv"
).
The result will be a list, of length equal to the number of
arguments ...
, containing new versions of each of these functions,
converted to a common sequence of values.
If the arguments were named (
name=value
) then the return value
also carries these names.
The range of values in the resulting functions
will be the intersection of the ranges of
values
in the original functions.
The spacing of
values in the resulting functions
will be the finest (narrowest) of the spacings of the
values in the original functions.
Function values are interpolated using
approxfun
.
If strict=TRUE
, each column of data will be retained only if
a column of the same name appears in all of the arguments ...
.
This ensures that the resulting objects are strictly compatible
in the sense of compatible.fv
,
and can be combined using eval.fv
or collapse.fv
.
If strict=FALSE
(the default), this does not occur,
and then the resulting objects are not guaranteed to be compatible
in the sense of compatible.fv
.
A list, of length equal to the number of arguments ...
,
whose entries are objects of class "fv"
.
If the arguments were named (name=value
) then the return value
also carries these names.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
fv.object
,
cbind.fv
,
eval.fv
,
compatible.fv
H <- harmonise(K=Kest(cells), G=Gest(cells)) H
H <- harmonise(K=Kest(cells), G=Gest(cells)) H
Estimates the spherical contact distribution function of a random set.
Hest(X, r=NULL, breaks=NULL, ..., W, correction=c("km", "rs", "han"), conditional=TRUE)
Hest(X, r=NULL, breaks=NULL, ..., W, correction=c("km", "rs", "han"), conditional=TRUE)
X |
The observed random set.
An object of class |
r |
Optional. Vector of values for the argument |
breaks |
This argument is for internal use only. |
... |
Arguments passed to |
W |
Optional. A window (object of class |
correction |
Optional.
The edge correction(s) to be used to estimate |
conditional |
Logical value indicating whether to compute the conditional or unconditional distribution. See Details. |
The spherical contact distribution function
of a stationary random set
is the cumulative distribution function
of the distance
from a fixed point in space to the nearest point of
,
given that the point lies outside
.
That is,
equals
the probability that
X
lies closer than units away
from the fixed point
, given that
X
does not cover .
Let be the shortest distance from an arbitrary
point
to the set
X
. Then the spherical contact
distribution function is
For a point process, the spherical contact distribution function
is the same as the empty space function discussed
in
Fest
.
The argument X
may be a point pattern
(object of class "ppp"
), a line segment pattern
(object of class "psp"
) or a window (object of class
"owin"
). It is assumed to be a realisation of a stationary
random set.
The algorithm first calls distmap
to compute the
distance transform of X
, then computes the Kaplan-Meier
and reduced-sample estimates of the cumulative distribution
following Hansen et al (1999).
If conditional=TRUE
(the default) the algorithm
returns an estimate of the spherical contact function
as defined above.
If
conditional=FALSE
, it instead returns an estimate of the
cumulative distribution function
which includes a jump at
if
X
has nonzero area.
Accuracy depends on the pixel resolution, which is controlled by the
arguments eps
, dimyx
and xy
passed to
as.mask
. For example, use eps=0.1
to specify
square pixels of side 0.1 units, and dimyx=256
to specify a
256 by 256 grid of pixels.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Essentially a data frame containing up to six columns:
r |
the values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
km |
the spatial Kaplan-Meier estimator of |
hazard |
the hazard rate |
han |
the spatial Hanisch-Chiu-Stoyan estimator of |
raw |
the uncorrected estimate of |
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected] with contributions from Kassel Hingee.
Baddeley, A.J. Spatial sampling and censoring. In O.E. Barndorff-Nielsen, W.S. Kendall and M.N.M. van Lieshout (eds) Stochastic Geometry: Likelihood and Computation. Chapman and Hall, 1998. Chapter 2, pages 37-78.
Baddeley, A.J. and Gill, R.D. The empty space hazard of a spatial pattern. Research Report 1994/3, Department of Mathematics, University of Western Australia, May 1994.
Hansen, M.B., Baddeley, A.J. and Gill, R.D. First contact distributions for spatial patterns: regularity and estimation. Advances in Applied Probability 31 (1999) 15-33.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
X <- runifpoint(42) H <- Hest(X) Y <- rpoisline(10) H <- Hest(Y) H <- Hest(Y, dimyx=256) X <- heather$coarse plot(Hest(X)) H <- Hest(X, conditional=FALSE) P <- owin(poly=list(x=c(5.3, 8.5, 8.3, 3.7, 1.3, 3.7), y=c(9.7, 10.0, 13.6, 14.4, 10.7, 7.2))) plot(X) plot(P, add=TRUE, col="red") H <- Hest(X, W=P) Z <- as.im(FALSE, Frame(X)) Z[X] <- TRUE Z <- Z[P, drop=FALSE] plot(Z) H <- Hest(Z)
X <- runifpoint(42) H <- Hest(X) Y <- rpoisline(10) H <- Hest(Y) H <- Hest(Y, dimyx=256) X <- heather$coarse plot(Hest(X)) H <- Hest(X, conditional=FALSE) P <- owin(poly=list(x=c(5.3, 8.5, 8.3, 3.7, 1.3, 3.7), y=c(9.7, 10.0, 13.6, 14.4, 10.7, 7.2))) plot(X) plot(P, add=TRUE, col="red") H <- Hest(X, W=P) Z <- as.im(FALSE, Frame(X)) Z[X] <- TRUE Z <- Z[P, drop=FALSE] plot(Z) H <- Hest(Z)
Perform the Hopkins-Skellam test of Complete Spatial Randomness, or simply calculate the test statistic.
hopskel(X) hopskel.test(X, ..., alternative=c("two.sided", "less", "greater", "clustered", "regular"), method=c("asymptotic", "MonteCarlo"), nsim=999)
hopskel(X) hopskel.test(X, ..., alternative=c("two.sided", "less", "greater", "clustered", "regular"), method=c("asymptotic", "MonteCarlo"), nsim=999)
X |
Point pattern (object of class |
alternative |
String indicating the type of alternative for the hypothesis test. Partially matched. |
method |
Method of performing the test. Partially matched. |
nsim |
Number of Monte Carlo simulations to perform, if a Monte Carlo p-value is required. |
... |
Ignored. |
Hopkins and Skellam (1954) proposed a test of Complete Spatial Randomness based on comparing nearest-neighbour distances with point-event distances.
If the point pattern X
contains n
points, we first compute the nearest-neighbour distances
so that
is the distance from the
th data
point to the nearest other data point. Then we
generate another completely random pattern
U
with
the same number n
of points, and compute for each point of U
the distance to the nearest point of X
, giving
distances .
The test statistic is
The null distribution of is roughly
an
distribution with shape parameters
.
(This is equivalent to using the test statistic
and referring
to the Beta distribution with parameters
).
The function hopskel
calculates the Hopkins-Skellam test statistic
, and returns its numeric value. This can be used as a simple
summary of spatial pattern: the value
is consistent
with Complete Spatial Randomness, while values
are
consistent with spatial clustering, and values
are consistent
with spatial regularity.
The function hopskel.test
performs the test.
If method="asymptotic"
(the default), the test statistic
is referred to the
distribution. If
method="MonteCarlo"
,
a Monte Carlo test is performed using nsim
simulated point
patterns.
The value of hopskel
is a single number.
The value of hopskel.test
is an object of class "htest"
representing the outcome of the test. It can be printed.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Hopkins, B. and Skellam, J.G. (1954) A new method of determining the type of distribution of plant individuals. Annals of Botany 18, 213–227.
clarkevans
,
clarkevans.test
,
nndist
,
nncross
hopskel(redwood) hopskel.test(redwood, alternative="clustered")
hopskel(redwood) hopskel.test(redwood, alternative="clustered")
Calculate values of the heat kernel in a rectangle with insulated edges.
hotbox(Xsource, Xquery, sigma, ..., W=NULL, squared=FALSE, nmax=20)
hotbox(Xsource, Xquery, sigma, ..., W=NULL, squared=FALSE, nmax=20)
Xsource |
Point pattern of sources of heat.
Object of class |
Xquery |
Locations where the heat kernel value is required.
An object of class |
sigma |
Bandwidth for kernel. A single number. |
... |
Extra arguments (passed to |
W |
Window (object of class |
squared |
Logical value indicating whether to take the square of each heat kernel value, before summing over the source points. |
nmax |
Number of terms to be used from the infinite-sum expression for the heat kernel. A single integer. |
This function computes the sum of heat kernels associated with each of the source points, evaluating them at each query location.
The window for evaluation of the heat kernel must be a rectangle.
The heat kernel in any region can be expressed as an infinite sum of terms
associated with the eigenfunctions of the Laplacian. The heat kernel
in a rectangle is the product of heat kernels for
one-dimensional intervals on the horizontal and vertical axes. This
function uses hotrod
to compute the
one-dimensional heat kernels, truncating the infinite sum to the
first nmax
terms, and then calculates the two-dimensional heat
kernel from each source point to each query location. If
squared=TRUE
these values are squared. Finally the values are
summed over all source points to obtain a single value for each
query location.
If Xquery
is a point pattern,
the result is a numeric vector with one entry for each query point.
If Xquery
is an image or window, the result is
a pixel image.
Adrian Baddeley and Greg McSwiggan.
Baddeley, A., Davies, T., Rakshit, S., Nair, G. and McSwiggan, G. (2021) Diffusion smoothing for spatial point patterns. Statistical Science, in press.
X <- runifpoint(10) Y <- runifpoint(5) hotbox(X, Y, 0.1) plot(hotbox(X, Window(X), 0.1)) points(X, pch=16)
X <- runifpoint(10) Y <- runifpoint(5) hotbox(X, Y, 0.1) plot(hotbox(X, Window(X), 0.1)) points(X, pch=16)
Performs spatial smoothing of numeric values observed at a set of irregular locations using inverse-distance weighting.
idw(X, power=2, at=c("pixels", "points"), ..., se=FALSE)
idw(X, power=2, at=c("pixels", "points"), ..., se=FALSE)
X |
A marked point pattern (object of class |
power |
Numeric. Power of distance used in the weighting. |
at |
Character string specifying whether to compute the intensity values
at a grid of pixel locations ( |
... |
Arguments passed to |
se |
Logical value specifying whether to calculate a standard error. |
This function performs spatial smoothing of numeric values observed at a set of irregular locations.
Smoothing is performed by inverse distance weighting. If the
observed values are
at locations
respectively,
then the smoothed value at a location
is
where the weights are the inverse -th powers of distance,
where
is the Euclidean distance from
to
.
The argument X
must be a marked point pattern (object
of class "ppp"
, see ppp.object
).
The points of the pattern are taken to be the
observation locations , and the marks of the pattern
are taken to be the numeric values
observed at these
locations.
The marks are allowed to be a data frame. Then the smoothing procedure is applied to each column of marks.
If at="pixels"
(the default), the smoothed mark value
is calculated at a grid of pixels, and the result is a pixel image.
The arguments ...
control the pixel resolution.
See as.mask
.
If at="points"
, the smoothed mark values are calculated
at the data points only, using a leave-one-out rule (the mark value
at a data point is excluded when calculating the smoothed value
for that point).
An estimate of standard error is also calculated, if se=TRUE
.
The calculation assumes that the data point locations are fixed,
that is, the standard error only takes into account the variability
in the mark values, and not the variability due to randomness of the
data point locations.
An alternative to inverse-distance weighting is kernel smoothing,
which is performed by Smooth.ppp
.
If X
has a single column of marks:
If at="pixels"
(the default), the result is
a pixel image (object of class "im"
).
Pixel values are values of the interpolated function.
If at="points"
, the result is a numeric vector
of length equal to the number of points in X
.
Entries are values of the interpolated function at the points of X
.
If X
has a data frame of marks:
If at="pixels"
(the default), the result is a named list of
pixel images (object of class "im"
). There is one
image for each column of marks. This list also belongs to
the class "solist"
, for which there is a plot method.
If at="points"
, the result is a data frame
with one row for each point of X
,
and one column for each column of marks.
Entries are values of the interpolated function at the points of X
.
If se=TRUE
, then the result is a list
with two entries named estimate
and SE
, which
each have the format described above.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]. Variance calculation by Andrew P Wheeler with modifications by Adrian Baddeley.
Shepard, D. (1968) A two-dimensional interpolation function for irregularly-spaced data. Proceedings of the 1968 ACM National Conference, 1968, pages 517–524. DOI: 10.1145/800186.810616
density.ppp
,
ppp.object
,
im.object
.
See Smooth.ppp
for kernel smoothing,
SpatialMedian.ppp
for median smoothing
and nnmark
for nearest-neighbour interpolation.
To perform other kinds of interpolation, see also the akima
package.
# data frame of marks: trees marked by diameter and height plot(idw(finpines)) idw(finpines, at="points")[1:5,] plot(idw(finpines, se=TRUE)$SE) idw(finpines, at="points", se=TRUE)$SE[1:5, ]
# data frame of marks: trees marked by diameter and height plot(idw(finpines)) idw(finpines, at="points")[1:5,] plot(idw(finpines, se=TRUE)$SE) idw(finpines, at="points", se=TRUE)$SE[1:5, ]
Estimates the summary function for a multitype point pattern.
Iest(X, ..., eps=NULL, r=NULL, breaks=NULL, correction=NULL)
Iest(X, ..., eps=NULL, r=NULL, breaks=NULL, correction=NULL)
X |
The observed point pattern,
from which an estimate of |
... |
Ignored. |
eps |
the resolution of the discrete approximation to Euclidean distance (see below). There is a sensible default. |
r |
Optional. Numeric vector of values for the argument |
breaks |
This argument is for internal use only. |
correction |
Optional. Vector of character strings specifying the edge correction(s)
to be used by |
The function
summarises the dependence between types in a multitype point process
(Van Lieshout and Baddeley, 1999)
It is based on the concept of the
function for an
unmarked point process (Van Lieshout and Baddeley, 1996).
See
Jest
for information about the function.
The function is defined as
where is the
function for
the entire point process ignoring the marks, while
is the
function for the
process consisting of points of type
only,
and
is the proportion of points which are of type
.
The function is designed to measure dependence between
points of different types, even if the points are
not Poisson. Let
be a stationary multitype point process,
and write
for the process of points of type
.
If the processes
are independent of each other,
then the
-function is identically equal to
.
Deviations
or
typically indicate negative and positive association, respectively,
between types.
See Van Lieshout and Baddeley (1999)
for further information.
An estimate of derived from a multitype spatial point pattern dataset
can be used in exploratory data analysis and formal inference
about the pattern. The estimate of
is compared against the
constant function
.
Deviations
or
may suggest negative and positive association, respectively.
This algorithm estimates the -function
from the multitype point pattern
X
.
It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial marked point process in the plane, observed through
a bounded window.
The argument X
is interpreted as a point pattern object
(of class "ppp"
, see ppp.object
) and can
be supplied in any of the formats recognised by
as.ppp()
. It must be a multitype point pattern
(it must have a marks
vector which is a factor
).
The function Jest
is called to
compute estimates of the functions in the formula above.
In fact three different estimates are computed
using different edge corrections. See
Jest
for
information.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Essentially a data frame containing
r |
the vector of values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
km |
the spatial Kaplan-Meier estimator of |
han |
the Hanisch-style estimator of |
un |
the uncorrected estimate of |
theo |
the theoretical value of |
Sizeable amounts of memory may be needed during the calculation.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Van Lieshout, M.N.M. and Baddeley, A.J. (1996) A nonparametric measure of spatial interaction in point patterns. Statistica Neerlandica 50, 344–361.
Van Lieshout, M.N.M. and Baddeley, A.J. (1999) Indices of dependence between types in multivariate point patterns. Scandinavian Journal of Statistics 26, 511–532.
Ic <- Iest(amacrine) plot(Ic, main="Amacrine Cells data") # values are below I= 0, suggesting negative association # between 'on' and 'off' cells.
Ic <- Iest(amacrine) plot(Ic, main="Amacrine Cells data") # values are below I= 0, suggesting negative association # between 'on' and 'off' cells.
Compute the change in the value of a function f
when the function argument increases by delta
.
increment.fv(f, delta)
increment.fv(f, delta)
f |
Object of class |
delta |
Numeric. The increase in the value of the function argument. |
This command computes the new function
where h = delta/2
. The value of is
the change in the value of
over an interval of length
delta
centred at .
Another object of class "fv"
compatible with X
.
Adrian Baddeley [email protected]
Rolf Turner [email protected]
and Ege Rubak [email protected]
plot(increment.fv(Kest(cells), 0.05))
plot(increment.fv(Kest(cells), 0.05))
Compute the integral of a function over a specified range.
## S3 method for class 'fv' integral(f, domain = NULL, ...)
## S3 method for class 'fv' integral(f, domain = NULL, ...)
f |
A function value table
(object of class |
domain |
Optional. Range of values of the argument |
... |
Ignored. |
This is a method for the generic function integral
.
It computes the numerical integral
of the function object f
.
If domain
is specified, the integral is restricted to the
interval of values given by the
domain
.
The result is a numeric value or numeric vector containing one entry
for each column of function values in f
.
Integrals are calculated numerically using the trapezoidal rule restricted to the domain given.
A single numerical value, or a numeric vector.
Adrian Baddeley [email protected].
g <- pcf(redwood, divisor="d") integral(g, domain=c(0, 0.1))
g <- pcf(redwood, divisor="d") integral(g, domain=c(0, 0.1))
For a multitype point pattern,
estimate the multitype function
summarising the interpoint dependence between
points of type
and of type
.
Jcross(X, i, j, eps=NULL, r=NULL, breaks=NULL, ..., correction=NULL)
Jcross(X, i, j, eps=NULL, r=NULL, breaks=NULL, ..., correction=NULL)
X |
The observed point pattern,
from which an estimate of the multitype |
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
eps |
A positive number. The resolution of the discrete approximation to Euclidean distance (see below). There is a sensible default. |
r |
Optional. Numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
... |
Ignored. |
correction |
Optional. Character string specifying the edge correction(s)
to be used. Options are |
This function Jcross
and its companions
Jdot
and Jmulti
are generalisations of the function Jest
to multitype point patterns.
A multitype point pattern is a spatial pattern of points classified into a finite number of possible “colours” or “types”. In the spatstat package, a multitype pattern is represented as a single point pattern object in which the points carry marks, and the mark value attached to each point determines the type of that point.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The argument i
will be interpreted as a
level of the factor X$marks
. (Warning: this means that
an integer value i=3
will be interpreted as the number 3,
not the 3rd smallest level).
The “type to type
” multitype
function
of a stationary multitype point process
was introduced by Van lieshout and Baddeley (1999). It is defined by
where is the distribution function of
the distance from a type
point to the nearest point of type
,
and
is the distribution
function of the distance from a fixed point in space to the nearest
point of type
in the pattern.
An estimate of
is a useful summary statistic in exploratory data analysis
of a multitype point pattern.
If the subprocess of type
points is independent
of the subprocess of points of type
,
then
.
Hence deviations of the empirical estimate of
from the value 1
may suggest dependence between types.
This algorithm estimates
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Jest
,
using the Kaplan-Meier and border corrections.
The main work is done by Gmulti
and Fest
.
The argument r
is the vector of values for the
distance at which
should be evaluated.
The values of
must be increasing nonnegative numbers
and the maximum
value must not exceed the radius of the
largest disc contained in the window.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing six numeric columns
J |
the recommended
estimator of |
r |
the values of the argument |
km |
the Kaplan-Meier
estimator of |
rs |
the “reduced sample” or “border correction”
estimator of |
han |
the Hanisch-style
estimator of |
un |
the “uncorrected”
estimator of |
theo |
the theoretical value of |
The result also has two attributes "G"
and "F"
which are respectively the outputs of Gcross
and Fest
for the point pattern.
The arguments i
and j
are always interpreted as
levels of the factor X$marks
. They are converted to character
strings if they are not already character strings.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Van Lieshout, M.N.M. and Baddeley, A.J. (1996) A nonparametric measure of spatial interaction in point patterns. Statistica Neerlandica 50, 344–361.
Van Lieshout, M.N.M. and Baddeley, A.J. (1999) Indices of dependence between types in multivariate point patterns. Scandinavian Journal of Statistics 26, 511–532.
# Lansing woods data: 6 types of trees woods <- lansing Jhm <- Jcross(woods, "hickory", "maple") # diagnostic plot for independence between hickories and maples plot(Jhm) # synthetic example with two types "a" and "b" pp <- runifpoint(30) %mark% factor(sample(c("a","b"), 30, replace=TRUE)) J <- Jcross(pp)
# Lansing woods data: 6 types of trees woods <- lansing Jhm <- Jcross(woods, "hickory", "maple") # diagnostic plot for independence between hickories and maples plot(Jhm) # synthetic example with two types "a" and "b" pp <- runifpoint(30) %mark% factor(sample(c("a","b"), 30, replace=TRUE)) J <- Jcross(pp)
For a multitype point pattern,
estimate the inhomogeneous multitype function
summarising the interpoint dependence between
points of type
and of type
.
Jcross.inhom(X, i, j, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
Jcross.inhom(X, i, j, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
X |
The observed point pattern,
from which an estimate of the multitype |
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
lambda |
Optional.
Values of the estimated intensity of the point process.
Either a pixel image (object of class |
lambdaI |
Optional.
Values of the estimated intensity of the sub-process of
points of type |
lambdaJ |
Optional.
Values of the the estimated intensity of the sub-process of
points of type |
lambdamin |
Optional. The minimum possible value of the intensity over the spatial domain. A positive numerical value. |
... |
Extra arguments passed to |
r |
vector of values for the argument |
ReferenceMeasureMarkSetI |
Optional. The total measure of the mark set. A positive number. |
ratio |
Logical value indicating whether to save ratio information. |
This function is the counterpart of Jcross
for inhomogeneous patterns. It is computed as a special case
of Jmulti.inhom
.
Object of class "fv"
containing the estimate of the
inhomogeneous multitype function.
Jonatan Gonzalez and Adrian Baddeley [email protected].
Cronie, O. and Van Lieshout, M.N.M. (2015) Summary statistics for inhomogeneous marked point processes. Annals of the Institute of Statistical Mathematics DOI: 10.1007/s10463-015-0515-z
Jdot.inhom
, Jmulti.inhom
,
Jcross
.
X <- rescale(amacrine) if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 dd <- NULL } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 dd <- 32 } JC <- Jcross.inhom(X, "on", "off", lambda=lam, lambdamin=lmin, dimyx=dd)
X <- rescale(amacrine) if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 dd <- NULL } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 dd <- 32 } JC <- Jcross.inhom(X, "on", "off", lambda=lam, lambdamin=lmin, dimyx=dd)
For a multitype point pattern,
estimate the multitype function
summarising the interpoint dependence between
the type
points and the points of any type.
Jdot(X, i, eps=NULL, r=NULL, breaks=NULL, ..., correction=NULL)
Jdot(X, i, eps=NULL, r=NULL, breaks=NULL, ..., correction=NULL)
X |
The observed point pattern,
from which an estimate of the multitype |
i |
The type (mark value)
of the points in |
eps |
A positive number. The resolution of the discrete approximation to Euclidean distance (see below). There is a sensible default. |
r |
numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
... |
Ignored. |
correction |
Optional. Character string specifying the edge correction(s)
to be used. Options are |
This function Jdot
and its companions
Jcross
and Jmulti
are generalisations of the function Jest
to multitype point patterns.
A multitype point pattern is a spatial pattern of points classified into a finite number of possible “colours” or “types”. In the spatstat package, a multitype pattern is represented as a single point pattern object in which the points carry marks, and the mark value attached to each point determines the type of that point.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The argument i
will be interpreted as a
level of the factor X$marks
. (Warning: this means that
an integer value i=3
will be interpreted as the number 3,
not the 3rd smallest level.)
The “type to any type” multitype
function
of a stationary multitype point process
was introduced by Van lieshout and Baddeley (1999). It is defined by
where is the distribution function of
the distance from a type
point to the nearest other point
of the pattern, and
is the distribution
function of the distance from a fixed point in space to the nearest
point of the pattern.
An estimate of
is a useful summary statistic in exploratory data analysis
of a multitype point pattern. If the pattern is
a marked Poisson point process, then
.
If the subprocess of type
points is independent
of the subprocess of points of all types not equal to
,
then
equals
, the ordinary
function
(see
Jest
and Van Lieshout and Baddeley (1996))
of the points of type .
Hence deviations from zero of the empirical estimate of
may suggest dependence between types.
This algorithm estimates
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Jest
,
using the Kaplan-Meier and border corrections.
The main work is done by Gmulti
and Fest
.
The argument r
is the vector of values for the
distance at which
should be evaluated.
The values of
must be increasing nonnegative numbers
and the maximum
value must not exceed the radius of the
largest disc contained in the window.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing six numeric columns
J |
the recommended
estimator of |
r |
the values of the argument |
km |
the Kaplan-Meier
estimator of |
rs |
the “reduced sample” or “border correction”
estimator of |
han |
the Hanisch-style
estimator of |
un |
the “uncorrected”
estimator of |
theo |
the theoretical value of |
The result also has two attributes "G"
and "F"
which are respectively the outputs of Gdot
and Fest
for the point pattern.
The argument i
is interpreted as
a level of the factor X$marks
. It is converted to a character
string if it is not already a character string.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Van Lieshout, M.N.M. and Baddeley, A.J. (1996) A nonparametric measure of spatial interaction in point patterns. Statistica Neerlandica 50, 344–361.
Van Lieshout, M.N.M. and Baddeley, A.J. (1999) Indices of dependence between types in multivariate point patterns. Scandinavian Journal of Statistics 26, 511–532.
# Lansing woods data: 6 types of trees woods <- lansing Jh. <- Jdot(woods, "hickory") plot(Jh.) # diagnostic plot for independence between hickories and other trees Jhh <- Jest(split(woods)$hickory) plot(Jhh, add=TRUE, legendpos="bottom") # synthetic example with two marks "a" and "b" pp <- runifpoint(30) %mark% factor(sample(c("a","b"), 30, replace=TRUE)) J <- Jdot(pp, "a")
# Lansing woods data: 6 types of trees woods <- lansing Jh. <- Jdot(woods, "hickory") plot(Jh.) # diagnostic plot for independence between hickories and other trees Jhh <- Jest(split(woods)$hickory) plot(Jhh, add=TRUE, legendpos="bottom") # synthetic example with two marks "a" and "b" pp <- runifpoint(30) %mark% factor(sample(c("a","b"), 30, replace=TRUE)) J <- Jdot(pp, "a")
For a multitype point pattern,
estimate the inhomogeneous multitype function
summarising the interpoint dependence between
points of type
and points of any type.
Jdot.inhom(X, i, lambdaI = NULL, lambdadot = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
Jdot.inhom(X, i, lambdaI = NULL, lambdadot = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
X |
The observed point pattern,
from which an estimate of the inhomogeneous multitype |
i |
The type (mark value)
of the points in |
lambdaI |
Optional.
Values of the estimated intensity of the sub-process of
points of type |
lambdadot |
Optional.
Values of the estimated intensity of the point process.
Either a pixel image (object of class |
lambdamin |
Optional. The minimum possible value of the intensity over the spatial domain. A positive numerical value. |
... |
Extra arguments passed to |
r |
vector of values for the argument |
ReferenceMeasureMarkSetI |
Optional. The total measure of the mark set. A positive number. |
ratio |
Logical value indicating whether to save ratio information. |
This function is the counterpart of Jdot
for inhomogeneous patterns. It is computed as a special case
of Jmulti.inhom
.
Object of class "fv"
containing the estimate of the
inhomogeneous multitype function.
Jonatan Gonzalez and Adrian Baddeley [email protected].
Cronie, O. and Van Lieshout, M.N.M. (2015) Summary statistics for inhomogeneous marked point processes. Annals of the Institute of Statistical Mathematics DOI: 10.1007/s10463-015-0515-z
Jdot.inhom
, Jmulti.inhom
,
Jdot
.
X <- rescale(amacrine) if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 dd <- NULL } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 dd <- 32 } lamI <- lam[marks(X) == "on"] JD <- Jdot.inhom(X, "on", lambdaI=lamI, lambdadot=lam, lambdamin=lmin, dimyx=dd)
X <- rescale(amacrine) if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 dd <- NULL } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 dd <- 32 } lamI <- lam[marks(X) == "on"] JD <- Jdot.inhom(X, "on", lambdaI=lamI, lambdadot=lam, lambdamin=lmin, dimyx=dd)
Estimates the summary function for a point pattern in a
window of arbitrary shape.
Jest(X, ..., eps=NULL, r=NULL, breaks=NULL, correction=NULL)
Jest(X, ..., eps=NULL, r=NULL, breaks=NULL, correction=NULL)
X |
The observed point pattern,
from which an estimate of |
... |
Ignored. |
eps |
the resolution of the discrete approximation to Euclidean distance (see below). There is a sensible default. |
r |
vector of values for the argument |
breaks |
This argument is for internal use only. |
correction |
Optional. Character string specifying the choice of edge
correction(s) in |
The function (Van Lieshout and Baddeley, 1996)
of a stationary point process is defined as
where is the nearest neighbour distance distribution
function of the point process (see
Gest
)
and is its empty space function (see
Fest
).
For a completely random (uniform Poisson) point process,
the -function is identically equal to
.
Deviations
or
typically indicate spatial clustering or spatial regularity, respectively.
The
-function is one of the few characteristics that can be
computed explicitly for a wide range of point processes.
See Van Lieshout and Baddeley (1996), Baddeley et al (2000),
Thonnes and Van Lieshout (1999) for further information.
An estimate of derived from a spatial point pattern dataset
can be used in exploratory data analysis and formal inference
about the pattern. The estimate of
is compared against the
constant function
.
Deviations
or
may suggest spatial clustering or spatial regularity, respectively.
This algorithm estimates the -function
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
The argument X
is interpreted as a point pattern object
(of class "ppp"
, see ppp.object
) and can
be supplied in any of the formats recognised by
as.ppp()
.
The functions Fest
and Gest
are called to
compute estimates of and
respectively.
These estimates are then combined by simply taking the ratio
.
In fact several different estimates are computed using different edge corrections (Baddeley, 1998).
The Kaplan-Meier estimate (returned as km
) is the ratio
J = (1-G)/(1-F)
of the Kaplan-Meier estimates of
and
computed by
Fest
and Gest
respectively.
This is computed if correction=NULL
or if correction
includes "km"
.
The Hanisch-style estimate (returned as han
) is the ratio
J = (1-G)/(1-F)
where F
is the Chiu-Stoyan estimate of
and
G
is the Hanisch estimate of .
This is computed if
correction=NULL
or if correction
includes "cs"
or "han"
.
The reduced-sample or border corrected estimate
(returned as rs
) is
the same ratio J = (1-G)/(1-F)
of the border corrected estimates.
This is computed if correction=NULL
or if correction
includes "rs"
or "border"
.
These edge-corrected estimators are slightly biased for ,
since they are ratios
of approximately unbiased estimators.
The logarithm of the
Kaplan-Meier estimate is exactly unbiased for
.
The uncorrected estimate (returned as un
and computed only if correction
includes "none"
)
is the ratio J = (1-G)/(1-F)
of the uncorrected (“raw”) estimates of the survival functions
of and
,
which are the empirical distribution functions of the
empty space distances
Fest(X,...)$raw
and of the nearest neighbour distances
Gest(X,...)$raw
. The uncorrected estimates
of and
are severely biased.
However the uncorrected estimate of
is approximately unbiased (if the process is close to Poisson);
it is insensitive to edge effects, and should be used when
edge effects are severe (see Baddeley et al, 2000).
The algorithm for Fest
uses two discrete approximations which are controlled
by the parameter eps
and by the spacing of values of r
respectively. See Fest
for details.
First-time users are strongly advised not to specify these arguments.
Note that the value returned by Jest
includes
the output of Fest
and Gest
as attributes (see the last example below).
If the user is intending to compute the F,G
and J
functions for the point pattern, it is only necessary to
call Jest
.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Essentially a data frame containing
r |
the vector of values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
km |
the spatial Kaplan-Meier estimator of |
han |
the Hanisch-style estimator of |
un |
the uncorrected estimate of |
theo |
the theoretical value of |
The data frame also has attributes
F |
the output of |
G |
the output of |
Sizeable amounts of memory may be needed during the calculation.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Baddeley, A.J. Spatial sampling and censoring. In O.E. Barndorff-Nielsen, W.S. Kendall and M.N.M. van Lieshout (eds) Stochastic Geometry: Likelihood and Computation. Chapman and Hall, 1998. Chapter 2, pages 37–78.
Baddeley, A.J. and Gill, R.D. The empty space hazard of a spatial pattern. Research Report 1994/3, Department of Mathematics, University of Western Australia, May 1994.
Baddeley, A.J. and Gill, R.D. Kaplan-Meier estimators of interpoint distance distributions for spatial point processes. Annals of Statistics 25 (1997) 263–292.
Baddeley, A., Kerscher, M., Schladitz, K. and Scott, B.T. Estimating the J function without edge correction. Statistica Neerlandica 54 (2000) 315–328.
Borgefors, G. Distance transformations in digital images. Computer Vision, Graphics and Image Processing 34 (1986) 344–371.
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
Thonnes, E. and Van Lieshout, M.N.M, A comparative study on the power of Van Lieshout and Baddeley's J-function. Biometrical Journal 41 (1999) 721–734.
Van Lieshout, M.N.M. and Baddeley, A.J. A nonparametric measure of spatial interaction in point patterns. Statistica Neerlandica 50 (1996) 344–361.
Jinhom
,
Fest
,
Gest
,
Kest
,
km.rs
,
reduced.sample
,
kaplan.meier
J <- Jest(cells, 0.01) plot(J, main="cells data") # values are far above J = 1, indicating regular pattern data(redwood) J <- Jest(redwood, 0.01, legendpos="center") plot(J, main="redwood data") # values are below J = 1, indicating clustered pattern
J <- Jest(cells, 0.01) plot(J, main="cells data") # values are far above J = 1, indicating regular pattern data(redwood) J <- Jest(redwood, 0.01, legendpos="center") plot(J, main="redwood data") # values are below J = 1, indicating clustered pattern
Estimates the inhomogeneous function of
a non-stationary point pattern.
Jinhom(X, lambda = NULL, lmin = NULL, ..., sigma = NULL, varcov = NULL, r = NULL, breaks = NULL, ratio=FALSE, update = TRUE, warn.bias=TRUE, savelambda=FALSE)
Jinhom(X, lambda = NULL, lmin = NULL, ..., sigma = NULL, varcov = NULL, r = NULL, breaks = NULL, ratio=FALSE, update = TRUE, warn.bias=TRUE, savelambda=FALSE)
X |
The observed data point pattern,
from which an estimate of the inhomogeneous |
lambda |
Optional.
Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern |
lmin |
Optional. The minimum possible value of the intensity over the spatial domain. A positive numerical value. |
sigma , varcov
|
Optional arguments passed to |
... |
Extra arguments passed to |
r |
vector of values for the argument |
breaks |
This argument is for internal use only. |
ratio |
Logical.
If |
update |
Logical. If |
warn.bias |
Logical value specifying whether to issue a warning when the inhomogeneity correction factor takes extreme values, which can often lead to biased results. This usually occurs when insufficient smoothing is used to estimate the intensity. |
savelambda |
Logical value specifying whether to save the values of
|
This command computes estimates of the
inhomogeneous -function (Van Lieshout, 2010)
of a point pattern. It is the counterpart, for inhomogeneous
spatial point patterns, of the
function
for homogeneous point patterns computed by
Jest
.
The argument X
should be a point pattern
(object of class "ppp"
).
The inhomogeneous function is computed as
where
are the inhomogeneous
and
functions computed using the border correction
(equations (7) and (6) respectively in Van Lieshout, 2010).
The argument lambda
should supply the
(estimated) values of the intensity function
of the point process. It may be either
containing the values
of the intensity function at the points of the pattern X
.
(object of class "im"
)
assumed to contain the values of the intensity function
at all locations in the window.
(object of class "ppm"
or "kppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
which can be evaluated to give values of the intensity at any locations.
if lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
If lambda
is a numeric vector, then its length should
be equal to the number of points in the pattern X
.
The value lambda[i]
is assumed to be the
the (estimated) value of the intensity
for
the point
of the pattern
.
Each value must be a positive number;
NA
's are not allowed.
If lambda
is a pixel image, the domain of the image should
cover the entire window of the point pattern. If it does not (which
may occur near the boundary because of discretisation error),
then the missing pixel values
will be obtained by applying a Gaussian blur to lambda
using
blur
, then looking up the values of this blurred image
for the missing locations.
(A warning will be issued in this case.)
If lambda
is a function, then it will be evaluated in the
form lambda(x,y)
where x
and y
are vectors
of coordinates of the points of X
. It should return a numeric
vector with length equal to the number of points in X
.
If lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
The estimate lambda[i]
for the
point X[i]
is computed by removing X[i]
from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point X[i]
. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
Original code by Marie-Colette van Lieshout. C implementation and R adaptation by Adrian Baddeley [email protected] and Ege Rubak [email protected].
van Lieshout, M.N.M. and Baddeley, A.J. (1996) A nonparametric measure of spatial interaction in point patterns. Statistica Neerlandica 50, 344–361.
van Lieshout, M.N.M. (2010) A J-function for inhomogeneous point processes. Statistica Neerlandica 65, 183–201.
online <- interactive() if(online) { plot(Jinhom(swedishpines, sigma=10)) plot(Jinhom(swedishpines, sigma=bw.diggle, adjust=2)) } else { ## use a coarse grid for faster computation and package testing plot(Jinhom(swedishpines, sigma=10, dimyx=32)) }
online <- interactive() if(online) { plot(Jinhom(swedishpines, sigma=10)) plot(Jinhom(swedishpines, sigma=bw.diggle, adjust=2)) } else { ## use a coarse grid for faster computation and package testing plot(Jinhom(swedishpines, sigma=10, dimyx=32)) }
For a marked point pattern,
estimate the multitype function
summarising dependence between the
points in subset
and those in subset
.
Jmulti(X, I, J, eps=NULL, r=NULL, breaks=NULL, ..., disjoint=NULL, correction=NULL)
Jmulti(X, I, J, eps=NULL, r=NULL, breaks=NULL, ..., disjoint=NULL, correction=NULL)
X |
The observed point pattern,
from which an estimate of the multitype distance distribution function
|
I |
Subset of points of |
J |
Subset of points in |
eps |
A positive number.
The pixel resolution of the discrete approximation to Euclidean
distance (see |
r |
numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
... |
Ignored. |
disjoint |
Optional flag indicating whether
the subsets |
correction |
Optional. Character string specifying the edge correction(s)
to be used. Options are |
The function Jmulti
generalises Jest
(for unmarked point
patterns) and Jdot
and Jcross
(for
multitype point patterns) to arbitrary marked point patterns.
Suppose ,
are subsets, possibly
overlapping, of a marked point process. Define
where is the cumulative distribution function of
the distance from a fixed location to the nearest point
of
, and
is the distribution function of the distance
from a typical point of
to the nearest distinct point of
.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
The arguments I
and J
specify two subsets of the
point pattern. They may be any type of subset indices, for example,
logical vectors of length equal to npoints(X)
,
or integer vectors with entries in the range 1 to
npoints(X)
, or negative integer vectors.
Alternatively, I
and J
may be functions
that will be applied to the point pattern X
to obtain
index vectors. If I
is a function, then evaluating
I(X)
should yield a valid subset index. This option
is useful when generating simulation envelopes using
envelope
.
It is assumed that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Jest
.
The argument r
is the vector of values for the
distance at which
should be evaluated.
It is also used to determine the breakpoints
(in the sense of
hist
)
for the computation of histograms of distances. The reduced-sample and
Kaplan-Meier estimators are computed from histogram counts.
In the case of the Kaplan-Meier estimator this introduces a discretisation
error which is controlled by the fineness of the breakpoints.
First-time users would be strongly advised not to specify r
.
However, if it is specified, r
must satisfy r[1] = 0
,
and max(r)
must be larger than the radius of the largest disc
contained in the window. Furthermore, the successive entries of r
must be finely spaced.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing six numeric columns
r |
the values of the argument |
rs |
the “reduced sample” or “border correction”
estimator of |
km |
the spatial Kaplan-Meier estimator of |
han |
the Hanisch-style estimator of |
un |
the uncorrected estimate of |
theo |
the theoretical value of |
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Van Lieshout, M.N.M. and Baddeley, A.J. (1999) Indices of dependence between types in multivariate point patterns. Scandinavian Journal of Statistics 26, 511–532.
trees <- longleaf # Longleaf Pine data: marks represent diameter Jm <- Jmulti(trees, marks(trees) <= 15, marks(trees) >= 25) plot(Jm)
trees <- longleaf # Longleaf Pine data: marks represent diameter Jm <- Jmulti(trees, marks(trees) <= 15, marks(trees) >= 25) plot(Jm)
For a marked point pattern,
estimate the inhomogeneous version of the multitype function.
Jmulti.inhom(X, I, J, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
Jmulti.inhom(X, I, J, lambda = NULL, lambdaI = NULL, lambdaJ = NULL, lambdamin = NULL, ..., r = NULL, ReferenceMeasureMarkSetI = NULL, ratio = FALSE)
X |
The observed point pattern,
from which an estimate of the inhomogeneous multitype |
I |
Subset index specifying the points of |
J |
Subset index specifying the points in |
lambda |
Optional.
Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern |
lambdaI |
Optional.
Values of the estimated intensity of the sub-process |
lambdaJ |
Optional.
Values of the estimated intensity of the sub-process |
lambdamin |
Optional. The minimum possible value of the intensity over the spatial domain. A positive numerical value. |
... |
Extra arguments passed to |
r |
vector of values for the argument |
ReferenceMeasureMarkSetI |
Optional. The total measure of the mark set. A positive number. |
ratio |
Logical value indicating whether to save ratio information. |
This function is the counterpart of Jmulti
for inhomogeneous patterns. It is computed by evaluating the
inhomogeneous function
GmultiInhom
and the inhomogeneous function
FmultiInhom
and computing the ratio .
Object of class "fv"
containing the estimate of the
inhomogeneous multitype function.
Jonatan Gonzalez and Adrian Baddeley [email protected].
Cronie, O. and Van Lieshout, M.N.M. (2015) Summary statistics for inhomogeneous marked point processes. Annals of the Institute of Statistical Mathematics DOI: 10.1007/s10463-015-0515-z
Jcross.inhom
, Jdot.inhom
for special cases.
GmultiInhom
, FmultiInhom
,
Jmulti
.
X <- rescale(amacrine) I <- (marks(X) == "on") J <- (marks(X) == "off") if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 dd <- NULL } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 dd <- 32 } JM <- Jmulti.inhom(X, I, J, lambda=lam, lambdamin=lmin, dimyx=dd)
X <- rescale(amacrine) I <- (marks(X) == "on") J <- (marks(X) == "off") if(interactive() && require(spatstat.model)) { ## how to do it normally mod <- ppm(X ~ marks * x) lam <- fitted(mod, dataonly=TRUE) lmin <- min(predict(mod)[["off"]]) * 0.9 dd <- NULL } else { ## for package testing lam <- intensity(X)[as.integer(marks(X))] lmin <- intensity(X)[2] * 0.9 dd <- 32 } JM <- Jmulti.inhom(X, I, J, lambda=lam, lambdamin=lmin, dimyx=dd)
Estimates the -function from a three-dimensional point pattern.
K3est(X, ..., rmax = NULL, nrval = 128, correction = c("translation", "isotropic"), ratio=FALSE)
K3est(X, ..., rmax = NULL, nrval = 128, correction = c("translation", "isotropic"), ratio=FALSE)
X |
Three-dimensional point pattern (object of class |
... |
Ignored. |
rmax |
Optional. Maximum value of argument |
nrval |
Optional. Number of values of |
correction |
Optional. Character vector specifying the edge correction(s) to be applied. See Details. |
ratio |
Logical.
If |
For a stationary point process in three-dimensional
space, the three-dimensional
function
is
where is the intensity of the process
(the expected number of points per unit volume) and
is the number of points of
, other than
itself, which fall within a
distance
of
. This is the three-dimensional
generalisation of Ripley's
function for two-dimensional
point processes (Ripley, 1977).
The three-dimensional point pattern X
is assumed to be a
partial realisation of a stationary point process .
The distance between each pair of distinct points is computed.
The empirical cumulative distribution
function of these values, with appropriate edge corrections, is
renormalised to give the estimate of
.
The available edge corrections are:
"translation"
:the Ohser translation correction estimator (Ohser, 1983; Baddeley et al, 1993)
"isotropic"
:the three-dimensional counterpart of Ripley's isotropic edge correction (Ripley, 1977; Baddeley et al, 1993).
Alternatively correction="all"
selects all options.
A function value table (object of class "fv"
) that can be
plotted, printed or coerced to a data frame containing the function values.
Adrian Baddeley [email protected] and Rana Moyeed.
Baddeley, A.J, Moyeed, R.A., Howard, C.V. and Boyde, A. (1993) Analysis of a three-dimensional point pattern with replication. Applied Statistics 42, 641–668.
Ohser, J. (1983) On estimators for the reduced second moment measure of point processes. Mathematische Operationsforschung und Statistik, series Statistics, 14, 63 – 71.
Ripley, B.D. (1977) Modelling spatial patterns (with discussion). Journal of the Royal Statistical Society, Series B, 39, 172 – 212.
pp3
to create a three-dimensional point
pattern (object of class "pp3"
).
pcf3est
,
F3est
,
G3est
for other summary functions of
a three-dimensional point pattern.
Kest
to estimate the -function of
point patterns in two dimensions or other spaces.
X <- rpoispp3(42) Z <- K3est(X) if(interactive()) plot(Z)
X <- rpoispp3(42) Z <- K3est(X) if(interactive()) plot(Z)
For a multitype point pattern,
estimate the multitype function
which counts the expected number of points of type
within a given distance of a point of type
.
Kcross(X, i, j, r=NULL, breaks=NULL, correction, ..., ratio=FALSE, from, to )
Kcross(X, i, j, r=NULL, breaks=NULL, correction, ..., ratio=FALSE, from, to )
X |
The observed point pattern,
from which an estimate of the cross type |
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
r |
numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
correction |
A character vector containing any selection of the
options |
... |
Ignored. |
ratio |
Logical.
If |
from , to
|
An alternative way to specify |
This function Kcross
and its companions
Kdot
and Kmulti
are generalisations of the function Kest
to multitype point patterns.
A multitype point pattern is a spatial pattern of points classified into a finite number of possible “colours” or “types”. In the spatstat package, a multitype pattern is represented as a single point pattern object in which the points carry marks, and the mark value attached to each point determines the type of that point.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The arguments i
and j
will be interpreted as
levels of the factor X$marks
.
If i
and j
are missing, they default to the first
and second level of the marks factor, respectively.
The “cross-type” (type to type
)
function
of a stationary multitype point process
is defined so that
equals the expected number of
additional random points of type
within a distance
of a
typical point of type
in the process
.
Here
is the intensity of the type
points,
i.e. the expected number of points of type
per unit area.
The function
is determined by the
second order moment properties of
.
An estimate of
is a useful summary statistic in exploratory data analysis
of a multitype point pattern.
If the process of type
points
were independent of the process of type
points,
then
would equal
.
Deviations between the empirical
curve
and the theoretical curve
may suggest dependence between the points of types
and
.
This algorithm estimates the distribution function
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Kest
,
using the border correction.
The argument r
is the vector of values for the
distance at which
should be evaluated.
The values of
must be increasing nonnegative numbers
and the maximum
value must not exceed the radius of the
largest disc contained in the window.
The pair correlation function can also be applied to the
result of Kcross
; see pcf
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
If ratio=TRUE
then the return value also has two
attributes called "numerator"
and "denominator"
which are "fv"
objects
containing the numerators and denominators of each
estimate of .
The arguments i
and j
are always interpreted as
levels of the factor X$marks
. They are converted to character
strings if they are not already character strings.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Harkness, R.D and Isham, V. (1983) A bivariate spatial point pattern of ants' nests. Applied Statistics 32, 293–303
Lotwick, H. W. and Silverman, B. W. (1982). Methods for analysing spatial processes of several types of points. J. Royal Statist. Soc. Ser. B 44, 406–413.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
# amacrine cells data K01 <- Kcross(amacrine, "off", "on") plot(K01) # synthetic example: point pattern with marks 0 and 1 pp <- runifpoispp(50) pp <- pp %mark% factor(sample(0:1, npoints(pp), replace=TRUE)) K <- Kcross(pp, "0", "1") K <- Kcross(pp, 0, 1) # equivalent
# amacrine cells data K01 <- Kcross(amacrine, "off", "on") plot(K01) # synthetic example: point pattern with marks 0 and 1 pp <- runifpoispp(50) pp <- pp %mark% factor(sample(0:1, npoints(pp), replace=TRUE)) K <- Kcross(pp, "0", "1") K <- Kcross(pp, 0, 1) # equivalent
For a multitype point pattern,
estimate the inhomogeneous version of the cross function,
which counts the expected number of points of type
within a given distance of a point of type
,
adjusted for spatially varying intensity.
Kcross.inhom(X, i, j, lambdaI=NULL, lambdaJ=NULL, ..., r=NULL, breaks=NULL, correction = c("border", "isotropic", "Ripley", "translate"), sigma=NULL, varcov=NULL, lambdaIJ=NULL, lambdaX=NULL, update=TRUE, leaveoneout=TRUE)
Kcross.inhom(X, i, j, lambdaI=NULL, lambdaJ=NULL, ..., r=NULL, breaks=NULL, correction = c("border", "isotropic", "Ripley", "translate"), sigma=NULL, varcov=NULL, lambdaIJ=NULL, lambdaX=NULL, update=TRUE, leaveoneout=TRUE)
X |
The observed point pattern,
from which an estimate of the inhomogeneous cross type |
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
lambdaI |
Optional.
Values of the estimated intensity of the sub-process of
points of type |
lambdaJ |
Optional.
Values of the the estimated intensity of the sub-process of
points of type |
r |
Optional. Numeric vector giving the values of the argument |
breaks |
This argument is for advanced use only. |
correction |
A character vector containing any selection of the
options |
... |
Ignored. |
sigma |
Standard deviation of isotropic Gaussian smoothing kernel,
used in computing leave-one-out kernel estimates of
|
varcov |
Variance-covariance matrix of anisotropic Gaussian kernel,
used in computing leave-one-out kernel estimates of
|
lambdaIJ |
Optional. A matrix containing estimates of the
product of the intensities |
lambdaX |
Optional. Values of the intensity for all points of |
update |
Logical value indicating what to do when
|
leaveoneout |
Logical value (passed to |
This is a generalisation of the function Kcross
to include an adjustment for spatially inhomogeneous intensity,
in a manner similar to the function Kinhom
.
The inhomogeneous cross-type function is described by
Moller and Waagepetersen (2003, pages 48-49 and 51-53).
Briefly, given a multitype point process, suppose the sub-process
of points of type has intensity function
at spatial locations
.
Suppose we place a mass of
at each point
of type
. Then the expected total
mass per unit area is 1. The
inhomogeneous “cross-type”
function
equals the expected
total mass within a radius
of a point of the process
of type
.
If the process of type points
were independent of the process of type
points,
then
would equal
.
Deviations between the empirical
curve
and the theoretical curve
suggest dependence between the points of types
and
.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The arguments i
and j
will be interpreted as
levels of the factor X$marks
. (Warning: this means that
an integer value i=3
will be interpreted as the number 3,
not the 3rd smallest level).
If i
and j
are missing, they default to the first
and second level of the marks factor, respectively.
The argument lambdaI
supplies the values
of the intensity of the sub-process of points of type i
.
It may be either
(object of class "im"
) which
gives the values of the type i
intensity
at all locations in the window containing X
;
containing the values of the
type i
intensity evaluated only
at the data points of type i
. The length of this vector
must equal the number of type i
points in X
.
which can be evaluated to give values of the intensity at any locations.
(object of class "ppm"
, "kppm"
or "dppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
if lambdaI
is omitted then it will be estimated
using a leave-one-out kernel smoother.
If lambdaI
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother,
as described in Baddeley, Moller
and Waagepetersen (2000). The estimate of lambdaI
for a given
point is computed by removing the point from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point in question. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
Similarly lambdaJ
should contain
estimated values of the intensity of the sub-process of points of
type j
. It may be either a pixel image, a function,
a numeric vector, or omitted.
Alternatively if the argument lambdaX
is given, then it specifies
the intensity values for all points of X
, and the
arguments lambdaI
, lambdaJ
will be ignored.
The optional argument lambdaIJ
is for advanced use only.
It is a matrix containing estimated
values of the products of these two intensities for each pair of
data points of types i
and j
respectively.
The argument r
is the vector of values for the
distance at which
should be evaluated.
The values of
must be increasing nonnegative numbers
and the maximum
value must not exceed the radius of the
largest disc contained in the window.
The argument correction
chooses the edge correction
as explained e.g. in Kest
.
The pair correlation function can also be applied to the
result of Kcross.inhom
; see pcf
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
The arguments i
and j
are always interpreted as
levels of the factor X$marks
. They are converted to character
strings if they are not already character strings.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Baddeley, A., Moller, J. and Waagepetersen, R. (2000) Non- and semiparametric estimation of interaction in inhomogeneous point patterns. Statistica Neerlandica 54, 329–350.
Moller, J. and Waagepetersen, R. Statistical Inference and Simulation for Spatial Point Processes Chapman and Hall/CRC Boca Raton, 2003.
Kcross
,
Kinhom
,
Kdot.inhom
,
Kmulti.inhom
,
pcf
# Lansing Woods data woods <- lansing ma <- split(woods)$maple wh <- split(woods)$whiteoak # method (1): estimate intensities by nonparametric smoothing lambdaM <- density.ppp(ma, sigma=0.15, at="points") lambdaW <- density.ppp(wh, sigma=0.15, at="points") K <- Kcross.inhom(woods, "whiteoak", "maple", lambdaW, lambdaM) # method (2): leave-one-out K <- Kcross.inhom(woods, "whiteoak", "maple", sigma=0.15) # method (3): fit parametric intensity model if(require("spatstat.model")) { fit <- ppm(woods ~marks * polynom(x,y,2)) # alternative (a): use fitted model as 'lambda' argument online <- interactive() K <- Kcross.inhom(woods, "whiteoak", "maple", lambdaI=fit, lambdaJ=fit, update=online, leaveoneout=online) K <- Kcross.inhom(woods, "whiteoak", "maple", lambdaX=fit, update=online, leaveoneout=online) # alternative (b): evaluate fitted intensities at data points # (these are the intensities of the sub-processes of each type) inten <- fitted(fit, dataonly=TRUE, leaveoneout=FALSE) # split according to types of points lambda <- split(inten, marks(woods)) K <- Kcross.inhom(woods, "whiteoak", "maple", lambda$whiteoak, lambda$maple) } # synthetic example: type A points have intensity 50, # type B points have intensity 100 * x lamB <- as.im(function(x,y){50 + 100 * x}, owin()) X <- superimpose(A=runifpoispp(50), B=rpoispp(lamB)) K <- Kcross.inhom(X, "A", "B", lambdaI=as.im(50, Window(X)), lambdaJ=lamB)
# Lansing Woods data woods <- lansing ma <- split(woods)$maple wh <- split(woods)$whiteoak # method (1): estimate intensities by nonparametric smoothing lambdaM <- density.ppp(ma, sigma=0.15, at="points") lambdaW <- density.ppp(wh, sigma=0.15, at="points") K <- Kcross.inhom(woods, "whiteoak", "maple", lambdaW, lambdaM) # method (2): leave-one-out K <- Kcross.inhom(woods, "whiteoak", "maple", sigma=0.15) # method (3): fit parametric intensity model if(require("spatstat.model")) { fit <- ppm(woods ~marks * polynom(x,y,2)) # alternative (a): use fitted model as 'lambda' argument online <- interactive() K <- Kcross.inhom(woods, "whiteoak", "maple", lambdaI=fit, lambdaJ=fit, update=online, leaveoneout=online) K <- Kcross.inhom(woods, "whiteoak", "maple", lambdaX=fit, update=online, leaveoneout=online) # alternative (b): evaluate fitted intensities at data points # (these are the intensities of the sub-processes of each type) inten <- fitted(fit, dataonly=TRUE, leaveoneout=FALSE) # split according to types of points lambda <- split(inten, marks(woods)) K <- Kcross.inhom(woods, "whiteoak", "maple", lambda$whiteoak, lambda$maple) } # synthetic example: type A points have intensity 50, # type B points have intensity 100 * x lamB <- as.im(function(x,y){50 + 100 * x}, owin()) X <- superimpose(A=runifpoispp(50), B=rpoispp(lamB)) K <- Kcross.inhom(X, "A", "B", lambdaI=as.im(50, Window(X)), lambdaJ=lamB)
For a multitype point pattern,
estimate the multitype function
which counts the expected number of other points of the process
within a given distance of a point of type
.
Kdot(X, i, r=NULL, breaks=NULL, correction, ..., ratio=FALSE, from)
Kdot(X, i, r=NULL, breaks=NULL, correction, ..., ratio=FALSE, from)
X |
The observed point pattern,
from which an estimate of the multitype |
i |
The type (mark value)
of the points in |
r |
numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
correction |
A character vector containing any selection of the
options |
... |
Ignored. |
ratio |
Logical.
If |
from |
An alternative way to specify |
This function Kdot
and its companions
Kcross
and Kmulti
are generalisations of the function Kest
to multitype point patterns.
A multitype point pattern is a spatial pattern of points classified into a finite number of possible “colours” or “types”. In the spatstat package, a multitype pattern is represented as a single point pattern object in which the points carry marks, and the mark value attached to each point determines the type of that point.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The argument i
will be interpreted as a
level of the factor X$marks
.
If i
is missing, it defaults to the first
level of the marks factor, i = levels(X$marks)[1]
.
The “type to any type” multitype
function
of a stationary multitype point process
is defined so that
equals the expected number of
additional random points within a distance
of a
typical point of type
in the process
.
Here
is the intensity of the process,
i.e. the expected number of points of
per unit area.
The function
is determined by the
second order moment properties of
.
An estimate of
is a useful summary statistic in exploratory data analysis
of a multitype point pattern.
If the subprocess of type
points were independent
of the subprocess of points of all types not equal to
,
then
would equal
.
Deviations between the empirical
curve
and the theoretical curve
may suggest dependence between types.
This algorithm estimates the distribution function
from the point pattern
X
. It assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Kest
,
using the chosen edge correction(s).
The argument r
is the vector of values for the
distance at which
should be evaluated.
The values of
must be increasing nonnegative numbers
and the maximum
value must not exceed the radius of the
largest disc contained in the window.
The pair correlation function can also be applied to the
result of Kdot
; see pcf
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
If ratio=TRUE
then the return value also has two
attributes called "numerator"
and "denominator"
which are "fv"
objects
containing the numerators and denominators of each
estimate of .
The argument i
is interpreted as
a level of the factor X$marks
. It is converted to a character
string if it is not already a character string.
The value i=1
does not
refer to the first level of the factor.
The reduced sample estimator of is pointwise approximately
unbiased, but need not be a valid distribution function; it may
not be a nondecreasing function of
.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Harkness, R.D and Isham, V. (1983) A bivariate spatial point pattern of ants' nests. Applied Statistics 32, 293–303
Lotwick, H. W. and Silverman, B. W. (1982). Methods for analysing spatial processes of several types of points. J. Royal Statist. Soc. Ser. B 44, 406–413.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
# Lansing woods data: 6 types of trees woods <- lansing Kh. <- Kdot(woods, "hickory") # diagnostic plot for independence between hickories and other trees plot(Kh.) # synthetic example with two marks "a" and "b" pp <- runifpoispp(50) pp <- pp %mark% factor(sample(c("a","b"), npoints(pp), replace=TRUE)) K <- Kdot(pp, "a")
# Lansing woods data: 6 types of trees woods <- lansing Kh. <- Kdot(woods, "hickory") # diagnostic plot for independence between hickories and other trees plot(Kh.) # synthetic example with two marks "a" and "b" pp <- runifpoispp(50) pp <- pp %mark% factor(sample(c("a","b"), npoints(pp), replace=TRUE)) K <- Kdot(pp, "a")
For a multitype point pattern,
estimate the inhomogeneous version of the dot function,
which counts the expected number of points of any type
within a given distance of a point of type
,
adjusted for spatially varying intensity.
Kdot.inhom(X, i, lambdaI=NULL, lambdadot=NULL, ..., r=NULL, breaks=NULL, correction = c("border", "isotropic", "Ripley", "translate"), sigma=NULL, varcov=NULL, lambdaIdot=NULL, lambdaX=NULL, update=TRUE, leaveoneout=TRUE)
Kdot.inhom(X, i, lambdaI=NULL, lambdadot=NULL, ..., r=NULL, breaks=NULL, correction = c("border", "isotropic", "Ripley", "translate"), sigma=NULL, varcov=NULL, lambdaIdot=NULL, lambdaX=NULL, update=TRUE, leaveoneout=TRUE)
X |
The observed point pattern,
from which an estimate of the inhomogeneous dot type |
i |
The type (mark value)
of the points in |
lambdaI |
Optional.
Values of the estimated intensity of the sub-process of
points of type |
lambdadot |
Optional.
Values of the estimated intensity of the entire point process,
Either a pixel image (object of class |
... |
Ignored. |
r |
Optional. Numeric vector giving the values of the argument |
breaks |
This argument is for internal use only. |
correction |
A character vector containing any selection of the
options |
sigma |
Standard deviation of isotropic Gaussian smoothing kernel,
used in computing leave-one-out kernel estimates of
|
varcov |
Variance-covariance matrix of anisotropic Gaussian kernel,
used in computing leave-one-out kernel estimates of
|
lambdaIdot |
Optional. A matrix containing estimates of the
product of the intensities |
lambdaX |
Optional. Values of the intensity for all points of |
update |
Logical value indicating what to do when
|
leaveoneout |
Logical value (passed to |
This is a generalisation of the function Kdot
to include an adjustment for spatially inhomogeneous intensity,
in a manner similar to the function Kinhom
.
Briefly, given a multitype point process, consider the points without
their types, and suppose this unmarked point process
has intensity function
at spatial locations
.
Suppose we place a mass of
at each point
of the process. Then the expected total
mass per unit area is 1. The
inhomogeneous “dot-type”
function
equals the expected
total mass within a radius
of a point of the process
of type
, discounting this point itself.
If the process of type points
were independent of the points of other types,
then
would equal
.
Deviations between the empirical
curve
and the theoretical curve
suggest dependence between the points of types
and
for
.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern, and the mark vector
X$marks
must be a factor.
The argument i
will be interpreted as a
level of the factor X$marks
. (Warning: this means that
an integer value i=3
will be interpreted as the number 3,
not the 3rd smallest level).
If i
is missing, it defaults to the first
level of the marks factor, i = levels(X$marks)[1]
.
The argument lambdaI
supplies the values
of the intensity of the sub-process of points of type i
.
It may be either
(object of class "im"
) which
gives the values of the type i
intensity
at all locations in the window containing X
;
containing the values of the
type i
intensity evaluated only
at the data points of type i
. The length of this vector
must equal the number of type i
points in X
.
of the form function(x,y)
which can be evaluated to give values of the intensity at
any locations.
(object of class "ppm"
, "kppm"
or "dppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
if lambdaI
is omitted then it will be estimated
using a leave-one-out kernel smoother.
If lambdaI
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother, as described in Baddeley,
Moller
and Waagepetersen (2000). The estimate of lambdaI
for a given
point is computed by removing the point from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point in question. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
Similarly the argument lambdadot
should contain
estimated values of the intensity of the entire point process.
It may be either a pixel image, a numeric vector of length equal
to the number of points in X
, a function, or omitted.
Alternatively if the argument lambdaX
is given, then it specifies
the intensity values for all points of X
, and the
arguments lambdaI
, lambdadot
will be ignored.
(The two arguments lambdaI
, lambdadot
allow the user
to specify two different methods for calculating the intensities of
the two kinds of points, while lambdaX
ensures that the same
method is used for both kinds of points.)
For advanced use only, the optional argument lambdaIdot
is a matrix containing estimated
values of the products of these two intensities for each pair of
points, the first point of type i
and the second of any type.
The argument r
is the vector of values for the
distance at which
should be evaluated.
The values of
must be increasing nonnegative numbers
and the maximum
value must not exceed the radius of the
largest disc contained in the window.
The argument correction
chooses the edge correction
as explained e.g. in Kest
.
The pair correlation function can also be applied to the
result of Kdot.inhom
; see pcf
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
The argument i
is interpreted as
a level of the factor X$marks
. It is converted to a character
string if it is not already a character string.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
Moller, J. and Waagepetersen, R. Statistical Inference and Simulation for Spatial Point Processes Chapman and Hall/CRC Boca Raton, 2003.
Kdot
,
Kinhom
,
Kcross.inhom
,
Kmulti.inhom
,
pcf
# Lansing Woods data woods <- lansing woods <- woods[seq(1,npoints(woods), by=10)] ma <- split(woods)$maple lg <- unmark(woods) # Estimate intensities by nonparametric smoothing lambdaM <- density.ppp(ma, sigma=0.15, at="points") lambdadot <- density.ppp(lg, sigma=0.15, at="points") K <- Kdot.inhom(woods, "maple", lambdaI=lambdaM, lambdadot=lambdadot) # Equivalent K <- Kdot.inhom(woods, "maple", sigma=0.15) # Fit model if(require("spatstat.model")) { fit <- ppm(woods ~ marks * polynom(x,y,2)) K <- Kdot.inhom(woods, "maple", lambdaX=fit, update=FALSE, leaveoneout=FALSE) } # synthetic example: type A points have intensity 50, # type B points have intensity 50 + 100 * x lamB <- as.im(function(x,y){50 + 100 * x}, owin()) lamdot <- as.im(function(x,y) { 100 + 100 * x}, owin()) X <- superimpose(A=runifpoispp(50), B=rpoispp(lamB)) K <- Kdot.inhom(X, "B", lambdaI=lamB, lambdadot=lamdot)
# Lansing Woods data woods <- lansing woods <- woods[seq(1,npoints(woods), by=10)] ma <- split(woods)$maple lg <- unmark(woods) # Estimate intensities by nonparametric smoothing lambdaM <- density.ppp(ma, sigma=0.15, at="points") lambdadot <- density.ppp(lg, sigma=0.15, at="points") K <- Kdot.inhom(woods, "maple", lambdaI=lambdaM, lambdadot=lambdadot) # Equivalent K <- Kdot.inhom(woods, "maple", sigma=0.15) # Fit model if(require("spatstat.model")) { fit <- ppm(woods ~ marks * polynom(x,y,2)) K <- Kdot.inhom(woods, "maple", lambdaX=fit, update=FALSE, leaveoneout=FALSE) } # synthetic example: type A points have intensity 50, # type B points have intensity 50 + 100 * x lamB <- as.im(function(x,y){50 + 100 * x}, owin()) lamdot <- as.im(function(x,y) { 100 + 100 * x}, owin()) X <- superimpose(A=runifpoispp(50), B=rpoispp(lamB)) K <- Kdot.inhom(X, "B", lambdaI=lamB, lambdadot=lamdot)
Estimates Ripley's reduced second moment function
from a point pattern in a window of arbitrary shape.
Kest(X, ..., r=NULL, rmax=NULL, breaks=NULL, correction=c("border", "isotropic", "Ripley", "translate"), nlarge=3000, domain=NULL, var.approx=FALSE, ratio=FALSE)
Kest(X, ..., r=NULL, rmax=NULL, breaks=NULL, correction=c("border", "isotropic", "Ripley", "translate"), nlarge=3000, domain=NULL, var.approx=FALSE, ratio=FALSE)
X |
The observed point pattern,
from which an estimate of |
... |
Ignored. |
r |
Optional. Vector of values for the argument |
rmax |
Optional. Maximum desired value of the argument |
breaks |
This argument is for internal use only. |
correction |
Optional. A character vector containing any selection of the
options |
nlarge |
Optional. Efficiency threshold.
If the number of points exceeds |
domain |
Optional. Calculations will be restricted to this subset of the window. See Details. |
var.approx |
Logical. If |
ratio |
Logical.
If |
The function (variously called “Ripley's K-function”
and the “reduced second moment function”)
of a stationary point process
is defined so that
equals the expected number of
additional random points within a distance
of a
typical random point of
. Here
is the intensity of the process,
i.e. the expected number of points of
per unit area.
The
function is determined by the
second order moment properties of
.
An estimate of derived from a spatial point pattern dataset
can be used in exploratory data analysis and formal inference
about the pattern (Cressie, 1991; Diggle, 1983; Ripley, 1977, 1988).
In exploratory analyses, the estimate of
is a useful statistic
summarising aspects of inter-point “dependence” and “clustering”.
For inferential purposes, the estimate of
is usually compared to the
true value of
for a completely random (Poisson) point process,
which is
.
Deviations between the empirical and theoretical
curves
may suggest spatial clustering or spatial regularity.
This routine Kest
estimates the function
of a stationary point process, given observation of the process
inside a known, bounded window.
The argument
X
is interpreted as a point pattern object
(of class "ppp"
, see ppp.object
) and can
be supplied in any of the formats recognised by
as.ppp()
.
The estimation of is hampered by edge effects arising from
the unobservability of points of the random pattern outside the window.
An edge correction is needed to reduce bias (Baddeley, 1998; Ripley, 1988).
The corrections implemented here are
the border method or “reduced sample” estimator (see Ripley, 1988). This is the least efficient (statistically) and the fastest to compute. It can be computed for a window of arbitrary shape.
Ripley's isotropic correction (see Ripley, 1988; Ohser, 1983). This is implemented for rectangular and polygonal windows (not for binary masks).
Translation correction (Ohser, 1983). Implemented for all window geometries, but slow for complex windows.
Rigid motion correction (Ohser and Stoyan, 1981). Implemented for all window geometries, but slow for complex windows.
Uncorrected estimate.
An estimate of the K function without edge correction.
(i.e. setting in the equation below.
This estimate is biased and should
not be used for data analysis, unless you have
an extremely large point pattern (more than 100,000 points).
Periodic (toroidal) edge correction. Defined only for rectangular windows.
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.
Selects the best edge correction
that can be computed in a reasonable time.
This is the same as "best"
for datasets with fewer
than 3000 points; otherwise the selected edge correction
is "border"
, unless there are more than 100,000 points, when
it is "none"
.
The estimates of are of the form
where is the area of the window,
is the number of
data points, and the sum is taken over all ordered pairs of points
and
in
X
.
Here is the distance between the two points,
and
is the indicator
that equals 1 if the distance is less than or equal to
.
The term
is the edge correction weight (which
depends on the choice of edge correction listed above).
Note that this estimator assumes the process is stationary (spatially
homogeneous). For inhomogeneous point patterns, see
Kinhom
.
If the point pattern X
contains more than about 3000 points,
the isotropic and translation edge corrections can be computationally
prohibitive. The computations for the border method are much faster,
and are statistically efficient when there are large numbers of
points. Accordingly, if the number of points in X
exceeds
the threshold nlarge
, then only the border correction will be
computed. Setting nlarge=Inf
or correction="best"
will prevent this from happening.
Setting nlarge=0
is equivalent to selecting only the border
correction with correction="border"
.
If X
contains more than about 100,000 points,
even the border correction is time-consuming. You may want to consider
setting correction="none"
in this case.
There is an even faster algorithm for the uncorrected estimate.
Approximations to the variance of
are available, for the case of the isotropic edge correction estimator,
assuming complete spatial randomness
(Ripley, 1988; Lotwick and Silverman, 1982; Diggle, 2003, pp 51-53).
If
var.approx=TRUE
, then the result of
Kest
also has a column named rip
giving values of Ripley's (1988) approximation to
,
and (if the window is a rectangle) a column named
ls
giving
values of Lotwick and Silverman's (1982) approximation.
If the argument domain
is given, the calculations will
be restricted to a subset of the data. In the formula for above,
the first point
will be restricted to lie inside
domain
. The result is an approximately unbiased estimate
of based on pairs of points in which the first point lies
inside
domain
and the second point is unrestricted.
This is useful in bootstrap techniques. The argument domain
should be a window (object of class "owin"
) or something acceptable to
as.owin
. It must be a subset of the
window of the point pattern X
.
The estimator Kest
ignores marks.
Its counterparts for multitype point patterns
are Kcross
, Kdot
,
and for general marked point patterns
see Kmulti
.
Some writers, particularly Stoyan (1994, 1995) advocate the use of the “pair correlation function”
where is the derivative of
.
See
pcf
on how to estimate this function.
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 |
theo |
the theoretical value |
together with columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function obtained by the edge corrections
named.
If var.approx=TRUE
then the return value
also has columns rip
and ls
containing approximations
to the variance of under CSR.
If ratio=TRUE
then the return value also has two
attributes called "numerator"
and "denominator"
which are "fv"
objects
containing the numerators and denominators of each
estimate of .
To compute simulation envelopes for the -function
under CSR, use
envelope
.
To compute a confidence interval for the true -function,
use
varblock
or lohboot
.
The estimator of is approximately unbiased for each fixed
, for point processes which do not have very strong
interaction. (For point processes with a strong clustering interaction,
the estimator is negatively biased; for point processes with a strong
inhibitive interaction, the estimator is positively biased.)
Bias increases with and depends on the window geometry.
For a rectangular window it is prudent to restrict the
values to
a maximum of
of the smaller side length of the rectangle
(Ripley, 1977, 1988; Diggle, 1983).
Bias may become appreciable for point patterns consisting of
fewer than 15 points.
While is always a non-decreasing function, the estimator
of
is not guaranteed to be non-decreasing. This is rarely
a problem in practice, except for the border correction estimators
when the number of points is small.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Baddeley, A.J. Spatial sampling and censoring. In O.E. Barndorff-Nielsen, W.S. Kendall and M.N.M. van Lieshout (eds) Stochastic Geometry: Likelihood and Computation. Chapman and Hall, 1998. Chapter 2, pages 37–78.
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Ohser, J. (1983) On estimators for the reduced second moment measure of point processes. Mathematische Operationsforschung und Statistik, series Statistics, 14, 63 – 71.
Ohser, J. and Stoyan, D. (1981) On the second-order and orientation analysis of planar stationary point processes. Biometrical Journal 23, 523–533.
Ripley, B.D. (1977) Modelling spatial patterns (with discussion). Journal of the Royal Statistical Society, Series B, 39, 172 – 212.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. (1995) Stochastic geometry and its applications. 2nd edition. Springer Verlag.
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
localK
to extract individual summands in the
function.
pcf
for the pair correlation.
Fest
,
Gest
,
Jest
for alternative summary functions.
Kcross
,
Kdot
,
Kinhom
,
Kmulti
for counterparts of the function
for multitype point patterns.
reduced.sample
for the calculation of reduced sample
estimators.
X <- runifpoint(50) K <- Kest(X) K <- Kest(cells, correction="isotropic") plot(K) plot(K, main="K function for cells") # plot the L function plot(K, sqrt(iso/pi) ~ r) plot(K, sqrt(./pi) ~ r, ylab="L(r)", main="L function for cells")
X <- runifpoint(50) K <- Kest(X) K <- Kest(cells, correction="isotropic") plot(K) plot(K, main="K function for cells") # plot the L function plot(K, sqrt(iso/pi) ~ r) plot(K, sqrt(./pi) ~ r, ylab="L(r)", main="L function for cells")
Estimates the reduced second moment function
from a point pattern in a window of arbitrary shape,
using the Fast Fourier Transform.
Kest.fft(X, sigma, r=NULL, ..., breaks=NULL)
Kest.fft(X, sigma, r=NULL, ..., breaks=NULL)
X |
The observed point pattern,
from which an estimate of |
sigma |
Standard deviation of the isotropic Gaussian smoothing kernel. |
r |
Optional. Vector of values for the argument |
... |
Arguments passed to |
breaks |
This argument is for internal use only. |
This is an alternative to the function Kest
for estimating the function. It may be useful for
very large patterns of points.
Whereas Kest
computes the distance between
each pair of points analytically, this function discretises the
point pattern onto a rectangular pixel raster and applies
Fast Fourier Transform techniques to estimate .
The hard work is done by the function
Kmeasure
.
The result is an approximation whose accuracy depends on the
resolution of the pixel raster. The resolution is controlled
by the arguments ...
, or by setting the parameter npixel
in
spatstat.options
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing columns
r |
the vector of values of the argument |
border |
the estimates of |
theo |
the theoretical value |
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Ohser, J. (1983) On estimators for the reduced second moment measure of point processes. Mathematische Operationsforschung und Statistik, series Statistics, 14, 63 – 71.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. (1995) Stochastic geometry and its applications. 2nd edition. Springer Verlag.
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
Kest
,
Kmeasure
,
spatstat.options
pp <- runifpoint(10000) Kpp <- Kest.fft(pp, 0.01) plot(Kpp)
pp <- runifpoint(10000) Kpp <- Kest.fft(pp, 0.01) plot(Kpp)
Estimates the inhomogeneous function of
a non-stationary point pattern.
Kinhom(X, lambda=NULL, ..., r = NULL, breaks = NULL, correction=c("border", "bord.modif", "isotropic", "translate"), renormalise=TRUE, normpower=1, update=TRUE, leaveoneout=TRUE, nlarge = 1000, lambda2=NULL, reciplambda=NULL, reciplambda2=NULL, diagonal=TRUE, sigma=NULL, varcov=NULL, ratio=FALSE)
Kinhom(X, lambda=NULL, ..., r = NULL, breaks = NULL, correction=c("border", "bord.modif", "isotropic", "translate"), renormalise=TRUE, normpower=1, update=TRUE, leaveoneout=TRUE, nlarge = 1000, lambda2=NULL, reciplambda=NULL, reciplambda2=NULL, diagonal=TRUE, sigma=NULL, varcov=NULL, ratio=FALSE)
X |
The observed data point pattern,
from which an estimate of the inhomogeneous |
lambda |
Optional.
Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern |
... |
Extra arguments. Ignored if |
r |
vector of values for the argument |
breaks |
This argument is for internal use only. |
correction |
A character vector containing any selection of the
options |
renormalise |
Logical. Whether to renormalise the estimate. See Details. |
normpower |
Integer (usually either 1 or 2). Normalisation power. See Details. |
update |
Logical value indicating what to do when |
leaveoneout |
Logical value (passed to |
nlarge |
Optional. Efficiency threshold.
If the number of points exceeds |
lambda2 |
Advanced use only.
Matrix containing estimates of the products
|
reciplambda |
Alternative to |
reciplambda2 |
Advanced use only. Alternative to |
diagonal |
Do not use this argument. |
sigma , varcov
|
Optional arguments passed to |
ratio |
Logical.
If |
This computes a generalisation of the function
for inhomogeneous point patterns, proposed by
Baddeley, Moller and Waagepetersen (2000).
The “ordinary” function
(variously known as the reduced second order moment function
and Ripley's
function), is
described under
Kest
. It is defined only
for stationary point processes.
The inhomogeneous function
is a direct generalisation to nonstationary point processes.
Suppose
is a point process with non-constant intensity
at each location
.
Define
to be the expected
value, given that
is a point of
,
of the sum of all terms
over all points
in the process separated from
by a distance less than
.
This reduces to the ordinary
function if
is constant.
If
is an inhomogeneous Poisson process with intensity
function
, then
.
Given a point pattern dataset, the
inhomogeneous function can be estimated
essentially by summing the values
for all pairs of points
separated by a distance less than
.
This allows us to inspect a point pattern for evidence of
interpoint interactions after allowing for spatial inhomogeneity
of the pattern. Values
are suggestive of clustering.
The argument lambda
should supply the
(estimated) values of the intensity function .
It may be either
containing the values
of the intensity function at the points of the pattern X
.
(object of class "im"
)
assumed to contain the values of the intensity function
at all locations in the window.
(object of class "ppm"
, "kppm"
or "dppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
which can be evaluated to give values of the intensity at any locations.
if lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
If lambda
is a numeric vector, then its length should
be equal to the number of points in the pattern X
.
The value lambda[i]
is assumed to be the
the (estimated) value of the intensity
for
the point
of the pattern
.
Each value must be a positive number;
NA
's are not allowed.
If lambda
is a pixel image, the domain of the image should
cover the entire window of the point pattern. If it does not (which
may occur near the boundary because of discretisation error),
then the missing pixel values
will be obtained by applying a Gaussian blur to lambda
using
blur
, then looking up the values of this blurred image
for the missing locations.
(A warning will be issued in this case.)
If lambda
is a function, then it will be evaluated in the
form lambda(x,y)
where x
and y
are vectors
of coordinates of the points of X
. It should return a numeric
vector with length equal to the number of points in X
.
If lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother,
as described in Baddeley, Moller
and Waagepetersen (2000). The estimate lambda[i]
for the
point X[i]
is computed by removing X[i]
from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point X[i]
. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
Edge corrections are used to correct bias in the estimation
of .
Each edge-corrected estimate of
is
of the form
where A
is a constant denominator,
is the distance between points
and
, and
is
an edge correction factor. For the ‘border’ correction,
where is the distance from
to the boundary of the window. For the ‘modified border’
correction,
where is the eroded window obtained
by trimming a margin of width
from the border of the original
window.
For the ‘translation’ correction,
and for the ‘isotropic’ correction,
where is the fraction of the
circumference of the circle with centre
and radius
which lies inside the window.
If renormalise=TRUE
(the default), then the estimates
described above
are multiplied by where
This rescaling reduces the variability and bias of the estimate
in small samples and in cases of very strong inhomogeneity.
The default value of
normpower
is 1 (for consistency with
previous versions of spatstat)
but the most sensible value is 2, which would correspond to rescaling
the lambda
values so that
If the point pattern X
contains more than about 1000 points,
the isotropic and translation edge corrections can be computationally
prohibitive. The computations for the border method are much faster,
and are statistically efficient when there are large numbers of
points. Accordingly, if the number of points in X
exceeds
the threshold nlarge
, then only the border correction will be
computed. Setting nlarge=Inf
or correction="best"
will prevent this from happening.
Setting nlarge=0
is equivalent to selecting only the border
correction with correction="border"
.
The pair correlation function can also be applied to the
result of Kinhom
; see pcf
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing at least the following columns,
r |
the vector of values of the argument |
theo |
vector of values of |
and containing additional columns
according to the choice specified in the correction
argument. The additional columns are named
border
, trans
and iso
and give the estimated values of
using the border correction, translation correction,
and Ripley isotropic correction, respectively.
If ratio=TRUE
then the return value also has two
attributes called "numerator"
and "denominator"
which are "fv"
objects
containing the numerators and denominators of each
estimate of .
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Baddeley, A., Moller, J. and Waagepetersen, R. (2000) Non- and semiparametric estimation of interaction in inhomogeneous point patterns. Statistica Neerlandica 54, 329–350.
# inhomogeneous pattern of maples X <- unmark(split(lansing)$maple) if(require("spatstat.model")) { # (1) intensity function estimated by model-fitting # Fit spatial trend: polynomial in x and y coordinates fit <- ppm(X, ~ polynom(x,y,2), Poisson()) # (a) predict intensity values at points themselves, # obtaining a vector of lambda values lambda <- predict(fit, locations=X, type="trend") # inhomogeneous K function Ki <- Kinhom(X, lambda) plot(Ki) # (b) predict intensity at all locations, # obtaining a pixel image lambda <- predict(fit, type="trend") Ki <- Kinhom(X, lambda) plot(Ki) } # (2) intensity function estimated by heavy smoothing Ki <- Kinhom(X, sigma=0.1) plot(Ki) # (3) simulated data: known intensity function lamfun <- function(x,y) { 50 + 100 * x } # inhomogeneous Poisson process Y <- rpoispp(lamfun, 150, owin()) # inhomogeneous K function Ki <- Kinhom(Y, lamfun) plot(Ki) # How to make simulation envelopes: # Example shows method (2) if(interactive()) { smo <- density.ppp(X, sigma=0.1) Ken <- envelope(X, Kinhom, nsim=99, simulate=expression(rpoispp(smo)), sigma=0.1, correction="trans") plot(Ken) }
# inhomogeneous pattern of maples X <- unmark(split(lansing)$maple) if(require("spatstat.model")) { # (1) intensity function estimated by model-fitting # Fit spatial trend: polynomial in x and y coordinates fit <- ppm(X, ~ polynom(x,y,2), Poisson()) # (a) predict intensity values at points themselves, # obtaining a vector of lambda values lambda <- predict(fit, locations=X, type="trend") # inhomogeneous K function Ki <- Kinhom(X, lambda) plot(Ki) # (b) predict intensity at all locations, # obtaining a pixel image lambda <- predict(fit, type="trend") Ki <- Kinhom(X, lambda) plot(Ki) } # (2) intensity function estimated by heavy smoothing Ki <- Kinhom(X, sigma=0.1) plot(Ki) # (3) simulated data: known intensity function lamfun <- function(x,y) { 50 + 100 * x } # inhomogeneous Poisson process Y <- rpoispp(lamfun, 150, owin()) # inhomogeneous K function Ki <- Kinhom(Y, lamfun) plot(Ki) # How to make simulation envelopes: # Example shows method (2) if(interactive()) { smo <- density.ppp(X, sigma=0.1) Ken <- envelope(X, Kinhom, nsim=99, simulate=expression(rpoispp(smo)), sigma=0.1, correction="trans") plot(Ken) }
Estimates the mark-weighted function
of a marked point pattern.
Kmark(X, f = NULL, r = NULL, correction = c("isotropic", "Ripley", "translate"), ..., f1 = NULL, normalise = TRUE, returnL = FALSE, fargs = NULL) markcorrint(X, f = NULL, r = NULL, correction = c("isotropic", "Ripley", "translate"), ..., f1 = NULL, normalise = TRUE, returnL = FALSE, fargs = NULL)
Kmark(X, f = NULL, r = NULL, correction = c("isotropic", "Ripley", "translate"), ..., f1 = NULL, normalise = TRUE, returnL = FALSE, fargs = NULL) markcorrint(X, f = NULL, r = NULL, correction = c("isotropic", "Ripley", "translate"), ..., f1 = NULL, normalise = TRUE, returnL = FALSE, fargs = NULL)
X |
The observed point pattern.
An object of class |
f |
Optional. Test function |
r |
Optional. Numeric vector. The values of the argument |
correction |
A character vector containing any selection of the
options |
... |
Ignored. |
f1 |
An alternative to |
normalise |
If |
returnL |
Compute the analogue of the K-function if |
fargs |
Optional. A list of extra arguments to be passed to the function
|
The functions Kmark
and markcorrint
are identical.
(Eventually markcorrint
will be deprecated.)
The mark-weighted function
of a marked point process (Penttinen et al, 1992)
is a generalisation of Ripley's
function, in which the contribution
from each pair of points is weighted by a function of their marks.
If the marks of the two points are
then
the weight is proportional to
where
is a specified test function.
The mark-weighted function is defined so that
where
for any spatial location taken to be a typical point of
the point process
. Here
is the
euclidean distance between
and
, so that the sum
is taken over all random points
that lie within a distance
of the point
. The function
is
the unnormalised mark-weighted
function.
To obtain
we standardise
by dividing by
, the expected value of
when
and
are
independent random marks with the same distribution as the marks in
the point process.
Under the hypothesis of random labelling, the
mark-weighted function
is equal to Ripley's
function,
.
The mark-weighted function is sometimes called the
mark correlation integral because it is related to the
mark correlation function
and the pair correlation function
by
See markcorr
for a definition of the
mark correlation function.
Given a marked point pattern X
,
this command computes edge-corrected estimates
of the mark-weighted function.
If
returnL=FALSE
then the estimated
function is returned;
otherwise the function
is returned.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the mark-weighted function
obtained by the edge corrections named (if
returnL=FALSE
).
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Penttinen, A., Stoyan, D. and Henttonen, H. M. (1992) Marked point processes in forest statistics. Forest Science 38 (1992) 806-824.
Illian, J., Penttinen, A., Stoyan, H. and Stoyan, D. (2008) Statistical analysis and modelling of spatial point patterns. Chichester: John Wiley.
markcorr
to estimate the mark correlation function.
# CONTINUOUS-VALUED MARKS: # (1) Spruces # marks represent tree diameter # mark correlation function ms <- Kmark(spruces) plot(ms) # (2) simulated data with independent marks X <- rpoispp(100) X <- X %mark% runif(npoints(X)) Xc <- Kmark(X) plot(Xc) # MULTITYPE DATA: # Hughes' amacrine data # Cells marked as 'on'/'off' M <- Kmark(amacrine, function(m1,m2) {m1==m2}, correction="translate") plot(M)
# CONTINUOUS-VALUED MARKS: # (1) Spruces # marks represent tree diameter # mark correlation function ms <- Kmark(spruces) plot(ms) # (2) simulated data with independent marks X <- rpoispp(100) X <- X %mark% runif(npoints(X)) Xc <- Kmark(X) plot(Xc) # MULTITYPE DATA: # Hughes' amacrine data # Cells marked as 'on'/'off' M <- Kmark(amacrine, function(m1,m2) {m1==m2}, correction="translate") plot(M)
Estimates the reduced second moment measure
from a point pattern in a window of arbitrary shape.
Kmeasure(X, sigma, edge=TRUE, ..., varcov=NULL)
Kmeasure(X, sigma, edge=TRUE, ..., varcov=NULL)
X |
The observed point pattern,
from which an estimate of |
sigma |
Standard deviation |
edge |
Logical value indicating whether an edge correction should be applied. |
... |
Arguments passed to |
varcov |
Variance-covariance matrix of the Gaussian smoothing kernel.
Incompatible with |
Given a point pattern dataset,
this command computes an estimate of the reduced second moment
measure of the point process.
The result is a pixel image whose pixel values are estimates of
the density of the reduced second moment measure.
The reduced second moment measure
can be regarded as a generalisation of the more familiar
-function.
An estimate of
derived from a spatial point
pattern dataset can be useful in exploratory data analysis.
Its advantage over the
-function is that it is also sensitive
to anisotropy and directional effects.
In a nutshell, the command Kmeasure
computes a smoothed version
of the Fry plot.
As explained under fryplot
, the Fry plot is a scatterplot of the
vectors joining all pairs of points in the pattern.
The reduced second moment measure is (essentially) defined as
the average of the Fry plot over different realisations of the point
process. The command Kmeasure
effectively smooths the Fry plot
of a dataset to obtain an estimate of the reduced second moment measure.
In formal terms, the reduced second moment measure
of a stationary point process
is a measure defined on the
two-dimensional plane such that,
for a ‘typical’ point
of the process,
the expected number of other points
of the process
such that the vector
lies in a region
,
equals
.
Here
is the intensity of the process,
i.e. the expected number of points of
per unit area.
The -function is a special case. The function value
is
the value of the reduced second moment measure
for the disc of radius
centred at the origin; that is,
.
The command Kmeasure
computes an estimate of
from a point pattern dataset
X
,
which is assumed to be a realisation of a stationary point process,
observed inside a known, bounded window. Marks are ignored.
The algorithm approximates the point pattern and its window by binary pixel
images, introduces a Gaussian smoothing kernel
and uses the Fast Fourier Transform fft
to form a density estimate of . The calculation
corresponds to the edge correction known as the “translation
correction”.
The Gaussian smoothing kernel may be specified by either of the
arguments sigma
or varcov
. If sigma
is a single
number, this specifies an isotropic Gaussian kernel
with standard deviation sigma
on each coordinate axis.
If sigma
is a vector of two numbers, this specifies a Gaussian
kernel with standard deviation sigma[1]
on the axis,
standard deviation
sigma[2]
on the axis, and zero
correlation between the
and
axes. If
varcov
is
given, this specifies the variance-covariance matrix of the
Gaussian kernel. There do not seem to be any well-established rules
for selecting the smoothing kernel in this context.
The density estimate of
is returned in the form of a real-valued pixel image.
Pixel values are estimates of the normalised
second moment density at the centre of the pixel.
(The uniform Poisson process would have values identically equal to
.)
The image
x
and y
coordinates are on the same scale as vector displacements in the
original point pattern window. The point x=0, y=0
corresponds
to the ‘typical point’.
A peak in the image near (0,0)
suggests clustering;
a dip in the image near (0,0)
suggests inhibition;
peaks or dips at other positions suggest possible periodicity.
If desired, the value of for a region
can be estimated by computing the integral of the pixel image
over the domain
, i.e.\ summing the pixel values and
multiplying by pixel area, using
integral.im
.
One possible application is to compute anisotropic counterparts of the
-function (in which the disc of radius
is replaced
by another shape). See Examples.
A real-valued pixel image (an object of class "im"
,
see im.object
) whose pixel values are estimates
of the density of the reduced second moment measure
at each location.
Some writers use the term reduced second moment measure
when they mean the -function. This has caused
confusion.
As originally defined, the
reduced second moment measure is a measure, obtained by modifying
the second moment measure, while the -function is a function
obtained by evaluating this measure for discs of increasing radius.
In spatstat, the
-function is computed by
Kest
and the reduced second moment measure is computed
by Kmeasure
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Stoyan, D, Kendall, W.S. and Mecke, J. (1995) Stochastic geometry and its applications. 2nd edition. Springer Verlag.
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
Kest
,
fryplot
,
spatstat.options
,
integral.im
,
im.object
plot(Kmeasure(cells, 0.05)) # shows pronounced dip around origin consistent with strong inhibition plot(Kmeasure(redwood, 0.03), col=grey(seq(1,0,length=32))) # shows peaks at several places, reflecting clustering and ?periodicity M <- Kmeasure(cells, 0.05) # evaluate measure on a sector W <- Window(M) ang <- as.im(atan2, W) rad <- as.im(function(x,y){sqrt(x^2+y^2)}, W) sector <- solutionset(ang > 0 & ang < 1 & rad < 0.6) integral.im(M[sector, drop=FALSE])
plot(Kmeasure(cells, 0.05)) # shows pronounced dip around origin consistent with strong inhibition plot(Kmeasure(redwood, 0.03), col=grey(seq(1,0,length=32))) # shows peaks at several places, reflecting clustering and ?periodicity M <- Kmeasure(cells, 0.05) # evaluate measure on a sector W <- Window(M) ang <- as.im(atan2, W) rad <- as.im(function(x,y){sqrt(x^2+y^2)}, W) sector <- solutionset(ang > 0 & ang < 1 & rad < 0.6) integral.im(M[sector, drop=FALSE])
For a marked point pattern,
estimate the multitype function
which counts the expected number of points of subset
within a given distance from a typical point in subset
I
.
Kmulti(X, I, J, r=NULL, breaks=NULL, correction, ..., rmax=NULL, ratio=FALSE)
Kmulti(X, I, J, r=NULL, breaks=NULL, correction, ..., rmax=NULL, ratio=FALSE)
X |
The observed point pattern,
from which an estimate of the multitype |
I |
Subset index specifying the points of |
J |
Subset index specifying the points in |
r |
numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
correction |
A character vector containing any selection of the
options |
... |
Ignored. |
rmax |
Optional. Maximum desired value of the argument |
ratio |
Logical.
If |
The function Kmulti
generalises Kest
(for unmarked point
patterns) and Kdot
and Kcross
(for
multitype point patterns) to arbitrary marked point patterns.
Suppose ,
are subsets, possibly
overlapping, of a marked point process.
The multitype
function
is defined so that
equals the expected number of
additional random points of
within a distance
of a
typical point of
.
Here
is the intensity of
i.e. the expected number of points of
per unit area.
The function
is determined by the
second order moment properties of
.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
The arguments I
and J
specify two subsets of the
point pattern. They may be any type of subset indices, for example,
logical vectors of length equal to npoints(X)
,
or integer vectors with entries in the range 1 to
npoints(X)
, or negative integer vectors.
Alternatively, I
and J
may be functions
that will be applied to the point pattern X
to obtain
index vectors. If I
is a function, then evaluating
I(X)
should yield a valid subset index. This option
is useful when generating simulation envelopes using
envelope
.
The argument r
is the vector of values for the
distance at which
should be evaluated.
It is also used to determine the breakpoints
(in the sense of
hist
)
for the computation of histograms of distances.
First-time users would be strongly advised not to specify r
.
However, if it is specified, r
must satisfy r[1] = 0
,
and max(r)
must be larger than the radius of the largest disc
contained in the window.
This algorithm assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Kest
.
The edge corrections implemented here are
the border method or “reduced sample” estimator (see Ripley, 1988). This is the least efficient (statistically) and the fastest to compute. It can be computed for a window of arbitrary shape.
Ripley's isotropic correction (see Ripley, 1988; Ohser, 1983). This is currently implemented only for rectangular and polygonal windows.
Translation correction (Ohser, 1983). Implemented for all window geometries.
The pair correlation function pcf
can also be applied to the
result of Kmulti
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
If ratio=TRUE
then the return value also has two
attributes called "numerator"
and "denominator"
which are "fv"
objects
containing the numerators and denominators of each
estimate of .
The function is not necessarily differentiable.
The border correction (reduced sample) estimator of
used here is pointwise approximately
unbiased, but need not be a nondecreasing function of
,
while the true
must be nondecreasing.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Cressie, N.A.C. Statistics for spatial data. John Wiley and Sons, 1991.
Diggle, P.J. Statistical analysis of spatial point patterns. Academic Press, 1983.
Diggle, P. J. (1986). Displaced amacrine cells in the retina of a rabbit : analysis of a bivariate spatial point pattern. J. Neurosci. Meth. 18, 115–125.
Harkness, R.D and Isham, V. (1983) A bivariate spatial point pattern of ants' nests. Applied Statistics 32, 293–303
Lotwick, H. W. and Silverman, B. W. (1982). Methods for analysing spatial processes of several types of points. J. Royal Statist. Soc. Ser. B 44, 406–413.
Ripley, B.D. Statistical inference for spatial processes. Cambridge University Press, 1988.
Stoyan, D, Kendall, W.S. and Mecke, J. Stochastic geometry and its applications. 2nd edition. Springer Verlag, 1995.
Van Lieshout, M.N.M. and Baddeley, A.J. (1999) Indices of dependence between types in multivariate point patterns. Scandinavian Journal of Statistics 26, 511–532.
# Longleaf Pine data: marks represent diameter trees <- longleaf K <- Kmulti(trees, marks(trees) <= 15, marks(trees) >= 25) plot(K) # functions determining subsets f1 <- function(X) { marks(X) <= 15 } f2 <- function(X) { marks(X) >= 15 } K <- Kmulti(trees, f1, f2)
# Longleaf Pine data: marks represent diameter trees <- longleaf K <- Kmulti(trees, marks(trees) <= 15, marks(trees) >= 25) plot(K) # functions determining subsets f1 <- function(X) { marks(X) <= 15 } f2 <- function(X) { marks(X) >= 15 } K <- Kmulti(trees, f1, f2)
For a marked point pattern,
estimate the inhomogeneous version of the multitype function
which counts the expected number of points of subset
within a given distance from a typical point in subset
I
,
adjusted for spatially varying intensity.
Kmulti.inhom(X, I, J, lambdaI=NULL, lambdaJ=NULL, ..., r=NULL, breaks=NULL, correction=c("border", "isotropic", "Ripley", "translate"), lambdaIJ=NULL, sigma=NULL, varcov=NULL, lambdaX=NULL, update=TRUE, leaveoneout=TRUE)
Kmulti.inhom(X, I, J, lambdaI=NULL, lambdaJ=NULL, ..., r=NULL, breaks=NULL, correction=c("border", "isotropic", "Ripley", "translate"), lambdaIJ=NULL, sigma=NULL, varcov=NULL, lambdaX=NULL, update=TRUE, leaveoneout=TRUE)
X |
The observed point pattern,
from which an estimate of the inhomogeneous multitype |
I |
Subset index specifying the points of |
J |
Subset index specifying the points in |
lambdaI |
Optional.
Values of the estimated intensity of the sub-process |
lambdaJ |
Optional.
Values of the estimated intensity of the sub-process |
... |
Ignored. |
r |
Optional. Numeric vector. The values of the argument |
breaks |
This argument is for internal use only. |
correction |
A character vector containing any selection of the
options |
lambdaIJ |
Optional. A matrix containing estimates of
the product of the intensities |
sigma , varcov
|
Optional arguments passed to |
lambdaX |
Optional. Values of the intensity for all points of |
update |
Logical value indicating what to do when
|
leaveoneout |
Logical value (passed to |
The function Kmulti.inhom
is the counterpart, for spatially-inhomogeneous marked point patterns,
of the multitype function
Kmulti
.
Suppose is a marked point process, with marks of any kind.
Suppose
,
are two sub-processes, possibly
overlapping. Typically
would consist of those points
of
whose marks lie in a specified range of mark values,
and similarly for
. Suppose that
,
are the
spatially-varying intensity functions of
and
respectively. Consider all the pairs of points
in the point process
such that the first point
belongs to
, the second point
belongs to
, and the distance between
and
is less than a specified distance
. Give this pair
the numerical weight
.
Calculate the sum of these weights over all pairs of points as
described. This sum (after appropriate edge-correction and
normalisation) is the estimated inhomogeneous multitype
function.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
The arguments I
and J
specify two subsets of the
point pattern. They may be any type of subset indices, for example,
logical vectors of length equal to npoints(X)
,
or integer vectors with entries in the range 1 to
npoints(X)
, or negative integer vectors.
Alternatively, I
and J
may be functions
that will be applied to the point pattern X
to obtain
index vectors. If I
is a function, then evaluating
I(X)
should yield a valid subset index. This option
is useful when generating simulation envelopes using
envelope
.
The argument lambdaI
supplies the values
of the intensity of the sub-process identified by index I
.
It may be either
(object of class "im"
) which
gives the values of the intensity of X[I]
at all locations in the window containing X
;
containing the values of the
intensity of X[I]
evaluated only
at the data points of X[I]
. The length of this vector
must equal the number of points in X[I]
.
of the form function(x,y)
which can be evaluated to give values of the intensity at
any locations.
(object of class "ppm"
, "kppm"
or "dppm"
)
whose fitted trend can be used as the fitted intensity.
(If update=TRUE
the model will first be refitted to the
data X
before the trend is computed.)
if lambdaI
is omitted then it will be estimated
using a leave-one-out kernel smoother.
If lambdaI
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother, as described in Baddeley,
Moller
and Waagepetersen (2000). The estimate of lambdaI
for a given
point is computed by removing the point from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point in question. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
Similarly lambdaJ
supplies the values
of the intensity of the sub-process identified by index J
.
Alternatively if the argument lambdaX
is given, then it specifies
the intensity values for all points of X
, and the
arguments lambdaI
, lambdaJ
will be ignored.
The argument r
is the vector of values for the
distance at which
should be evaluated.
It is also used to determine the breakpoints
(in the sense of
hist
)
for the computation of histograms of distances.
First-time users would be strongly advised not to specify r
.
However, if it is specified, r
must satisfy r[1] = 0
,
and max(r)
must be larger than the radius of the largest disc
contained in the window.
Biases due to edge effects are
treated in the same manner as in Kinhom
.
The edge corrections implemented here are
the border method or “reduced sample” estimator (see Ripley, 1988). This is the least efficient (statistically) and the fastest to compute. It can be computed for a window of arbitrary shape.
Ripley's isotropic correction (see Ripley, 1988; Ohser, 1983). This is currently implemented only for rectangular windows.
Translation correction (Ohser, 1983). Implemented for all window geometries.
The pair correlation function pcf
can also be applied to the
result of Kmulti.inhom
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Baddeley, A., Moller, J. and Waagepetersen, R. (2000) Non- and semiparametric estimation of interaction in inhomogeneous point patterns. Statistica Neerlandica 54, 329–350.
Kmulti
,
Kdot.inhom
,
Kcross.inhom
,
pcf
# Finnish Pines data: marked by diameter and height plot(finpines, which.marks="height") II <- (marks(finpines)$height <= 2) JJ <- (marks(finpines)$height > 3) K <- Kmulti.inhom(finpines, II, JJ) plot(K) # functions determining subsets f1 <- function(X) { marks(X)$height <= 2 } f2 <- function(X) { marks(X)$height > 3 } K <- Kmulti.inhom(finpines, f1, f2)
# Finnish Pines data: marked by diameter and height plot(finpines, which.marks="height") II <- (marks(finpines)$height <= 2) JJ <- (marks(finpines)$height > 3) K <- Kmulti.inhom(finpines, II, JJ) plot(K) # functions determining subsets f1 <- function(X) { marks(X)$height <= 2 } f2 <- function(X) { marks(X)$height > 3 } K <- Kmulti.inhom(finpines, f1, f2)
Estimates the locally-rescaled -function of
a point process.
Kscaled(X, lambda=NULL, ..., r = NULL, breaks = NULL, rmax = 2.5, correction=c("border", "isotropic", "translate"), renormalise=FALSE, normpower=1, sigma=NULL, varcov=NULL) Lscaled(...)
Kscaled(X, lambda=NULL, ..., r = NULL, breaks = NULL, rmax = 2.5, correction=c("border", "isotropic", "translate"), renormalise=FALSE, normpower=1, sigma=NULL, varcov=NULL) Lscaled(...)
X |
The observed data point pattern,
from which an estimate of the locally scaled |
lambda |
Optional.
Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern |
... |
Arguments passed from |
r |
vector of values for the argument |
breaks |
This argument is for internal use only. |
rmax |
maximum value of the argument |
correction |
A character vector containing any selection of the
options |
renormalise |
Logical. Whether to renormalise the estimate. See Details. |
normpower |
Integer (usually either 1 or 2). Normalisation power. See Details. |
sigma , varcov
|
Optional arguments passed to |
Kscaled
computes an estimate of the function
for a locally scaled point process.
Lscaled
computes the corresponding function
.
Locally scaled point processes are a class of models for inhomogeneous point patterns, introduced by Hahn et al (2003). They include inhomogeneous Poisson processes, and many other models.
The template function of a locally-scaled process is a counterpart
of the “ordinary” Ripley
function, in which
the distances between points of the process are measured
on a spatially-varying scale (such that the locally rescaled
process has unit intensity).
The template function is an indicator of interaction
between the points. For an inhomogeneous Poisson process, the
theoretical template
function is approximately equal
to
.
Values
are suggestive of clustering.
Kscaled
computes an estimate of the template function
and
Lscaled
computes the corresponding function
.
The locally scaled interpoint distances are computed using an approximation proposed by Hahn (2007). The Euclidean distance between two points is multiplied by the average of the square roots of the intensity values at the two points.
The argument lambda
should supply the
(estimated) values of the intensity function .
It may be either
containing the values
of the intensity function at the points of the pattern X
.
(object of class "im"
)
assumed to contain the values of the intensity function
at all locations in the window.
which can be evaluated to give values of the intensity at any locations.
if lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother.
If lambda
is a numeric vector, then its length should
be equal to the number of points in the pattern X
.
The value lambda[i]
is assumed to be the
the (estimated) value of the intensity
for
the point
of the pattern
.
Each value must be a positive number;
NA
's are not allowed.
If lambda
is a pixel image, the domain of the image should
cover the entire window of the point pattern. If it does not (which
may occur near the boundary because of discretisation error),
then the missing pixel values
will be obtained by applying a Gaussian blur to lambda
using
blur
, then looking up the values of this blurred image
for the missing locations.
(A warning will be issued in this case.)
If lambda
is a function, then it will be evaluated in the
form lambda(x,y)
where x
and y
are vectors
of coordinates of the points of X
. It should return a numeric
vector with length equal to the number of points in X
.
If lambda
is omitted, then it will be estimated using
a ‘leave-one-out’ kernel smoother,
as described in Baddeley, Moller
and Waagepetersen (2000). The estimate lambda[i]
for the
point X[i]
is computed by removing X[i]
from the
point pattern, applying kernel smoothing to the remaining points using
density.ppp
, and evaluating the smoothed intensity
at the point X[i]
. The smoothing kernel bandwidth is controlled
by the arguments sigma
and varcov
, which are passed to
density.ppp
along with any extra arguments.
If renormalise=TRUE
, the estimated intensity lambda
is multiplied by before performing other calculations,
where
. This
renormalisation has about the same effect as in
Kinhom
,
reducing the variability and bias of the estimate
in small samples and in cases of very strong inhomogeneity.
Edge corrections are used to correct bias in the estimation
of . First the interpoint distances are
rescaled, and then edge corrections are applied as in
Kest
.
See Kest
for details of the edge corrections
and the options for the argument correction
.
The pair correlation function can also be applied to the
result of Kscaled
; see pcf
and pcf.fv
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing at least the following columns,
r |
the vector of values of the argument |
theo |
vector of values of |
and containing additional columns
according to the choice specified in the correction
argument. The additional columns are named
border
, trans
and iso
and give the estimated values of
using the border correction, translation correction,
and Ripley isotropic correction, respectively.
Ute Hahn, Adrian Baddeley [email protected] and Rolf Turner [email protected]
Baddeley, A., Moller, J. and Waagepetersen, R. (2000) Non- and semiparametric estimation of interaction in inhomogeneous point patterns. Statistica Neerlandica 54, 329–350.
Hahn, U. (2007) Global and Local Scaling in the Statistics of Spatial Point Processes. Habilitationsschrift, Universitaet Augsburg.
Hahn, U., Jensen, E.B.V., van Lieshout, M.N.M. and Nielsen, L.S. (2003) Inhomogeneous spatial point processes by location-dependent scaling. Advances in Applied Probability 35, 319–336.
Prokesova, M., Hahn, U. and Vedel Jensen, E.B. (2006) Statistics for locally scaled point patterns. In A. Baddeley, P. Gregori, J. Mateu, R. Stoica and D. Stoyan (eds.) Case Studies in Spatial Point Pattern Modelling. Lecture Notes in Statistics 185. New York: Springer Verlag. Pages 99–123.
X <- unmark(bronzefilter) K <- Kscaled(X) if(require("spatstat.model")) { fit <- ppm(X, ~x) lam <- predict(fit) K <- Kscaled(X, lam) }
X <- unmark(bronzefilter) K <- Kscaled(X) if(require("spatstat.model")) { fit <- ppm(X, ~x) lam <- predict(fit) K <- Kscaled(X, lam) }
A directional counterpart of Ripley's function,
in which pairs of points are counted only when the
vector joining the pair happens to
lie in a particular range of angles.
Ksector(X, begin = 0, end = 360, ..., units = c("degrees", "radians"), r = NULL, breaks = NULL, correction = c("border", "isotropic", "Ripley", "translate"), domain=NULL, ratio = FALSE, verbose=TRUE)
Ksector(X, begin = 0, end = 360, ..., units = c("degrees", "radians"), r = NULL, breaks = NULL, correction = c("border", "isotropic", "Ripley", "translate"), domain=NULL, ratio = FALSE, verbose=TRUE)
X |
The observed point pattern,
from which an estimate of |
begin , end
|
Numeric values giving the range of angles inside which
points will be counted. Angles are measured in degrees
(if |
... |
Ignored. |
units |
Units in which the angles |
r |
Optional. Vector of values for the argument |
breaks |
This argument is for internal use only. |
correction |
Optional. A character vector containing any selection of the
options |
domain |
Optional window. The first point |
ratio |
Logical.
If |
verbose |
Logical value indicating whether to print progress reports and warnings. |
This is a directional counterpart of Ripley's function
(see
Kest
) in which, instead of counting all
pairs of points within a specified distance , we
count only the pairs
for which the vector
falls in a particular range of angles.
This can be used to evaluate evidence for anisotropy
in the point pattern X
.
An object of class "fv"
containing the estimated
function.
Adrian Baddeley [email protected]
Rolf Turner [email protected]
and Ege Rubak [email protected]
K <- Ksector(swedishpines, 0, 90) plot(K)
K <- Ksector(swedishpines, 0, 90) plot(K)
Apply Laslett's Transform to a spatial region, returning the original and transformed regions, and the original and transformed positions of the lower tangent points. This is a diagnostic for the Boolean model.
laslett(X, ..., verbose = FALSE, plotit = TRUE, discretise = FALSE, type=c("lower", "upper", "left", "right"))
laslett(X, ..., verbose = FALSE, plotit = TRUE, discretise = FALSE, type=c("lower", "upper", "left", "right"))
X |
Spatial region to be transformed.
A window (object of class |
... |
Graphics arguments to control the plot (passed to
|
verbose |
Logical value indicating whether to print progress reports. |
plotit |
Logical value indicating whether to plot the result. |
discretise |
Logical value indicating whether polygonal windows should first be
converted to pixel masks before the Laslett transform is
computed. This should be set to |
type |
Type of tangent points to be detected.
This also determines the direction of contraction in the
set transformation.
Default is |
This function finds the lower tangent points of the spatial region X
,
then applies Laslett's Transform to the space,
and records the transformed positions of the lower tangent points.
Laslett's transform is a diagnostic for the Boolean Model. A test of the Boolean model can be performed by applying a test of CSR to the transformed tangent points. See the Examples.
The rationale is that, if the region X
was generated by a
Boolean model with convex grains, then the lower tangent points of
X
, when subjected to Laslett's transform,
become a Poisson point process (Cressie, 1993, section 9.3.5;
Molchanov, 1997; Barbour and Schmidt, 2001).
Intuitively, Laslett's transform is a way to account for the fact that
tangent points of X
cannot occur inside X
.
It treats the interior of X
as empty space, and collapses
this empty space so that only the exterior of X
remains.
In this collapsed space, the tangent points are completely random.
Formally, Laslett's transform is a random (i.e. data-dependent)
spatial transformation which maps each spatial
location to a new location
at the same height
. The transformation is defined so that
is the total uncovered length of the line segment from
to
, that is, the total length of the parts of this segment that
fall outside the region
X
.
In more colourful terms, suppose we use an abacus to display a
pixellated version of X
. Each wire of the abacus represents one
horizontal line in the pixel image. Each pixel lying outside
the region X
is represented by a bead of the abacus; pixels
inside X
are represented by the absence of a bead. Next
we find any beads which are lower tangent points of X
, and
paint them green. Then Laslett's Transform is applied by pushing all
beads to the left, as far as possible. The final locations of all the
beads provide a new spatial region, inside which is the point pattern
of tangent points (marked by the green-painted beads).
If plotit=TRUE
(the default), a before-and-after plot is
generated, showing the region X
and the tangent points
before and after the transformation. This plot can also be generated
by calling plot(a)
where a
is the object returned by
the function laslett
.
If the argument type
is given, then this determines the
type of tangents that will be detected, and also the direction of
contraction in Laslett's transform. The computation is performed
by first rotating X
, applying Laslett's transform for lower
tangent points, then rotating back.
There are separate algorithms for polygonal windows and
pixellated windows (binary masks). The polygonal algorithm may be slow
for very complicated polygons. If this happens, setting
discretise=TRUE
will convert the polygonal window to a binary
mask and invoke the pixel raster algorithm.
A list, which also belongs to the class "laslett"
so that it can immediately be printed and plotted.
The list elements are:
the original dataset X
;
a point pattern, whose window is Frame(X)
,
containing the lower tangent points of X
;
a point pattern, whose window is the Laslett transform
of Frame(X)
, and which contains the Laslett-transformed
positions of the tangent points;
a rectangular window, which is the largest rectangle lying inside the transformed set;
a data frame giving the locations of the tangent points before and after transformation.
character string specifying the type of tangents.
Kassel Hingee and Adrian Baddeley [email protected].
Barbour, A.D. and Schmidt, V. (2001) On Laslett's Transform for the Boolean Model. Advances in Applied Probability 33(1), 1–5.
Cressie, N.A.C. (1993) Statistics for spatial data, second edition. John Wiley and Sons.
Molchanov, I. (1997) Statistics of the Boolean Model for Practitioners and Mathematicians. Wiley.
a <- laslett(heather$coarse) transformedHeather <- with(a, Window(TanNew)) plot(transformedHeather, invert=TRUE) with(a, clarkevans.test(TanNew[Rect], correction="D", nsim=39)) X <- discs(runifrect(15) %mark% 0.2, npoly=16) b <- laslett(X, type="left") b
a <- laslett(heather$coarse) transformedHeather <- with(a, Window(TanNew)) plot(transformedHeather, invert=TRUE) with(a, clarkevans.test(TanNew[Rect], correction="D", nsim=39)) X <- discs(runifrect(15) %mark% 0.2, npoly=16) b <- laslett(X, type="left") b
Calculates an estimate of the cross-type L-function for a multitype point pattern.
Lcross(X, i, j, ..., from, to, correction)
Lcross(X, i, j, ..., from, to, correction)
X |
The observed point pattern,
from which an estimate of the cross-type |
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
correction , ...
|
Arguments passed to |
from , to
|
An alternative way to specify |
The cross-type L-function is a transformation of the cross-type K-function,
where is the cross-type K-function
from type
i
to type j
.
See Kcross
for information
about the cross-type K-function.
The command Lcross
first calls
Kcross
to compute the estimate of the cross-type K-function,
and then applies the square root transformation.
For a marked point pattern in which the points of type i
are independent of the points of type j
,
the theoretical value of the L-function is
.
The square root also has the effect of stabilising
the variance of the estimator, so that
is more appropriate
for use in simulation envelopes and hypothesis tests.
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 |
theo |
the theoretical value |
together with columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function obtained by the edge corrections
named.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
L <- Lcross(amacrine, "off", "on") plot(L)
L <- Lcross(amacrine, "off", "on") plot(L)
For a multitype point pattern,
estimate the inhomogeneous version of the cross-type function.
Lcross.inhom(X, i, j, ..., correction)
Lcross.inhom(X, i, j, ..., correction)
X |
The observed point pattern,
from which an estimate of the inhomogeneous cross type |
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
correction , ...
|
Other arguments passed to |
This is a generalisation of the function Lcross
to include an adjustment for spatially inhomogeneous intensity,
in a manner similar to the function Linhom
.
All the arguments are passed to Kcross.inhom
, which
estimates the inhomogeneous multitype K function
for the point pattern.
The resulting values are then
transformed by taking
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
The arguments i
and j
are always interpreted as
levels of the factor X$marks
. They are converted to character
strings if they are not already character strings.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Moller, J. and Waagepetersen, R. Statistical Inference and Simulation for Spatial Point Processes Chapman and Hall/CRC Boca Raton, 2003.
# Lansing Woods data woods <- lansing ma <- split(woods)$maple wh <- split(woods)$whiteoak # method (1): estimate intensities by nonparametric smoothing lambdaM <- density.ppp(ma, sigma=0.15, at="points") lambdaW <- density.ppp(wh, sigma=0.15, at="points") L <- Lcross.inhom(woods, "whiteoak", "maple", lambdaW, lambdaM) # method (2): fit parametric intensity model if(require("spatstat.model")) { fit <- ppm(woods ~marks * polynom(x,y,2)) # evaluate fitted intensities at data points # (these are the intensities of the sub-processes of each type) inten <- fitted(fit, dataonly=TRUE) # split according to types of points lambda <- split(inten, marks(woods)) L <- Lcross.inhom(woods, "whiteoak", "maple", lambda$whiteoak, lambda$maple) } # synthetic example: type A points have intensity 50, # type B points have intensity 100 * x lamB <- as.im(function(x,y){50 + 100 * x}, owin()) X <- superimpose(A=runifpoispp(50), B=rpoispp(lamB)) L <- Lcross.inhom(X, "A", "B", lambdaI=as.im(50, Window(X)), lambdaJ=lamB)
# Lansing Woods data woods <- lansing ma <- split(woods)$maple wh <- split(woods)$whiteoak # method (1): estimate intensities by nonparametric smoothing lambdaM <- density.ppp(ma, sigma=0.15, at="points") lambdaW <- density.ppp(wh, sigma=0.15, at="points") L <- Lcross.inhom(woods, "whiteoak", "maple", lambdaW, lambdaM) # method (2): fit parametric intensity model if(require("spatstat.model")) { fit <- ppm(woods ~marks * polynom(x,y,2)) # evaluate fitted intensities at data points # (these are the intensities of the sub-processes of each type) inten <- fitted(fit, dataonly=TRUE) # split according to types of points lambda <- split(inten, marks(woods)) L <- Lcross.inhom(woods, "whiteoak", "maple", lambda$whiteoak, lambda$maple) } # synthetic example: type A points have intensity 50, # type B points have intensity 100 * x lamB <- as.im(function(x,y){50 + 100 * x}, owin()) X <- superimpose(A=runifpoispp(50), B=rpoispp(lamB)) L <- Lcross.inhom(X, "A", "B", lambdaI=as.im(50, Window(X)), lambdaJ=lamB)
Calculates an estimate of the multitype L-function
(from type i
to any type)
for a multitype point pattern.
Ldot(X, i, ..., from, correction)
Ldot(X, i, ..., from, correction)
X |
The observed point pattern,
from which an estimate of the dot-type |
i |
The type (mark value)
of the points in |
correction , ...
|
Arguments passed to |
from |
An alternative way to specify |
This command computes
where is the multitype
-function
from points of type
i
to points of any type.
See Kdot
for information
about .
The command Ldot
first calls
Kdot
to compute the estimate of the i
-to-any
-function, and then applies the square root transformation.
For a marked Poisson point process,
the theoretical value of the L-function is
.
The square root also has the effect of stabilising
the variance of the estimator, so that
is more appropriate
for use in simulation envelopes and hypothesis tests.
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 |
theo |
the theoretical value |
together with columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
L <- Ldot(amacrine, "off") plot(L)
L <- Ldot(amacrine, "off") plot(L)
For a multitype point pattern,
estimate the inhomogeneous version of the dot function.
Ldot.inhom(X, i, ..., correction)
Ldot.inhom(X, i, ..., correction)
X |
The observed point pattern,
from which an estimate of the inhomogeneous cross type |
i |
The type (mark value)
of the points in |
correction , ...
|
Other arguments passed to |
This a generalisation of the function Ldot
to include an adjustment for spatially inhomogeneous intensity,
in a manner similar to the function Linhom
.
All the arguments are passed to Kdot.inhom
, which
estimates the inhomogeneous multitype K function
for the point pattern.
The resulting values are then
transformed by taking
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
The argument i
is interpreted as
a level of the factor X$marks
. It is converted to a character
string if it is not already a character string.
The value i=1
does not
refer to the first level of the factor.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
Moller, J. and Waagepetersen, R. Statistical Inference and Simulation for Spatial Point Processes Chapman and Hall/CRC Boca Raton, 2003.
Ldot
,
Linhom
,
Kdot.inhom
,
Lcross.inhom
.
# Lansing Woods data lan <- lansing lan <- lan[seq(1,npoints(lan), by=10)] ma <- split(lan)$maple lg <- unmark(lan) # Estimate intensities by nonparametric smoothing lambdaM <- density(ma, sigma=0.15, at="points") lambdadot <- density(lg, sigma=0.15, at="points") L <- Ldot.inhom(lan, "maple", lambdaI=lambdaM, lambdadot=lambdadot) # synthetic example: type A points have intensity 50, # type B points have intensity 50 + 100 * x lamB <- as.im(function(x,y){50 + 100 * x}, owin()) lamdot <- as.im(function(x,y) { 100 + 100 * x}, owin()) X <- superimpose(A=runifpoispp(50), B=rpoispp(lamB)) L <- Ldot.inhom(X, "B", lambdaI=lamB, lambdadot=lamdot)
# Lansing Woods data lan <- lansing lan <- lan[seq(1,npoints(lan), by=10)] ma <- split(lan)$maple lg <- unmark(lan) # Estimate intensities by nonparametric smoothing lambdaM <- density(ma, sigma=0.15, at="points") lambdadot <- density(lg, sigma=0.15, at="points") L <- Ldot.inhom(lan, "maple", lambdaI=lambdaM, lambdadot=lambdadot) # synthetic example: type A points have intensity 50, # type B points have intensity 50 + 100 * x lamB <- as.im(function(x,y){50 + 100 * x}, owin()) lamdot <- as.im(function(x,y) { 100 + 100 * x}, owin()) X <- superimpose(A=runifpoispp(50), B=rpoispp(lamB)) L <- Ldot.inhom(X, "B", lambdaI=lamB, lambdadot=lamdot)
Calculates an estimate of the -function (Besag's
transformation of Ripley's
-function)
for a spatial point pattern.
Lest(X, ..., correction)
Lest(X, ..., correction)
X |
The observed point pattern,
from which an estimate of |
correction , ...
|
Other arguments passed to |
This command computes an estimate of the -function
for the spatial point pattern
X
.
The -function is a transformation of Ripley's
-function,
where is the
-function.
See Kest
for information
about Ripley's -function. The transformation to
was
proposed by Besag (1977).
The command Lest
first calls
Kest
to compute the estimate of the -function,
and then applies the square root transformation.
For a completely random (uniform Poisson) point pattern,
the theoretical value of the -function is
.
The square root also has the effect of stabilising
the variance of the estimator, so that
is more appropriate
for use in simulation envelopes and hypothesis tests.
See Kest
for the list of arguments.
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 |
theo |
the theoretical value |
together with columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function obtained by the edge corrections
named.
If the argument var.approx=TRUE
is given, the return value
includes columns rip
and ls
containing approximations
to the variance of under CSR.
These are obtained by the delta method from the variance
approximations described in
Kest
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Besag, J. (1977) Discussion of Dr Ripley's paper. Journal of the Royal Statistical Society, Series B, 39, 193–195.
L <- Lest(cells) plot(L, main="L function for cells")
L <- Lest(cells) plot(L, main="L function for cells")
Calculates an estimate of the inhomogeneous version of
the -function (Besag's transformation of Ripley's
-function)
for a spatial point pattern.
Linhom(X, ..., correction)
Linhom(X, ..., correction)
X |
The observed point pattern,
from which an estimate of |
correction , ...
|
Other arguments passed to |
This command computes an estimate of the inhomogeneous version of
the -function for a spatial point pattern.
The original -function is a transformation
(proposed by Besag) of Ripley's
-function,
where is the Ripley
-function of a spatially homogeneous
point pattern, estimated by
Kest
.
The inhomogeneous -function is the corresponding transformation
of the inhomogeneous
-function, estimated by
Kinhom
.
It is appropriate when the point pattern clearly does not have a
homogeneous intensity of points. It was proposed by
Baddeley, Moller and Waagepetersen (2000).
The command Linhom
first calls
Kinhom
to compute the estimate of the inhomogeneous K-function,
and then applies the square root transformation.
For a Poisson point pattern (homogeneous or inhomogeneous),
the theoretical value of the inhomogeneous -function is
.
The square root also has the effect of stabilising
the variance of the estimator, so that
is more appropriate
for use in simulation envelopes and hypothesis tests.
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 |
theo |
the theoretical value |
together with columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function obtained by the edge corrections
named.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Baddeley, A., Moller, J. and Waagepetersen, R. (2000) Non- and semiparametric estimation of interaction in inhomogeneous point patterns. Statistica Neerlandica 54, 329–350.
X <- japanesepines L <- Linhom(X, sigma=0.1) plot(L, main="Inhomogeneous L function for Japanese Pines")
X <- japanesepines L <- Linhom(X, sigma=0.1) plot(L, main="Inhomogeneous L function for Japanese Pines")
Computes the neighbourhood density function, a local version of
the -function or
-function,
defined by Getis and Franklin (1987).
localK(X, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL) localL(X, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL)
localK(X, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL) localL(X, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL)
X |
A point pattern (object of class |
... |
Ignored. |
rmax |
Optional. Maximum desired value of the argument |
correction |
String specifying the edge correction to be applied.
Options are |
verbose |
Logical flag indicating whether to print progress reports during the calculation. |
rvalue |
Optional. A single value of the distance argument
|
The command localL
computes the neighbourhood density function,
a local version of the -function (Besag's transformation of Ripley's
-function) that was proposed by Getis and Franklin (1987).
The command
localK
computes the corresponding
local analogue of the K-function.
Given a spatial point pattern X
, the neighbourhood density function
associated with the
th point
in
X
is computed by
where the sum is over all points that lie
within a distance
of the
th point,
is the area of the observation window,
is the number
of points in
X
, and is an edge correction
term (as described in
Kest
).
The value of can also be interpreted as one
of the summands that contributes to the global estimate of the L
function.
By default, the function or
is computed for a range of
values
for each point
. The results are stored as a function value
table (object of class
"fv"
) with a column of the table
containing the function estimates for each point of the pattern
X
.
Alternatively, if the argument rvalue
is given, and it is a
single number, then the function will only be computed for this value
of , and the results will be returned as a numeric vector,
with one entry of the vector for each point of the pattern
X
.
Inhomogeneous counterparts of localK
and localL
are computed by localKinhom
and localLinhom
.
If rvalue
is given, the result is a numeric vector
of length equal to the number of points in the point pattern.
If rvalue
is absent, the result is
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 |
theo |
the theoretical value |
together with columns containing the values of the
neighbourhood density function for each point in the pattern.
Column i
corresponds to the i
th point.
The last two columns contain the r
and theo
values.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Getis, A. and Franklin, J. (1987) Second-order neighbourhood analysis of mapped point patterns. Ecology 68, 473–477.
Kest
,
Lest
,
localKinhom
,
localLinhom
.
X <- ponderosa # compute all the local L functions L <- localL(X) # plot all the local L functions against r plot(L, main="local L functions for ponderosa", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r) # compute the values of L(r) for r = 12 metres L12 <- localL(X, rvalue=12) # Spatially interpolate the values of L12 # Compare Figure 5(b) of Getis and Franklin (1987) X12 <- X %mark% L12 Z <- Smooth(X12, sigma=5, dimyx=128) plot(Z, col=topo.colors(128), main="smoothed neighbourhood density") contour(Z, add=TRUE) points(X, pch=16, cex=0.5)
X <- ponderosa # compute all the local L functions L <- localL(X) # plot all the local L functions against r plot(L, main="local L functions for ponderosa", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r) # compute the values of L(r) for r = 12 metres L12 <- localL(X, rvalue=12) # Spatially interpolate the values of L12 # Compare Figure 5(b) of Getis and Franklin (1987) X12 <- X %mark% L12 Z <- Smooth(X12, sigma=5, dimyx=128) plot(Z, col=topo.colors(128), main="smoothed neighbourhood density") contour(Z, add=TRUE) points(X, pch=16, cex=0.5)
for a multitype point pattern, computes the cross-type version of the local K function.
localKcross(X, from, to, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL) localLcross(X, from, to, ..., rmax = NULL, correction = "Ripley")
localKcross(X, from, to, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL) localLcross(X, from, to, ..., rmax = NULL, correction = "Ripley")
X |
A multitype point pattern (object of class |
... |
Further arguments passed from |
rmax |
Optional. Maximum desired value of the argument |
from |
Type of points from which distances should be measured.
A single value;
one of the possible levels of |
to |
Type of points to which distances should be measured.
A single value;
one of the possible levels of |
correction |
String specifying the edge correction to be applied.
Options are |
verbose |
Logical flag indicating whether to print progress reports during the calculation. |
rvalue |
Optional. A single value of the distance argument
|
Given a multitype spatial point pattern X
,
the local cross-type function
localKcross
is the local version of the multitype function
Kcross
.
Recall that Kcross(X, from, to)
is a sum of contributions
from all pairs of points in X
where
the first point belongs to from
and the second point belongs to type to
.
The local cross-type
function is defined for each point
X[i]
that belongs to
type from
, and it consists of all the contributions to
the cross-type function that originate from point
X[i]
:
where the sum is over all points
belonging to type
to
, that lie
within a distance of the
th point,
is the area of the observation window,
is the number
of points in
X
, and is an edge correction
term (as described in
Kest
).
The value of
can also be interpreted as one
of the summands that contributes to the global estimate of the
Kcross
function.
By default, the function
is computed for a range of
values
for each point
belonging to type
from
.
The results are stored as a function value
table (object of class "fv"
) with a column of the table
containing the function estimates for each point of the pattern
X
belonging to type from
.
Alternatively, if the argument rvalue
is given, and it is a
single number, then the function will only be computed for this value
of , and the results will be returned as a numeric vector,
with one entry of the vector for each point of the pattern
X
belonging to type from
.
The local cross-type function
localLcross
is computed by applying the transformation
.
If rvalue
is given, the result is a numeric vector
of length equal to the number of points in the point pattern
that belong to type from
.
If rvalue
is absent, the result is
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 |
theo |
the theoretical value |
together with columns containing the values of the
neighbourhood density function for each point in the pattern.
Column i
corresponds to the i
th point
of type from
.
The last two columns contain the r
and theo
values.
Ege Rubak [email protected] and Adrian Baddeley [email protected].
Kcross
,
Lcross
,
localK
,
localL
.
Inhomogeneous counterparts of localK
and localL
are computed by localKcross.inhom
and
localLinhom
.
X <- amacrine # compute all the local Lcross functions L <- localLcross(X) # plot all the local Lcross functions against r plot(L, main="local Lcross functions for amacrine", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r) # compute the values of L(r) for r = 0.1 metres L12 <- localLcross(X, rvalue=0.1)
X <- amacrine # compute all the local Lcross functions L <- localLcross(X) # plot all the local Lcross functions against r plot(L, main="local Lcross functions for amacrine", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r) # compute the values of L(r) for r = 0.1 metres L12 <- localLcross(X, rvalue=0.1)
Computes spatially-weighted versions of the
the local multitype -function or
-function.
localKcross.inhom(X, from, to, lambdaFrom=NULL, lambdaTo=NULL, ..., rmax = NULL, correction = "Ripley", sigma=NULL, varcov=NULL, lambdaX=NULL, update=TRUE, leaveoneout=TRUE) localLcross.inhom(X, from, to, lambdaFrom=NULL, lambdaTo=NULL, ..., rmax = NULL)
localKcross.inhom(X, from, to, lambdaFrom=NULL, lambdaTo=NULL, ..., rmax = NULL, correction = "Ripley", sigma=NULL, varcov=NULL, lambdaX=NULL, update=TRUE, leaveoneout=TRUE) localLcross.inhom(X, from, to, lambdaFrom=NULL, lambdaTo=NULL, ..., rmax = NULL)
X |
A point pattern (object of class |
from |
Type of points from which distances should be measured.
A single value;
one of the possible levels of |
to |
Type of points to which distances should be measured.
A single value;
one of the possible levels of |
lambdaFrom , lambdaTo
|
Optional.
Values of the estimated intensity function
for the points of type |
... |
Extra arguments. Ignored if |
rmax |
Optional. Maximum desired value of the argument |
correction |
String specifying the edge correction to be applied.
Options are |
sigma , varcov
|
Optional arguments passed to |
lambdaX |
Optional.
Values of the estimated intensity function
for all points of |
update |
Logical value indicating what to do when |
leaveoneout |
Logical value (passed to |
The functions localKcross.inhom
and localLcross.inhom
are inhomogeneous or weighted versions of the
local multitype and
functions implemented in
localKcross
and localLcross
.
Given a multitype spatial point pattern X
,
and two designated types from
and to
,
the local multitype function is
defined for each point
X[i]
that belongs to type from
,
and is computed by
where the sum is over all points
of type
to
that lie
within a distance of the
th point,
is the estimated intensity of the
point pattern at the point
,
and
is an edge correction
term (as described in
Kest
).
The function
is computed for a range of
values
for each point
. The results are stored as a function value
table (object of class
"fv"
) with a column of the table
containing the function estimates for each point of the pattern
X
of type from
.
The corresponding function
is computed by applying the
transformation
.
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 |
theo |
the theoretical value |
together with columns containing the values of the
neighbourhood density function for each point in the pattern
of type from
.
The last two columns contain the r
and theo
values.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Kinhom
,
Linhom
,
localK
,
localL
.
X <- amacrine # compute all the local L functions L <- localLcross.inhom(X) # plot all the local L functions against r plot(L, main="local L functions for ponderosa", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r)
X <- amacrine # compute all the local L functions L <- localLcross.inhom(X) # plot all the local L functions against r plot(L, main="local L functions for ponderosa", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r)
for a multitype point pattern, computes the dot-type version of the local K function.
localKdot(X, from, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL) localLdot(X, from, ..., rmax = NULL, correction = "Ripley")
localKdot(X, from, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL) localLdot(X, from, ..., rmax = NULL, correction = "Ripley")
X |
A multitype point pattern (object of class |
... |
Further arguments passed from |
rmax |
Optional. Maximum desired value of the argument |
from |
Type of points from which distances should be measured.
A single value;
one of the possible levels of |
correction |
String specifying the edge correction to be applied.
Options are |
verbose |
Logical flag indicating whether to print progress reports during the calculation. |
rvalue |
Optional. A single value of the distance argument
|
Given a multitype spatial point pattern X
,
the local dot-type function
localKdot
is the local version of the multitype function
Kdot
.
Recall that Kdot(X, from)
is a sum of contributions
from all pairs of points in X
where
the first point belongs to from
.
The local dot-type
function is defined for each point
X[i]
that belongs to
type from
, and it consists of all the contributions to
the dot-type function that originate from point
X[i]
:
where the sum is over all points
that lie within a distance
of the
th point,
is the area of the observation window,
is the number
of points in
X
, and is an edge correction
term (as described in
Kest
).
The value of
can also be interpreted as one
of the summands that contributes to the global estimate of the
Kdot
function.
By default, the function
is computed for a range of
values
for each point
belonging to type
from
.
The results are stored as a function value
table (object of class "fv"
) with a column of the table
containing the function estimates for each point of the pattern
X
belonging to type from
.
Alternatively, if the argument rvalue
is given, and it is a
single number, then the function will only be computed for this value
of , and the results will be returned as a numeric vector,
with one entry of the vector for each point of the pattern
X
belonging to type from
.
The local dot-type function
localLdot
is computed by applying the transformation
.
If rvalue
is given, the result is a numeric vector
of length equal to the number of points in the point pattern
that belong to type from
.
If rvalue
is absent, the result is
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 |
theo |
the theoretical value |
together with columns containing the values of the
neighbourhood density function for each point in the pattern.
Column i
corresponds to the i
th point
of type from
.
The last two columns contain the r
and theo
values.
Ege Rubak [email protected] and Adrian Baddeley [email protected].
X <- amacrine # compute all the local Ldot functions L <- localLdot(X) # plot all the local Ldot functions against r plot(L, main="local Ldot functions for amacrine", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r) # compute the values of L(r) for r = 0.1 metres L12 <- localLdot(X, rvalue=0.1)
X <- amacrine # compute all the local Ldot functions L <- localLdot(X) # plot all the local Ldot functions against r plot(L, main="local Ldot functions for amacrine", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r) # compute the values of L(r) for r = 0.1 metres L12 <- localLdot(X, rvalue=0.1)
Computes spatially-weighted versions of the
the local -function or
-function.
localKinhom(X, lambda, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL, sigma = NULL, varcov = NULL, update=TRUE, leaveoneout=TRUE) localLinhom(X, lambda, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL, sigma = NULL, varcov = NULL, update=TRUE, leaveoneout=TRUE)
localKinhom(X, lambda, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL, sigma = NULL, varcov = NULL, update=TRUE, leaveoneout=TRUE) localLinhom(X, lambda, ..., rmax = NULL, correction = "Ripley", verbose = TRUE, rvalue=NULL, sigma = NULL, varcov = NULL, update=TRUE, leaveoneout=TRUE)
X |
A point pattern (object of class |
lambda |
Optional.
Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern |
... |
Extra arguments. Ignored if |
rmax |
Optional. Maximum desired value of the argument |
correction |
String specifying the edge correction to be applied.
Options are |
verbose |
Logical flag indicating whether to print progress reports during the calculation. |
rvalue |
Optional. A single value of the distance argument
|
sigma , varcov
|
Optional arguments passed to |
leaveoneout |
Logical value (passed to |
update |
Logical value indicating what to do when |
The functions localKinhom
and localLinhom
are inhomogeneous or weighted versions of the
neighbourhood density function implemented in
localK
and localL
.
Given a spatial point pattern X
, the
inhomogeneous neighbourhood density function
associated with the
th point
in
X
is computed by
where the sum is over all points that lie
within a distance
of the
th point,
is the estimated intensity of the
point pattern at the point
,
and
is an edge correction
term (as described in
Kest
).
The value of can also be interpreted as one
of the summands that contributes to the global estimate of the
inhomogeneous L function (see
Linhom
).
By default, the function or
is computed for a range of
values
for each point
. The results are stored as a function value
table (object of class
"fv"
) with a column of the table
containing the function estimates for each point of the pattern
X
.
Alternatively, if the argument rvalue
is given, and it is a
single number, then the function will only be computed for this value
of , and the results will be returned as a numeric vector,
with one entry of the vector for each point of the pattern
X
.
If rvalue
is given, the result is a numeric vector
of length equal to the number of points in the point pattern.
If rvalue
is absent, the result is
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 |
theo |
the theoretical value |
together with columns containing the values of the
neighbourhood density function for each point in the pattern.
Column i
corresponds to the i
th point.
The last two columns contain the r
and theo
values.
Mike Kuhn, Adrian Baddeley [email protected] and Rolf Turner [email protected]
Kinhom
,
Linhom
,
localK
,
localL
.
X <- ponderosa # compute all the local L functions L <- localLinhom(X) # plot all the local L functions against r plot(L, main="local L functions for ponderosa", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r) # compute the values of L(r) for r = 12 metres L12 <- localL(X, rvalue=12)
X <- ponderosa # compute all the local L functions L <- localLinhom(X) # plot all the local L functions against r plot(L, main="local L functions for ponderosa", legend=FALSE) # plot only the local L function for point number 7 plot(L, iso007 ~ r) # compute the values of L(r) for r = 12 metres L12 <- localL(X, rvalue=12)
Computes individual contributions to the pair correlation function from each data point.
localpcf(X, ..., delta=NULL, rmax=NULL, nr=512, stoyan=0.15, rvalue=NULL) localpcfinhom(X, ..., delta=NULL, rmax=NULL, nr=512, stoyan=0.15, lambda=NULL, sigma=NULL, varcov=NULL, update=TRUE, leaveoneout=TRUE, rvalue=NULL)
localpcf(X, ..., delta=NULL, rmax=NULL, nr=512, stoyan=0.15, rvalue=NULL) localpcfinhom(X, ..., delta=NULL, rmax=NULL, nr=512, stoyan=0.15, lambda=NULL, sigma=NULL, varcov=NULL, update=TRUE, leaveoneout=TRUE, rvalue=NULL)
X |
A point pattern (object of class |
delta |
Smoothing bandwidth for pair correlation. The halfwidth of the Epanechnikov kernel. |
rmax |
Optional. Maximum value of distance |
nr |
Optional. Number of values of distance |
stoyan |
Optional. The value of the constant |
lambda |
Optional.
Values of the estimated intensity function, for the
inhomogeneous pair correlation.
Either a vector giving the intensity values
at the points of the pattern |
sigma , varcov , ...
|
These arguments are ignored by |
leaveoneout |
Logical value (passed to |
update |
Logical value indicating what to do when |
rvalue |
Optional. A single value of the distance argument
|
localpcf
computes the contribution, from each individual
data point in a point pattern X
, to the
empirical pair correlation function of X
.
These contributions are sometimes known as LISA (local indicator
of spatial association) functions based on pair correlation.
localpcfinhom
computes the corresponding contribution
to the inhomogeneous empirical pair correlation function of X
.
Given a spatial point pattern X
, the local pcf
associated with the
th point
in
X
is computed by
where the sum is over all points ,
is the area of the observation window,
is the number
of points in
X
, and is the distance
between points
i
and j
. Here k
is the
Epanechnikov kernel,
Edge correction is performed using the border method
(for the sake of computational efficiency):
the estimate is set to
NA
if
, where
is the distance from point
to the boundary of the
observation window.
The smoothing bandwidth may be specified.
If not, it is chosen by Stoyan's rule of thumb
where
is the estimated intensity
and
is a constant, usually taken to be 0.15.
The value of
is controlled by the argument
stoyan
.
For localpcfinhom
, the optional argument lambda
specifies the values of the estimated intensity function.
If lambda
is given, it should be either a
numeric vector giving the intensity values
at the points of the pattern X
,
a pixel image (object of class "im"
) giving the
intensity values at all locations, a fitted point process model
(object of class "ppm"
, "kppm"
or "dppm"
)
or a function(x,y)
which
can be evaluated to give the intensity value at any location.
If lambda
is not given, then it will be estimated
using a leave-one-out kernel density smoother as described
in pcfinhom
.
Alternatively, if the argument rvalue
is given, and it is a
single number, then the function will only be computed for this value
of , and the results will be returned as a numeric vector,
with one entry of the vector for each point of the pattern
X
.
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 |
theo |
the theoretical value |
together with columns containing the values of the
local pair correlation function for each point in the pattern.
Column i
corresponds to the i
th point.
The last two columns contain the r
and theo
values.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
localK
,
localKinhom
,
pcf
,
pcfinhom
X <- ponderosa g <- localpcf(X, stoyan=0.5) colo <- c(rep("grey", npoints(X)), "blue") a <- plot(g, main=c("local pair correlation functions", "Ponderosa pines"), legend=FALSE, col=colo, lty=1) # plot only the local pair correlation function for point number 7 plot(g, est007 ~ r) # Extract the local pair correlation at distance 15 metres, for each point g15 <- localpcf(X, rvalue=15, stoyan=0.5) g15[1:10] # Check that the value for point 7 agrees with the curve for point 7: points(15, g15[7], col="red") # Inhomogeneous gi <- localpcfinhom(X, stoyan=0.5) a <- plot(gi, main=c("inhomogeneous local pair correlation functions", "Ponderosa pines"), legend=FALSE, col=colo, lty=1)
X <- ponderosa g <- localpcf(X, stoyan=0.5) colo <- c(rep("grey", npoints(X)), "blue") a <- plot(g, main=c("local pair correlation functions", "Ponderosa pines"), legend=FALSE, col=colo, lty=1) # plot only the local pair correlation function for point number 7 plot(g, est007 ~ r) # Extract the local pair correlation at distance 15 metres, for each point g15 <- localpcf(X, rvalue=15, stoyan=0.5) g15[1:10] # Check that the value for point 7 agrees with the curve for point 7: points(15, g15[7], col="red") # Inhomogeneous gi <- localpcfinhom(X, stoyan=0.5) a <- plot(gi, main=c("inhomogeneous local pair correlation functions", "Ponderosa pines"), legend=FALSE, col=colo, lty=1)
Computes a bootstrap confidence band for a summary function of a point process.
lohboot(X, fun=c("pcf", "Kest", "Lest", "pcfinhom", "Kinhom", "Linhom", "Kcross", "Lcross", "Kdot", "Ldot", "Kcross.inhom", "Lcross.inhom"), ..., block=FALSE, global=FALSE, basicboot=FALSE, Vcorrection=FALSE, confidence=0.95, nx = 4, ny = nx, nsim=200, type=7)
lohboot(X, fun=c("pcf", "Kest", "Lest", "pcfinhom", "Kinhom", "Linhom", "Kcross", "Lcross", "Kdot", "Ldot", "Kcross.inhom", "Lcross.inhom"), ..., block=FALSE, global=FALSE, basicboot=FALSE, Vcorrection=FALSE, confidence=0.95, nx = 4, ny = nx, nsim=200, type=7)
X |
A point pattern (object of class |
fun |
Name of the summary function for which confidence intervals are
desired: one of the strings |
... |
Arguments passed to the corresponding local version of the summary function (see Details). |
block |
Logical value indicating whether to use Loh's block bootstrap
as originally proposed. Default is |
global |
Logical. If |
basicboot |
Logical value indicating whether to use the so-called basic bootstrap confidence interval. See Details. |
Vcorrection |
Logical value indicating whether to use a variance correction
when |
confidence |
Confidence level, as a fraction between 0 and 1. |
nx , ny
|
Integers.
If |
nsim |
Number of bootstrap simulations. |
type |
Integer. Type of quantiles.
Argument passed to |
This algorithm computes
confidence bands for the true value of the summary function
fun
using the bootstrap method of Loh (2008)
and a modification described in Baddeley, Rubak, Turner (2015).
If fun="pcf"
, for example, the algorithm computes a pointwise
(100 * confidence)
% confidence interval for the true value of
the pair correlation function for the point process,
normally estimated by pcf
.
It starts by computing the array of
local pair correlation functions,
localpcf
, of the data pattern X
.
This array consists of the contributions to the estimate of the
pair correlation function from each
data point.
If block=FALSE
, these contributions are resampled nsim
times
with replacement as described in Baddeley, Rubak, Turner (2015);
from each resampled dataset the total contribution
is computed, yielding nsim
random pair correlation functions.
If block=TRUE
, the calculation is performed as originally
proposed by Loh (2008, 2010). The (bounding box of the) window is divided
into rectangles (blocks).
The average contribution of a block
is obtained by averaging the contribution of each point included in the block.
Then, the average contributions on each block are resampled
nsim
times
with replacement as described in Loh (2008) and Loh (2010);
from each resampled dataset the total contribution
is computed, yielding nsim
random pair correlation functions.
Notice that for non-rectangular windows any blocks not fully contained in the
window are discarded before doing the resampling, so the effective number of
blocks may be substantially smaller than in this case.
The pointwise alpha/2
and 1 - alpha/2
quantiles of
these functions are computed, where alpha = 1 - confidence
.
The average of the local functions is also computed as an estimate
of the pair correlation function.
There are several ways to define a bootstrap confidence interval.
If basicbootstrap=TRUE
,
the so-called basic confidence bootstrap interval
is used as described in Loh (2008).
It has been noticed in Loh (2010) that
when the intensity of the point process is unknown,
the bootstrap error estimate is larger than it should be.
When the function is used,
an adjustment procedure has been proposed in Loh (2010)
that is used if
Vcorrection=TRUE
.
In this case, the basic confidence bootstrap interval is implicitly used.
To control the estimation algorithm, use the
arguments ...
, which are passed to the local version
of the summary function, as shown below:
For fun="Lest"
, the calculations are first performed
as if fun="Kest"
, and then the square-root transformation is
applied to obtain the -function. Similarly for
fun="Linhom", "Lcross", "Ldot", "Lcross.inhom"
.
Note that the confidence bands computed by
lohboot(fun="pcf")
may not contain the estimate of the
pair correlation function computed by pcf
,
because of differences between the algorithm parameters
(such as the choice of edge correction)
in localpcf
and pcf
.
If you are using lohboot
, the
appropriate point estimate of the pair correlation itself is
the pointwise mean of the local estimates, which is provided
in the result of lohboot
and is shown in the default plot.
If the confidence bands seem unbelievably narrow, this may occur because the point pattern has a hard core (the true pair correlation function is zero for certain values of distance) or because of an optical illusion when the function is steeply sloping (remember the width of the confidence bands should be measured vertically).
An alternative to lohboot
is varblock
.
A function value table
(object of class "fv"
)
containing columns giving the estimate of the summary function,
the upper and lower limits of the bootstrap confidence interval,
and the theoretical value of the summary function for a Poisson process.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected] and Christophe Biscio.
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Loh, J.M. (2008) A valid and fast spatial bootstrap for correlation functions. The Astrophysical Journal, 681, 726–734.
Loh, J.M. (2010) Bootstrapping an inhomogeneous point process. Journal of Statistical Planning and Inference, 140, 734–749.
Summary functions
Kest
,
pcf
,
Kinhom
,
pcfinhom
,
localK
,
localpcf
,
localKinhom
,
localpcfinhom
,
localKcross
,
localKdot
,
localLcross
,
localLdot
.
localKcross.inhom
,
localLcross.inhom
.
See varblock
for an alternative bootstrap technique.
p <- lohboot(simdat, stoyan=0.5) g <- lohboot(simdat, stoyan=0.5, block=TRUE) g plot(g)
p <- lohboot(simdat, stoyan=0.5) g <- lohboot(simdat, stoyan=0.5, block=TRUE) g plot(g)
Estimate the marked connection function of a multitype point pattern.
markconnect(X, i, j, r=NULL, correction=c("isotropic", "Ripley", "translate"), method="density", ..., normalise=FALSE)
markconnect(X, i, j, r=NULL, correction=c("isotropic", "Ripley", "translate"), method="density", ..., normalise=FALSE)
X |
The observed point pattern.
An object of class |
i |
Number or character string identifying the type (mark value)
of the points in |
j |
Number or character string identifying the type (mark value)
of the points in |
r |
numeric vector. The values of the argument |
correction |
A character vector containing any selection of the
options |
method |
A character vector indicating the user's choice of
density estimation technique to be used. Options are
|
... |
Arguments passed to |
normalise |
If |
The mark connection function
of a multitype point process
is a measure of the dependence between the types of two
points of the process a distance
apart.
Informally is defined
as the conditional probability,
given that there is a point of the process at a location
and another point of the process at a location
separated by a distance
, that the first point
is of type
and the second point is of type
.
See Stoyan and Stoyan (1994).
If the marks attached to the points of X
are independent
and identically distributed, then
where
denotes the probability that a point is of type
. Values larger than this,
,
indicate positive association between the two types,
while smaller values indicate negative association.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a multitype point pattern (a marked point pattern
with factor-valued marks).
The argument r
is the vector of values for the
distance at which
is estimated.
There is a sensible default.
This algorithm assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Kest
.
The edge corrections implemented here are
Ripley's isotropic correction (see Ripley, 1988; Ohser, 1983). This is implemented only for rectangular and polygonal windows (not for binary masks) and is slow for complicated polygons.
Translation correction (Ohser, 1983). Implemented for all window geometries.
No edge correction.
The option correction="none"
should only be used if the
number of data points is extremely large (otherwise an edge correction
is needed to correct bias).
Note that the estimator assumes the process is stationary (spatially homogeneous).
The mark connection function is estimated using density estimation techniques. The user can choose between
"density"
which uses the standard kernel
density estimation routine density
, and
works only for evenly-spaced r
values;
"loess"
which uses the function loess
in the
package modreg;
"sm"
which uses the function sm.density
in the
package sm and is extremely slow;
"smrep"
which uses the function sm.density
in the
package sm and is relatively fast, but may require manual
control of the smoothing parameter hmult
.
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
Multitype pair correlation pcfcross
and multitype K-functions Kcross
, Kdot
.
Use alltypes
to compute the mark connection functions
between all pairs of types.
Mark correlation markcorr
and
mark variogram markvario
for numeric-valued marks.
# Hughes' amacrine data # Cells marked as 'on'/'off' M <- markconnect(amacrine, "on", "off") plot(M) # Compute for all pairs of types at once plot(alltypes(amacrine, markconnect))
# Hughes' amacrine data # Cells marked as 'on'/'off' M <- markconnect(amacrine, "on", "off") plot(M) # Compute for all pairs of types at once plot(alltypes(amacrine, markconnect))
Estimate the marked correlation function of a marked point pattern.
markcorr(X, f = function(m1, m2) { m1 * m2}, r=NULL, correction=c("isotropic", "Ripley", "translate"), method="density", ..., weights=NULL, f1=NULL, normalise=TRUE, fargs=NULL, internal=NULL)
markcorr(X, f = function(m1, m2) { m1 * m2}, r=NULL, correction=c("isotropic", "Ripley", "translate"), method="density", ..., weights=NULL, f1=NULL, normalise=TRUE, fargs=NULL, internal=NULL)
X |
The observed point pattern.
An object of class |
f |
Optional. Test function |
r |
Optional. Numeric vector. The values of the argument |
correction |
A character vector containing any selection of the
options |
method |
A character vector indicating the user's choice of
density estimation technique to be used. Options are
|
... |
Arguments passed to the density estimation routine
( |
weights |
Optional. Numeric weights for each data point in |
f1 |
An alternative to |
normalise |
If |
fargs |
Optional. A list of extra arguments to be passed to the function
|
internal |
Do not use this argument. |
By default, this command calculates an estimate of
Stoyan's mark correlation
for the point pattern.
Alternatively if the argument f
or f1
is given, then it
calculates Stoyan's generalised mark correlation
with test function
.
Theoretical definitions are as follows (see Stoyan and Stoyan (1994, p. 262)):
For a point process with numeric marks,
Stoyan's mark correlation function
,
is
where denotes the conditional expectation
given that there are points of the process at the locations
and
separated by a distance
,
and where
denote the marks attached to these
two points. On the denominator,
are random marks
drawn independently from the marginal distribution of marks,
and
is the usual expectation.
For a multitype point process , the mark correlation is
where and
denote the
probability and conditional probability.
The generalised mark correlation function
of a marked point process
, with test function
,
is
The test function is any function
with two arguments which are possible marks of the pattern,
and which returns a nonnegative real value.
Common choices of
are:
for continuous nonnegative real-valued marks,
for discrete marks (multitype point patterns),
and for marks taking values in ,
.
Note that is not a “correlation”
in the usual statistical sense. It can take any
nonnegative real value. The value 1 suggests “lack of correlation”:
if the marks attached to the points of
X
are independent
and identically distributed, then
.
The interpretation of values larger or smaller than 1 depends
on the choice of function
.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern.
The argument f
determines the function to be applied to
pairs of marks. It has a sensible default, which depends on the
kind of marks in X
. If the marks
are numeric values, then f <- function(m1, m2) { m1 * m2}
computes the product of two marks.
If the marks are a factor (i.e. if X
is a multitype point
pattern) then f <- function(m1, m2) { m1 == m2}
yields
the value 1 when the two marks are equal, and 0 when they are unequal.
These are the conventional definitions for numerical
marks and multitype points respectively.
The argument f
may be specified by the user.
It must be an R function, accepting two arguments m1
and m2
which are vectors of equal length containing mark
values (of the same type as the marks of X
).
(It may also take additional arguments, passed through fargs
).
It must return a vector of numeric
values of the same length as m1
and m2
.
The values must be non-negative, and NA
values are not permitted.
Alternatively the user may specify the argument f1
instead of f
. This indicates that the test function
should take the form
where
is given by the argument
f1
.
The argument f1
should be an R function with at least one
argument.
(It may also take additional arguments, passed through fargs
).
The argument r
is the vector of values for the
distance at which
is estimated.
This algorithm assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated in the same manner as in Kest
.
The edge corrections implemented here are
Ripley's isotropic correction (see Ripley, 1988; Ohser, 1983). This is implemented only for rectangular and polygonal windows (not for binary masks).
Translation correction (Ohser, 1983). Implemented for all window geometries, but slow for complex windows.
Note that the estimator assumes the process is stationary (spatially homogeneous).
The numerator and denominator of the mark correlation function (in the expression above) are estimated using density estimation techniques. The user can choose between
"density"
which uses the standard kernel
density estimation routine density
, and
works only for evenly-spaced r
values;
"loess"
which uses the function loess
in the
package modreg;
"sm"
which uses the function sm.density
in the
package sm and is extremely slow;
"smrep"
which uses the function sm.density
in the
package sm and is relatively fast, but may require manual
control of the smoothing parameter hmult
.
If normalise=FALSE
then the algorithm will compute
only the numerator
of the expression for the mark correlation function.
In this case, negative values of f
are permitted.
A function value table (object of class "fv"
)
or a list of function value tables, one for each column of marks.
An object of class "fv"
(see fv.object
)
is essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the mark correlation function
obtained by the edge corrections named.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
Mark variogram markvario
for numeric marks.
Mark connection function markconnect
and
multitype K-functions Kcross
, Kdot
for factor-valued marks.
Mark cross-correlation function markcrosscorr
for point patterns with several columns of marks.
Kmark
to estimate a cumulative function
related to the mark correlation function.
# CONTINUOUS-VALUED MARKS: # (1) Spruces # marks represent tree diameter # mark correlation function ms <- markcorr(spruces) plot(ms) # (2) simulated data with independent marks X <- rpoispp(100) X <- X %mark% runif(npoints(X)) Xc <- markcorr(X) plot(Xc) # MULTITYPE DATA: # Hughes' amacrine data # Cells marked as 'on'/'off' X <- if(interactive()) amacrine else amacrine[c(FALSE, TRUE)] # (3) Kernel density estimate with Epanecnikov kernel # (as proposed by Stoyan & Stoyan) M <- markcorr(X, function(m1,m2) {m1==m2}, correction="translate", method="density", kernel="epanechnikov") # Note: kernel="epanechnikov" comes from help(density) # (4) Same again with explicit control over bandwidth M <- markcorr(X, correction="translate", method="density", kernel="epanechnikov", bw=0.02) # see help(density) for correct interpretation of 'bw' # weighted mark correlation X <- if(interactive()) betacells else betacells[c(TRUE,FALSE)] Y <- subset(X, select=type) a <- marks(X)$area v <- markcorr(Y, weights=a)
# CONTINUOUS-VALUED MARKS: # (1) Spruces # marks represent tree diameter # mark correlation function ms <- markcorr(spruces) plot(ms) # (2) simulated data with independent marks X <- rpoispp(100) X <- X %mark% runif(npoints(X)) Xc <- markcorr(X) plot(Xc) # MULTITYPE DATA: # Hughes' amacrine data # Cells marked as 'on'/'off' X <- if(interactive()) amacrine else amacrine[c(FALSE, TRUE)] # (3) Kernel density estimate with Epanecnikov kernel # (as proposed by Stoyan & Stoyan) M <- markcorr(X, function(m1,m2) {m1==m2}, correction="translate", method="density", kernel="epanechnikov") # Note: kernel="epanechnikov" comes from help(density) # (4) Same again with explicit control over bandwidth M <- markcorr(X, correction="translate", method="density", kernel="epanechnikov", bw=0.02) # see help(density) for correct interpretation of 'bw' # weighted mark correlation X <- if(interactive()) betacells else betacells[c(TRUE,FALSE)] Y <- subset(X, select=type) a <- marks(X)$area v <- markcorr(Y, weights=a)
Given a spatial point pattern with several columns of marks, this function computes the mark correlation function between each pair of columns of marks.
markcrosscorr(X, r = NULL, correction = c("isotropic", "Ripley", "translate"), method = "density", ..., normalise = TRUE, Xname = NULL)
markcrosscorr(X, r = NULL, correction = c("isotropic", "Ripley", "translate"), method = "density", ..., normalise = TRUE, Xname = NULL)
X |
The observed point pattern.
An object of class |
r |
Optional. Numeric vector. The values of the argument |
correction |
A character vector containing any selection of the
options |
method |
A character vector indicating the user's choice of
density estimation technique to be used. Options are
|
... |
Arguments passed to the density estimation routine
( |
normalise |
If |
Xname |
Optional character string name for the dataset |
First, all columns of marks are converted to numerical values.
A factor with possible levels is converted to
columns of dummy (indicator) values.
Next, each pair of columns is considered, and the mark cross-correlation is defined as
where denotes the conditional expectation
given that there are points of the process at the locations
and
separated by a distance
.
On the numerator,
and
are the marks attached to locations
and
respectively
in the
th and
th columns of marks respectively.
On the denominator,
and
are
independent random values drawn from the
th and
th columns of marks, respectively,
and
is the usual expectation.
Note that is not a “correlation”
in the usual statistical sense. It can take any
nonnegative real value. The value 1 suggests “lack of correlation”:
if the marks attached to the points of
X
are independent
and identically distributed, then
.
The argument X
must be a point pattern (object of class
"ppp"
) or any data that are acceptable to as.ppp
.
It must be a marked point pattern.
The cross-correlations are estimated in the same manner as
for markcorr
.
A function array (object of class "fasp"
) containing
the mark cross-correlation functions for each possible pair
of columns of marks.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
# The dataset 'betacells' has two columns of marks: # 'type' (factor) # 'area' (numeric) if(interactive()) plot(betacells) plot(markcrosscorr(betacells))
# The dataset 'betacells' has two columns of marks: # 'type' (factor) # 'area' (numeric) if(interactive()) plot(betacells) plot(markcrosscorr(betacells))
Generates the mark-mark scatter plot of a point pattern.
markmarkscatter(X, rmax, ..., col = NULL, symap = NULL, transform=I, jit=FALSE)
markmarkscatter(X, rmax, ..., col = NULL, symap = NULL, transform=I, jit=FALSE)
X |
A point pattern (object of class |
rmax |
Maximum distance between pairs of points which contribute to the plot. |
... |
Additional arguments passed to |
transform |
Optional. A function which should be applied to the mark values. |
jit |
Logical value indicating whether mark values should be randomly
perturbed using |
col |
Optional. A vector of colour values, or a |
symap |
Optional. A |
The mark-mark scatter plot (Ballani et al, 2019) is a
scatterplot of the mark values of all pairs of distinct points in X
which are closer than the distance rmax
.
The dots in the scatterplot are coloured according to the
pairwise distance between the two spatial points.
The plot is augmented by three curves explained by
Ballani et al (2019).
If the marks only take a few different values, then
it is usually appropriate to apply random perturbation (jitter)
to the mark values, by setting jit=TRUE
.
Null.
Adrian Baddeley (coded from the description in Ballani et al.)
Ballani, F., Pommerening, A. and Stoyan, D. (2019) Mark-mark scatterplots improve pattern analysis in spatial plant ecology. Ecological Informatics 49, 13–21.
markmarkscatter(longleaf, 10) markmarkscatter(spruces, 10, jit=TRUE)
markmarkscatter(longleaf, 10) markmarkscatter(spruces, 10, jit=TRUE)
Visit each point in a multitype point pattern, find the neighbouring points, and compile a frequency table of the marks of these neighbour points.
marktable(X, R, N, exclude=TRUE, collapse=FALSE)
marktable(X, R, N, exclude=TRUE, collapse=FALSE)
X |
A multitype point pattern.
An object of class |
R |
Neighbourhood radius. Incompatible with |
N |
Number of neighbours of each point. Incompatible with |
exclude |
Logical. If |
collapse |
Logical. If |
This algorithm visits each point in the point pattern X
,
inspects all the neighbouring points within a radius R
of the current
point (or the N
nearest neighbours of the current point),
and compiles a frequency table of the marks attached to the
neighbours.
The dataset X
must be a multitype point pattern, that is,
marks(X)
must be a factor
.
If collapse=FALSE
(the default),
the result is a two-dimensional contingency table with one row for
each point in the pattern, and one column for each possible mark
value. The [i,j]
entry in the table gives the number of
neighbours of point i
that have mark j
.
If collapse=TRUE
, this contingency table is aggregated
according to the type of point, so that the result is a contingency
table with one row and one column for each possible mark value.
The [i,j]
entry in the table gives the number of
neighbours of a point with mark i
that have mark j
.
To perform more complicated calculations on the neighbours of every
point, use markstat
or applynbd
.
A contingency table (object of class "table"
).
If collapse=FALSE
, the table has one row for
each point in X
, and one column for each possible mark value.
If collapse=TRUE
, the table has one row and one column
for each possible mark value.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
markstat
,
applynbd
,
Kcross
,
ppp.object
,
table
head(marktable(amacrine, 0.1)) head(marktable(amacrine, 0.1, exclude=FALSE)) marktable(amacrine, N=1, collapse=TRUE)
head(marktable(amacrine, 0.1)) head(marktable(amacrine, 0.1, exclude=FALSE)) marktable(amacrine, N=1, collapse=TRUE)
Estimate the mark variogram of a marked point pattern.
markvario(X, correction = c("isotropic", "Ripley", "translate"), r = NULL, method = "density", ..., normalise=FALSE)
markvario(X, correction = c("isotropic", "Ripley", "translate"), r = NULL, method = "density", ..., normalise=FALSE)
X |
The observed point pattern.
An object of class |
correction |
A character vector containing any selection of the
options |
r |
numeric vector. The values of the argument |
method |
A character vector indicating the user's choice of
density estimation technique to be used. Options are
|
... |
Other arguments passed to |
normalise |
If |
The mark variogram
of a marked point process
is a measure of the dependence between the marks of two
points of the process a distance
apart.
It is informally defined as
where denotes expectation and
are the marks attached to two points of the process
a distance
apart.
The mark variogram of a marked point process is analogous, but not equivalent, to the variogram of a random field in geostatistics. See Waelder and Stoyan (1996).
An object of class "fv"
(see fv.object
).
Essentially a data frame containing numeric columns
r |
the values of the argument |
theo |
the theoretical value of |
together with a column or columns named
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Cressie, N.A.C. (1991) Statistics for spatial data. John Wiley and Sons, 1991.
Mase, S. (1996) The threshold method for estimating annual rainfall. Annals of the Institute of Statistical Mathematics 48 (1996) 201-213.
Waelder, O. and Stoyan, D. (1996) On variograms in point process statistics. Biometrical Journal 38 (1996) 895-905.
Mark correlation function markcorr
for numeric marks.
Mark connection function markconnect
and
multitype K-functions Kcross
, Kdot
for factor-valued marks.
# Longleaf Pine data # marks represent tree diameter # Subset of this large pattern swcorner <- owin(c(0,100),c(0,100)) sub <- longleaf[ , swcorner] # mark correlation function mv <- markvario(sub) plot(mv)
# Longleaf Pine data # marks represent tree diameter # Subset of this large pattern swcorner <- owin(c(0,100),c(0,100)) sub <- longleaf[ , swcorner] # mark correlation function mv <- markvario(sub) plot(mv)
These are group generic methods for objects of class "fasp"
, which
allows for usual mathematical functions and operators to be applied
directly to function arrays. See Details for a list of implemented functions.
## S3 methods for group generics have prototypes: Math(x, ...) Ops(e1, e2) Complex(z) Summary(..., na.rm=FALSE, drop=TRUE)
## S3 methods for group generics have prototypes: Math(x, ...) Ops(e1, e2) Complex(z) Summary(..., na.rm=FALSE, drop=TRUE)
x , z , e1 , e2
|
objects of class |
... |
further arguments passed to methods. |
na.rm |
Logical value specifying whether missing values should be removed. |
Below is a list of mathematical functions and operators which are
defined for objects of class "fasp"
.
The methods are implemented using eval.fasp
, which tries
to harmonise the functions via harmonise.fv
if they aren't
compatible to begin with.
Group "Math"
:
abs
, sign
, sqrt
,floor
, ceiling
, trunc
,round
, signif
exp
, log
, expm1
, log1p
,cos
, sin
, tan
,cospi
, sinpi
, tanpi
,acos
, asin
, atan
cosh
, sinh
, tanh
,acosh
, asinh
, atanh
lgamma
, gamma
, digamma
, trigamma
cumsum
, cumprod
, cummax
, cummin
Group "Ops"
:
"+"
, "-"
, "*"
, "/"
,
"^"
, "%%"
, "%/%"
"&"
, "|"
, "!"
"=="
, "!="
,
"<"
, "<="
, ">="
, ">"
Group "Summary"
:
all
, any
sum
, prod
min
, max
range
Group "Complex"
:
Arg
, Conj
, Im
, Mod
, Re
For the Ops
group, one of the arguments is permitted to be
a single atomic value, or a function table, instead of a function array.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
eval.fasp
for evaluating expressions involving function arrays.
## convert array of K functions to array of L functions K <- alltypes(amacrine, "K") L <- sqrt(K/pi)
## convert array of K functions to array of L functions K <- alltypes(amacrine, "K") L <- sqrt(K/pi)
These are group generic methods for objects of class "fv"
, which
allows for usual mathematical functions and operators to be applied
directly to function tables. See Details for a list of implemented functions.
## S3 methods for group generics have prototypes: Math(x, ...) Ops(e1, e2) Complex(z) Summary(..., na.rm=FALSE, drop=TRUE)
## S3 methods for group generics have prototypes: Math(x, ...) Ops(e1, e2) Complex(z) Summary(..., na.rm=FALSE, drop=TRUE)
x , z , e1 , e2
|
objects of class |
... |
further arguments passed to methods. |
na.rm |
Logical value specifying whether missing values should be removed. |
Below is a list of mathematical functions and operators which are
defined for objects of class "fv"
.
The methods are implemented using eval.fv
, which tries
to harmonise the functions via harmonise.fv
if they aren't
compatible to begin with.
Group "Math"
:
abs
, sign
, sqrt
,floor
, ceiling
, trunc
,round
, signif
exp
, log
, expm1
, log1p
,cos
, sin
, tan
,cospi
, sinpi
, tanpi
,acos
, asin
, atan
cosh
, sinh
, tanh
,acosh
, asinh
, atanh
lgamma
, gamma
, digamma
, trigamma
cumsum
, cumprod
, cummax
, cummin
Group "Ops"
:
"+"
, "-"
, "*"
, "/"
,
"^"
, "%%"
, "%/%"
"&"
, "|"
, "!"
"=="
, "!="
,
"<"
, "<="
, ">="
, ">"
Group "Summary"
:
all
, any
sum
, prod
min
, max
range
Group "Complex"
:
Arg
, Conj
, Im
, Mod
, Re
For the Ops
group, one of the arguments is permitted to be
a single atomic value instead of a function table.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
eval.fv
for evaluating expressions involving function tables.
## Convert K function to L function K <- Kest(cells) L <- sqrt(K/pi) ## Manually calculate J function FR <- Fest(redwood) GR <- Gest(redwood) suppressWarnings(JR <- (1-GR)/(1-FR))
## Convert K function to L function K <- Kest(cells) L <- sqrt(K/pi) ## Manually calculate J function FR <- Fest(redwood) GR <- Gest(redwood) suppressWarnings(JR <- (1-GR)/(1-FR))
These are methods for the class "rho2hat"
.
## S3 method for class 'rho2hat' plot(x, ..., do.points=FALSE) ## S3 method for class 'rho2hat' print(x, ...) ## S3 method for class 'rho2hat' predict(object, ..., relative=FALSE)
## S3 method for class 'rho2hat' plot(x, ..., do.points=FALSE) ## S3 method for class 'rho2hat' print(x, ...) ## S3 method for class 'rho2hat' predict(object, ..., relative=FALSE)
x , object
|
An object of class |
... |
Arguments passed to other methods. |
do.points |
Logical value indicating whether to plot the observed values of the covariates at the data points. |
relative |
Logical value indicating whether to compute the
estimated point process intensity ( |
These functions are methods for the generic commands
print
,
predict
and
plot
for the class "rho2hat"
.
An object of class "rho2hat"
is an estimate
of the intensity of a point process, as a function of two
given spatial covariates. See rho2hat
.
The method plot.rho2hat
displays the estimated function
using
plot.fv
, and optionally
adds a rug
plot of the observed values of the covariate.
In this plot the two axes represent possible values of the two covariates.
The method predict.rho2hat
computes a pixel image of the
intensity
at each spatial location
, where
and
are the two spatial covariates.
For predict.rho2hat
the value is a pixel image
(object of class "im"
).
For other functions, the value is NULL
.
Adrian Baddeley [email protected]
r2 <- with(bei.extra, rho2hat(bei, elev, grad)) r2 plot(r2) plot(predict(r2))
r2 <- with(bei.extra, rho2hat(bei, elev, grad)) r2 plot(r2) plot(predict(r2))
These are methods for the class "rhohat"
.
## S3 method for class 'rhohat' print(x, ...) ## S3 method for class 'rhohat' plot(x, ..., do.rug=TRUE) ## S3 method for class 'rhohat' predict(object, ..., relative=FALSE, what=c("rho", "lo", "hi", "se")) ## S3 method for class 'rhohat' simulate(object, nsim=1, ..., drop=TRUE)
## S3 method for class 'rhohat' print(x, ...) ## S3 method for class 'rhohat' plot(x, ..., do.rug=TRUE) ## S3 method for class 'rhohat' predict(object, ..., relative=FALSE, what=c("rho", "lo", "hi", "se")) ## S3 method for class 'rhohat' simulate(object, nsim=1, ..., drop=TRUE)
x , object
|
An object of class |
... |
Arguments passed to other methods. |
do.rug |
Logical value indicating whether to plot the observed values of the covariate as a rug plot along the horizontal axis. |
relative |
Logical value indicating whether to compute the
estimated point process intensity ( |
nsim |
Number of simulations to be generated. |
drop |
Logical value indicating what to do when |
what |
Optional character string (partially matched) specifying which
value should be calculated: either the function estimate ( |
These functions are methods for the generic commands
print
,
plot
,
predict
and
simulate
for the class "rhohat"
.
An object of class "rhohat"
is an estimate
of the intensity of a point process, as a function of a
given spatial covariate. See rhohat
.
The method plot.rhohat
displays the estimated function
using
plot.fv
, and optionally
adds a rug
plot of the observed values of the covariate.
The method predict.rhohat
computes a pixel image of the
intensity at each spatial location
, where
is the spatial covariate.
The method simulate.rhohat
invokes predict.rhohat
to determine the predicted intensity, and then simulates a
Poisson point process with this intensity.
For predict.rhohat
the value is a pixel image
(object of class "im"
or "linim"
).
For simulate.rhohat
the value is a point pattern
(object of class "ppp"
or "lpp"
).
For other functions, the value is NULL
.
Adrian Baddeley [email protected]
X <- rpoispp(function(x,y){exp(3+3*x)}) rho <- rhohat(X, function(x,y){x}) rho plot(rho) Y <- predict(rho) plot(Y) plot(simulate(rho), add=TRUE) # if(require("spatstat.model")) { fit <- ppm(X, ~x) rho <- rhohat(fit, "y") opa <- par(mfrow=c(1,2)) plot(predict(rho)) plot(predict(rho, relative=TRUE)) par(opa) plot(predict(rho, what="se")) }
X <- rpoispp(function(x,y){exp(3+3*x)}) rho <- rhohat(X, function(x,y){x}) rho plot(rho) Y <- predict(rho) plot(Y) plot(simulate(rho), add=TRUE) # if(require("spatstat.model")) { fit <- ppm(X, ~x) rho <- rhohat(fit, "y") opa <- par(mfrow=c(1,2)) plot(predict(rho)) plot(predict(rho, relative=TRUE)) par(opa) plot(predict(rho, what="se")) }
Methods for various generic commands, for the class
"ssf"
of spatially sampled functions.
## S3 method for class 'ssf' marks(x, ...) ## S3 replacement method for class 'ssf' marks(x, ...) <- value ## S3 method for class 'ssf' unmark(X) ## S3 method for class 'ssf' as.im(X, ...) ## S3 method for class 'ssf' as.function(x, ...) ## S3 method for class 'ssf' as.ppp(X, ...) ## S3 method for class 'ssf' print(x, ..., brief=FALSE) ## S3 method for class 'ssf' summary(object, ...) ## S3 method for class 'ssf' range(x, ...) ## S3 method for class 'ssf' min(x, ...) ## S3 method for class 'ssf' max(x, ...) ## S3 method for class 'ssf' integral(f, domain=NULL, ..., weights=attr(f, "weights"))
## S3 method for class 'ssf' marks(x, ...) ## S3 replacement method for class 'ssf' marks(x, ...) <- value ## S3 method for class 'ssf' unmark(X) ## S3 method for class 'ssf' as.im(X, ...) ## S3 method for class 'ssf' as.function(x, ...) ## S3 method for class 'ssf' as.ppp(X, ...) ## S3 method for class 'ssf' print(x, ..., brief=FALSE) ## S3 method for class 'ssf' summary(object, ...) ## S3 method for class 'ssf' range(x, ...) ## S3 method for class 'ssf' min(x, ...) ## S3 method for class 'ssf' max(x, ...) ## S3 method for class 'ssf' integral(f, domain=NULL, ..., weights=attr(f, "weights"))
x , X , f , object
|
A spatially sampled function (object of class |
... |
Arguments passed to the default method. |
brief |
Logical value controlling the amount of detail printed. |
value |
Matrix of replacement values for the function. |
domain |
Optional.
Domain of integration. An object of class |
weights |
Optional. Numeric vector of quadrature weights associated with the sample points. |
An object of class "ssf"
represents a
function (real- or vector-valued) that has been
sampled at a finite set of points.
The commands documented here are methods for this class,
for the generic commands
marks
,
marks<-
,
unmark
,
as.im
,
as.function
,
as.ppp
,
print
,
summary
,
range
,
min
,
max
and integral
.
marks
returns a matrix.
marks(x) <- value
returns an object of class "ssf"
.
as.owin
returns a window (object of class "owin"
).
as.ppp
and unmark
return a point pattern (object of class "ppp"
).
as.function
returns a function(x,y)
of class "funxy"
.
print
returns NULL
.
summary
returns an object of class
"summary.ssf"
which has a print method.
range
returns a numeric vector of length 2.
min
and max
return a single numeric value.
integral
returns a numeric or complex value, vector, or matrix.
integral(f)
returns a numeric or complex value
(if f
had numeric or complex values)
or a numeric vector (if f
had vector values).
If domain
is a tessellation then integral(f, domain)
returns a numeric or complex vector with one entry for each tile
(if f
had numeric or complex values)
or a numeric matrix with one row for each tile
(if f
had vector values).
Adrian Baddeley
g <- distfun(cells[1:4]) X <- rsyst(Window(cells), 10) f <- ssf(X, g(X)) f summary(f) marks(f) as.ppp(f) as.im(f) integral(f) integral(f, quadrats(Window(f), 3))
g <- distfun(cells[1:4]) X <- rsyst(Window(cells), 10) f <- ssf(X, g(X)) f summary(f) marks(f) as.ppp(f) as.im(f) integral(f) integral(f, quadrats(Window(f), 3))
Displays the Morisita Index Plot of a spatial point pattern.
miplot(X, ...)
miplot(X, ...)
X |
A point pattern (object of class |
... |
Optional arguments to control the appearance of the plot. |
Morisita (1959) defined an index of spatial aggregation for a spatial
point pattern based on quadrat counts. The spatial domain of the point
pattern is first divided into subsets (quadrats) of equal size and
shape. The numbers of points falling in each quadrat are counted.
Then the Morisita Index is computed as
where is the number of points falling in the
-th
quadrat, and
is the total number of points.
If the pattern is completely random,
MI
should be approximately
equal to 1. Values of MI
greater than 1 suggest clustering.
The Morisita Index plot is a plot of the Morisita Index
MI
against the linear dimension of the quadrats.
The point pattern dataset is divided into
quadrats, then
quadrats, etc, and the
Morisita Index is computed each time. This plot is an attempt to
discern different scales of dependence in the point pattern data.
None.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
M. Morisita (1959) Measuring of the dispersion of individuals and analysis of the distributional patterns. Memoir of the Faculty of Science, Kyushu University, Series E: Biology. 2: 215–235.
miplot(longleaf) opa <- par(mfrow=c(2,3)) plot(cells) plot(japanesepines) plot(redwood) miplot(cells) miplot(japanesepines) miplot(redwood) par(opa)
miplot(longleaf) opa <- par(mfrow=c(2,3)) plot(cells) plot(japanesepines) plot(redwood) miplot(cells) miplot(japanesepines) miplot(redwood) par(opa)
Detect features in a 2D or 3D spatial point pattern using nearest neighbour clutter removal.
nnclean(X, k, ...) ## S3 method for class 'ppp' nnclean(X, k, ..., edge.correct = FALSE, wrap = 0.1, convergence = 0.001, plothist = FALSE, verbose = TRUE, maxit = 50) ## S3 method for class 'pp3' nnclean(X, k, ..., convergence = 0.001, plothist = FALSE, verbose = TRUE, maxit = 50)
nnclean(X, k, ...) ## S3 method for class 'ppp' nnclean(X, k, ..., edge.correct = FALSE, wrap = 0.1, convergence = 0.001, plothist = FALSE, verbose = TRUE, maxit = 50) ## S3 method for class 'pp3' nnclean(X, k, ..., convergence = 0.001, plothist = FALSE, verbose = TRUE, maxit = 50)
X |
A two-dimensional spatial point pattern (object of class
|
k |
Degree of neighbour: |
... |
Arguments passed to |
edge.correct |
Logical flag specifying whether periodic edge correction should be performed (only implemented in 2 dimensions). |
wrap |
Numeric value specifying the relative size of the margin
in which data will be replicated for the
periodic edge correction (if |
convergence |
Relative tolerance threshold for testing convergence of EM algorithm. |
maxit |
Maximum number of iterations for EM algorithm. |
plothist |
Logical flag specifying whether to plot a diagnostic histogram of the nearest neighbour distances and the fitted distribution. |
verbose |
Logical flag specifying whether to print progress reports. |
Byers and Raftery (1998) developed a technique for recognising features in a spatial point pattern in the presence of random clutter.
For each point in the pattern, the distance to the
th nearest neighbour is computed. Then the E-M algorithm is
used to fit a mixture distribution to the
th nearest neighbour distances.
The mixture components represent the feature and the clutter. The
mixture model can be used to classify each point as belong to one
or other component.
The function nnclean
is generic, with methods for
two-dimensional point patterns (class "ppp"
)
and three-dimensional point patterns (class "pp3"
)
currently implemented.
The result is a point pattern (2D or 3D) with two additional columns of marks:
A factor, with levels "noise"
and "feature"
,
indicating the maximum likelihood classification of each point.
Numeric vector giving the estimated probabilities that each point belongs to a feature.
The object also has extra information stored in attributes:
"theta"
contains the fitted parameters
of the mixture model, "info"
contains
information about the fitting procedure, and "hist"
contains
the histogram structure returned from hist.default
if plothist = TRUE
.
An object of the same kind as X
,
obtained by attaching marks to the points of X
.
The object also has attributes, as described under Details.
Original by Simon Byers and Adrian Raftery. Adapted for spatstat by Adrian Baddeley [email protected].
Byers, S. and Raftery, A.E. (1998) Nearest-neighbour clutter removal for estimating features in spatial point processes. Journal of the American Statistical Association 93, 577–584.
# shapley galaxy cluster X <- nnclean(shapley, k=17, plothist=TRUE) plot(X, which.marks=1, chars=c(".", "+"), cols=1:2, main="Shapley data, cluster and noise") plot(X, which.marks=2, cols=function(x)hsv(0.2+0.8*(1-x),1,1), main="Shapley data, probability of cluster") Y <- split(X, un=TRUE) plot(Y, chars="+", cex=0.5) marks(X) <- marks(X)$prob plot(cut(X, breaks=3), chars=c(".", "+", "+"), cols=1:3)
# shapley galaxy cluster X <- nnclean(shapley, k=17, plothist=TRUE) plot(X, which.marks=1, chars=c(".", "+"), cols=1:2, main="Shapley data, cluster and noise") plot(X, which.marks=2, cols=function(x)hsv(0.2+0.8*(1-x),1,1), main="Shapley data, probability of cluster") Y <- split(X, un=TRUE) plot(Y, chars="+", cex=0.5) marks(X) <- marks(X)$prob plot(cut(X, breaks=3), chars=c(".", "+", "+"), cols=1:3)
Computes nearest-neighbour correlation indices of a marked point
pattern, including the nearest-neighbour mark product index
(default case of nncorr
),
the nearest-neighbour mark index (nnmean
),
and the nearest-neighbour variogram index (nnvario
).
nncorr(X, f = function(m1, m2) { m1 * m2 }, k = 1, ..., use = "all.obs", method = c("pearson", "kendall", "spearman"), denominator=NULL, na.action="warn") nnmean(X, k=1, na.action="warn") nnvario(X, k=1, na.action="warn")
nncorr(X, f = function(m1, m2) { m1 * m2 }, k = 1, ..., use = "all.obs", method = c("pearson", "kendall", "spearman"), denominator=NULL, na.action="warn") nnmean(X, k=1, na.action="warn") nnvario(X, k=1, na.action="warn")
X |
The observed point pattern.
An object of class |
f |
Function |
k |
Integer. The |
... |
Extra arguments passed to |
use , method
|
Arguments passed to the standard correlation function |
denominator |
Internal use only. |
na.action |
Character string (passed to |
The nearest neighbour correlation index
of a marked point process
is a number measuring the dependence between the mark of a typical point
and the mark of its nearest neighbour.
The command nncorr
computes the nearest neighbour correlation index
based on any test function f
provided by the user.
The default behaviour of nncorr
is to compute the
nearest neighbour mark product index.
The commands nnmean
and nnvario
are
convenient abbreviations for other special choices of f
.
In the default case, nncorr(X)
computes three different
versions of the nearest-neighbour correlation index:
the unnormalised, normalised, and classical correlations.
The unnormalised nearest neighbour correlation (Stoyan and Stoyan, 1994, section 14.7) is defined as
where denotes mean value,
is the mark attached to a
typical point of the point process, and
is the mark
attached to its nearest neighbour (i.e. the nearest other point of the
point process).
Here is any function
with two arguments which are possible marks of the pattern,
and which returns a nonnegative real value.
Common choices of
are:
for continuous real-valued marks,
for discrete marks (multitype point patterns),
and for marks taking values in ,
For example, in the second case, the unnormalised nearest neighbour
correlation equals the proportion of
points in the pattern which have the same mark as their nearest
neighbour.
Note that is not a “correlation”
in the usual statistical sense. It can take values greater than 1.
We can define a normalised nearest neighbour correlation by
where again is the
mark attached to a typical point,
is the mark
attached to its nearest neighbour, and
is an independent
copy of
with the same distribution.
This normalisation is also not a “correlation”
in the usual statistical sense, but is normalised so that
the value 1 suggests “lack of correlation”:
if the marks attached to the points of
X
are independent
and identically distributed, then
.
The interpretation of values larger or smaller than 1 depends
on the choice of function
.
Finally if the marks of X
are real numbers,
we can also compute the
classical correlation, that is, the correlation coefficient
of the two random variables and
.
The classical correlation has a value between
and
.
Values close to
or
indicate strong dependence between
the marks.
In the default case where f
is not given,
nncorr(X)
computes
If the marks of X
are real numbers,
the unnormalised and normalised
versions of the nearest-neighbour product index
,
and the classical correlation
between
and
.
If the marks of X
are factor valued,
the unnormalised and normalised
versions of the nearest-neighbour equality index
.
The wrapper functions nnmean
and nnvario
compute the correlation indices for two special choices of the
function . They are defined only when the
marks are numeric.
nnmean
computes the correlation indices for
. The unnormalised index
is simply the mean value of the mark of the neighbour of a typical point,
, while the normalised index is
, the ratio of the mean mark of the
neighbour of a typical point to the mean mark of a typical point.
nnvario
computes the correlation indices for
.
The argument X
must be a point pattern (object of class
"ppp"
) and must be a marked point pattern.
(The marks may be a data frame, containing several columns of mark variables;
each column is treated separately.)
If the argument f
is given, it
must be a function, accepting two arguments m1
and m2
which are vectors of equal length containing mark
values (of the same type as the marks of X
).
It must return a vector of numeric
values of the same length as m1
and m2
.
The values must be non-negative.
The arguments use
and method
control
the calculation of the classical correlation using cor
,
as explained in the help file for cor
.
Other arguments may be passed to f
through the ...
argument.
This algorithm assumes that X
can be treated
as a realisation of a stationary (spatially homogeneous)
random spatial point process in the plane, observed through
a bounded window.
The window (which is specified in X
as Window(X)
)
may have arbitrary shape.
Biases due to edge effects are
treated using the ‘border method’ edge correction.
Labelled vector of length 2 or 3 containing the unnormalised and normalised nearest neighbour correlations, and the classical correlation if appropriate. Alternatively a matrix with 2 or 3 rows, containing this information for each mark variable.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
nnmean(finpines) nnvario(finpines) nncorr(finpines) # heights of neighbouring trees are slightly negatively correlated nncorr(amacrine) # neighbouring cells are usually of different type
nnmean(finpines) nnvario(finpines) nncorr(finpines) # heights of neighbouring trees are slightly negatively correlated nncorr(amacrine) # neighbouring cells are usually of different type
Estimates the intensity of a point pattern
using the distance from each spatial location
to the k
th nearest data point.
nndensity(x, ...) ## S3 method for class 'ppp' nndensity(x, k, ..., verbose = TRUE)
nndensity(x, ...) ## S3 method for class 'ppp' nndensity(x, k, ..., verbose = TRUE)
x |
A point pattern (object of class |
k |
Integer. The distance to the |
... |
Arguments passed to |
verbose |
Logical. If |
This function computes a quick estimate of the intensity of the point
process that generated the point pattern x
.
For each spatial location , let
be the distance from
to the
-th nearest point in the dataset
x
.
If the data came from a homogeneous
Poisson process with intensity ,
then
would follow a
negative exponential distribution with mean
, and the maximum likelihood estimate of
would be
.
This is the estimate computed by
nndensity
,
apart from an edge effect correction.
See Cressie (1991, equation (8.5.14), p. 654) and Silverman (1986, p. 96).
This estimator of intensity is relatively fast to compute, and is spatially adaptive (so that it can handle wide variation in the intensity function). However, it implicitly assumes the points are independent, so it does not perform well if the pattern is strongly clustered or strongly inhibited.
In normal use, the value of k
should be at least 3.
(Theoretically the estimator has infinite expected value if ,
and infinite variance if
.
The computed intensity estimate will have infinite peaks
around each data point if
k = 1
.)
The default value of k
is the square root of the number of
points in x
, which seems to work well in many cases.
The window of x
is digitised using as.mask
and the values are computed using
nnmap
.
To control the pixel resolution, see as.mask
.
A pixel image (object of class "im"
) giving the
estimated intensity of the point process at each spatial location.
Pixel values are intensities (number of points per unit area).
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Cressie, N.A.C. (1991) Statistics for spatial data. John Wiley and Sons, New York.
Silverman, B.W. (1986) Density Estimation. Chapman and Hall, New York.
density.ppp
,
intensity.ppp
for alternative estimates of point process intensity.
plot(nndensity(swedishpines))
plot(nndensity(swedishpines))
Computes the distribution of the orientation of the vectors from each point to its nearest neighbour.
nnorient(X, ..., cumulative = FALSE, correction, k = 1, unit = c("degree", "radian"), domain = NULL, ratio = FALSE)
nnorient(X, ..., cumulative = FALSE, correction, k = 1, unit = c("degree", "radian"), domain = NULL, ratio = FALSE)
X |
Point pattern (object of class |
... |
Arguments passed to |
cumulative |
Logical value specifying whether to estimate the probability density
( |
correction |
Character vector specifying edge correction or corrections.
Options are |
k |
Integer. The |
ratio |
Logical.
If |
unit |
Unit in which the angles should be expressed.
Either |
domain |
Optional window. The first point |
This algorithm considers each point in the pattern X
and finds its nearest neighbour (or th nearest neighour).
The direction of the arrow joining the data point to its neighbour
is measured, as an angle in degrees or radians,
anticlockwise from the
axis.
If cumulative=FALSE
(the default),
a kernel estimate of the probability density of the angles
is calculated using circdensity
.
This is the function defined
in Illian et al (2008), equation (4.5.3), page 253.
If cumulative=TRUE
, then the cumulative distribution
function of these angles is calculated.
In either case the result can be plotted as a rose diagram by
rose
, or as a function plot by plot.fv
.
The algorithm gives each observed direction a weight,
determined by an edge correction, to adjust for the fact that some
interpoint distances are more likely to be observed than others.
The choice of edge correction or corrections is determined by the argument
correction
.
It is also possible to calculate an estimate of the probability
density from the cumulative distribution function,
by numerical differentiation.
Use deriv.fv
with the argument Dperiodic=TRUE
.
A function value table (object of class "fv"
)
containing the estimates of the probability density or the
cumulative distribution function of angles,
in degrees (if unit="degree"
)
or radians (if unit="radian"
).
Adrian Baddeley [email protected]
Rolf Turner [email protected]
and Ege Rubak [email protected]
Illian, J., Penttinen, A., Stoyan, H. and Stoyan, D. (2008) Statistical Analysis and Modelling of Spatial Point Patterns. Wiley.
rose(nnorient(redwood, adjust=0.6), col="grey") plot(CDF <- nnorient(redwood, cumulative=TRUE))
rose(nnorient(redwood, adjust=0.6), col="grey") plot(CDF <- nnorient(redwood, cumulative=TRUE))
Computes the mean value, or the double integral, of a specified function of the distance between two independent random points in a given window or windows.
pairMean(fun, W, V = NULL, ..., normalise = TRUE)
pairMean(fun, W, V = NULL, ..., normalise = TRUE)
fun |
A function in the R language which takes one argument. |
W |
A window (object of class |
V |
Optional. Another window containing the second random point.
Defaults to |
... |
Further optional arguments passed to |
normalise |
Logical value specifying whether to calculate the mean
value ( |
This command computes the mean value of
fun(T)
where T
is
the Euclidean distance
between two independent random points
and
.
In the simplest case, the command pairMean(fun, W)
,
the random points are assumed to be uniformly distributed in the same
window W
. Alternatively the two random points may be
uniformly distributed in two different windows W
and V
.
Other options are described in distcdf
.
The algorithm uses distcdf
to compute the cumulative
distribution function of T
, and stieltjes
to
compute the mean value of fun(T)
.
If normalise=TRUE
(the default) the result is the mean value of
fun(T)
. If normalise=FALSE
the result is the double
integral.
A single numeric value.
Adrian Baddeley [email protected].
pairMean(function(d) { d^2 }, disc())
pairMean(function(d) { d^2 }, disc())
Computes the distribution of the orientation of vectors joining pairs of points at a particular range of distances.
pairorient(X, r1, r2, ..., cumulative=FALSE, correction, ratio = FALSE, unit=c("degree", "radian"), domain=NULL)
pairorient(X, r1, r2, ..., cumulative=FALSE, correction, ratio = FALSE, unit=c("degree", "radian"), domain=NULL)
X |
Point pattern (object of class |
r1 , r2
|
Minimum and maximum values of distance to be considered. |
... |
Arguments passed to |
cumulative |
Logical value specifying whether to estimate the probability density
( |
correction |
Character vector specifying edge correction or corrections.
Options are |
ratio |
Logical.
If |
unit |
Unit in which the angles should be expressed.
Either |
domain |
Optional window. The first point |
This algorithm considers all pairs of points in the pattern
X
that lie more than r1
and less than r2
units apart. The direction of the arrow joining the points
is measured, as an angle in degrees or radians,
anticlockwise from the axis.
If cumulative=FALSE
(the default),
a kernel estimate of the probability density of the orientations
is calculated using circdensity
.
If cumulative=TRUE
, then the cumulative distribution
function of these directions is calculated.
This is the function defined
in Stoyan and Stoyan (1994), equation (14.53), page 271.
In either case the result can be plotted as a rose diagram by
rose
, or as a function plot by plot.fv
.
The algorithm gives each observed direction a weight,
determined by an edge correction, to adjust for the fact that some
interpoint distances are more likely to be observed than others.
The choice of edge correction or corrections is determined by the argument
correction
. See the help for Kest
for details
of edge corrections, and explanation of the options available.
The choice correction="none"
is not recommended;
it is included for demonstration purposes only. The default is to
compute all corrections except "none"
.
It is also possible to calculate an estimate of the probability
density from the cumulative distribution function,
by numerical differentiation.
Use deriv.fv
with the argument Dperiodic=TRUE
.
A function value table (object of class "fv"
)
containing the estimates of the probability density or the
cumulative distribution function of angles,
in degrees (if unit="degree"
)
or radians (if unit="radian"
).
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Stoyan, D. and Stoyan, H. (1994) Fractals, Random Shapes and Point Fields: Methods of Geometrical Statistics. John Wiley and Sons.
rose(pairorient(redwood, 0.05, 0.15, sigma=8), col="grey") plot(CDF <- pairorient(redwood, 0.05, 0.15, cumulative=TRUE)) plot(f <- deriv(CDF, spar=0.6, Dperiodic=TRUE))
rose(pairorient(redwood, 0.05, 0.15, sigma=8), col="grey") plot(CDF <- pairorient(redwood, 0.05, 0.15, cumulative=TRUE)) plot(f <- deriv(CDF, spar=0.6, Dperiodic=TRUE))
Produces a scatterplot matrix of the pixel values in two or more pixel images.
## S3 method for class 'im' pairs(..., plot=TRUE, drop=TRUE)
## S3 method for class 'im' pairs(..., plot=TRUE, drop=TRUE)
... |
Any number of arguments, each of which is either
a pixel image (object of class |
plot |
Logical. If |
drop |
Logical value specifying whether pixel values that are |
This is a method for the generic function pairs
for the class of pixel images.
It produces a square array of plot panels, in which each panel shows a scatterplot of the pixel values of one image against the corresponding pixel values of another image.
At least two of the arguments ...
should be pixel images (objects of class "im"
).
Their spatial domains must overlap, but need not have the same
pixel dimensions.
First the pixel image domains are intersected, and converted to a
common pixel resolution. Then the corresponding pixel values of each image are
extracted. Then pairs.default
is called to
plot the scatterplot matrix.
Any arguments in ...
which are not pixel images will be
passed to pairs.default
to control the plot.
The return value of pairs.im
is a data frame, returned
invisibly. The data frame has one column
for each image. Each row contains the pixel values of
the different images for one pixel in the raster.
If drop=TRUE
(the default), any row which contains NA
is deleted. The plot is not affected by the value of drop
.
Invisible. A data.frame
containing the
corresponding pixel values for each image.
The return value also belongs to the class plotpairsim
which has
a plot method, so that it can be re-plotted.
Since the scatterplots may show very dense concentrations of points,
it may be useful to set panel=panel.image
or panel=panel.contour
to draw a colour image or contour plot
of the kernel-smoothed density of the scatterplot in each panel.
The argument panel
is passed
to pairs.default
. See the help for
panel.image
and panel.contour
.
To control the appearance of the individual scatterplot panels,
see pairs.default
, points
or par
.
To control the plotting symbol for the points in the scatterplot,
use the arguments pch
, col
, bg
as described
under points
(because
the default panel plotter is the function points
).
To suppress the tick marks on the plot axes,
type par(xaxt="n", yaxt="n")
before calling pairs
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
pairs
,
pairs.default
,
panel.contour
,
panel.image
,
plot.im
,
cov.im
,
im
,
par
X <- density(rpoispp(30)) Y <- density(rpoispp(40)) Z <- density(rpoispp(30)) p <- pairs(X,Y,Z) p plot(p)
X <- density(rpoispp(30)) Y <- density(rpoispp(40)) Z <- density(rpoispp(30)) p <- pairs(X,Y,Z) p plot(p)
These functions can be passed to pairs
or
coplot
to determine what kind of plotting is done in each panel
of a multi-panel graphical display.
panel.contour(x, y, ..., sigma = NULL) panel.image(x, y, ..., sigma = NULL) panel.histogram(x, ...)
panel.contour(x, y, ..., sigma = NULL) panel.image(x, y, ..., sigma = NULL) panel.histogram(x, ...)
x , y
|
Coordinates of points in a scatterplot. |
... |
Extra graphics arguments, passed to |
sigma |
Bandwidth of kernel smoother, on a scale where
|
These functions can serve as one of the arguments panel
,
lower.panel
, upper.panel
, diag.panel
passed to graphics commands like
pairs
or coplot
,
to determine what kind of plotting is done in each panel
of a multi-panel graphical display. In particular they work
with pairs.im
.
The functions panel.contour
and panel.contour
are suitable for the off-diagonal plots which involve
two datasets x
and y
.
They first rescale x
and y
to the unit square,
then apply kernel smoothing with bandwidth sigma
using density.ppp
.
Then panel.contour
draws a contour plot
while panel.image
draws a colour image.
The function panel.histogram
is suitable for the
diagonal plots which involve a single dataset x
.
It displays a histogram of the data.
Null.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
pairs.im
,
pairs.default
,
panel.smooth
pairs(bei.extra, panel = panel.contour, diag.panel = panel.histogram) with(bei.extra, pairs(grad, elev, panel = panel.image, diag.panel = panel.histogram)) pairs(marks(finpines), panel=panel.contour, diag.panel=panel.histogram)
pairs(bei.extra, panel = panel.contour, diag.panel = panel.histogram) with(bei.extra, pairs(grad, elev, panel = panel.image, diag.panel = panel.histogram)) pairs(marks(finpines), panel=panel.contour, diag.panel=panel.histogram)
Estimate the pair correlation function.
pcf(X, ...)
pcf(X, ...)
X |
Either the observed data point pattern,
or an estimate of its |
... |
Other arguments passed to the appropriate method. |
The pair correlation function of a stationary point process is
where is the derivative of
, the
reduced second moment function (aka “Ripley's
function”)
of the point process. See
Kest
for information
about . For a stationary Poisson process, the
pair correlation function is identically equal to 1. Values
suggest inhibition between points;
values greater than 1 suggest clustering.
We also apply the same definition to
other variants of the classical function,
such as the multitype
functions
(see
Kcross
, Kdot
) and the
inhomogeneous function (see
Kinhom
).
For all these variants, the benchmark value of
corresponds to
.
This routine computes an estimate of
either directly from a point pattern,
or indirectly from an estimate of
or one of its variants.
This function is generic, with methods for
the classes "ppp"
, "fv"
and "fasp"
.
If X
is a point pattern (object of class "ppp"
)
then the pair correlation function is estimated using
a traditional kernel smoothing method (Stoyan and Stoyan, 1994).
See pcf.ppp
for details.
If X
is a function value table (object of class "fv"
),
then it is assumed to contain estimates of the function
or one of its variants (typically obtained from
Kest
or
Kinhom
).
This routine computes an estimate of
using smoothing splines to approximate the derivative.
See
pcf.fv
for details.
If X
is a function value array (object of class "fasp"
),
then it is assumed to contain estimates of several functions
(typically obtained from
Kmulti
or
alltypes
). This routine computes
an estimate of for each cell in the array,
using smoothing splines to approximate the derivatives.
See
pcf.fasp
for details.
Either a function value table
(object of class "fv"
, see fv.object
)
representing a pair correlation function,
or a function array (object of class "fasp"
,
see fasp.object
)
representing an array of pair correlation functions.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
pcf.ppp
,
pcf.fv
,
pcf.fasp
,
Kest
,
Kinhom
,
Kcross
,
Kdot
,
Kmulti
,
alltypes
# ppp object X <- simdat p <- pcf(X) plot(p) # fv object K <- Kest(X) p2 <- pcf(K, spar=0.8, method="b") plot(p2) # multitype pattern; fasp object amaK <- alltypes(amacrine, "K") amap <- pcf(amaK, spar=1, method="b") plot(amap)
# ppp object X <- simdat p <- pcf(X) plot(p) # fv object K <- Kest(X) p2 <- pcf(K, spar=0.8, method="b") plot(p2) # multitype pattern; fasp object amaK <- alltypes(amacrine, "K") amap <- pcf(amaK, spar=1, method="b") plot(amap)
Estimates the (bivariate) pair correlation functions of a point pattern, given an array of (bivariate) K functions.
## S3 method for class 'fasp' pcf(X, ..., method="c")
## S3 method for class 'fasp' pcf(X, ..., method="c")
X |
An array of multitype |
... |
Arguments controlling the smoothing spline
function |
method |
Letter |
The pair correlation function of a stationary point process is
where is the derivative of
, the
reduced second moment function (aka “Ripley's
function”)
of the point process. See
Kest
for information
about . For a stationary Poisson process, the
pair correlation function is identically equal to 1. Values
suggest inhibition between points;
values greater than 1 suggest clustering.
We also apply the same definition to
other variants of the classical function,
such as the multitype
functions
(see
Kcross
, Kdot
) and the
inhomogeneous function (see
Kinhom
).
For all these variants, the benchmark value of
corresponds to
.
This routine computes an estimate of
from an array of estimates of
or its variants,
using smoothing splines to approximate the derivatives.
It is a method for the generic function
pcf
.
The argument X
should be
a function array (object of class "fasp"
,
see fasp.object
)
containing several estimates of functions.
This should have been obtained from
alltypes
with the argument fun="K"
.
The smoothing spline operations are performed by
smooth.spline
and predict.smooth.spline
from the modreg
library.
Four numerical methods are available:
"a" apply smoothing to ,
estimate its derivative, and plug in to the formula above;
"b" apply smoothing to
constraining
,
estimate the derivative of
, and solve;
"c" apply smoothing to
constraining
,
estimate its derivative, and solve.
"d" apply smoothing to
,
estimate its derivative, and solve.
Method "c"
seems to be the best at
suppressing variability for small values of .
However it effectively constrains
.
If the point pattern seems to have inhibition at small distances,
you may wish to experiment with method
"b"
which effectively
constrains . Method
"a"
seems
comparatively unreliable.
Useful arguments to control the splines
include the smoothing tradeoff parameter spar
and the degrees of freedom df
. See smooth.spline
for details.
A function array (object of class "fasp"
,
see fasp.object
)
representing an array of pair correlation functions.
This can be thought of as a matrix Y
each of whose entries
Y[i,j]
is a function value table (class "fv"
)
representing the pair correlation function between
points of type i
and points of type j
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Stoyan, D, Kendall, W.S. and Mecke, J. (1995) Stochastic geometry and its applications. 2nd edition. Springer Verlag.
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
Kest
,
Kinhom
,
Kcross
,
Kdot
,
Kmulti
,
alltypes
,
smooth.spline
,
predict.smooth.spline
# multitype point pattern KK <- alltypes(amacrine, "K") p <- pcf.fasp(KK, spar=0.5, method="b") plot(p) # strong inhibition between points of the same type
# multitype point pattern KK <- alltypes(amacrine, "K") p <- pcf.fasp(KK, spar=0.5, method="b") plot(p) # strong inhibition between points of the same type
Estimates the pair correlation function of a point pattern, given an estimate of the K function.
## S3 method for class 'fv' pcf(X, ..., method="c")
## S3 method for class 'fv' pcf(X, ..., method="c")
X |
An estimate of the |
... |
Arguments controlling the smoothing spline
function |
method |
Letter |
The pair correlation function of a stationary point process is
where is the derivative of
, the
reduced second moment function (aka “Ripley's
function”)
of the point process. See
Kest
for information
about . For a stationary Poisson process, the
pair correlation function is identically equal to 1. Values
suggest inhibition between points;
values greater than 1 suggest clustering.
We also apply the same definition to
other variants of the classical function,
such as the multitype
functions
(see
Kcross
, Kdot
) and the
inhomogeneous function (see
Kinhom
).
For all these variants, the benchmark value of
corresponds to
.
This routine computes an estimate of
from an estimate of
or its variants,
using smoothing splines to approximate the derivative.
It is a method for the generic function
pcf
for the class "fv"
.
The argument X
should be an estimated function,
given as a function value table (object of class
"fv"
,
see fv.object
).
This object should be the value returned by
Kest
, Kcross
, Kmulti
or Kinhom
.
The smoothing spline operations are performed by
smooth.spline
and predict.smooth.spline
from the modreg
library.
Four numerical methods are available:
"a" apply smoothing to ,
estimate its derivative, and plug in to the formula above;
"b" apply smoothing to
constraining
,
estimate the derivative of
, and solve;
"c" apply smoothing to
constraining
,
estimate its derivative, and solve.
"d" apply smoothing to
,
estimate its derivative, and solve.
Method "c"
seems to be the best at
suppressing variability for small values of .
However it effectively constrains
.
If the point pattern seems to have inhibition at small distances,
you may wish to experiment with method
"b"
which effectively
constrains . Method
"a"
seems
comparatively unreliable.
Useful arguments to control the splines
include the smoothing tradeoff parameter spar
and the degrees of freedom df
. See smooth.spline
for details.
A function value table
(object of class "fv"
, see fv.object
)
representing a pair correlation function.
Essentially a data frame containing (at least) the variables
r |
the vector of values of the argument |
pcf |
vector of values of |
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Stoyan, D, Kendall, W.S. and Mecke, J. (1995) Stochastic geometry and its applications. 2nd edition. Springer Verlag.
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
pcf
,
pcf.ppp
,
Kest
,
Kinhom
,
Kcross
,
Kdot
,
Kmulti
,
alltypes
,
smooth.spline
,
predict.smooth.spline
# univariate point pattern X <- simdat K <- Kest(X) p <- pcf.fv(K, spar=0.5, method="b") plot(p, main="pair correlation function for simdat") # indicates inhibition at distances r < 0.3
# univariate point pattern X <- simdat K <- Kest(X) p <- pcf.fv(K, spar=0.5, method="b") plot(p, main="pair correlation function for simdat") # indicates inhibition at distances r < 0.3
Estimates the pair correlation function of a point pattern using kernel methods.
## S3 method for class 'ppp' pcf(X, ..., r = NULL, kernel="epanechnikov", bw=NULL, stoyan=0.15, correction=c("translate", "Ripley"), divisor = c("r", "d"), var.approx = FALSE, domain=NULL, ratio=FALSE, close=NULL)
## S3 method for class 'ppp' pcf(X, ..., r = NULL, kernel="epanechnikov", bw=NULL, stoyan=0.15, correction=c("translate", "Ripley"), divisor = c("r", "d"), var.approx = FALSE, domain=NULL, ratio=FALSE, close=NULL)
X |
A point pattern (object of class |
r |
Vector of values for the argument |
kernel |
Choice of smoothing kernel,
passed to |
bw |
Bandwidth for smoothing kernel,
passed to |
... |
Other arguments passed to the kernel density estimation
function |
stoyan |
Coefficient for Stoyan's bandwidth selection rule; see Details. |
correction |
Edge correction. A character vector specifying the choice (or choices) of edge correction. See Details. |
divisor |
Choice of divisor in the estimation formula:
either |
var.approx |
Logical value indicating whether to compute an analytic approximation to the variance of the estimated pair correlation. |
domain |
Optional. Calculations will be restricted to this subset of the window. See Details. |
ratio |
Logical.
If |
close |
Advanced use only. Precomputed data. See section on Advanced Use. |
The pair correlation function
is a summary of the dependence between points in a spatial point
process. The best intuitive interpretation is the following: the probability
of finding two points at locations
and
separated by a distance
is equal to
where is the intensity of the point process.
For a completely random (uniform Poisson) process,
so
.
Formally, the pair correlation function of a stationary point process
is defined by
where is the derivative of
, the
reduced second moment function (aka “Ripley's
function”)
of the point process. See
Kest
for information
about .
For a stationary Poisson process, the
pair correlation function is identically equal to 1. Values
suggest inhibition between points;
values greater than 1 suggest clustering.
This routine computes an estimate of
by kernel smoothing.
If divisor="r"
(the default), then the standard
kernel estimator (Stoyan and Stoyan, 1994, pages 284–285)
is used. By default, the recommendations of Stoyan and Stoyan (1994)
are followed exactly.
If divisor="d"
then a modified estimator is used
(Guan, 2007): the contribution from
an interpoint distance to the
estimate of
is divided by
instead of dividing by
. This usually improves the
bias of the estimator when
is close to zero.
There is also a choice of spatial edge corrections (which are needed to avoid bias due to edge effects associated with the boundary of the spatial window):
If correction="translate"
or correction="translation"
then the translation correction
is used. For divisor="r"
the translation-corrected estimate
is given in equation (15.15), page 284 of Stoyan and Stoyan (1994).
If correction="Ripley"
or correction="isotropic"
then Ripley's isotropic edge correction
is used. For divisor="r"
the isotropic-corrected estimate
is given in equation (15.18), page 285 of Stoyan and Stoyan (1994).
If correction="none"
then no edge correction is used,
that is, an uncorrected estimate is computed.
Multiple corrections can be selected. The default is
correction=c("translate", "Ripley")
.
Alternatively correction="all"
selects all options;
correction="best"
selects the option which has the best
statistical performance; correction="good"
selects the option
which is the best compromise between statistical performance and speed
of computation.
The choice of smoothing kernel is controlled by the
argument kernel
which is passed to density.default
.
The default is the Epanechnikov kernel, recommended by
Stoyan and Stoyan (1994, page 285).
The bandwidth of the smoothing kernel can be controlled by the
argument bw
. Bandwidth is defined as the standard deviation
of the kernel; see the documentation for density.default
.
For the Epanechnikov kernel with half-width h
,
the argument bw
is equivalent to .
Stoyan and Stoyan (1994, page 285) recommend using the Epanechnikov
kernel with support chosen by the rule of thumn
,
where
is the (estimated) intensity of the
point process, and
is a constant in the range from 0.1 to 0.2.
See equation (15.16).
If
bw
is missing or NULL
,
then this rule of thumb will be applied.
The argument stoyan
determines the value of .
The smoothing bandwidth that was used in the calculation is returned
as an attribute of the final result.
The argument r
is the vector of values for the
distance at which
should be evaluated.
There is a sensible default.
If it is specified,
r
must be a vector of increasing numbers
starting from r[1] = 0
,
and max(r)
must not exceed half the diameter of
the window.
If the argument domain
is given, estimation will be restricted
to this region. That is, the estimate of
will be based on pairs of points in which the first point lies
inside
domain
and the second point is unrestricted.
The argument domain
should be a window (object of class "owin"
) or something acceptable to
as.owin
. It must be a subset of the
window of the point pattern X
.
To compute a confidence band for the true value of the
pair correlation function, use lohboot
.
If var.approx = TRUE
, the variance of the
estimate of the pair correlation will also be calculated using
an analytic approximation (Illian et al, 2008, page 234)
which is valid for stationary point processes which are not
too clustered. This calculation is not yet implemented when
the argument domain
is given.
A function value table
(object of class "fv"
).
Essentially a data frame containing the variables
r |
the vector of values of the argument |
theo |
vector of values equal to 1,
the theoretical value of |
trans |
vector of values of |
iso |
vector of values of |
v |
vector of approximate values of the variance of
the estimate of |
as required.
If ratio=TRUE
then the return value also has two
attributes called "numerator"
and "denominator"
which are "fv"
objects
containing the numerators and denominators of each
estimate of .
The return value also has an attribute "bw"
giving the
smoothing bandwidth that was used.
To perform the same computation using several different bandwidths bw
,
it is efficient to use the argument close
.
This should be the result of closepairs(X, rmax)
for a suitably large value of rmax
, namely
rmax >= max(r) + 3 * bw
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected] and Martin Hazelton [email protected].
Guan, Y. (2007) A least-squares cross-validation bandwidth selection approach in pair correlation function estimation. Statistics and Probability Letters 77 (18) 1722–1729.
Illian, J., Penttinen, A., Stoyan, H. and Stoyan, D. (2008) Statistical Analysis and Modelling of Spatial Point Patterns. Wiley.
Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.
Kest
,
pcf
,
density.default
,
bw.stoyan
,
bw.pcf
,
lohboot
.
X <- simdat p <- pcf(X) plot(p, main="pair correlation function for X") # indicates inhibition at distances r < 0.3 pd <- pcf(X, divisor="d") # compare estimates plot(p, cbind(iso, theo) ~ r, col=c("blue", "red"), ylim.covers=0, main="", lwd=c(2,1), lty=c(1,3), legend=FALSE) plot(pd, iso ~ r, col="green", lwd=2, add=TRUE) legend("center", col=c("blue", "green"), lty=1, lwd=2, legend=c("divisor=r","divisor=d")) # calculate approximate variance and show POINTWISE confidence bands pv <- pcf(X, var.approx=TRUE) plot(pv, cbind(iso, iso+2*sqrt(v), iso-2*sqrt(v)) ~ r)
X <- simdat p <- pcf(X) plot(p, main="pair correlation function for X") # indicates inhibition at distances r < 0.3 pd <- pcf(X, divisor="d") # compare estimates plot(p, cbind(iso, theo) ~ r, col=c("blue", "red"), ylim.covers=0, main="", lwd=c(2,1), lty=c(1,3), legend=FALSE) plot(pd, iso ~ r, col="green", lwd=2, add=TRUE) legend("center", col=c("blue", "green"), lty=1, lwd=2, legend=c("divisor=r","divisor=d")) # calculate approximate variance and show POINTWISE confidence bands pv <- pcf(X, var.approx=TRUE) plot(pv, cbind(iso, iso+2*sqrt(v), iso-2*sqrt(v)) ~ r)
Estimates the pair correlation function from a three-dimensional point pattern.
pcf3est(X, ..., rmax = NULL, nrval = 128, correction = c("translation", "isotropic"), delta=NULL, adjust=1, biascorrect=TRUE)
pcf3est(X, ..., rmax = NULL, nrval = 128, correction = c("translation", "isotropic"), delta=NULL, adjust=1, biascorrect=TRUE)
X |
Three-dimensional point pattern (object of class |
... |
Ignored. |
rmax |
Optional. Maximum value of argument |
nrval |
Optional. Number of values of |
correction |
Optional. Character vector specifying the edge correction(s) to be applied. See Details. |
delta |
Optional. Half-width of the Epanechnikov smoothing kernel. |
adjust |
Optional. Adjustment factor for the default value of |
biascorrect |
Logical value. Whether to correct for underestimation due to
truncation of the kernel near |
For a stationary point process in three-dimensional
space, the pair correlation function is
where is the derivative of the
three-dimensional
-function (see
K3est
).
The three-dimensional point pattern X
is assumed to be a
partial realisation of a stationary point process .
The distance between each pair of distinct points is computed.
Kernel smoothing is applied to these distance values (weighted by
an edge correction factor) and the result is
renormalised to give the estimate of
.
The available edge corrections are:
"translation"
:the Ohser translation correction estimator (Ohser, 1983; Baddeley et al, 1993)
"isotropic"
:the three-dimensional counterpart of Ripley's isotropic edge correction (Ripley, 1977; Baddeley et al, 1993).
Kernel smoothing is performed using the Epanechnikov kernel
with half-width delta
. If delta
is missing, the
default is to use the rule-of-thumb
where
is the estimated intensity, computed
from the number
of data points and the volume
of the
enclosing box. This default value of
delta
is multiplied by
the factor adjust
.
The smoothing estimate of the pair correlation
is typically an underestimate when
is small, due to
truncation of the kernel at
.
If
biascorrect=TRUE
, the smoothed estimate is
approximately adjusted for this bias. This is advisable whenever
the dataset contains a sufficiently large number of points.
A function value table (object of class "fv"
) that can be
plotted, printed or coerced to a data frame containing the function
values.
Additionally the value of delta
is returned as an attribute
of this object.
Adrian Baddeley [email protected] and Rana Moyeed.
Baddeley, A.J, Moyeed, R.A., Howard, C.V. and Boyde, A. (1993) Analysis of a three-dimensional point pattern with replication. Applied Statistics 42, 641–668.
Ohser, J. (1983) On estimators for the reduced second moment measure of point processes. Mathematische Operationsforschung und Statistik, series Statistics, 14, 63 – 71.
Ripley, B.D. (1977) Modelling spatial patterns (with discussion). Journal of the Royal Statistical Society, Series B, 39, 172 – 212.
pp3
to create a three-dimensional point
pattern (object of class "pp3"
).
F3est
,
G3est
,
K3est
for other summary functions of
a three-dimensional point pattern.
pcf
to estimate the pair correlation function of
point patterns in two dimensions or other spaces.
X <- rpoispp3(250) Z <- pcf3est(X) Zbias <- pcf3est(X, biascorrect=FALSE) if(interactive()) { opa <- par(mfrow=c(1,2)) plot(Z, ylim.covers=c(0, 1.2)) plot(Zbias, ylim.covers=c(0, 1.2)) par(opa) } attr(Z, "delta")
X <- rpoispp3(250) Z <- pcf3est(X) Zbias <- pcf3est(X, biascorrect=FALSE) if(interactive()) { opa <- par(mfrow=c(1,2)) plot(Z, ylim.covers=c(0, 1.2)) plot(Zbias, ylim.covers=c(0, 1.2)) par(opa) } attr(Z, "delta")
Calculates an estimate of the cross-type pair correlation function for a multitype point pattern.
pcfcross(X, i, j, ..., r = NULL, kernel = "epanechnikov", bw = NULL, stoyan = 0.15, correction = c("isotropic", "Ripley", "translate"), divisor = c("r", "d"), ratio = FALSE)
pcfcross(X, i, j, ..., r = NULL, kernel = "epanechnikov", bw = NULL, stoyan = 0.15, correction = c("isotropic", "Ripley", "translate"), divisor = c("r", "d"), ratio = FALSE)
X |
The observed point pattern,
from which an estimate of the cross-type pair correlation function
|
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
... |
Ignored. |
r |
Vector of values for the argument |
kernel |
Choice of smoothing kernel,
passed to |
bw |
Bandwidth for smoothing kernel,
passed to |
stoyan |
Coefficient for default bandwidth rule; see Details. |
correction |
Choice of edge correction. |
divisor |
Choice of divisor in the estimation formula:
either |
ratio |
Logical.
If |
The cross-type pair correlation function
is a generalisation of the pair correlation function pcf
to multitype point patterns.
For two locations and
separated by a distance
,
the probability
of finding a point of type
at location
and a point of type
at location
is
where is the intensity of the points
of type
.
For a completely random Poisson marked point process,
so
.
Indeed for any marked point pattern in which the points of type
i
are independent of the points of type j
,
the theoretical value of the cross-type pair correlation is
.
For a stationary multitype point process, the cross-type pair correlation
function between marks and
is formally defined as
where is the derivative of
the cross-type
function
.
of the point process. See
Kest
for information
about .
The command pcfcross
computes a kernel estimate of
the cross-type pair correlation function between marks and
.
If divisor="r"
(the default), then the multitype
counterpart of the standard
kernel estimator (Stoyan and Stoyan, 1994, pages 284–285)
is used. By default, the recommendations of Stoyan and Stoyan (1994)
are followed exactly.
If divisor="d"
then a modified estimator is used:
the contribution from
an interpoint distance to the
estimate of
is divided by
instead of dividing by
. This usually improves the
bias of the estimator when
is close to zero.
There is also a choice of spatial edge corrections
(which are needed to avoid bias due to edge effects
associated with the boundary of the spatial window):
correction="translate"
is the Ohser-Stoyan translation
correction, and correction="isotropic"
or "Ripley"
is Ripley's isotropic correction.
The choice of smoothing kernel is controlled by the
argument kernel
which is passed to density
.
The default is the Epanechnikov kernel.
The bandwidth of the smoothing kernel can be controlled by the
argument bw
. Its precise interpretation
is explained in the documentation for density.default
.
For the Epanechnikov kernel with support ,
the argument
bw
is equivalent to .
If bw
is not specified, the default bandwidth
is determined by Stoyan's rule of thumb (Stoyan and Stoyan, 1994, page
285) applied to the points of type j
. That is,
,
where
is the (estimated) intensity of the
point process of type
j
,
and is a constant in the range from 0.1 to 0.2.
The argument
stoyan
determines the value of .
The companion function pcfdot
computes the
corresponding analogue of Kdot
.
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 |
theo |
the theoretical value |
together with columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Mark connection function markconnect
.
Multitype pair correlation pcfdot
, pcfmulti
.
p <- pcfcross(amacrine, "off", "on") p <- pcfcross(amacrine, "off", "on", stoyan=0.1) plot(p)
p <- pcfcross(amacrine, "off", "on") p <- pcfcross(amacrine, "off", "on", stoyan=0.1) plot(p)
Estimates the inhomogeneous cross-type pair correlation function for a multitype point pattern.
pcfcross.inhom(X, i, j, lambdaI = NULL, lambdaJ = NULL, ..., r = NULL, breaks = NULL, kernel="epanechnikov", bw=NULL, adjust.bw = 1, stoyan=0.15, correction = c("isotropic", "Ripley", "translate"), sigma = NULL, adjust.sigma = 1, varcov = NULL)
pcfcross.inhom(X, i, j, lambdaI = NULL, lambdaJ = NULL, ..., r = NULL, breaks = NULL, kernel="epanechnikov", bw=NULL, adjust.bw = 1, stoyan=0.15, correction = c("isotropic", "Ripley", "translate"), sigma = NULL, adjust.sigma = 1, varcov = NULL)
X |
The observed point pattern,
from which an estimate of the inhomogeneous
cross-type pair correlation function
|
i |
The type (mark value)
of the points in |
j |
The type (mark value)
of the points in |
lambdaI |
Optional.
Values of the estimated intensity function of the points of type |
lambdaJ |
Optional.
Values of the estimated intensity function of the points of type |
r |
Vector of values for the argument |
breaks |
This argument is for internal use only. |
kernel |
Choice of one-dimensional smoothing kernel,
passed to |
bw |
Bandwidth for one-dimensional smoothing kernel,
passed to |
adjust.bw |
Numeric value. |
... |
Other arguments passed to the one-dimensional kernel density estimation
function |
stoyan |
Bandwidth coefficient; see Details. |
correction |
Choice of edge correction. |
sigma , varcov
|
Optional arguments passed to |
adjust.sigma |
Numeric value. |
The inhomogeneous cross-type pair correlation function
is a summary of the dependence between two types of points in a
multitype spatial point process that does not have a uniform
density of points.
The best intuitive interpretation is the following: the probability
of finding two points, of types
and
respectively, at locations
and
separated by a distance
is equal to
where is the intensity function
of the process of points of type
.
For a multitype Poisson point process,
this probability is
so
.
The command pcfcross.inhom
estimates the inhomogeneous
pair correlation using a modified version of
the algorithm in pcf.ppp
.
The arguments bw
and adjust.bw
control the
degree of one-dimensional smoothing of the estimate of pair correlation.
If the arguments lambdaI
and/or lambdaJ
are missing or
null, they will be estimated from X
by spatial kernel smoothing
using a leave-one-out estimator, computed by density.ppp
.
The arguments sigma
, varcov
and adjust.sigma
control the degree of spatial smoothing.
A function value table (object of class "fv"
).
Essentially a data frame containing the variables
r |
the vector of values of the argument |
theo |
vector of values equal to 1,
the theoretical value of |
trans |
vector of values of |
iso |
vector of values of |
as required.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
pcf.ppp
,
pcfinhom
,
pcfcross
,
pcfdot.inhom
plot(pcfcross.inhom(amacrine, "on", "off", stoyan=0.1), legendpos="bottom")
plot(pcfcross.inhom(amacrine, "on", "off", stoyan=0.1), legendpos="bottom")
Calculates an estimate of the multitype pair correlation function
(from points of type i
to points of any type)
for a multitype point pattern.
pcfdot(X, i, ..., r = NULL, kernel = "epanechnikov", bw = NULL, stoyan = 0.15, correction = c("isotropic", "Ripley", "translate"), divisor = c("r", "d"), ratio=FALSE)
pcfdot(X, i, ..., r = NULL, kernel = "epanechnikov", bw = NULL, stoyan = 0.15, correction = c("isotropic", "Ripley", "translate"), divisor = c("r", "d"), ratio=FALSE)
X |
The observed point pattern,
from which an estimate of the dot-type pair correlation function
|
i |
The type (mark value)
of the points in |
... |
Ignored. |
r |
Vector of values for the argument |
kernel |
Choice of smoothing kernel,
passed to |
bw |
Bandwidth for smoothing kernel,
passed to |
stoyan |
Coefficient for default bandwidth rule; see Details. |
correction |
Choice of edge correction. |
divisor |
Choice of divisor in the estimation formula:
either |
ratio |
Logical.
If |
This is a generalisation of the pair correlation function pcf
to multitype point patterns.
For two locations and
separated by a nonzero
distance
,
the probability
of finding a point of type
at location
and a point of any type at location
is
where is the intensity of all points,
and
is the intensity of the points
of type
.
For a completely random Poisson marked point process,
so
.
For a stationary multitype point process, the
type-i
-to-any-type pair correlation
function between marks and
is formally defined as
where is the derivative of
the type-
i
-to-any-type function
.
of the point process. See
Kdot
for information
about .
The command pcfdot
computes a kernel estimate of
the multitype pair correlation function from points of type
to points of any type.
If divisor="r"
(the default), then the multitype
counterpart of the standard
kernel estimator (Stoyan and Stoyan, 1994, pages 284–285)
is used. By default, the recommendations of Stoyan and Stoyan (1994)
are followed exactly.
If divisor="d"
then a modified estimator is used:
the contribution from
an interpoint distance to the
estimate of
is divided by
instead of dividing by
. This usually improves the
bias of the estimator when
is close to zero.
There is also a choice of spatial edge corrections
(which are needed to avoid bias due to edge effects
associated with the boundary of the spatial window):
correction="translate"
is the Ohser-Stoyan translation
correction, and correction="isotropic"
or "Ripley"
is Ripley's isotropic correction.
The choice of smoothing kernel is controlled by the
argument kernel
which is passed to density
.
The default is the Epanechnikov kernel.
The bandwidth of the smoothing kernel can be controlled by the
argument bw
. Its precise interpretation
is explained in the documentation for density.default
.
For the Epanechnikov kernel with support ,
the argument
bw
is equivalent to .
If bw
is not specified, the default bandwidth
is determined by Stoyan's rule of thumb (Stoyan and Stoyan, 1994, page
285). That is,
,
where
is the (estimated) intensity of the
unmarked point process,
and
is a constant in the range from 0.1 to 0.2.
The argument
stoyan
determines the value of .
The companion function pcfcross
computes the
corresponding analogue of Kcross
.
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 |
theo |
the theoretical value |
together with columns named
"border"
, "bord.modif"
,
"iso"
and/or "trans"
,
according to the selected edge corrections. These columns contain
estimates of the function
obtained by the edge corrections named.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Mark connection function markconnect
.
Multitype pair correlation pcfcross
, pcfmulti
.
p <- pcfdot(amacrine, "on") p <- pcfdot(amacrine, "on", stoyan=0.1) plot(p)
p <- pcfdot(amacrine, "on") p <- pcfdot(amacrine, "on", stoyan=0.1) plot(p)
Estimates the inhomogeneous multitype pair correlation function
(from type to any type)
for a multitype point pattern.
pcfdot.inhom(X, i, lambdaI = NULL, lambdadot = NULL, ..., r = NULL, breaks = NULL, kernel="epanechnikov", bw=NULL, adjust.bw=1, stoyan=0.15, correction = c("isotropic", "Ripley", "translate"), sigma = NULL, adjust.sigma = 1, varcov = NULL)
pcfdot.inhom(X, i, lambdaI = NULL, lambdadot = NULL, ..., r = NULL, breaks = NULL, kernel="epanechnikov", bw=NULL, adjust.bw=1, stoyan=0.15, correction = c("isotropic", "Ripley", "translate"), sigma = NULL, adjust.sigma = 1, varcov = NULL)
X |
The observed point pattern,
from which an estimate of the inhomogeneous
multitype pair correlation function
|
i |
The type (mark value)
of the points in |
lambdaI |
Optional.
Values of the estimated intensity function of the points of type |
lambdadot |
Optional.
Values of the estimated intensity function of the point pattern |
r |
Vector of values for the argument |
breaks |
This argument is for internal use only. |
kernel |
Choice of one-dimensional smoothing kernel,
passed to |
bw |
Bandwidth for one-dimensional smoothing kernel,
passed to |
adjust.bw |
Numeric value. |
... |
Other arguments passed to the one-dimensional kernel density estimation
function |
stoyan |
Bandwidth coefficient; see Details. |
correction |
Choice of edge correction. |
sigma , varcov
|
Optional arguments passed to |
adjust.sigma |
Numeric value. |
The inhomogeneous multitype (type to any type)
pair correlation function
is a summary of the dependence between different types of points in a
multitype spatial point process that does not have a uniform
density of points.
The best intuitive interpretation is the following: the probability
of finding a point of type
at location
and another point of any type at location
,
where
and
are separated by a distance
,
is equal to
where is the intensity function
of the process of points of type
, and
where
is the intensity function of the points
of all types.
For a multitype Poisson point process, this probability is
so
.
The command pcfdot.inhom
estimates the inhomogeneous
multitype pair correlation using a modified version of
the algorithm in pcf.ppp
.
The arguments bw
and adjust.bw
control the
degree of one-dimensional smoothing of the estimate of pair correlation.
If the arguments lambdaI
and/or lambdadot
are missing or
null, they will be estimated from X
by spatial kernel
smoothing using a leave-one-out estimator,
computed by density.ppp
.
The arguments sigma
, varcov
and adjust.sigma
control the degree of spatial smoothing.
A function value table (object of class "fv"
).
Essentially a data frame containing the variables
r |
the vector of values of the argument |
theo |
vector of values equal to 1,
the theoretical value of |
trans |
vector of values of |
iso |
vector of values of |
as required.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
pcf.ppp
,
pcfinhom
,
pcfdot
,
pcfcross.inhom
plot(pcfdot.inhom(amacrine, "on", stoyan=0.1), legendpos="bottom")
plot(pcfdot.inhom(amacrine, "on", stoyan=0.1), legendpos="bottom")
Estimates the inhomogeneous pair correlation function of a point pattern using kernel methods.
pcfinhom(X, lambda = NULL, ..., r = NULL, kernel = "epanechnikov", bw = NULL, adjust.bw=1, stoyan = 0.15, correction = c("translate", "Ripley"), divisor = c("r", "d"), renormalise = TRUE, normpower=1, update = TRUE, leaveoneout = TRUE, reciplambda = NULL, sigma = NULL, adjust.sigma = 1, varcov = NULL, close=NULL)
pcfinhom(X, lambda = NULL, ..., r = NULL, kernel = "epanechnikov", bw = NULL, adjust.bw=1, stoyan = 0.15, correction = c("translate", "Ripley"), divisor = c("r", "d"), renormalise = TRUE, normpower=1, update = TRUE, leaveoneout = TRUE, reciplambda = NULL, sigma = NULL, adjust.sigma = 1, varcov = NULL, close=NULL)
X |
A point pattern (object of class |
lambda |
Optional.
Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern |
r |
Vector of values for the argument |
kernel |
Choice of smoothing kernel, passed to |
bw |
Bandwidth for one-dimensional smoothing kernel,
passed to |
adjust.bw |
Numeric value. |
... |
Other arguments passed to the kernel density estimation
function |
stoyan |
Coefficient for Stoyan's bandwidth selection rule;
see |
correction |
Character string or character vector
specifying the choice of edge correction.
See |
divisor |
Choice of divisor in the estimation formula:
either |
renormalise |
Logical. Whether to renormalise the estimate. See Details. |
normpower |
Integer (usually either 1 or 2). Normalisation power. See Details. |
update |
Logical. If |
leaveoneout |
Logical value (passed to |
reciplambda |
Alternative to |
sigma , varcov
|
Optional arguments passed to |
adjust.sigma |
Numeric value. |
close |
Advanced use only. Precomputed data. See section on Advanced Use. |
The inhomogeneous pair correlation function
is a summary of the dependence between points in a spatial point
process that does not have a uniform density of points.
The best intuitive interpretation is the following: the probability
of finding two points at locations
and
separated by a distance
is equal to
where is the intensity function
of the point process.
For a Poisson point process with intensity function
, this probability is
so
.
The inhomogeneous pair correlation function
is related to the inhomogeneous function through
where
is the derivative of
, the
inhomogeneous
function. See
Kinhom
for information
about .
The command pcfinhom
estimates the inhomogeneous
pair correlation using a modified version of
the algorithm in pcf.ppp
.
If renormalise=TRUE
(the default), then the estimates
are multiplied by where
This rescaling reduces the variability and bias of the estimate
in small samples and in cases of very strong inhomogeneity.
The default value of
normpower
is 1
but the most sensible value is 2, which would correspond to rescaling
the lambda
values so that
A function value table (object of class "fv"
).
Essentially a data frame containing the variables
r |
the vector of values of the argument |
theo |
vector of values equal to 1,
the theoretical value of |
trans |
vector of values of |
iso |
vector of values of |
as required.
To perform the same computation using several different bandwidths bw
,
it is efficient to use the argument close
.
This should be the result of closepairs(X, rmax)
for a suitably large value of rmax
, namely
rmax >= max(r) + 3 * bw
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
pcf
,
pcf.ppp
,
bw.stoyan
,
bw.pcf
,
Kinhom
X <- residualspaper$Fig4b online <- interactive() if(!online) { ## reduce size of dataset X <- X[c(FALSE, TRUE)] } plot(pcfinhom(X, stoyan=0.2, sigma=0.1)) if(require("spatstat.model")) { if(online) { fit <- ppm(X ~ polynom(x,y,2)) } else { ## simpler model, faster computation fit <- ppm(X ~ x) } plot(pcfinhom(X, lambda=fit, normpower=2)) }
X <- residualspaper$Fig4b online <- interactive() if(!online) { ## reduce size of dataset X <- X[c(FALSE, TRUE)] } plot(pcfinhom(X, stoyan=0.2, sigma=0.1)) if(require("spatstat.model")) { if(online) { fit <- ppm(X ~ polynom(x,y,2)) } else { ## simpler model, faster computation fit <- ppm(X ~ x) } plot(pcfinhom(X, lambda=fit, normpower=2)) }
For a marked point pattern, estimate the multitype pair correlation function using kernel methods.
pcfmulti(X, I, J, ..., r = NULL, kernel = "epanechnikov", bw = NULL, stoyan = 0.15, correction = c("translate", "Ripley"), divisor = c("r", "d"), Iname = "points satisfying condition I", Jname = "points satisfying condition J", ratio = FALSE)
pcfmulti(X, I, J, ..., r = NULL, kernel = "epanechnikov", bw = NULL, stoyan = 0.15, correction = c("translate", "Ripley"), divisor = c("r", "d"), Iname = "points satisfying condition I", Jname = "points satisfying condition J", ratio = FALSE)
X |
The observed point pattern,
from which an estimate of the cross-type pair correlation function
|
I |
Subset index specifying the points of |
J |
Subset index specifying the points in |
... |
Ignored. |
r |
Vector of values for the argument |
kernel |
Choice of smoothing kernel,
passed to |
bw |
Bandwidth for smoothing kernel,
passed to |
stoyan |
Coefficient for default bandwidth rule. |
correction |
Choice of edge correction. |
divisor |
Choice of divisor in the estimation formula:
either |
Iname , Jname
|
Optional. Character strings describing the members of
the subsets |
ratio |
Logical.
If |
This is a generalisation of pcfcross
to arbitrary collections of points.
The algorithm measures the distance from each data point
in subset I
to each data point in subset J
,
excluding identical pairs of points. The distances are
kernel-smoothed and renormalised to form a pair correlation
function.
If divisor="r"
(the default), then the multitype
counterpart of the standard
kernel estimator (Stoyan and Stoyan, 1994, pages 284–285)
is used. By default, the recommendations of Stoyan and Stoyan (1994)
are followed exactly.
If divisor="d"
then a modified estimator is used:
the contribution from
an interpoint distance to the
estimate of
is divided by
instead of dividing by
. This usually improves the
bias of the estimator when
is close to zero.
There is also a choice of spatial edge corrections
(which are needed to avoid bias due to edge effects
associated with the boundary of the spatial window):
correction="translate"
is the Ohser-Stoyan translation
correction, and correction="isotropic"
or "Ripley"
is Ripley's isotropic correction.
The arguments I
and J
specify two subsets of the
point pattern X
. They may be any type of subset indices, for example,
logical vectors of length equal to npoints(X)
,
or integer vectors with entries in the range 1 to
npoints(X)
, or negative integer vectors.
Alternatively, I
and J
may be functions
that will be applied to the point pattern X
to obtain
index vectors. If I
is a function, then evaluating
I(X)
should yield a valid subset index. This option
is useful when generating simulation envelopes using
envelope
.
The choice of smoothing kernel is controlled by the
argument kernel
which is passed to density
.
The default is the Epanechnikov kernel.
The bandwidth of the smoothing kernel can be controlled by the
argument bw
. Its precise interpretation
is explained in the documentation for density.default
.
For the Epanechnikov kernel with support ,
the argument
bw
is equivalent to .
If bw
is not specified, the default bandwidth
is determined by Stoyan's rule of thumb (Stoyan and Stoyan, 1994, page
285) applied to the points of type j
. That is,
,
where
is the (estimated) intensity of the
point process of type
j
,
and is a constant in the range from 0.1 to 0.2.
The argument
stoyan
determines the value of .
An object of class "fv"
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
adult <- (marks(longleaf) >= 30) juvenile <- !adult p <- pcfmulti(longleaf, adult, juvenile)
adult <- (marks(longleaf) >= 30) juvenile <- !adult p <- pcfmulti(longleaf, adult, juvenile)
Plot the result of Berman's test of goodness-of-fit
## S3 method for class 'bermantest' plot(x, ..., lwd=par("lwd"), col=par("col"), lty=par("lty"), lwd0=lwd, col0=2, lty0=2)
## S3 method for class 'bermantest' plot(x, ..., lwd=par("lwd"), col=par("col"), lty=par("lty"), lwd0=lwd, col0=2, lty0=2)
x |
Object to be plotted. An object of class |
... |
extra arguments that will be passed to the plotting function
|
col , lwd , lty
|
The width, colour and type of lines used to plot the empirical distribution curve. |
col0 , lwd0 , lty0
|
The width, colour and type of lines used to plot the predicted (null) distribution curve. |
This is the plot
method for the class "bermantest"
.
An object of this class represents the outcome of Berman's test
of goodness-of-fit of a spatial Poisson point process model,
computed by berman.test
.
For the Z1 test (i.e. if x
was computed using
berman.test( ,which="Z1")
),
the plot displays the two cumulative distribution functions
that are compared by the test: namely the empirical cumulative distribution
function of the covariate at the data points, ,
and the predicted
cumulative distribution function of the covariate under the model,
, both plotted against the value of the covariate.
Two vertical lines show the mean values of these two distributions.
If the model is correct, the two curves should be close; the test is
based on comparing the two vertical lines.
For the Z2 test (i.e. if x
was computed using
berman.test( ,which="Z2")
), the plot displays the empirical
cumulative distribution function of the values
where
is the
value of the covariate at the
-th data point. The diagonal line
with equation
is also shown. Two vertical lines show the
mean of the values
and the value
. If the
model is correct, the two curves should be close. The test is based on
comparing the two vertical lines.
NULL
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
plot(berman.test(cells, "x")) if(require("spatstat.model")) { # synthetic data: nonuniform Poisson process X <- rpoispp(function(x,y) { 100 * exp(-x) }, win=square(1)) # fit uniform Poisson process fit0 <- ppm(X ~1) # test covariate = x coordinate xcoord <- function(x,y) { x } # test wrong model k <- berman.test(fit0, xcoord, "Z1") # plot result of test plot(k, col="red", col0="green") # Z2 test k2 <- berman.test(fit0, xcoord, "Z2") plot(k2, col="red", col0="green") }
plot(berman.test(cells, "x")) if(require("spatstat.model")) { # synthetic data: nonuniform Poisson process X <- rpoispp(function(x,y) { 100 * exp(-x) }, win=square(1)) # fit uniform Poisson process fit0 <- ppm(X ~1) # test covariate = x coordinate xcoord <- function(x,y) { x } # test wrong model k <- berman.test(fit0, xcoord, "Z1") # plot result of test plot(k, col="red", col0="green") # Z2 test k2 <- berman.test(fit0, xcoord, "Z2") plot(k2, col="red", col0="green") }
Plot the result of a spatial distribution test
computed by cdf.test
.
## S3 method for class 'cdftest' plot(x, ..., style=c("cdf", "PP", "QQ"), lwd=par("lwd"), col=par("col"), lty=par("lty"), lwd0=lwd, col0=2, lty0=2, do.legend)
## S3 method for class 'cdftest' plot(x, ..., style=c("cdf", "PP", "QQ"), lwd=par("lwd"), col=par("col"), lty=par("lty"), lwd0=lwd, col0=2, lty0=2, do.legend)
x |
Object to be plotted. An object of class |
... |
extra arguments that will be passed to the plotting function
|
style |
Style of plot. See Details. |
col , lwd , lty
|
The width, colour and type of lines used to plot the empirical curve (the empirical distribution, or PP plot or QQ plot). |
col0 , lwd0 , lty0
|
The width, colour and type of lines used to plot the reference curve (the predicted distribution, or the diagonal). |
do.legend |
Logical value indicating whether to add an
explanatory legend. Applies only when |
This is the plot
method for the class "cdftest"
.
An object of this class represents the outcome of
a spatial distribution test, computed by cdf.test
,
and based on either the Kolmogorov-Smirnov,
Cramer-von Mises
or Anderson-Darling test.
If style="cdf"
(the default),
the plot displays the two cumulative distribution functions
that are compared by the test: namely the empirical cumulative distribution
function of the covariate at the data points, and the predicted
cumulative distribution function of the covariate under the model,
both plotted against the value of the covariate. The
Kolmogorov-Smirnov test statistic (for example)
is the maximum vertical separation
between the two curves.
If style="PP"
then the P-P plot is drawn. The
coordinates of the plot are cumulative
probabilities for the covariate under the model.
The
coordinates are cumulative probabilities
for the covariate at the data points. The diagonal line
is also drawn for reference. The Kolmogorov-Smirnov
test statistic is the maximum vertical separation
between the P-P plot and the diagonal reference line.
If style="QQ"
then the Q-Q plot is drawn. The
coordinates of the plot are quantiles
of the covariate under the model.
The
coordinates are quantiles of the
covariate at the data points. The diagonal line
is also drawn for reference. The Kolmogorov-Smirnov
test statistic cannot be read off the Q-Q plot.
NULL
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
op <- options(useFancyQuotes=FALSE) plot(cdf.test(cells, "x")) if(require("spatstat.model")) { # synthetic data: nonuniform Poisson process X <- rpoispp(function(x,y) { 100 * exp(x) }, win=square(1)) # fit uniform Poisson process fit0 <- ppm(X ~1) # test covariate = x coordinate xcoord <- function(x,y) { x } # test wrong model k <- cdf.test(fit0, xcoord) # plot result of test plot(k, lwd0=3) plot(k, style="PP") plot(k, style="QQ") } options(op)
op <- options(useFancyQuotes=FALSE) plot(cdf.test(cells, "x")) if(require("spatstat.model")) { # synthetic data: nonuniform Poisson process X <- rpoispp(function(x,y) { 100 * exp(x) }, win=square(1)) # fit uniform Poisson process fit0 <- ppm(X ~1) # test covariate = x coordinate xcoord <- function(x,y) { x } # test wrong model k <- cdf.test(fit0, xcoord) # plot result of test plot(k, lwd0=3) plot(k, style="PP") plot(k, style="QQ") } options(op)
Plot method for the class "envelope"
.
## S3 method for class 'envelope' plot(x, ..., main)
## S3 method for class 'envelope' plot(x, ..., main)
x |
An object of class |
main |
Main title for plot. |
... |
Extra arguments passed to |
This is the plot
method for the class "envelope"
of simulation envelopes. Objects of this class are
created by the command envelope
.
This plot method is currently identical to plot.fv
.
Its default behaviour is to shade the region
between the upper and lower envelopes in a light grey colour.
To suppress the shading and plot the upper and lower envelopes
as curves, set shade=NULL
.
To change the colour of the shading, use the argument shadecol
which is passed to plot.fv
.
See plot.fv
for further information on how to
control the plot.
Either NULL
, or a data frame giving the meaning of the
different line types and colours.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
E <- envelope(cells, Kest, nsim=19) plot(E) plot(E, sqrt(./pi) ~ r)
E <- envelope(cells, Kest, nsim=19) plot(E) plot(E, sqrt(./pi) ~ r)
Plots an array of summary functions, usually associated with a
point pattern, stored in an object of class "fasp"
.
A method for plot
.
## S3 method for class 'fasp' plot(x,formule=NULL, ..., subset=NULL, title=NULL, banner=TRUE, transpose=FALSE, samex=FALSE, samey=FALSE, mar.panel=NULL, outerlabels=TRUE, cex.outerlabels=1.25, legend=FALSE)
## S3 method for class 'fasp' plot(x,formule=NULL, ..., subset=NULL, title=NULL, banner=TRUE, transpose=FALSE, samex=FALSE, samey=FALSE, mar.panel=NULL, outerlabels=TRUE, cex.outerlabels=1.25, legend=FALSE)
x |
An object of class |
formule |
A formula or list of formulae indicating what
variables are to be plotted against what variable. Each formula is
either an R language formula object, or a string that can be parsed
as a formula. If |
... |
Arguments passed to |
subset |
A logical vector, or a vector of indices, or an
expression or a character string, or a list of such,
indicating a subset of the data to be included in each plot.
If |
title |
Overall title for the plot. |
banner |
Logical. If |
transpose |
Logical. If |
samex , samey
|
Logical values indicating whether all individual plot panels should have the same x axis limits and the same y axis limits, respectively. This makes it easier to compare the plots. |
mar.panel |
Vector of length 4 giving the value of the
graphics parameter |
outerlabels |
Logical.
If |
cex.outerlabels |
Character expansion factor for row and column labels of array. |
legend |
Logical flag determining whether to plot a legend in each panel. |
An object of class "fasp"
represents
an array of summary functions, usually associated with a point
pattern. See fasp.object
for details.
Such an object is created, for example,
by alltypes
.
The function plot.fasp
is
a method for plot
. It calls plot.fv
to plot the
individual panels.
For information about the interpretation of the
arguments formule
and subset
,
see plot.fv
.
Arguments that are often passed through ...
include
col
to control the colours of the different lines in a panel,
and lty
and lwd
to control the line type and line width
of the different lines in a panel. The argument shade
can also be used to display confidence intervals or significance bands
as filled grey shading. See plot.fv
.
The argument title
, if present, will determine the
overall title of the plot. If it is absent, it defaults to x$title
.
Titles for the individual plot panels will be taken from
x$titles
.
None.
(Each component of) the subset
argument may be a
logical vector (of the same length as the vectors of data which
are extracted from x
), or a vector of indices, or an
expression such as expression(r<=0.2)
, or a text string,
such as "r<=0.2"
.
Attempting a syntax such as subset = r<=0.2
(without
wrapping r<=0.2
either in quote marks or in expression()
)
will cause this function to fall over.
Variables referred to in any formula must exist in the data frames
stored in x
. What the names of these variables are will
of course depend upon the nature of x
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
alltypes
,
plot.fv
,
fasp.object
if(interactive()) { X.G <- alltypes(amacrine,"G") plot(X.G) plot(X.G,subset="r<=0.2") plot(X.G,formule=asin(sqrt(cbind(km,theo))) ~ asin(sqrt(theo))) plot(X.G,fo=cbind(km,theo) - theo~r, subset="theo<=0.9") }
if(interactive()) { X.G <- alltypes(amacrine,"G") plot(X.G) plot(X.G,subset="r<=0.2") plot(X.G,formule=asin(sqrt(cbind(km,theo))) ~ asin(sqrt(theo))) plot(X.G,fo=cbind(km,theo) - theo~r, subset="theo<=0.9") }
Plot method for the class "fv"
.
## S3 method for class 'fv' plot(x, fmla, ..., subset=NULL, lty=NULL, col=NULL, lwd=NULL, xlim=NULL, ylim=NULL, xlab=NULL, ylab=NULL, clip.xlim=TRUE, ylim.covers=NULL, legend=!add, legendpos="topleft", legendavoid=missing(legendpos), legendmath=TRUE, legendargs=list(), shade=fvnames(x, ".s"), shadecol="grey", add=FALSE, log="", mathfont=c("italic", "plain", "bold", "bolditalic"), limitsonly=FALSE)
## S3 method for class 'fv' plot(x, fmla, ..., subset=NULL, lty=NULL, col=NULL, lwd=NULL, xlim=NULL, ylim=NULL, xlab=NULL, ylab=NULL, clip.xlim=TRUE, ylim.covers=NULL, legend=!add, legendpos="topleft", legendavoid=missing(legendpos), legendmath=TRUE, legendargs=list(), shade=fvnames(x, ".s"), shadecol="grey", add=FALSE, log="", mathfont=c("italic", "plain", "bold", "bolditalic"), limitsonly=FALSE)
x |
An object of class |
fmla |
an R language formula determining which variables or expressions are plotted. Either a formula object, or a string that can be parsed as a formula. See Details. |
subset |
(optional) subset of rows of the data frame that will be plotted. |
lty |
(optional) numeric vector of values of the graphical parameter
|
col |
(optional) numeric vector of values of the graphical parameter
|
lwd |
(optional) numeric vector of values of the graphical parameter
|
xlim |
(optional) range of x axis |
ylim |
(optional) range of y axis |
xlab |
(optional) label for x axis |
ylab |
(optional) label for y axis |
... |
Extra arguments passed to |
clip.xlim |
Logical value specifying whether the range of the horizontal axis
|
ylim.covers |
Optional vector of |
legend |
Logical flag or |
legendpos |
The position of the legend. Either a character string keyword
(see |
legendavoid |
Whether to avoid collisions between the legend and the graphics.
Logical value.
If |
legendmath |
Logical. If |
legendargs |
Named list containing additional arguments to be passed to
|
shade |
A character vector giving the names of two columns of |
shadecol |
The colour to be used in the |
add |
Logical. Whether the plot should be added to an existing plot |
log |
A character string which contains |
mathfont |
Character string. The font to be used for mathematical expressions in the axis labels and the legend. |
limitsonly |
Logical. If |
This is the plot
method for the class "fv"
.
An object of class "fv"
is a convenient way of storing several different
statistical estimates of a summary function; see fv.object
.
The default behaviour, executed by plot(x)
, displays these
different estimates as curves with different colours and line styles,
and plots a legend explaining them.
The use of the argument fmla
is like plot.formula
, but offers
some extra functionality.
The left and right hand sides of fmla
are evaluated,
and the results are plotted against each other
(the left side on the axis
against the right side on the
axis).
The left and right hand sides of fmla
may be
the names of columns of the data frame x
,
or expressions involving these names. If a variable in fmla
is not the name of a column of x
, the algorithm will search for
an object of this name in the environment where plot.fv
was
called, and then in the enclosing environment, and so on.
Multiple curves may be specified by a single formula
of the form
cbind(y1,y2,...,yn) ~ x
, where x,y1,y2,...,yn
are
expressions involving the variables in the data frame.
Each of the variables y1,y2,...,yn
in turn will be plotted
against x
.
See the examples.
Convenient abbreviations which can be used in the formula are
the symbol .
which represents all the
columns in the data frame that will be plotted by default;
the symbol .x
which represents the function argument;
the symbol .y
which represents the recommended value
of the function.
For further information, see fvnames
.
The value returned by this plot function indicates the meaning of the line types and colours in the plot. It can be used to make a suitable legend for the plot if you want to do this by hand. See the examples.
The argument shade
can be used to display critical bands
or confidence intervals. If it is not NULL
, then it should be
a subset index for the columns of x
, that identifies exactly
2 columns. When the corresponding curves are plotted, the region
between the curves will be shaded in light grey. See the Examples.
The default values of lty
, col
and lwd
can
be changed using spatstat.options("plot.fv")
.
Use type = "n"
to create the plot region and draw the axes
without plotting any data.
Use limitsonly=TRUE
to suppress all plotting
and just compute the and
limits. This can be used
to calculate common
and
scales for several plots.
To change the kind of parenthesis enclosing the
explanatory text about the unit of length, use
spatstat.options('units.paren')
Invisible: either NULL
, or a data frame giving the meaning of the
different line types and colours.
The plot generated by plot(x)
does not necessarily display all the data that is contained in the object.
The range of values of the function argument
displayed in the plot may be narrower than the
range of values actually contained in the data frame.
To override this behaviour and display all the available data,
set clip.xlim=FALSE
.
Statistical literature for summary functions of spatial data
recommends that, when the function is plotted,
the values of the function argument on the horizontal axis
should be restricted to a limited range of values.
For example, Ripley recommends that the K-function
should be plotted only for
values of distance
between
and
where
is the shortest side of the enclosing rectangle of the data.
This may be desirable so that the interesting detail is clearly visible in the plot. It may be necessary because values outside the recommended range are theoretically invalid, or unreliable due to high variance or large bias.
To support this standard practice, each object of class "fv"
may include data specifying a “recommended range” of values of
the function argument. The object produced by Kest
includes a recommended range following Ripley's recommendation above.
Similarly for Gest
, Fest
and many other
commands.
When plot(x)
is executed, the horizontal axis is restricted
to the recommended range of values. This recommendation can be
overridden by setting clip.xlim=FALSE
or by specifying the numerical limits xlim
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
K <- Kest(cells) # K is an object of class "fv" plot(K, iso ~ r) # plots iso against r plot(K, sqrt(iso/pi) ~ r) # plots sqrt(iso/r) against r plot(K, cbind(iso,theo) ~ r) # plots iso against r AND theo against r plot(K, . ~ r) # plots all available estimates of K against r plot(K, sqrt(./pi) ~ r) # plots all estimates of L-function # L(r) = sqrt(K(r)/pi) plot(K, cbind(iso,theo) ~ r, col=c(2,3)) # plots iso against r in colour 2 # and theo against r in colour 3 plot(K, iso ~ r, subset=quote(r < 0.2)) # plots iso against r for r < 10 # Can't remember the names of the columns? No problem.. plot(K, sqrt(./pi) ~ .x) # making a legend by hand v <- plot(K, . ~ r, legend=FALSE) legend("topleft", legend=v$meaning, lty=v$lty, col=v$col) # significance bands KE <- envelope(cells, Kest, nsim=19) plot(KE, shade=c("hi", "lo")) # how to display two functions on a common scale Kr <- Kest(redwood) a <- plot(K, limitsonly=TRUE) b <- plot(Kr, limitsonly=TRUE) xlim <- range(a$xlim, b$xlim) ylim <- range(a$ylim, b$ylim) opa <- par(mfrow=c(1,2)) plot(K, xlim=xlim, ylim=ylim) plot(Kr, xlim=xlim, ylim=ylim) par(opa) # For a shortcut, try plot(anylist(K, Kr), equal.scales=TRUE)
K <- Kest(cells) # K is an object of class "fv" plot(K, iso ~ r) # plots iso against r plot(K, sqrt(iso/pi) ~ r) # plots sqrt(iso/r) against r plot(K, cbind(iso,theo) ~ r) # plots iso against r AND theo against r plot(K, . ~ r) # plots all available estimates of K against r plot(K, sqrt(./pi) ~ r) # plots all estimates of L-function # L(r) = sqrt(K(r)/pi) plot(K, cbind(iso,theo) ~ r, col=c(2,3)) # plots iso against r in colour 2 # and theo against r in colour 3 plot(K, iso ~ r, subset=quote(r < 0.2)) # plots iso against r for r < 10 # Can't remember the names of the columns? No problem.. plot(K, sqrt(./pi) ~ .x) # making a legend by hand v <- plot(K, . ~ r, legend=FALSE) legend("topleft", legend=v$meaning, lty=v$lty, col=v$col) # significance bands KE <- envelope(cells, Kest, nsim=19) plot(KE, shade=c("hi", "lo")) # how to display two functions on a common scale Kr <- Kest(redwood) a <- plot(K, limitsonly=TRUE) b <- plot(Kr, limitsonly=TRUE) xlim <- range(a$xlim, b$xlim) ylim <- range(a$ylim, b$ylim) opa <- par(mfrow=c(1,2)) plot(K, xlim=xlim, ylim=ylim) plot(Kr, xlim=xlim, ylim=ylim) par(opa) # For a shortcut, try plot(anylist(K, Kr), equal.scales=TRUE)
Plot the result of Laslett's Transform.
## S3 method for class 'laslett' plot(x, ..., Xpars = list(box = TRUE, col = "grey"), pointpars = list(pch = 3, cols = "blue"), rectpars = list(lty = 3, border = "green"))
## S3 method for class 'laslett' plot(x, ..., Xpars = list(box = TRUE, col = "grey"), pointpars = list(pch = 3, cols = "blue"), rectpars = list(lty = 3, border = "green"))
x |
Object of class |
... |
Additional plot arguments passed to |
Xpars |
A list of plot arguments passed to |
pointpars |
A list of plot arguments passed to |
rectpars |
A list of plot arguments passed to |
This is the plot
method for the class "laslett"
.
The function laslett
applies Laslett's Transform
to a spatial region X
and returns an object of class
"laslett"
representing the result of the transformation.
The result is plotted by this method.
The plot function plot.solist
is used to align
the before-and-after pictures. See plot.solist
for
further options to control the plot.
None.
Kassel Hingee and Adrian Baddeley [email protected].
b <- laslett(heather$coarse, plotit=FALSE) plot(b, main="Heather Data")
b <- laslett(heather$coarse, plotit=FALSE) plot(b, main="Heather Data")
Given the result of a quadrat counting test, graphically display the quadrats that were used, the observed and expected counts, and the residual in each quadrat.
## S3 method for class 'quadrattest' plot(x, ..., textargs=list())
## S3 method for class 'quadrattest' plot(x, ..., textargs=list())
x |
Object of class |
... |
Additional arguments passed to |
textargs |
List of additional arguments passed to
|
This is the plot method for objects
of class "quadrattest"
. Such an object is produced by
quadrat.test
and represents the result of
a test for a spatial point pattern.
The quadrats are first plotted using plot.tess
.
Then in each quadrat, the observed and expected counts
and the Pearson residual are displayed as text using
text.default
.
Observed count is displayed at top left; expected count at top right;
and Pearson residual at bottom.
Null.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
quadrat.test
,
plot.tess
,
text.default
,
plot.quadratcount
plot(quadrat.test(swedishpines, 3))
plot(quadrat.test(swedishpines, 3))
Computes or plots an image showing the likelihood ratio test statistic for the scan test, or the optimal circle radius.
## S3 method for class 'scan.test' plot(x, ..., what=c("statistic", "radius"), do.window = TRUE) ## S3 method for class 'scan.test' as.im(X, ..., what=c("statistic", "radius"))
## S3 method for class 'scan.test' plot(x, ..., what=c("statistic", "radius"), do.window = TRUE) ## S3 method for class 'scan.test' as.im(X, ..., what=c("statistic", "radius"))
x , X
|
Result of a scan test. An object of class |
... |
Arguments passed to |
what |
Character string indicating whether to produce an image of the
(profile) likelihood ratio test statistic ( |
do.window |
Logical value indicating whether to plot the original window of the data as well. |
These functions extract, and plot, the spatially-varying value of the likelihood ratio test statistic which forms the basis of the scan test.
If the test result X
was based on circles of
the same radius r
, then as.im(X)
is a pixel image
of the likelihood ratio test statistic as a function of the
position of the centre of the circle.
If the test result X
was based on circles of
several different radii r
, then as.im(X)
is a pixel image
of the profile (maximum value over all radii r
)
likelihood ratio test statistic as a function of the
position of the centre of the circle, and
as.im(X, what="radius")
is a pixel image giving
for each location the value of
r
which maximised
the likelihood ratio test statistic at that location.
The plot
method plots the corresponding image.
The value of as.im.scan.test
is a pixel image (object of
class "im"
). The value of plot.scan.test
is NULL
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
online <- interactive() Nsim <- if(online) 19 else 2 r <- if(online) seq(0.04, 0.1, by=0.01) else c(0.05, 0.1) a <- scan.test(redwood, r=r, method="poisson", nsim=Nsim) plot(a) as.im(a) plot(a, what="radius")
online <- interactive() Nsim <- if(online) 19 else 2 r <- if(online) seq(0.04, 0.1, by=0.01) else c(0.05, 0.1) a <- scan.test(redwood, r=r, method="poisson", nsim=Nsim) plot(a) as.im(a) plot(a, what="radius")
Plot a spatially sampled function object.
## S3 method for class 'ssf' plot(x, ..., how = c("smoothed", "nearest", "points"), style = c("image", "contour", "imagecontour"), sigma = NULL, contourargs=list()) ## S3 method for class 'ssf' image(x, ...) ## S3 method for class 'ssf' contour(x, ..., main, sigma = NULL)
## S3 method for class 'ssf' plot(x, ..., how = c("smoothed", "nearest", "points"), style = c("image", "contour", "imagecontour"), sigma = NULL, contourargs=list()) ## S3 method for class 'ssf' image(x, ...) ## S3 method for class 'ssf' contour(x, ..., main, sigma = NULL)
x |
Spatially sampled function (object of class |
... |
Arguments passed to |
how |
Character string determining whether to display the
function values at the data points ( |
style |
Character string indicating whether to plot the smoothed function as a colour image, a contour map, or both. |
contourargs |
Arguments passed to |
sigma |
Smoothing bandwidth for smooth interpolation. |
main |
Optional main title for the plot. |
These are methods for the generic
plot
,
image
and
contour
for the class "ssf"
.
An object of class "ssf"
represents a
function (real- or vector-valued) that has been
sampled at a finite set of points.
For plot.ssf
there are three types of display.
If how="points"
the exact function values
will be displayed as circles centred at the locations where they
were computed. If how="smoothed"
(the default) these
values will be kernel-smoothed using Smooth.ppp
and displayed as a pixel image.
If how="nearest"
the values will be interpolated
by nearest neighbour interpolation using nnmark
and displayed as a pixel image.
For image.ssf
and contour.ssf
the values are
kernel-smoothed before being displayed.
NULL
.
Adrian Baddeley [email protected].
Baddeley, A. (2017) Local composite likelihood for spatial point processes. Spatial Statistics 22, 261–295.
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
a <- ssf(cells, nndist(cells, k=1:3)) plot(a, how="points") plot(a, how="smoothed") plot(a, how="nearest")
a <- ssf(cells, nndist(cells, k=1:3)) plot(a, how="points") plot(a, how="smoothed") plot(a, how="nearest")
Plot the result of the studentised permutation test.
## S3 method for class 'studpermutest' plot(x, fmla, ..., lty = NULL, col = NULL, lwd = NULL, lty.theo = NULL, col.theo = NULL, lwd.theo = NULL, lwd.mean = if (meanonly) 1 else NULL, lty.mean = lty, col.mean = col, separately = FALSE, meanonly = FALSE, main = if (meanonly) "group means" else NULL, xlim = NULL, ylim = NULL, ylab = NULL, legend = !add, legendpos = "topleft", lbox = FALSE, add = FALSE)
## S3 method for class 'studpermutest' plot(x, fmla, ..., lty = NULL, col = NULL, lwd = NULL, lty.theo = NULL, col.theo = NULL, lwd.theo = NULL, lwd.mean = if (meanonly) 1 else NULL, lty.mean = lty, col.mean = col, separately = FALSE, meanonly = FALSE, main = if (meanonly) "group means" else NULL, xlim = NULL, ylim = NULL, ylab = NULL, legend = !add, legendpos = "topleft", lbox = FALSE, add = FALSE)
x |
An object of class |
fmla |
Plot formula used in |
... |
Additional graphical arguments passed to |
lty , col , lwd
|
Line type, colour, and line width of the curves plotting the summary function for each point pattern in the original data. Either a single value or a vector of length equal to the number of point patterns. |
lty.theo , col.theo , lwd.theo
|
Line type, colour, and line width of the curve representing the theoretical value of the summary function. |
lty.mean , col.mean , lwd.mean
|
Line type, colour, and line width (as a multiple of |
separately |
Logical value indicating whether to plot each group of data in a separate panel. |
meanonly |
Logical value indicating whether to plot only the group means of the summary function. |
main |
Character string giving a main title for the plot. |
xlim , ylim
|
Numeric vectors of length 2 giving the limits for the |
ylab |
Character string or expression to be used for the label on the
|
legend |
Logical value indicating whether to plot a legend explaining the meaning of each curve. |
legendpos |
Position of legend. See |
lbox |
Logical value indicating whether to plot a box around the plot. |
add |
Logical value indicating whether the plot should be added to
the existing plot ( |
This is the plot
method for objects of class
"studpermutest"
which represent the result of a studentised
permutation test applied to several point patterns. The test is
performed by studpermu.test
.
The plot shows the summary functions for each point pattern, coloured according to group. Optionally it can show the different groups in separate plot panels, or show only the group means in a single panel.
Null.
Ute Hahn.
Modified for spatstat
by
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
np <- if(interactive()) 99 else 19 testpyramidal <- studpermu.test(pyramidal, Neurons ~ group, nperm=np) plot(testpyramidal) plot(testpyramidal, meanonly=TRUE) plot(testpyramidal, col.theo=8, lwd.theo=4, lty.theo=1) plot(testpyramidal, . ~ pi * r^2) op <- par(mfrow=c(1,3)) plot(testpyramidal, separately=TRUE) plot(testpyramidal, separately=TRUE, col=2, lty=1, lwd.mean=2, col.mean=4) par(op)
np <- if(interactive()) 99 else 19 testpyramidal <- studpermu.test(pyramidal, Neurons ~ group, nperm=np) plot(testpyramidal) plot(testpyramidal, meanonly=TRUE) plot(testpyramidal, col.theo=8, lwd.theo=4, lty.theo=1) plot(testpyramidal, . ~ pi * r^2) op <- par(mfrow=c(1,3)) plot(testpyramidal, separately=TRUE) plot(testpyramidal, separately=TRUE, col=2, lty=1, lwd.mean=2, col.mean=4) par(op)
Pool the data from several objects of the same class.
pool(...)
pool(...)
... |
Objects of the same type. |
The function pool
is generic. There are methods for several
classes, listed below.
pool
is used to combine the data from several objects of the same type,
and to compute statistics based on the combined dataset.
It may be used to pool the estimates obtained from replicated datasets.
It may also be used in high-performance computing applications,
when the objects ...
have been computed on different processors
or in different batch runs, and we wish to combine them.
An object of the same class as the arguments ...
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
pool.envelope
,
pool.fasp
,
pool.rat
,
pool.fv
Pool the data from the objects in a list.
## S3 method for class 'anylist' pool(x, ...)
## S3 method for class 'anylist' pool(x, ...)
x |
A list, belonging to the class |
... |
Optional additional objects
which can be pooled with the elements of |
The function pool
is generic. Its purpose is to combine
data from several objects of the same type (typically computed
from different datasets) into a common, pooled estimate.
The function pool.anyist
is the method
for the class "anylist"
. It is used when the objects to be
pooled are given in a list x
.
Each of the elements of the list x
, and each of the
subsequent arguments ...
if provided, must be an object of the same
class.
An object of the same class as each of the entries in x
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Keach <- anylapply(waterstriders, Kest, ratio=TRUE, correction="iso") K <- pool(Keach)
Keach <- anylapply(waterstriders, Kest, ratio=TRUE, correction="iso") K <- pool(Keach)
Pool the simulation data from several simulation envelopes
(objects of class "envelope"
)
and compute a new envelope.
## S3 method for class 'envelope' pool(..., savefuns=FALSE, savepatterns=FALSE)
## S3 method for class 'envelope' pool(..., savefuns=FALSE, savepatterns=FALSE)
... |
Objects of class |
savefuns |
Logical flag indicating whether to save all the simulated function values. |
savepatterns |
Logical flag indicating whether to save all the simulated point patterns. |
The function pool
is generic. This is the method for the
class "envelope"
of simulation envelopes. It is used to
combine the simulation data from several simulation envelopes
and to compute an envelope based on the combined data.
Each of the arguments ...
must be an object of class
"envelope"
. These envelopes must be compatible,
in that they are envelopes for the same function,
and were computed using the same options.
In normal use, each envelope object will have been
created by running the command envelope
with the argument savefuns=TRUE
.
This ensures that each object contains the simulated data
(summary function values for the simulated point patterns)
that were used to construct the envelope.
The simulated data are extracted from each object and combined. A new envelope is computed from the combined set of simulations.
Alternatively, if each envelope object was created
by running envelope
with VARIANCE=TRUE
,
then the saved functions are not required.
The sample means and sample variances from each envelope will be pooled. A new envelope is computed from the pooled mean and variance.
Warnings or errors will be issued if the envelope objects ...
appear to be incompatible. Apart from these basic checks,
the code is not smart enough to decide whether it is sensible
to pool the data.
To modify the envelope parameters or the type of envelope that is
computed, first pool the envelope data using pool.envelope
,
then use envelope.envelope
to modify the envelope
parameters.
An object of class "envelope"
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
envelope
,
envelope.envelope
,
pool
,
pool.fasp
E1 <- envelope(cells, Kest, nsim=10, savefuns=TRUE) E2 <- envelope(cells, Kest, nsim=20, savefuns=TRUE) pool(E1, E2) V1 <- envelope(E1, VARIANCE=TRUE) V2 <- envelope(E2, VARIANCE=TRUE) pool(V1, V2)
E1 <- envelope(cells, Kest, nsim=10, savefuns=TRUE) E2 <- envelope(cells, Kest, nsim=20, savefuns=TRUE) pool(E1, E2) V1 <- envelope(E1, VARIANCE=TRUE) V2 <- envelope(E2, VARIANCE=TRUE) pool(V1, V2)
Pool the simulation data from several function arrays
(objects of class "fasp"
)
and compute a new function array.
## S3 method for class 'fasp' pool(...)
## S3 method for class 'fasp' pool(...)
... |
Objects of class |
The function pool
is generic. This is the method for the
class "fasp"
of function arrays. It is used to
combine the simulation data from several arrays of simulation envelopes
and to compute a new array of envelopes based on the combined data.
Each of the arguments ...
must be a function array
(object of class "fasp"
) containing simulation envelopes.
This is typically created by running the command
alltypes
with the arguments
envelope=TRUE
and savefuns=TRUE
.
This ensures that each object is an array of simulation envelopes,
and that each envelope contains the simulated data
(summary function values) that were used to construct the envelope.
The simulated data are extracted from each object and combined. A new array of envelopes is computed from the combined set of simulations.
Warnings or errors will be issued if the objects ...
appear to be incompatible. However, the code is not smart enough to
decide whether it is sensible to pool the data.
An object of class "fasp"
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
fasp
,
alltypes
,
pool.envelope
,
pool
A1 <- alltypes(amacrine,"K",nsim=9,envelope=TRUE,savefuns=TRUE) A2 <- alltypes(amacrine,"K",nsim=10,envelope=TRUE,savefuns=TRUE) pool(A1, A2)
A1 <- alltypes(amacrine,"K",nsim=9,envelope=TRUE,savefuns=TRUE) A2 <- alltypes(amacrine,"K",nsim=10,envelope=TRUE,savefuns=TRUE) pool(A1, A2)
Combine several summary functions into a single function.
## S3 method for class 'fv' pool(..., weights=NULL, relabel=TRUE, variance=TRUE)
## S3 method for class 'fv' pool(..., weights=NULL, relabel=TRUE, variance=TRUE)
... |
Objects of class |
weights |
Optional numeric vector of weights for the functions. |
relabel |
Logical value indicating whether the columns of the resulting function should be labelled to show that they were obtained by pooling. |
variance |
Logical value indicating whether to compute the sample variance and related terms. |
The function pool
is generic. This is the method for the
class "fv"
of summary functions. It is used to
combine several estimates of the same function into a single function.
Each of the arguments ...
must be an object of class
"fv"
. They must be compatible,
in that they are estimates of the same function,
and were computed using the same options.
The sample mean and sample variance of the corresponding estimates will be computed.
An object of class "fv"
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
K <- lapply(waterstriders, Kest, correction="iso") Kall <- pool(K[[1]], K[[2]], K[[3]]) Kall <- pool(as.anylist(K)) plot(Kall, cbind(pooliso, pooltheo) ~ r, shade=c("loiso", "hiiso"), main="Pooled K function of waterstriders")
K <- lapply(waterstriders, Kest, correction="iso") Kall <- pool(K[[1]], K[[2]], K[[3]]) Kall <- pool(as.anylist(K)) plot(Kall, cbind(pooliso, pooltheo) ~ r, shade=c("loiso", "hiiso"), main="Pooled K function of waterstriders")
Pool several quadrat tests into a single quadrat test.
## S3 method for class 'quadrattest' pool(..., df=NULL, df.est=NULL, nsim=1999, Xname=NULL, CR=NULL)
## S3 method for class 'quadrattest' pool(..., df=NULL, df.est=NULL, nsim=1999, Xname=NULL, CR=NULL)
... |
Any number of objects, each of which is a quadrat test
(object of class |
df |
Optional. Number of degrees of freedom of the test statistic.
Relevant only for |
df.est |
Optional. The number of fitted parameters, or the
number of degrees of freedom lost by estimation of
parameters.
Relevant only for |
nsim |
Number of simulations, for Monte Carlo test. |
Xname |
Optional. Name of the original data. |
CR |
Optional. Numeric value of the Cressie-Read exponent |
The function pool
is generic. This is the method for the
class "quadrattest"
.
An object of class "quadrattest"
represents a
test or Monte Carlo test
of goodness-of-fit for a point process model, based on quadrat counts.
Such objects are created by the command
quadrat.test
.
Each of the arguments ...
must be an object of class
"quadrattest"
. They must all be the same type of test
(chi-squared test or Monte Carlo test, conditional or unconditional)
and must all have the same type of alternative hypothesis.
The test statistic of the pooled test is the Pearson
statistic taken over all cells (quadrats) of all tests.
The
value of the pooled test is then computed using
either a Monte Carlo test or a
test.
For a pooled test, the number of degrees of freedom of
the combined test is computed by adding the degrees of freedom
of all the tests (equivalent to assuming the tests are independent)
unless it is determined by the arguments
df
or df.est
.
The resulting value is computed to obtain the
pooled test.
For a pooled Monte Carlo test, new simulations are performed
to determine the pooled Monte Carlo value.
Another object of class "quadrattest"
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Y <- split(humberside) test1 <- quadrat.test(Y[[1]]) test2 <- quadrat.test(Y[[2]]) pool(test1, test2, Xname="Humberside")
Y <- split(humberside) test1 <- quadrat.test(Y[[1]]) test2 <- quadrat.test(Y[[2]]) pool(test1, test2, Xname="Humberside")
Pool the data from several ratio objects
(objects of class "rat"
)
and compute a pooled estimate.
## S3 method for class 'rat' pool(..., weights=NULL, relabel=TRUE, variance=TRUE)
## S3 method for class 'rat' pool(..., weights=NULL, relabel=TRUE, variance=TRUE)
... |
Objects of class |
weights |
Numeric vector of weights. |
relabel |
Logical value indicating whether the result should be relabelled to show that it was obtained by pooling. |
variance |
Logical value indicating whether to compute the sample variance and related terms. |
The function pool
is generic. This is the method for the
class "rat"
of ratio objects. It is used to
combine several estimates of the same quantity
when each estimate is a ratio.
Each of the arguments ...
must be an object of class
"rat"
representing a ratio object (basically a
numerator and a denominator; see rat
).
We assume that these ratios are all estimates of the same quantity.
If the objects are called
and if
has numerator
and
denominator
, so that notionally
, then the pooled estimate is the
ratio-of-sums estimator
The standard error of is computed using the delta method
as described in Baddeley et al. (1993)
or Cochran (1977, pp 154, 161).
If the argument weights
is given, it should be a numeric vector
of length equal to the number of objects to be pooled.
The pooled estimator is the ratio-of-sums estimator
where is the
i
th weight.
This calculation is implemented only for certain classes of objects where the arithmetic can be performed.
This calculation is currently implemented only for objects which
also belong to the class "fv"
(function value tables).
For example, if Kest
is called with argument
ratio=TRUE
, the result is a suitable object (belonging to the classes
"rat"
and "fv"
).
Warnings or errors will be issued if the ratio objects ...
appear to be incompatible. However, the code is not smart enough to
decide whether it is sensible to pool the data.
An object of the same class as the input.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Baddeley, A.J, Moyeed, R.A., Howard, C.V. and Boyde, A. (1993) Analysis of a three-dimensional point pattern with replication. Applied Statistics 42, 641–668.
Cochran, W.G. (1977) Sampling techniques, 3rd edition. New York: John Wiley and Sons.
K1 <- Kest(runifpoint(42), ratio=TRUE, correction="iso") K2 <- Kest(runifpoint(42), ratio=TRUE, correction="iso") K3 <- Kest(runifpoint(42), ratio=TRUE, correction="iso") K <- pool(K1, K2, K3) plot(K, pooliso ~ r, shade=c("hiiso", "loiso"))
K1 <- Kest(runifpoint(42), ratio=TRUE, correction="iso") K2 <- Kest(runifpoint(42), ratio=TRUE, correction="iso") K3 <- Kest(runifpoint(42), ratio=TRUE, correction="iso") K <- pool(K1, K2, K3) plot(K, pooliso ~ r, shade=c("hiiso", "loiso"))
Given a function object f
containing both the estimated
and theoretical versions of a summary function, these operations
combine the estimated and theoretical functions into a new function.
When plotted, the new function gives either the P-P plot or Q-Q plot
of the original f
.
PPversion(f, theo = "theo", columns = ".") QQversion(f, theo = "theo", columns = ".")
PPversion(f, theo = "theo", columns = ".") QQversion(f, theo = "theo", columns = ".")
f |
The function to be transformed. An object of class |
theo |
The name of the column of |
columns |
Character vector, specifying the columns of |
The argument f
should be an object of class "fv"
,
containing both empirical estimates
and a theoretical value
for a summary function.
The P–P version of f
is the function
where
is the inverse function of
.
A plot of
against
is equivalent to a plot of
against
for all
.
If
f
is a cumulative distribution function (such as the
result of Fest
or Gest
) then
this is a P–P plot, a plot of the observed versus theoretical
probabilities for the distribution.
The diagonal line
corresponds to perfect agreement between observed and theoretical
distribution.
The Q–Q version of f
is the function
.
If
f
is a cumulative distribution function,
a plot of against
is a Q–Q plot, a plot of the observed versus theoretical
quantiles of the distribution.
The diagonal line
corresponds to perfect agreement between observed and theoretical
distribution.
Another straight line corresponds to the situation where the
observed variable is a linear transformation of the theoretical variable.
For a point pattern
X
, the Q–Q version of Kest(X)
is
essentially equivalent to Lest(X)
.
Another object of class "fv"
.
Tom Lawrence and Adrian Baddeley.
Implemented by Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
opa <- par(mar=0.1+c(5,5,4,2)) G <- Gest(redwoodfull) plot(PPversion(G)) plot(QQversion(G)) par(opa)
opa <- par(mar=0.1+c(5,5,4,2)) G <- Gest(redwoodfull) plot(PPversion(G)) plot(QQversion(G)) par(opa)
Performs a test of Complete Spatial Randomness for a given point pattern, based on quadrat counts. Alternatively performs a goodness-of-fit test of a fitted inhomogeneous Poisson model. By default performs chi-squared tests; can also perform Monte Carlo based tests.
quadrat.test(X, ...) ## S3 method for class 'ppp' quadrat.test(X, nx=5, ny=nx, alternative=c("two.sided", "regular", "clustered"), method=c("Chisq", "MonteCarlo"), conditional=TRUE, CR=1, lambda=NULL, df.est=NULL, ..., xbreaks=NULL, ybreaks=NULL, tess=NULL, nsim=1999) ## S3 method for class 'quadratcount' quadrat.test(X, alternative=c("two.sided", "regular", "clustered"), method=c("Chisq", "MonteCarlo"), conditional=TRUE, CR=1, lambda=NULL, df.est=NULL, ..., nsim=1999)
quadrat.test(X, ...) ## S3 method for class 'ppp' quadrat.test(X, nx=5, ny=nx, alternative=c("two.sided", "regular", "clustered"), method=c("Chisq", "MonteCarlo"), conditional=TRUE, CR=1, lambda=NULL, df.est=NULL, ..., xbreaks=NULL, ybreaks=NULL, tess=NULL, nsim=1999) ## S3 method for class 'quadratcount' quadrat.test(X, alternative=c("two.sided", "regular", "clustered"), method=c("Chisq", "MonteCarlo"), conditional=TRUE, CR=1, lambda=NULL, df.est=NULL, ..., nsim=1999)
X |
A point pattern (object of class |
nx , ny
|
Numbers of quadrats in the |
alternative |
Character string (partially matched) specifying the alternative hypothesis. |
method |
Character string (partially matched) specifying the test to use:
either |
conditional |
Logical. Should the Monte Carlo test be conducted
conditionally upon the observed number of points of the pattern?
Ignored if |
CR |
Optional. Numerical value. The exponent for the Cressie-Read test statistic. See Details. |
lambda |
Optional. Pixel image (object of class |
df.est |
Optional. Advanced use only. The number of fitted parameters, or the number of degrees of freedom lost by estimation of parameters. |
... |
Ignored. |
xbreaks |
Optional. Numeric vector giving the |
ybreaks |
Optional. Numeric vector giving the |
tess |
Tessellation (object of class |
nsim |
The number of simulated samples to generate when
|
These functions perform tests or Monte Carlo tests
of goodness-of-fit for a point process model, based on quadrat counts.
The function quadrat.test
is generic, with methods for
point patterns (class "ppp"
), split point patterns
(class "splitppp"
), point process models
(class "ppm"
or "slrm"
)
and quadrat count tables (class "quadratcount"
).
if X
is a point pattern, we test the null hypothesis
that the data pattern is a realisation of Complete Spatial
Randomness (the uniform Poisson point process). Marks in the point
pattern are ignored. (If lambda
is given then the null
hypothesis is the Poisson process with intensity lambda
.)
if X
is a split point pattern, then for each of the
component point patterns (taken separately) we test
the null hypotheses of Complete Spatial Randomness.
See quadrat.test.splitppp
for documentation.
If X
is a fitted point process model, then it should be
a Poisson point process model. The
data to which this model was fitted are extracted from the model
object, and are treated as the data point pattern for the test.
We test the null hypothesis
that the data pattern is a realisation of the (inhomogeneous) Poisson point
process specified by X
.
In all cases, the window of observation is divided
into tiles, and the number of data points in each tile is
counted, as described in quadratcount
.
The quadrats are rectangular by default, or may be regions of arbitrary shape
specified by the argument tess
.
The expected number of points in each quadrat is also calculated,
as determined by CSR (in the first case) or by the fitted model
(in the second case).
Then the Pearson statistic
is computed.
If method="Chisq"
then a test of
goodness-of-fit is performed by comparing the test statistic
to the
distribution
with
degrees of freedom, where
m
is the number of
quadrats and is the number of fitted parameters
(equal to 1 for
quadrat.test.ppp
). The default is to
compute the two-sided -value, so that the test will
be declared significant if
is either very large or very
small. One-sided
-values can be obtained by specifying the
alternative
. An important requirement of the
test is that the expected counts in each quadrat
be greater than 5.
If method="MonteCarlo"
then a Monte Carlo test is performed,
obviating the need for all expected counts to be at least 5. In the
Monte Carlo test, nsim
random point patterns are generated
from the null hypothesis (either CSR or the fitted point process
model). The Pearson statistic is computed as above.
The
-value is determined by comparing the
statistic for the observed point pattern, with the values obtained
from the simulations. Again the default is to
compute the two-sided
-value.
If conditional
is TRUE
then the simulated samples are
generated from the multinomial distribution with the number of “trials”
equal to the number of observed points and the vector of probabilities
equal to the expected counts divided by the sum of the expected counts.
Otherwise the simulated samples are independent Poisson counts, with
means equal to the expected counts.
If the argument CR
is given, then instead of the
Pearson statistic, the Cressie-Read (1984) power divergence
test statistic
is computed, where is the
th observed count
and
is the corresponding expected count.
The value
CR=1
gives the Pearson statistic;
CR=0
gives the likelihood ratio test statistic ;
CR=-1/2
gives the Freeman-Tukey statistic ;
CR=-1
gives the modified likelihood ratio test statistic ;
and
CR=-2
gives Neyman's modified statistic .
In all cases the asymptotic distribution of this test statistic is
the same
distribution as above.
The return value is an object of class "htest"
.
Printing the object gives comprehensible output
about the outcome of the test.
The return value also belongs to
the special class "quadrat.test"
. Plotting the object
will display the quadrats, annotated by their observed and expected
counts and the Pearson residuals. See the examples.
An object of class "htest"
. See chisq.test
for explanation.
The return value is also an object of the special class
"quadrattest"
, and there is a plot method for this class.
See the examples.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Cressie, N. and Read, T.R.C. (1984) Multinomial goodness-of-fit tests. Journal of the Royal Statistical Society, Series B 46, 440–464.
quadrat.test.splitppp
,
quadratcount
,
quadrats
,
quadratresample
,
chisq.test
,
cdf.test
.
To test a Poisson point process model against a specific alternative,
use anova.ppm
.
quadrat.test(simdat) quadrat.test(simdat, 4, 3) quadrat.test(simdat, alternative="regular") quadrat.test(simdat, alternative="clustered") ## Likelihood ratio test quadrat.test(simdat, CR=0) ## Power divergence tests quadrat.test(simdat, CR=-1)$p.value quadrat.test(simdat, CR=-2)$p.value # Using Monte Carlo p-values quadrat.test(swedishpines) # Get warning, small expected values. Nsim <- if(interactive()) 4999 else 9 quadrat.test(swedishpines, method="M", nsim=Nsim) quadrat.test(swedishpines, method="M", nsim=Nsim, conditional=FALSE) # quadrat counts qS <- quadratcount(simdat, 4, 3) quadrat.test(qS) te <- quadrat.test(simdat, 4) residuals(te) # Pearson residuals plot(te) plot(simdat, pch="+", cols="green", lwd=2) plot(te, add=TRUE, col="red", cex=1.4, lty=2, lwd=3) sublab <- eval(substitute(expression(p[chi^2]==z), list(z=signif(te$p.value,3)))) title(sub=sublab, cex.sub=3) # quadrats of irregular shape B <- dirichlet(runifpoint(6, Window(simdat))) qB <- quadrat.test(simdat, tess=B) plot(simdat, main="quadrat.test(simdat, tess=B)", pch="+") plot(qB, add=TRUE, col="red", lwd=2, cex=1.2)
quadrat.test(simdat) quadrat.test(simdat, 4, 3) quadrat.test(simdat, alternative="regular") quadrat.test(simdat, alternative="clustered") ## Likelihood ratio test quadrat.test(simdat, CR=0) ## Power divergence tests quadrat.test(simdat, CR=-1)$p.value quadrat.test(simdat, CR=-2)$p.value # Using Monte Carlo p-values quadrat.test(swedishpines) # Get warning, small expected values. Nsim <- if(interactive()) 4999 else 9 quadrat.test(swedishpines, method="M", nsim=Nsim) quadrat.test(swedishpines, method="M", nsim=Nsim, conditional=FALSE) # quadrat counts qS <- quadratcount(simdat, 4, 3) quadrat.test(qS) te <- quadrat.test(simdat, 4) residuals(te) # Pearson residuals plot(te) plot(simdat, pch="+", cols="green", lwd=2) plot(te, add=TRUE, col="red", cex=1.4, lty=2, lwd=3) sublab <- eval(substitute(expression(p[chi^2]==z), list(z=signif(te$p.value,3)))) title(sub=sublab, cex.sub=3) # quadrats of irregular shape B <- dirichlet(runifpoint(6, Window(simdat))) qB <- quadrat.test(simdat, tess=B) plot(simdat, main="quadrat.test(simdat, tess=B)", pch="+") plot(qB, add=TRUE, col="red", lwd=2, cex=1.2)
Performs a test of Complete Spatial Randomness for each of the component patterns in a split point pattern, based on quadrat counts. By default performs chi-squared tests; can also perform Monte Carlo based tests.
## S3 method for class 'splitppp' quadrat.test(X, ..., df=NULL, df.est=NULL, Xname=NULL)
## S3 method for class 'splitppp' quadrat.test(X, ..., df=NULL, df.est=NULL, Xname=NULL)
X |
A split point pattern (object of class |
... |
Arguments passed to |
df , df.est , Xname
|
Arguments passed to |
The function quadrat.test
is generic, with methods for
point patterns (class "ppp"
), split point patterns
(class "splitppp"
) and point process models
(class "ppm"
).
If X
is a split point pattern, then for each of the
component point patterns (taken separately) we test
the null hypotheses of Complete Spatial Randomness,
then combine the result into a single test.
The method quadrat.test.ppp
is applied to each
component point pattern. Then the results are pooled using
pool.quadrattest
to obtain a single test.
An object of class "quadrattest"
which can be printed and
plotted.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
quadrat.test
,
quadratcount
,
quadrats
,
quadratresample
,
chisq.test
,
cdf.test
.
To test a Poisson point process model against a specific Poisson alternative,
use anova.ppm
.
qH <- quadrat.test(split(humberside), 2, 3) plot(qH) qH
qH <- quadrat.test(split(humberside), 2, 3) plot(qH) qH
Compute the cumulative integral of an image over increasing radial distances from the origin.
radcumint(X, ..., origin, Xname, result = c("fv", "im"))
radcumint(X, ..., origin, Xname, result = c("fv", "im"))
X |
A pixel image (object of class |
... |
Ignored. |
origin |
Optional. Origin about which the rotations should be performed.
Either a numeric vector or a character string as described
in the help for |
Xname |
Optional name for |
result |
Character string specifying the kind of result required: either a function object or a pixel image. |
This command computes, for each possible distance ,
the integral of the pixel values lying inside the disc of radius
centred at the origin.
If result="fv"
(the default) the result is a function
object f
of class "fv"
. For each value of radius ,
the function value
f(r)
is the integral of X
over the disc of radius .
If result="im"
the result is a pixel image, with the same
dimensions as X
. At a given pixel, the result is
equal to f(r)
where r
is the distance from the given
pixel to the origin. That is, at any given pixel, the resulting value
is the integral of X
over the disc
centred at the origin whose boundary passes through the given pixel.
An object of class "fv"
or "im"
,
with the same coordinate units as X
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
D <- density(redwood) plot(radcumint(D)) plot(radcumint(D, result="im"))
D <- density(redwood) plot(radcumint(D)) plot(radcumint(D, result="im"))
Stores the numerator, denominator, and value of a ratio as a single object.
rat(ratio, numerator, denominator, check = TRUE)
rat(ratio, numerator, denominator, check = TRUE)
ratio , numerator , denominator
|
Three objects belonging to the same class. |
check |
Logical. Whether to check that
the objects are |
The class "rat"
is a simple mechanism for keeping track of
the numerator and denominator when calculating a ratio. Its main
purpose is simply to signal that the object is a ratio.
The function rat
creates an object of class "rat"
given the numerator, the denominator and the ratio.
No calculation is performed;
the three objects are simply stored together.
The arguments ratio
, numerator
, denominator
can be objects of any kind. They should belong to the same class.
It is assumed that the relationship
holds in some version of arithmetic. However, no calculation is performed.
By default the algorithm checks
whether the three arguments ratio
, numerator
,
denominator
are compatible objects, according to
compatible
.
The result is equivalent to ratio
except for the
addition of extra information.
An object equivalent to the object ratio
except that it also belongs to the class "rat"
and has additional attributes numerator
and denominator
.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Computes an estimate of the contact distribution function of a set, using a rectangular structuring element.
rectcontact(X, ..., asp = 1, npasses=4, eps = NULL, r = NULL, breaks = NULL, correction = c("rs", "km"))
rectcontact(X, ..., asp = 1, npasses=4, eps = NULL, r = NULL, breaks = NULL, correction = c("rs", "km"))
X |
Logical-valued image. The |
... |
Ignored. |
asp |
Aspect ratio for the rectangular metric. A single positive number.
See |
npasses |
Number of passes to perform in the distance algorithm. A positive integer.
See |
eps |
Pixel size, if the image should be converted to a finer grid. |
r |
Optional vector of distance values. Do Not Use This. |
breaks |
Do Not Use This. |
correction |
Character vector specifying the edge correction. |
To be written.
Object of class "fv"
.
Adrian Baddeley [email protected].
## make an image which is TRUE/FALSE inside/outside the letter R V <- letterR Frame(V) <- grow.rectangle(Frame(V), 0.5) Z <- as.im(V, value=TRUE, na.replace=FALSE) ## analyse plot(rectcontact(Z))
## make an image which is TRUE/FALSE inside/outside the letter R V <- letterR Frame(V) <- grow.rectangle(Frame(V), 0.5) Z <- as.im(V, value=TRUE, na.replace=FALSE) ## analyse plot(rectcontact(Z))
If the designated file does not yet exist, evaluate the expression and save the results in the file. If the file already exists, re-load the results from the file.
reload.or.compute(filename, expr, objects = NULL, context = parent.frame(), destination = parent.frame(), force=FALSE, verbose=TRUE)
reload.or.compute(filename, expr, objects = NULL, context = parent.frame(), destination = parent.frame(), force=FALSE, verbose=TRUE)
filename |
Name of data file. A character string. |
expr |
R language expression to be evaluated. |
objects |
Optional character vector of names of objects to be saved
in |
context |
Environment containing objects that are mentioned in |
destination |
Environment into which the resulting objects should be assigned. |
force |
Logical value indicating whether to perform the computation in any case. |
verbose |
Logical value indicating whether to print a message indicating whether the data were recomputed or reloaded from the file. |
This facility is useful for saving, and later re-loading, the results of
time-consuming computations. It would typically be
used in an R script file or an Sweave
document.
If the file called filename
does not yet exist,
then expr
will be evaluated
and the results will be saved in filename
.
The optional argument objects
specifies which results should be saved
to the file: the default is to save all objects that were created
by evaluating the expression.
If the file called filename
already exists, then it
will be loaded.
The optional argument objects
specifies the names
of objects that should be present in the file; a warning is issued
if any of them are missing.
The resulting objects can be assigned into any desired destination
.
The default behaviour is equivalent to evaluating expr
in the current environment.
If force=TRUE
then expr
will be evaluated
(regardless of whether the file already exists or not)
and the results will be saved in filename
, overwriting
any previously-existing file with that name. This is a convenient
way to force the code to re-compute everything
in an R script file or Sweave
document.
Character vector (invisible) giving the names of the objects computed or loaded.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
## Demonstration using a temporary file ## (For real applications, use a permanent file in your own filespace) myfile <- paste0(tempdir(), .Platform$file.sep, "mydata.rda") reload.or.compute(myfile, { # some very long computation ending with .. x <- 42 y <- sqrt(x) })
## Demonstration using a temporary file ## (For real applications, use a permanent file in your own filespace) myfile <- paste0(tempdir(), .Platform$file.sep, "mydata.rda") reload.or.compute(myfile, { # some very long computation ending with .. x <- 42 y <- sqrt(x) })
Generic command to estimate the spatially-varying probability of each type of point, or the ratios of such probabilities.
relrisk(X, ...)
relrisk(X, ...)
X |
Either a point pattern (class |
... |
Additional arguments appropriate to the method. |
In a point pattern containing several different types of points, we may be interested in the spatially-varying probability of each possible type, or the relative risks which are the ratios of such probabilities.
The command relrisk
is generic and can be used to
estimate relative risk in different ways.
The function relrisk.ppp
is the method for point pattern
datasets. It computes nonparametric estimates of relative risk
by kernel smoothing.
The function relrisk.ppm
is the method for fitted point
process models (class "ppm"
). It computes parametric
estimates of relative risk, using the fitted model.
A pixel image, or a list of pixel images, or a numeric vector or matrix, containing the requested estimates of relative risk.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Given a multitype point pattern, this function estimates the spatially-varying probability of each type of point, or the ratios of such probabilities, using kernel smoothing. The default smoothing bandwidth is selected by cross-validation.
## S3 method for class 'ppp' relrisk(X, sigma = NULL, ..., at = c("pixels", "points"), weights = NULL, varcov = NULL, relative=FALSE, adjust=1, edge=TRUE, diggle=FALSE, se=FALSE, wtype=c("value", "multiplicity"), casecontrol=TRUE, control=1, case, fudge=0)
## S3 method for class 'ppp' relrisk(X, sigma = NULL, ..., at = c("pixels", "points"), weights = NULL, varcov = NULL, relative=FALSE, adjust=1, edge=TRUE, diggle=FALSE, se=FALSE, wtype=c("value", "multiplicity"), casecontrol=TRUE, control=1, case, fudge=0)
X |
A multitype point pattern (object of class |
sigma |
Optional. The numeric value of the smoothing bandwidth
(the standard deviation of isotropic
Gaussian smoothing kernel).
Alternatively |
... |
Arguments passed to |
at |
Character string specifying whether to compute the probability values
at a grid of pixel locations ( |
weights |
Optional. Weights for the data points of |
varcov |
Optional. Variance-covariance matrix of anisotopic Gaussian
smoothing kernel. Incompatible with |
relative |
Logical.
If |
adjust |
Optional. Adjustment factor for the bandwidth |
edge |
Logical value indicating whether to apply edge correction. |
diggle |
Logical. If |
se |
Logical value indicating whether to compute standard errors as well. |
wtype |
Character string (partially matched) specifying how the weights should be interpreted for the calculation of standard error. See Details. |
casecontrol |
Logical. Whether to treat a bivariate point pattern as consisting of cases and controls, and return only the probability or relative risk of a case. Ignored if there are more than 2 types of points. See Details. |
control |
Integer, or character string, identifying which mark value corresponds to a control. |
case |
Integer, or character string, identifying which mark value
corresponds to a case (rather than a control)
in a bivariate point pattern.
This is an alternative to the argument |
fudge |
Optional. A single numeric value, or a numeric vector with one entry for each type of point. This value will be added to the estimates of point process intensity, before calculation of the relative risk. |
The command relrisk
is generic and can be used to
estimate relative risk in different ways.
This function relrisk.ppp
is the method for point pattern
datasets. It computes nonparametric estimates of relative risk
by kernel smoothing (Bithell, 1990, 1991; Diggle, 2003; Baddeley,
Rubak and Turner, 2015).
If X
is a bivariate point pattern
(a multitype point pattern consisting of two types of points)
then by default,
the points of the first type (the first level of marks(X)
)
are treated as controls or non-events, and points of the second type
are treated as cases or events. Then by default this command computes
the spatially-varying probability of a case,
i.e. the probability
that a point at spatial location
will be a case. If
relative=TRUE
, it computes the
spatially-varying relative risk of a case relative to a
control, .
If X
is a multitype point pattern with types,
or if
X
is a bivariate point pattern
and casecontrol=FALSE
,
then by default this command computes, for each type ,
a nonparametric estimate of
the spatially-varying probability of an event of type
.
This is the probability
that a point at spatial location
will belong to type
.
If
relative=TRUE
, the command computes the
relative risk of an event of type
relative to a control,
,
where events of type
are treated as controls.
The argument
control
determines which type
is treated as a control.
If at = "pixels"
the calculation is performed for
every spatial location on a fine pixel grid, and the result
is a pixel image representing the function
or a list of pixel images representing the functions
or
for
.
An infinite value of relative risk (arising because the
probability of a control is zero) will be returned as
NA
.
If at = "points"
the calculation is performed
only at the data points . By default
the result is a vector of values
giving the estimated probability of a case
at each data point, or a matrix of values
giving the estimated probability of
each possible type
at each data point.
If
relative=TRUE
then the relative risks
or
are
returned.
An infinite value of relative risk (arising because the
probability of a control is zero) will be returned as
Inf
.
Estimation is performed by a simple Nadaraja-Watson type kernel smoother (Bithell, 1990, 1991; Diggle, 2003; Baddeley, Rubak and Turner, 2015, section 14.4). The smoothing bandwidth can be specified in any of the following ways:
sigma
is a single numeric value, giving the standard
deviation of the isotropic Gaussian kernel.
sigma
is a numeric vector of length 2, giving the
standard deviations in the and
directions of
a Gaussian kernel.
varcov
is a 2 by 2 matrix giving the
variance-covariance matrix of the Gaussian kernel.
sigma
is a function
which selects
the bandwidth.
Bandwidth selection will be applied
separately to each type of point.
An example of such a function is bw.diggle
.
sigma
and varcov
are both missing or null. Then a common
smoothing bandwidth sigma
will be selected by cross-validation using bw.relrisk
.
An infinite smoothing bandwidth, sigma=Inf
, is permitted
and yields a constant estimate of relative risk.
If se=TRUE
then standard errors will also be computed,
based on asymptotic theory, assuming a Poisson process.
The optional argument weights
may provide numerical weights
for the points of X
. It should be a numeric vector of length
equal to npoints(X)
.
The argument weights
can also be an expression
.
It will be evaluated in the data frame as.data.frame(X)
to obtain a vector of weights. The expression may involve
the symbols x
and y
representing the Cartesian
coordinates, and the symbol marks
representing the mark values.
The argument weights
can also be a pixel image
(object of class "im"
). numerical weights for the data points
will be extracted from this image (by looking up the pixel values
at the locations of the data points in X
).
If se=FALSE
(the default), the format is described below.
If se=TRUE
, the result is a list of two entries,
estimate
and SE
, each having the format described below.
If X
consists of only two types of points,
and if casecontrol=TRUE
,
the result is a pixel image (if at="pixels"
)
or a vector (if at="points"
).
The pixel values or vector values
are the probabilities of a case if relative=FALSE
,
or the relative risk of a case (probability of a case divided by the
probability of a control) if relative=TRUE
.
If X
consists of more than two types of points,
or if casecontrol=FALSE
, the result is:
(if at="pixels"
)
a list of pixel images, with one image for each possible type of point.
The result also belongs to the class "solist"
so that it can
be printed and plotted.
(if at="points"
)
a matrix of probabilities, with rows corresponding to
data points , and columns corresponding
to types
.
The pixel values or matrix entries
are the probabilities of each type of point if relative=FALSE
,
or the relative risk of each type (probability of each type divided by the
probability of a control) if relative=TRUE
.
If relative=FALSE
, the resulting values always lie between 0
and 1. If relative=TRUE
, the results are either non-negative
numbers, or the values Inf
or NA
.
If se=TRUE
, the standard error of the estimate will also be
calculated. The calculation assumes a Poisson point process.
If weights
are given, then the calculation of standard error
depends on the interpretation of the weights. This is controlled by
the argument wtype
.
If wtype="value"
(the default),
the weights are interpreted as numerical values observed
at the data locations. Roughly speaking,
standard errors are proportional to the absolute
values of the weights.
If wtype="multiplicity"
the weights are interpreted as
multiplicities so that a weight of 2 is equivalent to having a pair
of duplicated points at the data location. Roughly speaking,
standard errors are proportional
to the square roots of the weights. Negative weights are not
permitted.
The default rule is now wtype="value"
but previous versions
of relrisk.ppp
(in spatstat.explore versions
3.1-0
and earlier) effectively used wtype="multiplicity"
.
Adrian Baddeley [email protected] and Rolf Turner [email protected].
Baddeley, A., Rubak, E. and Turner, R. (2015) Spatial Point Patterns: Methodology and Applications with R. Chapman and Hall/CRC Press.
Bithell, J.F. (1990) An application of density estimation to geographical epidemiology. Statistics in Medicine 9, 691–701.
Bithell, J.F. (1991) Estimation of relative risk functions. Statistics in Medicine 10, 1745–1751.
Diggle, P.J. (2003) Statistical analysis of spatial point patterns, Second edition. Arnold.
Diggle, P.J., Zheng, P. and Durr, P. (2005) Non-parametric estimation of spatial segregation in a multivariate point process: bovine tuberculosis in Cornwall, UK. Applied Statistics 54, 645–658.
There is another method relrisk.ppm
for point process
models which computes parametric
estimates of relative risk, using the fitted model.
See also
bw.relrisk
,
density.ppp
,
Smooth.ppp
,
eval.im
p.oak <- relrisk(urkiola, 20) if(interactive()) { plot(p.oak, main="proportion of oak") plot(eval.im(p.oak > 0.3), main="More than 30 percent oak") plot(split(lansing), main="Lansing Woods") p.lan <- relrisk(lansing, 0.05, se=TRUE) plot(p.lan$estimate, main="Lansing Woods species probability") plot(p.lan$SE, main="Lansing Woods standard error") wh <- im.apply(p.lan$estimate, which.max) types <- levels(marks(lansing)) wh <- eval.im(types[wh]) plot(wh, main="Most common species") }
p.oak <- relrisk(urkiola, 20) if(interactive()) { plot(p.oak, main="proportion of oak") plot(eval.im(p.oak > 0.3), main="More than 30 percent oak") plot(split(lansing), main="Lansing Woods") p.lan <- relrisk(lansing, 0.05, se=TRUE) plot(p.lan$estimate, main="Lansing Woods species probability") plot(p.lan$SE, main="Lansing Woods standard error") wh <- im.apply(p.lan$estimate, which.max) types <- levels(marks(lansing)) wh <- eval.im(types[wh]) plot(wh, main="Most common species") }
Computes the conditional probability estimator of relative risk based on a multitype point pattern using the diffusion estimate of the type-specific intensities.
relriskHeat(X, ...) ## S3 method for class 'ppp' relriskHeat(X, ..., sigmaX=NULL, weights=NULL)
relriskHeat(X, ...) ## S3 method for class 'ppp' relriskHeat(X, ..., sigmaX=NULL, weights=NULL)
X |
A multitype point pattern (object of class |
... |
Arguments passed to |
sigmaX |
Optional.
Numeric vector of bandwidths, one associated with each data point in
|
weights |
Optional numeric vector of weights associated with each point of
|
The function relriskHeat
is generic. This file documents the
method relriskHeat.ppp
for spatial point patterns (objects of
class "ppp"
).
This function estimates the spatially-varying conditional probability that a random point (given that it is present) will belong to a given type.
The algorithm separates X
into
the sub-patterns consisting of points of each type.
It then applies densityHeat
to each sub-pattern,
using the same bandwidth and smoothing regimen for each sub-pattern,
as specified by the arguments ...
.
If weights
is specified, it should be a numeric vector
of length equal to the number of points in X
, so that
weights[i]
is the weight for data point X[i]
.
Similarly when performing lagged-arrival smoothing,
the argument sigmaX
must be a numeric vector of the same length
as the number of points in X
, and thus contain the
point-specific bandwidths in the order corresponding to each of these
points regardless of mark.
A named list (of class solist
)
containing pixel im
ages,
giving the estimated conditional probability surfaces for each type.
Adrian Baddeley [email protected] and Tilman Davies [email protected].
Agarwal, N. and Aluru, N.R. (2010) A data-driven stochastic collocation approach for uncertainty quantification in MEMS. International Journal for Numerical Methods in Engineering 83, 575–597.
Baddeley, A., Davies, T., Rakshit, S., Nair, G. and McSwiggan, G. (2022) Diffusion smoothing for spatial point patterns. Statistical Science 37, 123–142.
Barry, R.P. and McIntyre, J. (2011) Estimating animal densities and home range in regions with irregular boundaries and holes: a lattice-based alternative to the kernel density estimator. Ecological Modelling 222, 1666–1672.
Botev, Z.I. and Grotowski, J.F. and Kroese, D.P. (2010) Kernel density estimation via diffusion. Annals of Statistics 38, 2916–2957.
relrisk.ppp
for the
traditional convolution-based kernel estimator of
conditional probability surfaces,
and the function risk
in the sparr package for the
density-ratio-based estimator.
## bovine tuberculosis data X <- subset(btb, select=spoligotype) plot(X) P <- relriskHeat(X,sigma=9) plot(P)
## bovine tuberculosis data X <- subset(btb, select=spoligotype) plot(X) P <- relriskHeat(X,sigma=9) plot(P)
Given a point pattern and two spatial covariates and
, construct a smooth estimate of the relative risk of
the pair
.
rho2hat(object, cov1, cov2, ..., method=c("ratio", "reweight"))
rho2hat(object, cov1, cov2, ..., method=c("ratio", "reweight"))
object |
A point pattern (object of class |
cov1 , cov2
|
The two covariates.
Each argument is either a |
... |
Additional arguments passed to |
method |
Character string determining the smoothing method. See Details. |
This is a bivariate version of rhohat
.
If object
is a point pattern, this command
produces a smoothed version of the scatterplot of
the values of the covariates cov1
and cov2
observed at the points of the point pattern.
The covariates cov1,cov2
must have continuous values.
If object
is a fitted point process model, suppose X
is
the original data point pattern to which the model was fitted. Then
this command assumes X
is a realisation of a Poisson point
process with intensity function of the form
where is the intensity of the fitted model
object
, and is a function
to be estimated. The algorithm computes a smooth estimate of the
function
.
The method
determines how the density estimates will be
combined to obtain an estimate of :
If method="ratio"
, then is
estimated by the ratio of two density estimates.
The numerator is a (rescaled) density estimate obtained by
smoothing the points
obtained by evaluating the two covariate
at the data points
. The denominator
is a density estimate of the reference distribution of
.
If method="reweight"
, then is
estimated by applying density estimation to the
points
obtained by evaluating the two covariate
at the data points
,
with weights inversely proportional to the reference density of
.
A pixel image (object of class "im"
). Also
belongs to the special class "rho2hat"
which has a plot method.
Adrian Baddeley [email protected]
Baddeley, A., Chang, Y.-M., Song, Y. and Turner, R. (2012) Nonparametric estimation of the dependence of a point process on spatial covariates. Statistics and Its Interface 5 (2), 221–236.
attach(bei.extra) plot(rho2hat(bei, elev, grad)) if(require("spatstat.model")) { fit <- ppm(bei ~elev, covariates=bei.extra) plot(rho2hat(fit, elev, grad)) plot(rho2hat(fit, elev, grad, method="reweight")) }
attach(bei.extra) plot(rho2hat(bei, elev, grad)) if(require("spatstat.model")) { fit <- ppm(bei ~elev, covariates=bei.extra) plot(rho2hat(fit, elev, grad)) plot(rho2hat(fit, elev, grad, method="reweight")) }
Computes a nonparametric estimate of the intensity of a point process, as a function of a (continuous) spatial covariate.
rhohat(object, covariate, ...) ## S3 method for class 'ppp' rhohat(object, covariate, ..., baseline=NULL, weights=NULL, method=c("ratio", "reweight", "transform"), horvitz=FALSE, smoother=c("kernel", "local", "decreasing", "increasing", "mountain", "valley", "piecewise"), subset=NULL, do.CI=TRUE, jitter=TRUE, jitterfactor=1, interpolate=TRUE, dimyx=NULL, eps=NULL, rule.eps = c("adjust.eps", "grow.frame", "shrink.frame"), n = 512, bw = "nrd0", adjust=1, from = NULL, to = NULL, bwref=bw, covname, confidence=0.95, positiveCI, breaks=NULL) ## S3 method for class 'quad' rhohat(object, covariate, ..., baseline=NULL, weights=NULL, method=c("ratio", "reweight", "transform"), horvitz=FALSE, smoother=c("kernel", "local", "decreasing", "increasing", "mountain", "valley", "piecewise"), subset=NULL, do.CI=TRUE, jitter=TRUE, jitterfactor=1, interpolate=TRUE, dimyx=NULL, eps=NULL, rule.eps = c("adjust.eps", "grow.frame", "shrink.frame"), n = 512, bw = "nrd0", adjust=1, from = NULL, to = NULL, bwref=bw, covname, confidence=0.95, positiveCI, breaks=NULL)
rhohat(object, covariate, ...) ## S3 method for class 'ppp' rhohat(object, covariate, ..., baseline=NULL, weights=NULL, method=c("ratio", "reweight", "transform"), horvitz=FALSE, smoother=c("kernel", "local", "decreasing", "increasing", "mountain", "valley", "piecewise"), subset=NULL, do.CI=TRUE, jitter=TRUE, jitterfactor=1, interpolate=TRUE, dimyx=NULL, eps=NULL, rule.eps = c("adjust.eps", "grow.frame", "shrink.frame"), n = 512, bw = "nrd0", adjust=1, from = NULL, to = NULL, bwref=bw, covname, confidence=0.95, positiveCI, breaks=NULL) ## S3 method for class 'quad' rhohat(object, covariate, ..., baseline=NULL, weights=NULL, method=c("ratio", "reweight", "transform"), horvitz=FALSE, smoother=c("kernel", "local", "decreasing", "increasing", "mountain", "valley", "piecewise"), subset=NULL, do.CI=TRUE, jitter=TRUE, jitterfactor=1, interpolate=TRUE, dimyx=NULL, eps=NULL, rule.eps = c("adjust.eps", "grow.frame", "shrink.frame"), n = 512, bw = "nrd0", adjust=1, from = NULL, to = NULL, bwref=bw, covname, confidence=0.95, positiveCI, breaks=NULL)
object |
A point pattern (object of class |
covariate |
Either a |
weights |
Optional weights attached to the data points.
Either a numeric vector of weights for each data point,
or a pixel image (object of class |
baseline |
Optional baseline for intensity function.
A |
method |
Character string determining the estimation method. See Details. |
horvitz |
Logical value indicating whether to use Horvitz-Thompson weights. See Details. |
smoother |
Character string determining the smoothing algorithm and the type of curve that will be estimated. See Details. |
subset |
Optional. A spatial window (object of class |
do.CI |
Logical value specifying whether to calculate standard errors and confidence bands. |
jitter |
Logical value. If |
jitterfactor |
Numeric value controlling the scale of noise added to the
covariate values at the data points when |
interpolate |
Logical value specifying whether to use spatial interpolation
to obtain the values of the covariate at the data points,
when the covariate is a pixel image
(object of class |
dimyx , eps , rule.eps
|
Arguments controlling the pixel resolution at which the covariate will be evaluated. See Details. |
bw |
Smoothing bandwidth or bandwidth rule
(passed to |
adjust |
Smoothing bandwidth adjustment factor
(passed to |
n , from , to
|
Arguments passed to |
bwref |
Optional. An alternative value of |
... |
Additional arguments passed to |
covname |
Optional. Character string to use as the name of the covariate. |
confidence |
Confidence level for confidence intervals. A number between 0 and 1. |
positiveCI |
Logical value.
If |
breaks |
Breakpoints for the piecewise-constant function
computed when |
This command estimates the relationship between point process intensity and a given spatial covariate. Such a relationship is sometimes called a resource selection function (if the points are organisms and the covariate is a descriptor of habitat) or a prospectivity index (if the points are mineral deposits and the covariate is a geological variable). This command uses nonparametric methods which do not assume a particular form for the relationship.
If object
is a point pattern, and baseline
is missing or
null, this command assumes that object
is a realisation of a
point process with intensity function
of the form
where is the spatial
covariate function given by
covariate
, and
is the resource selection function
or prospectivity index.
A nonparametric estimator of the function
is computed.
If object
is a point pattern, and baseline
is given,
then the intensity function is assumed to be
where is the baseline intensity at location
.
A nonparametric estimator of the relative intensity
is computed.
If object
is a fitted point process model, suppose X
is
the original data point pattern to which the model was fitted. Then
this command assumes X
is a realisation of a Poisson point
process with intensity function of the form
where is the intensity of the fitted model
object
. A nonparametric estimator of
the relative intensity is computed.
The nonparametric estimation procedure is controlled by the
arguments smoother
, method
and horvitz
.
The argument smoother
selects the type of estimation technique.
If smoother="kernel"
(the default),
the nonparametric estimator is a kernel smoothing estimator
of (Guan, 2008; Baddeley et al, 2012).
The estimated function
will be
a smooth function of
which takes nonnegative values.
If
do.CI=TRUE
(the default),
confidence bands are also computed, assuming a Poisson point process.
See the section on Smooth estimates.
If smoother="local"
,
the nonparametric estimator is a local regression estimator
of (Baddeley et al, 2012) obtained using
local likelihood.
The estimated function
will be
a smooth function of
.
If
do.CI=TRUE
(the default),
confidence bands are also computed, assuming a Poisson point process.
See the section on Smooth estimates.
If smoother="increasing"
, we assume that
is an increasing function of
,
and use the nonparametric maximum likelihood estimator
of
described by Sager (1982).
The estimated function will be a step function, that is increasing
as a function of
. Confidence bands are not computed.
See the section on Monotone estimates.
If smoother="decreasing"
, we assume that
is a decreasing function of
,
and use the nonparametric maximum likelihood estimator
of
described by Sager (1982).
The estimated function will be a step function, that is decreasing
as a function of
. Confidence bands are not computed.
See the section on Monotone estimates.
If smoother="mountain"
, we assume that
is a function with an inverted U shape,
with a single peak at a value
, so that
is an increasing function of
for
and a decreasing function of
for
.
We compute the nonparametric maximum likelihood estimator.
The estimated function will be a step function, which is
increasing and then decreasing as a function of
.
Confidence bands are not computed.
See the section on Unimodal estimates.
If smoother="valley"
, we assume that
is a function with a U shape,
with a single minimum at a value
, so that
is a decreasing function of
for
and an increasing function of
for
.
We compute the nonparametric maximum likelihood estimator.
The estimated function will be a step function, which is
decreasing and then increasing as a function of
.
Confidence bands are not computed.
See the section on Unimodal estimates.
If smoother="piecewise"
, the estimate of
is piecewise constant.
The range of covariate values is divided into several intervals
(ranges or bands). The endpoints of these intervals are the
breakpoints, which may be specified by the argument
breaks
;
there is a sensible default. The estimate of
takes a constant value on each interval.
The estimate of
in each interval of covariate
values is simply the average intensity
(number of points per unit area) in the relevant sub-region.
If
do.CI=TRUE
(the default),
confidence bands are computed assuming a Poisson process.
See Baddeley (2018) for a comparison of these estimation techniques
(except for "mountain"
and "valley"
).
If the argument weights
is present, then the contribution
from each data point X[i]
to the estimate of is
multiplied by
weights[i]
.
If the argument subset
is present, then the calculations are
performed using only the data inside this spatial region.
This technique assumes that covariate
has continuous values.
It is not applicable to covariates with categorical (factor) values
or discrete values such as small integers.
For a categorical covariate, use
intensity.quadratcount
applied to the result of
quadratcount(X, tess=covariate)
.
The argument covariate
should be a pixel image, or a function,
or one of the strings "x"
or "y"
signifying the
cartesian coordinates. It will be evaluated on a fine grid of locations,
with spatial resolution controlled by the arguments
dimyx,eps,rule.eps
which are passed to as.mask
.
A function value table (object of class "fv"
)
containing the estimated values of
(and confidence limits) for a sequence of values of
.
Also belongs to the class
"rhohat"
which has special methods for print
, plot
and predict
.
Smooth estimators of
were proposed by Baddeley and Turner (2005) and Baddeley et al (2012).
Similar estimators were proposed by Guan (2008) and in the literature
on relative distributions (Handcock and Morris, 1999).
The estimated function will be a smooth function
of
.
The smooth estimation procedure involves computing several density estimates
and combining them. The algorithm used to compute density estimates is
determined by smoother
:
If smoother="kernel"
,
the smoothing procedure is based on
fixed-bandwidth kernel density estimation,
performed by density.default
.
If smoother="local"
, the smoothing procedure
is based on local likelihood density estimation, performed by
locfit
.
The argument method
determines how the density estimates will be
combined to obtain an estimate of :
If method="ratio"
, then is
estimated by the ratio of two density estimates,
The numerator is a (rescaled) density estimate obtained by
smoothing the values
of the covariate
observed at the data points
. The denominator
is a density estimate of the reference distribution of
.
See Baddeley et al (2012), equation (8). This is similar but not
identical to an estimator proposed by Guan (2008).
If method="reweight"
, then is
estimated by applying density estimation to the
values
of the covariate
observed at the data points
,
with weights inversely proportional to the reference density of
.
See Baddeley et al (2012), equation (9).
If method="transform"
,
the smoothing method is variable-bandwidth kernel
smoothing, implemented by applying the Probability Integral Transform
to the covariate values, yielding values in the range 0 to 1,
then applying edge-corrected density estimation on the interval
, and back-transforming.
See Baddeley et al (2012), equation (10).
If horvitz=TRUE
, then the calculations described above
are modified by using Horvitz-Thompson weighting.
The contribution to the numerator from
each data point is weighted by the reciprocal of the
baseline value or fitted intensity value at that data point;
and a corresponding adjustment is made to the denominator.
Pointwise confidence intervals for the true value of
are also calculated for each
,
and will be plotted as grey shading.
The confidence intervals are derived using the central limit theorem,
based on variance calculations which assume a Poisson point process.
If
positiveCI=FALSE
, the lower limit of the confidence
interval may sometimes be negative, because the confidence intervals
are based on a normal approximation to the estimate of .
If
positiveCI=TRUE
, the confidence limits are always
positive, because the confidence interval is based on a normal
approximation to the estimate of .
For consistency with earlier versions, the default is
positiveCI=FALSE
for smoother="kernel"
and positiveCI=TRUE
for smoother="local"
.
The nonparametric maximum likelihood estimator
of a monotone function was described by Sager (1982).
This method assumes that
is either an increasing
function of
, or a decreasing function of
.
The estimated function will be a step function,
increasing or decreasing as a function of
.
This estimator is chosen by specifying
smoother="increasing"
or smoother="decreasing"
.
The argument method
is ignored this case.
To compute the estimate of , the algorithm first
computes several primitive step-function estimates, and then takes
the maximum of these primitive functions.
If smoother="decreasing"
, each primitive step function
takes the form when
,
and
when
, where
and
is a primitive estimate of intensity
based on the data for
. The jump location
will be the value of the covariate
at one of the
data points. The primitive estimate
is the average intensity (number of points divided by area)
for the region of space where the covariate value is less than
or equal to
.
If horvitz=TRUE
, then the calculations described above
are modified by using Horvitz-Thompson weighting.
The contribution to the numerator from
each data point is weighted by the reciprocal of the
baseline value or fitted intensity value at that data point;
and a corresponding adjustment is made to the denominator.
Confidence intervals are not available for the monotone estimators.
If smoother="valley"
then we estimate a U-shaped function.
A function is U-shaped if it is
decreasing when
and
increasing when
, where
is
called the critical value. The nonparametric maximum likelihood
estimate of such a function can be computed by profiling over
.
The algorithm considers all possible candidate values of the critical value
, and estimates the function
separately on the left and right of
using the monotone
estimators described above. These function estimates are combined into
a single function, and the Poisson point process likelihood is
computed. The optimal value of
is the one which maximises the Poisson point process likelihood.
If smoother="mountain"
then we estimate a function which has
an inverted U shape. A function is
inverted-U-shaped if it is
increasing when
and
decreasing when
. The nonparametric maximum likelihood
estimate of such a function can be computed by profiling over
using the same technique mutatis mutandis.
Confidence intervals are not available for the unimodal estimators.
By default, rhohat
adds a small amount of random noise to the
data. This is designed to suppress the effects of
discretisation in pixel images.
This strategy means that rhohat
does not produce exactly the same result when the computation is
repeated. If you need the results to be exactly reproducible, set
jitter=FALSE
.
By default, the values of the covariate at the data points
will be randomly perturbed by adding a small amount
of noise using the function jitter
. To reduce this
effect, set jitterfactor
to a number smaller than 1. To
suppress this effect entirely, set jitter=FALSE
.
Smoothing algorithm by Adrian Baddeley [email protected], Ya-Mei Chang, Yong Song, and Rolf Turner [email protected].
Nonparametric maximum likelihood algorithm by Adrian Baddeley [email protected].
Baddeley, A., Chang, Y.-M., Song, Y. and Turner, R. (2012) Nonparametric estimation of the dependence of a point process on spatial covariates. Statistics and Its Interface 5 (2), 221–236.
Baddeley, A. and Turner, R. (2005) Modelling spatial point patterns in R. In: A. Baddeley, P. Gregori, J. Mateu, R. Stoica, and D. Stoyan, editors, Case Studies in Spatial Point Pattern Modelling, Lecture Notes in Statistics number 185. Pages 23–74. Springer-Verlag, New York, 2006. ISBN: 0-387-28311-0.
Baddeley, A. (2018) A statistical commentary on mineral prospectivity analysis. Chapter 2, pages 25–65 in Handbook of Mathematical Geosciences: Fifty Years of IAMG, edited by B.S. Daya Sagar, Q. Cheng and F.P. Agterberg. Springer, Berlin.
Guan, Y. (2008) On consistent nonparametric intensity estimation for inhomogeneous spatial point processes. Journal of the American Statistical Association 103, 1238–1247.
Handcock, M.S. and Morris, M. (1999) Relative Distribution Methods in the Social Sciences. Springer, New York.
Sager, T.W. (1982) Nonparametric maximum likelihood estimation of spatial patterns. Annals of Statistics 10, 1125–1136.
rho2hat
,
methods.rhohat
,
parres
.
See ppm
for a parametric method for the same problem.
X <- rpoispp(function(x,y){exp(3+3*x)}) rho <- rhohat(X, "x") rho <- rhohat(X, function(x,y){x}) plot(rho) curve(exp(3+3*x), lty=3, col=4, lwd=2, add=TRUE) rhoB <- rhohat(X, "x", method="reweight") rhoC <- rhohat(X, "x", method="transform") rhoI <- rhohat(X, "x", smoother="increasing") rhoM <- rhohat(X, "x", smoother="mountain") plot(rhoI, add=TRUE, .y ~ .x, col=6) legend("top", lty=c(3, 1), col=c(4, 6), lwd=c(2, 1), legend=c("true", "increasing"))
X <- rpoispp(function(x,y){exp(3+3*x)}) rho <- rhohat(X, "x") rho <- rhohat(X, function(x,y){x}) plot(rho) curve(exp(3+3*x), lty=3, col=4, lwd=2, add=TRUE) rhoB <- rhohat(X, "x", method="reweight") rhoC <- rhohat(X, "x", method="transform") rhoI <- rhohat(X, "x", smoother="increasing") rhoM <- rhohat(X, "x", smoother="mountain") plot(rhoI, add=TRUE, .y ~ .x, col=6) legend("top", lty=c(3, 1), col=c(4, 6), lwd=c(2, 1), legend=c("true", "increasing"))
Computes the Receiver Operating Characteristic curve for a point pattern or a fitted point process model.
roc(X, ...) ## S3 method for class 'ppp' roc(X, covariate, ..., high = TRUE)
roc(X, ...) ## S3 method for class 'ppp' roc(X, covariate, ..., high = TRUE)
X |
Point pattern (object of class |
covariate |
Spatial covariate. Either a |
high |
Logical value indicating whether the threshold operation should favour high or low values of the covariate. |
... |
Arguments passed to |
This command computes Receiver Operating
Characteristic curve. The area under the ROC is computed by auc
.
For a point pattern X
and a covariate Z
, the
ROC is a plot showing the ability of the
covariate to separate the spatial domain
into areas of high and low density of points.
For each possible threshold , the algorithm calculates
the fraction
of area in the study region where the
covariate takes a value greater than
, and the
fraction
of data points for which the covariate value
is greater than
. The ROC is a plot of
against
for all thresholds
.
For a fitted point process model, the ROC shows the ability of the fitted model intensity to separate the spatial domain into areas of high and low density of points. The ROC is not a diagnostic for the goodness-of-fit of the model (Lobo et al, 2007).
(For spatial logistic regression models (class "slrm"
)
replace “intensity” by “probability of presence”
in the text above.)
Function value table (object of class "fv"
)
which can be plotted to show the ROC curve.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Lobo, J.M., Jimenez-Valverde, A. and Real, R. (2007) AUC: a misleading measure of the performance of predictive distribution models. Global Ecology and Biogeography 17(2) 145–151.
Nam, B.-H. and D'Agostino, R. (2002) Discrimination index, the area under the ROC curve. Pages 267–279 in Huber-Carol, C., Balakrishnan, N., Nikulin, M.S. and Mesbah, M., Goodness-of-fit tests and model validity, Birkhauser, Basel.
plot(roc(swedishpines, "x"))
plot(roc(swedishpines, "x"))
Plots a rose diagram (rose of directions), the analogue of a histogram or density plot for angular data.
rose(x, ...) ## Default S3 method: rose(x, breaks = NULL, ..., weights=NULL, nclass = NULL, unit = c("degree", "radian"), start=0, clockwise=FALSE, main) ## S3 method for class 'histogram' rose(x, ..., unit = c("degree", "radian"), start=0, clockwise=FALSE, main, labels=TRUE, at=NULL, do.plot = TRUE) ## S3 method for class 'density' rose(x, ..., unit = c("degree", "radian"), start=0, clockwise=FALSE, main, labels=TRUE, at=NULL, do.plot = TRUE) ## S3 method for class 'fv' rose(x, ..., unit = c("degree", "radian"), start=0, clockwise=FALSE, main, labels=TRUE, at=NULL, do.plot = TRUE)
rose(x, ...) ## Default S3 method: rose(x, breaks = NULL, ..., weights=NULL, nclass = NULL, unit = c("degree", "radian"), start=0, clockwise=FALSE, main) ## S3 method for class 'histogram' rose(x, ..., unit = c("degree", "radian"), start=0, clockwise=FALSE, main, labels=TRUE, at=NULL, do.plot = TRUE) ## S3 method for class 'density' rose(x, ..., unit = c("degree", "radian"), start=0, clockwise=FALSE, main, labels=TRUE, at=NULL, do.plot = TRUE) ## S3 method for class 'fv' rose(x, ..., unit = c("degree", "radian"), start=0, clockwise=FALSE, main, labels=TRUE, at=NULL, do.plot = TRUE)
x |
Data to be plotted.
A numeric vector containing angles,
or a |
breaks , nclass
|
Arguments passed to |
... |
Additional arguments passed to |
unit |
The unit in which the angles are expressed. |
start |
The starting direction for measurement of angles,
that is, the spatial direction which corresponds to a measured angle
of zero. Either a character string giving a compass direction
( |
clockwise |
Logical value indicating whether angles increase in the clockwise
direction ( |
weights |
Optional vector of numeric weights associated with |
main |
Optional main title for the plot. |
labels |
Either a logical value indicating whether to plot labels next to the tick marks, or a vector of labels for the tick marks. |
at |
Optional vector of angles at which tick marks should be plotted.
Set |
do.plot |
Logical value indicating whether to really perform the plot. |
A rose diagram or rose of directions is the analogue of a histogram or bar chart for data which represent angles in two dimensions. The bars of the bar chart are replaced by circular sectors in the rose diagram.
The function rose
is generic, with a default method
for numeric data, and methods for histograms and function tables.
If x
is a numeric vector, it must contain angular values
in the range 0 to 360 (if unit="degree"
)
or in the range 0 to 2 * pi
(if unit="radian"
).
A histogram of the data will first be computed using
hist
. Then the rose diagram of this histogram
will be plotted by rose.histogram
.
If x
is an object of class "histogram"
produced by
the function hist
, representing the histogram
of angular data, then the rose diagram of the densities
(rather than the counts) in this histogram object will be plotted.
If x
is an object of class "density"
produced by
circdensity
or density.default
,
representing a kernel smoothed density estimate of angular data,
then the rose diagram of the density estimate will be plotted.
If x
is a function value table (object of class "fv"
)
then the argument of the function will be interpreted as an angle,
and the value of the function will be interpreted as the radius.
By default, angles are interpreted using the mathematical convention
where the zero angle is the horizontal axis, and angles
increase anti-clockwise. Other conventions can be specified
using the arguments
start
and clockwise
.
Standard compass directions are obtained by setting unit="degree"
,
start="N"
and clockwise=TRUE
.
A window (class "owin"
) containing the plotted region.
Adrian Baddeley [email protected]
Rolf Turner [email protected]
and Ege Rubak [email protected]
fv
, hist
,
circdensity
,
density.default
.
ang <- runif(1000, max=360) rose(ang, col="grey") rose(ang, col="grey", start="N", clockwise=TRUE)
ang <- runif(1000, max=360) rose(ang, col="grey") rose(ang, col="grey", start="N", clockwise=TRUE)
Compute the average pixel value over all rotations of the image about the origin, as a function of distance from the origin.
rotmean(X, ..., origin, padzero=TRUE, Xname, result=c("fv", "im"), adjust=1)
rotmean(X, ..., origin, padzero=TRUE, Xname, result=c("fv", "im"), adjust=1)
X |
A pixel image. |
... |
Ignored. |
origin |
Optional. Origin about which the rotations should be performed.
Either a numeric vector or a character string as described
in the help for |
padzero |
Logical. If |
Xname |
Optional name for |
result |
Character string specifying the kind of result required: either a function object or a pixel image. |
adjust |
Adjustment factor for bandwidth used in kernel smoothing. |
This command computes, for each possible distance ,
the average pixel value of the pixels lying at
distance
from the origin. Kernel smoothing is used
to obtain a smooth function of
.
If result="fv"
(the default) the result is a function
object of class "fv"
giving the mean pixel value of X
as a function of distance from the origin.
If result="im"
the result is a pixel image, with the same
dimensions as X
, giving the mean value of X
over all pixels lying at the same distance from the origin
as the current pixel.
If padzero=TRUE
(the default), the value of X
is assumed to be zero outside the window of X
. The rotational
mean at a given distance is the average value of the image
X
over the entire circle of radius ,
including zero values outside the window if the circle
lies partly outside the window.
If padzero=FALSE
, the value of X
is taken to be
undefined outside the window of X
. The rotational mean
is the average of the X
values over the subset of the circle
of radius that lies entirely inside the window.
An object of class "fv"
or "im"
,
with the same coordinate units as X
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
online <- interactive() resolution <- if(online) 128 else 32 Z <- setcov(square(1), dimyx=resolution) f <- rotmean(Z) if(online) { plot(rotmean(Z)) plot(rotmean(Z, result="im")) }
online <- interactive() resolution <- if(online) 128 else 32 Z <- setcov(square(1), dimyx=resolution) f <- rotmean(Z) if(online) { plot(rotmean(Z)) plot(rotmean(Z, result="im")) }
Performs the Spatial Scan Test for clustering in a spatial point pattern, or for clustering of one type of point in a bivariate spatial point pattern.
scan.test(X, r, ..., method = c("poisson", "binomial"), nsim = 19, baseline = NULL, case = 2, alternative = c("greater", "less", "two.sided"), verbose = TRUE)
scan.test(X, r, ..., method = c("poisson", "binomial"), nsim = 19, baseline = NULL, case = 2, alternative = c("greater", "less", "two.sided"), verbose = TRUE)
X |
A point pattern (object of class |
r |
Radius of circle to use. A single number or a numeric vector. |
... |
Optional. Arguments passed to |
method |
Either |
nsim |
Number of simulations for computing Monte Carlo p-value. |
baseline |
Baseline for the Poisson intensity, if |
case |
Which type of point should be interpreted as a case,
if |
alternative |
Alternative hypothesis: |
verbose |
Logical. Whether to print progress reports. |
The spatial scan test (Kulldorf, 1997) is applied
to the point pattern X
.
In a nutshell,
If method="poisson"
then
a significant result would mean that there is a circle of radius
r
, located somewhere in the spatial domain of the data,
which contains a significantly higher than
expected number of points of X
. That is, the
pattern X
exhibits spatial clustering.
If method="binomial"
then X
must be a bivariate (two-type)
point pattern. By default, the first type of point is interpreted as
a control (non-event) and the second type of point as a case (event).
A significant result would mean that there is a
circle of radius r
which contains a significantly higher than
expected number of cases. That is, the cases are clustered together,
conditional on the locations of all points.
Following is a more detailed explanation.
If method="poisson"
then the scan test based on Poisson
likelihood is performed (Kulldorf, 1997).
The dataset X
is treated as an unmarked point pattern.
By default (if baseline
is not specified)
the null hypothesis is complete spatial randomness CSR
(i.e. a uniform Poisson process).
The alternative hypothesis is a Poisson process with
one intensity inside some circle of radius
r
and another intensity outside the
circle.
If
baseline
is given, then it should be a pixel image
or a function(x,y)
. The null hypothesis is
an inhomogeneous Poisson process with intensity proportional
to baseline
. The alternative hypothesis is an inhomogeneous
Poisson process with intensity
beta1 * baseline
inside some circle of radius r
,
and beta0 * baseline
outside the circle.
If method="binomial"
then the scan test based on
binomial likelihood is performed (Kulldorf, 1997).
The dataset X
must be a bivariate point pattern,
i.e. a multitype point pattern with two types.
The null hypothesis is that all permutations of the type labels are
equally likely.
The alternative hypothesis is that some circle of radius
r
has a higher proportion of points of the second type,
than expected under the null hypothesis.
The result of scan.test
is a hypothesis test
(object of class "htest"
) which can be plotted to
report the results. The component p.value
contains the
-value.
The result of scan.test
can also be plotted (using the plot
method for the class "scan.test"
). The plot is
a pixel image of the Likelihood Ratio Test Statistic
(2 times the log likelihood ratio) as a function
of the location of the centre of the circle.
This pixel image can be extracted from the object
using as.im.scan.test
.
The Likelihood Ratio Test Statistic is computed by
scanLRTS
.
An object of class "htest"
(hypothesis test)
which also belongs to the class "scan.test"
.
Printing this object gives the result of the test.
Plotting this object displays the Likelihood Ratio Test Statistic
as a function of the location of the centre of the circle.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Kulldorff, M. (1997) A spatial scan statistic. Communications in Statistics — Theory and Methods 26, 1481–1496.
plot.scan.test
,
as.im.scan.test
,
relrisk
,
scanLRTS
nsim <- if(interactive()) 19 else 2 rr <- if(interactive()) seq(0.5, 1, by=0.1) else c(0.5, 1) scan.test(redwood, 0.1 * rr, method="poisson", nsim=nsim) scan.test(chorley, rr, method="binomial", case="larynx", nsim=nsim)
nsim <- if(interactive()) 19 else 2 rr <- if(interactive()) seq(0.5, 1, by=0.1) else c(0.5, 1) scan.test(redwood, 0.1 * rr, method="poisson", nsim=nsim) scan.test(chorley, rr, method="binomial", case="larynx", nsim=nsim)
Calculate the Likelihood Ratio Test Statistic for the Scan Test, at each spatial location.
scanLRTS(X, r, ..., method = c("poisson", "binomial"), baseline = NULL, case = 2, alternative = c("greater", "less", "two.sided"), saveopt = FALSE, Xmask = NULL)
scanLRTS(X, r, ..., method = c("poisson", "binomial"), baseline = NULL, case = 2, alternative = c("greater", "less", "two.sided"), saveopt = FALSE, Xmask = NULL)
X |
A point pattern (object of class |
r |
Radius of circle to use. A single number or a numeric vector. |
... |
Optional. Arguments passed to |
method |
Either |
baseline |
Baseline for the Poisson intensity, if |
case |
Which type of point should be interpreted as a case,
if |
alternative |
Alternative hypothesis: |
saveopt |
Logical value indicating to save the optimal value of |
Xmask |
Internal use only. |
This command computes, for all spatial locations u
,
the Likelihood Ratio Test Statistic
for a test of homogeneity at the location
, as described
below. The result is a pixel image giving the values of
at each pixel.
The maximum value of over all locations
is the scan statistic, which is the basis of
the scan test performed by
scan.test
.
If method="poisson"
then the test statistic is based on Poisson
likelihood.
The dataset X
is treated as an unmarked point pattern.
By default (if baseline
is not specified)
the null hypothesis is complete spatial randomness CSR
(i.e. a uniform Poisson process).
At the spatial location ,
the alternative hypothesis is a Poisson process with
one intensity
inside the circle of radius
r
centred at ,
and another intensity
outside the
circle.
If
baseline
is given, then it should be a pixel image
or a function(x,y)
. The null hypothesis is
an inhomogeneous Poisson process with intensity proportional
to baseline
. The alternative hypothesis is an inhomogeneous
Poisson process with intensity
beta1 * baseline
inside the circle,
and beta0 * baseline
outside the circle.
If method="binomial"
then the test statistic is based on
binomial likelihood.
The dataset X
must be a bivariate point pattern,
i.e. a multitype point pattern with two types.
The null hypothesis is that all permutations of the type labels are
equally likely.
The alternative hypothesis is that the circle of radius
r
centred at
has a higher proportion of points of the second type,
than expected under the null hypothesis.
If r
is a vector of more than one value for the radius,
then the calculations described above are performed for
every value of r
. Then the maximum over r
is taken
for each spatial location .
The resulting pixel value of
scanLRTS
at a location
is the profile maximum of the Likelihood Ratio Test Statistic,
that is, the maximum of the
Likelihood Ratio Test Statistic for circles of all radii,
centred at the same location
.
If you have already performed a scan test using
scan.test
, the Likelihood Ratio Test Statistic
can be extracted from the test result using the
function as.im.scan.test
.
A pixel image (object of class "im"
) whose pixel values
are the values of the (profile) Likelihood Ratio Test Statistic at each
spatial location.
Note that the result of scanLRTS
is a pixel image
on a larger window than the original window of X
.
The expanded window contains the centre of any circle
of radius r
that has nonempty intersection with the original window.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Kulldorff, M. (1997) A spatial scan statistic. Communications in Statistics — Theory and Methods 26, 1481–1496.
plot(scanLRTS(redwood, 0.1, method="poisson")) sc <- scanLRTS(chorley, 1, method="binomial", case="larynx") plot(sc) scanstatchorley <- max(sc)
plot(scanLRTS(redwood, 0.1, method="poisson")) sc <- scanLRTS(chorley, 1, method="binomial", case="larynx") plot(sc) scanstatchorley <- max(sc)
Given a point pattern and a set of predictors, find a minimal set of new predictors, each constructed as a linear combination of the original predictors.
sdr(X, covariates, ...) ## S3 method for class 'ppp' sdr(X, covariates, method = c("DR", "NNIR", "SAVE", "SIR", "TSE"), Dim1 = 1, Dim2 = 1, predict=FALSE, ...)
sdr(X, covariates, ...) ## S3 method for class 'ppp' sdr(X, covariates, method = c("DR", "NNIR", "SAVE", "SIR", "TSE"), Dim1 = 1, Dim2 = 1, predict=FALSE, ...)
X |
A point pattern (object of class |
covariates |
A list of pixel images (objects of class |
method |
Character string indicating which method to use. See Details. |
Dim1 |
Dimension of the first order Central Intensity Subspace
(applicable when |
Dim2 |
Dimension of the second order Central Intensity Subspace
(applicable when |
predict |
Logical value indicating whether to compute the new predictors as well. |
... |
Additional arguments (ignored by |
Given a point pattern and predictor variables
,
Sufficient Dimension Reduction methods
(Guan and Wang, 2010) attempt to find a minimal set
of new predictor variables, each constructed by taking a linear combination
of the original predictors, which explain the dependence of
on
.
The methods do not assume any particular form of dependence
of the point pattern on the predictors.
The predictors are assumed to
be Gaussian random fields.
Available methods are:
method="DR" |
directional regression |
method="NNIR" |
nearest neighbour inverse regression |
method="SAVE" |
sliced average variance estimation |
method="SIR" |
sliced inverse regression |
method="TSE" |
two-step estimation |
The result includes a matrix B
whose columns are estimates
of the basis vectors of the space of new predictors. That is,
the j
th column of B
expresses the j
th new
predictor as a linear combination of the original predictors.
If predict=TRUE
, the new predictors are also evaluated.
They can also be evaluated using sdrPredict
.
A list with components B, M
or B, M1, M2
where
B
is a matrix whose columns are estimates of the basis vectors
for the space, and M
or M1,M2
are matrices containing
estimates of the kernel.
If predict=TRUE
, the result also includes a component
Y
which is a list of pixel images giving the values of the
new predictors.
Matlab original by Yongtao Guan, translated to R by Suman Rakshit.
Guan, Y. and Wang, H. (2010) Sufficient dimension reduction for spatial point processes directed by Gaussian random fields. Journal of the Royal Statistical Society, Series B, 72, 367–387.
sdrPredict
to compute the new predictors from the
coefficient matrix.
dimhat
to estimate the subspace dimension.
A <- sdr(bei, bei.extra, predict=TRUE) A Y1 <- A$Y[[1]] plot(Y1) points(bei, pch=".", cex=2) # investigate likely form of dependence plot(rhohat(bei, Y1))
A <- sdr(bei, bei.extra, predict=TRUE) A Y1 <- A$Y[[1]] plot(Y1) points(bei, pch=".", cex=2) # investigate likely form of dependence plot(rhohat(bei, Y1))
Given the result of a Sufficient Dimension Reduction method, compute the new predictors.
sdrPredict(covariates, B)
sdrPredict(covariates, B)
covariates |
A list of pixel images (objects of class |
B |
Either a matrix of coefficients for the covariates, or the result of
a call to |
This function assumes that sdr
has already been used to
find a minimal set of predictors based on the covariates
.
The argument B
should be either the result of sdr
or the coefficient matrix returned as one of the
results of sdr
. The columns of this matrix define linear
combinations of the covariates
. This function evaluates those
linear combinations, and returns a list of pixel images containing the
new predictors.
A list of pixel images (objects of class "im"
)
with one entry for each column of B
.
Adrian Baddeley [email protected]
A <- sdr(bei, bei.extra) Y <- sdrPredict(bei.extra, A) Y
A <- sdr(bei, bei.extra) Y <- sdrPredict(bei.extra, A) Y
Performs a Monte Carlo test of spatial segregation of the types in a multitype point pattern.
segregation.test(X, ...) ## S3 method for class 'ppp' segregation.test(X, ..., nsim = 19, permute = TRUE, verbose = TRUE, Xname)
segregation.test(X, ...) ## S3 method for class 'ppp' segregation.test(X, ..., nsim = 19, permute = TRUE, verbose = TRUE, Xname)
X |
Multitype point pattern (object of class |
... |
Additional arguments passed to |
nsim |
Number of simulations for the Monte Carlo test. |
permute |
Argument passed to |
verbose |
Logical value indicating whether to print progress reports. |
Xname |
Optional character string giving the name of the dataset |
The Monte Carlo test of spatial segregation of types,
proposed by Kelsall and Diggle (1995)
and Diggle et al (2005), is applied to the point pattern X
.
The test statistic is
where is the
leave-one-out kernel smoothing estimate of the probability that the
-th data point has type
, and
is the average fraction of data points
which are of type
.
The statistic
is evaluated for the data and
for
nsim
randomised versions of X
, generated by
randomly permuting or resampling the marks.
Note that, by default, automatic bandwidth selection will be
performed separately for each randomised pattern. This computation
can be very time-consuming but is necessary for the test to be
valid in most conditions. A short-cut is to specify the value of
the smoothing bandwidth sigma
as shown in the examples.
An object of class "htest"
representing the result of the test.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Bithell, J.F. (1991) Estimation of relative risk functions. Statistics in Medicine 10, 1745–1751.
Kelsall, J.E. and Diggle, P.J. (1995) Kernel estimation of relative risk. Bernoulli 1, 3–16.
Diggle, P.J., Zheng, P. and Durr, P. (2005) Non-parametric estimation of spatial segregation in a multivariate point process: bovine tuberculosis in Cornwall, UK. Applied Statistics 54, 645–658.
segregation.test(hyytiala, 5) if(interactive()) segregation.test(hyytiala, hmin=0.05)
segregation.test(hyytiala, 5) if(interactive()) segregation.test(hyytiala, hmin=0.05)
Performs Choi-Hall data sharpening of a spatial point pattern.
sharpen(X, ...) ## S3 method for class 'ppp' sharpen(X, sigma=NULL, ..., varcov=NULL, edgecorrect=FALSE)
sharpen(X, ...) ## S3 method for class 'ppp' sharpen(X, sigma=NULL, ..., varcov=NULL, edgecorrect=FALSE)
X |
A marked point pattern (object of class |
sigma |
Standard deviation of isotropic Gaussian smoothing kernel. |
varcov |
Variance-covariance matrix of anisotropic Gaussian kernel.
Incompatible with |
edgecorrect |
Logical value indicating whether to apply edge effect bias correction. |
... |
Arguments passed to |
Choi and Hall (2001) proposed a procedure for data sharpening of spatial point patterns. This procedure is appropriate for earthquake epicentres and other point patterns which are believed to exhibit strong concentrations of points along a curve. Data sharpening causes such points to concentrate more tightly along the curve.
If the original data points are
then the sharpened points are
where is a smoothing kernel in two dimensions.
Thus, the new point
is a
vector average of the nearby points
.
The function sharpen
is generic. It currently has only one
method, for two-dimensional point patterns (objects of class
"ppp"
).
If sigma
is given, the smoothing kernel is the
isotropic two-dimensional Gaussian density with standard deviation
sigma
in each axis. If varcov
is given, the smoothing
kernel is the Gaussian density with variance-covariance matrix
varcov
.
The data sharpening procedure tends to cause the point pattern
to contract away from the boundary of the window. That is,
points that lie 'quite close to the edge of the window
of the point pattern tend to be displaced inward.
If
edgecorrect=TRUE
then the algorithm is modified to
correct this vector bias.
A point pattern (object of class "ppp"
) in the same window
as the original pattern X
, and with the same marks as X
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected]
Choi, E. and Hall, P. (2001) Nonparametric analysis of earthquake point-process data. In M. de Gunst, C. Klaassen and A. van der Vaart (eds.) State of the art in probability and statistics: Festschrift for Willem R. van Zwet, Institute of Mathematical Statistics, Beachwood, Ohio. Pages 324–344.
X <- unmark(shapley) Y <- sharpen(X, sigma=0.5) Z <- sharpen(X, sigma=0.5, edgecorrect=TRUE) opa <- par(mar=rep(0.2, 4)) plot(solist(X, Y, Z), main= " ", main.panel=c("data", "sharpen", "sharpen, correct"), pch=".", equal.scales=TRUE, mar.panel=0.2) par(opa)
X <- unmark(shapley) Y <- sharpen(X, sigma=0.5) Z <- sharpen(X, sigma=0.5, edgecorrect=TRUE) opa <- par(mar=rep(0.2, 4)) plot(solist(X, Y, Z), main= " ", main.panel=c("data", "sharpen", "sharpen, correct"), pch=".", equal.scales=TRUE, mar.panel=0.2) par(opa)
Generic function to perform spatial smoothing of spatial data.
Smooth(X, ...)
Smooth(X, ...)
X |
Some kind of spatial data |
... |
Arguments passed to methods. |
This generic function calls an appropriate method
to perform spatial smoothing on the spatial dataset X
.
Methods for this function include
Smooth.ppp
for point patterns
Smooth.msr
for measures
Smooth.fv
for function value tables
An object containing smoothed values of the input data, in an appropriate format. See the documentation for the methods.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Smooth.ppp
,
Smooth.im
,
Smooth.msr
,
Smooth.fv
.
Applies smoothing to the values in selected columns of a function value table.
## S3 method for class 'fv' Smooth(X, which = "*", ..., method=c("smooth.spline", "loess"), xinterval=NULL)
## S3 method for class 'fv' Smooth(X, which = "*", ..., method=c("smooth.spline", "loess"), xinterval=NULL)
X |
Values to be smoothed.
A function value table (object of class |
which |
Character vector identifying which columns of the table
should be smoothed. Either a vector containing names
of columns, or one of the wildcard strings |
... |
Extra arguments passed to |
method |
Smoothing algorithm. A character string, partially matched
to either |
xinterval |
Optional. Numeric vector of length 2 specifying a range of
|
The command Smooth.fv
applies smoothing to the function values in
a function value table (object of class "fv"
).
Smooth.fv
is a method for the generic function
Smooth
.
The smoothing is performed either by
smooth.spline
or by
loess
.
Smoothing is applied to every column
(or to each of the selected columns) of function values in turn,
using the function argument as the coordinate
and the selected column as the
coordinate.
The original function values are then replaced by the corresponding
smooth interpolated function values.
The optional argument which
specifies which of the
columns of function values in x
will be smoothed.
The default (indicated by the wildcard which="*"
)
is to smooth all function values, i.e.\ all columns except the
function argument. Alternatively which="."
designates
the subset of function values that are displayed in the default plot.
Alternatively which
can be a character vector containing the
names of columns of x
.
If the argument xinterval
is given, then
smoothing will be performed only in the specified range
of values.
Another function value table (object of class "fv"
)
of the same format.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Smooth
,
with.fv
,
fv.object
,
smooth.spline
,
smooth.spline
G <- Gest(cells) plot(G) plot(Smooth(G, df=9), add=TRUE)
G <- Gest(cells) plot(G) plot(Smooth(G, df=9), add=TRUE)
Performs spatial smoothing of numeric values observed at a set of irregular locations. Uses kernel smoothing and least-squares cross-validated bandwidth selection.
## S3 method for class 'ppp' Smooth(X, sigma=NULL, ..., weights = rep(1, npoints(X)), at = "pixels", leaveoneout=TRUE, adjust = 1, varcov = NULL, edge = TRUE, diggle = FALSE, kernel = "gaussian", scalekernel = is.character(kernel), se = FALSE, loctype = c("random", "fixed"), wtype = c("multiplicity", "importance"), geometric = FALSE) markmean(X, ...) markvar(X, sigma=NULL, ..., weights=NULL, varcov=NULL)
## S3 method for class 'ppp' Smooth(X, sigma=NULL, ..., weights = rep(1, npoints(X)), at = "pixels", leaveoneout=TRUE, adjust = 1, varcov = NULL, edge = TRUE, diggle = FALSE, kernel = "gaussian", scalekernel = is.character(kernel), se = FALSE, loctype = c("random", "fixed"), wtype = c("multiplicity", "importance"), geometric = FALSE) markmean(X, ...) markvar(X, sigma=NULL, ..., weights=NULL, varcov=NULL)
X |
A marked point pattern (object of class |
sigma |
Smoothing bandwidth.
A single positive number, a numeric vector of length 2,
or a function that selects the bandwidth automatically.
See |
... |
Further arguments passed to
|
weights |
Optional weights attached to the observations.
A numeric vector, a |
at |
String specifying whether to compute the smoothed values
at a grid of pixel locations ( |
leaveoneout |
Logical value indicating whether to compute a leave-one-out
estimator. Applicable only when |
edge , diggle
|
Arguments passed to |
adjust |
Optional. Adjustment factor for the bandwidth |
varcov |
Variance-covariance matrix. An alternative
to |
kernel |
The smoothing kernel.
A character string specifying the smoothing kernel
(current options are |
scalekernel |
Logical value.
If |
se |
Logical value specifying whether to calculate standard errors. This calculation is experimental. |
loctype |
Character string (partially matched) specifying whether the point locations are assumed to be fixed or random, in the calculation of standard error. Experimental. |
wtype |
Character string (partially matched) specifying whether the weights should be interpreted as multiplicities or as importance weights, in the calculation of standard error. Experimental. |
geometric |
Logical value indicating whether to perform geometric mean smoothing instead of arithmetic mean smoothing. See Details. |
The function Smooth.ppp
performs spatial smoothing of numeric values
observed at a set of irregular locations. The functions
markmean
and markvar
are wrappers for Smooth.ppp
which compute the spatially-varying mean and variance of the marks of
a point pattern.
Smooth.ppp
is a method for the generic function
Smooth
for the class "ppp"
of point patterns.
Thus you can type simply Smooth(X)
.
Smoothing is performed by kernel weighting, using the Gaussian kernel
by default. If the observed values are
at locations
respectively,
then the smoothed value at a location
is
(ignoring edge corrections)
where is the kernel (a Gaussian kernel by default).
This is known as the
Nadaraya-Watson smoother (Nadaraya, 1964, 1989; Watson, 1964).
By default, the smoothing kernel bandwidth is chosen by
least squares cross-validation (see below).
The argument X
must be a marked point pattern (object
of class "ppp"
, see ppp.object
).
The points of the pattern are taken to be the
observation locations , and the marks of the pattern
are taken to be the numeric values
observed at these
locations.
The marks are allowed to be a data frame (in
Smooth.ppp
and markmean
). Then the smoothing procedure is applied to each
column of marks.
The numerator and denominator are computed by density.ppp
.
The arguments ...
control the smoothing kernel parameters
and determine whether edge correction is applied.
The smoothing kernel bandwidth can be specified by either of the arguments
sigma
or varcov
which are passed to density.ppp
.
If neither of these arguments is present, then by default the
bandwidth is selected by least squares cross-validation,
using bw.smoothppp
.
The optional argument weights
allows numerical weights to
be applied to the data. If a weight
is associated with location
, then the smoothed
function is
(ignoring edge corrections)
If geometric=TRUE
then geometric mean smoothing
is performed instead of arithmetic mean smoothing.
The mark values must be non-negative numbers.
The logarithm of the mark values is computed; these logarithmic values are
kernel-smoothed as described above; then the exponential function
is applied to the smoothed values.
An alternative to kernel smoothing is inverse-distance weighting,
which is performed by idw
.
If X
has a single column of marks:
If at="pixels"
(the default), the result is
a pixel image (object of class "im"
).
Pixel values are values of the interpolated function.
If at="points"
, the result is a numeric vector
of length equal to the number of points in X
.
Entries are values of the interpolated function at the points of X
.
If X
has a data frame of marks:
If at="pixels"
(the default), the result is a named list of
pixel images (object of class "im"
). There is one
image for each column of marks. This list also belongs to
the class "solist"
, for which there is a plot method.
If at="points"
, the result is a data frame
with one row for each point of X
,
and one column for each column of marks.
Entries are values of the interpolated function at the points of X
.
The return value has attributes
"sigma"
and "varcov"
which report the smoothing
bandwidth that was used.
If the chosen bandwidth sigma
is very small,
kernel smoothing is mathematically equivalent
to nearest-neighbour interpolation; the result will
be computed by nnmark
. This is
unless at="points"
and leaveoneout=FALSE
,
when the original mark values are returned.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Nadaraya, E.A. (1964) On estimating regression. Theory of Probability and its Applications 9, 141–142.
Nadaraya, E.A. (1989) Nonparametric estimation of probability densities and regression curves. Kluwer, Dordrecht.
Watson, G.S. (1964) Smooth regression analysis. Sankhya A 26, 359–372.
density.ppp
,
bw.smoothppp
,
nnmark
,
ppp.object
,
im.object
.
See idw
for inverse-distance weighted smoothing.
To perform interpolation, see also the akima
package.
# Longleaf data - tree locations, marked by tree diameter # Local smoothing of tree diameter (automatic bandwidth selection) Z <- Smooth(longleaf) # Kernel bandwidth sigma=5 plot(Smooth(longleaf, 5)) # mark variance plot(markvar(longleaf, sigma=5)) # data frame of marks: trees marked by diameter and height plot(Smooth(finpines, sigma=2)) head(Smooth(finpines, sigma=2, at="points"))
# Longleaf data - tree locations, marked by tree diameter # Local smoothing of tree diameter (automatic bandwidth selection) Z <- Smooth(longleaf) # Kernel bandwidth sigma=5 plot(Smooth(longleaf, 5)) # mark variance plot(markvar(longleaf, sigma=5)) # data frame of marks: trees marked by diameter and height plot(Smooth(finpines, sigma=2)) head(Smooth(finpines, sigma=2, at="points"))
Applies kernel smoothing to a spatially sampled function.
## S3 method for class 'ssf' Smooth(X, ...)
## S3 method for class 'ssf' Smooth(X, ...)
X |
Object of class |
... |
Arguments passed to |
An object of class "ssf"
represents a real-valued or
vector-valued function that has been evaluated or sampled at an
irregular set of points.
The function values will be smoothed using a Gaussian kernel.
A pixel image or a list of pixel images.
Adrian Baddeley [email protected].
f <- ssf(redwood, nndist(redwood)) Smooth(f, sigma=0.1)
f <- ssf(redwood, nndist(redwood)) Smooth(f, sigma=0.1)
Perform spatial smoothing of numeric values observed at a set of irregular locations, and return the result as a function of spatial location.
Smoothfun(X, ...) ## S3 method for class 'ppp' Smoothfun(X, sigma = NULL, ..., weights = NULL, edge = TRUE, diggle = FALSE)
Smoothfun(X, ...) ## S3 method for class 'ppp' Smoothfun(X, sigma = NULL, ..., weights = NULL, edge = TRUE, diggle = FALSE)
X |
Marked point pattern (object of class |
sigma |
Smoothing bandwidth, or bandwidth selection function,
passed to |
... |
Additional arguments passed to |
weights |
Optional vector of weights associated with the points of |
edge , diggle
|
Logical arguments controlling the edge correction.
Arguments passed to |
The commands Smoothfun
and Smooth
both perform kernel-smoothed spatial interpolation
of numeric values observed at irregular spatial locations.
The difference is that Smooth
returns a pixel image,
containing the interpolated values at a grid of locations, while
Smoothfun
returns a function(x,y)
which can be used
to compute the interpolated value at any spatial location.
For purposes such as model-fitting it is more accurate to
use Smoothfun
to interpolate data.
A function
with arguments x,y
.
The function also belongs to the class "Smoothfun"
which has
methods for print
and as.im
.
It also belongs to the class "funxy"
which has methods
for plot
, contour
and persp
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
f <- Smoothfun(longleaf) f f(120, 80) plot(f)
f <- Smoothfun(longleaf) f f(120, 80) plot(f)
Generic function to perform spatial smoothing of spatial data by diffusion.
SmoothHeat(X, ...)
SmoothHeat(X, ...)
X |
Some kind of spatial data |
... |
Arguments passed to methods. |
This generic function calls an appropriate method
to perform spatial smoothing on the spatial dataset X
using diffusion.
Methods for this function include
SmoothHeat.ppp
for point patterns
SmoothHeat.im
for pixel images.
An object containing smoothed values of the input data, in an appropriate format. See the documentation for the methods.
Adrian Baddeley [email protected].
SmoothHeat.ppp
,
SmoothHeat.im
.
Performs spatial smoothing of numeric values observed at a set of irregular locations, using the diffusion estimate of the density.
## S3 method for class 'ppp' SmoothHeat(X, sigma, ..., weights=NULL)
## S3 method for class 'ppp' SmoothHeat(X, sigma, ..., weights=NULL)
X |
Point pattern (object of class |
sigma |
Smoothing bandwidth. A single number giving the equivalent standard deviation of the smoother. |
... |
Arguments passed to |
weights |
Optional numeric vector of weights associated with each data point. |
This is the analogue of the Nadaraya-Watson smoother, using the
diffusion smoothing estimation procedure (Baddeley et al, 2022).
The numerator and denominator of the Nadaraya-Watson smoother are
calculated using densityHeat.ppp
.
Pixel image (object of class "im"
) giving the smoothed
mark value.
Adrian Baddeley [email protected], Tilman Davies [email protected] and Suman Rakshit.
Baddeley, A., Davies, T., Rakshit, S., Nair, G. and McSwiggan, G. (2022) Diffusion smoothing for spatial point patterns. Statistical Science 37, 123–142.
Smooth.ppp
for the usual kernel-based
smoother (the Nadaraya-Watson smoother)
and densityHeat
for the diffusion estimate of density.
plot(SmoothHeat(longleaf, 10))
plot(SmoothHeat(longleaf, 10))
Given a pixel image, calculate an estimate of the spatial covariance function. Given two pixel images, calculate an estimate of their spatial cross-covariance function.
spatcov(X, Y=X, ..., correlation=FALSE, isotropic = TRUE, clip = TRUE, pooling=TRUE)
spatcov(X, Y=X, ..., correlation=FALSE, isotropic = TRUE, clip = TRUE, pooling=TRUE)
X |
A pixel image (object of class |
Y |
Optional. Another pixel image. |
correlation |
Logical value specifying whether to standardise so that the spatial correlation function is returned. |
isotropic |
Logical value specifying whether to assume the covariance is isotropic, so that the result is a function of the lag distance. |
clip |
Logical value specifying whether to restrict the results to the range of spatial lags where the estimate is reliable. |
pooling |
Logical value specifying the estimation method when |
... |
Ignored. |
In normal usage, only the first argument X
is given.
Then the pixel image X
is treated as a realisation of a stationary
random field, and its spatial covariance function is estimated.
Alternatively if Y
is given,
then X
and Y
are assumed to be
jointly stationary random fields, and their spatial cross-covariance
function is estimated.
For any random field X
, the spatial covariance
is defined for any two spatial locations and
by
where and
are the values of the random field
at those locations. Here
denotes the
statistical covariance, defined for any random variables
and
by
where
denotes the expected value of
.
If the random field is assumed to be stationary (at least second-order
stationary) then the spatial covariance
depends only on the lag vector
:
where is a function of a single vector argument.
If the random field is stationary and isotropic, then the spatial
covariance depends only on the lag distance
:
where is a function of distance.
The function spatcov
computes estimates of the
covariance function or
as follows:
If isotropic=FALSE
, an estimate of the
covariance function is computed,
assuming the random field is stationary, using the naive
moment estimator,
C2 = imcov(X-mean(X))/setcov(Window(X))
.
The result is a pixel image.
If isotropic=TRUE
(the default)
an estimate of the covariance function
is computed, assuming the random field is stationary and isotropic.
When pooling=FALSE
, the estimate of
is the rotational average of the naive estimate of
.
When pooling=TRUE
(the default), the estimate of
is the ratio of the rotational averages of the numerator and
denominator which form the naive estimate of
.
The result is a function object (class "fv"
).
If the argument Y
is given, it should be a pixel image
compatible with X
. An estimate of the spatial cross-covariance function
between X
and Y
will be computed.
If isotropic=TRUE
(the default), the result is a function value
table (object of class "fv"
) giving the estimated values of the
covariance function or spatial correlation function
for a sequence of values of the spatial lag
distance r
.
If isotropic=FALSE
, the result is a pixel image
(object of class "im"
) giving the estimated values of the
spatial covariance function or spatial correlation function
for a grid of values of the spatial lag vector.
Adrian Baddeley [email protected]
if(offline <- !interactive()) op <- spatstat.options(npixel=32) D <- density(cells) plot(spatcov(D)) if(offline) spatstat.options(op)
if(offline <- !interactive()) op <- spatstat.options(npixel=32) D <- density(cells) plot(spatcov(D)) if(offline) spatstat.options(op)
Compute the spatial cumulative distribution function of a spatial covariate, optionally using spatially-varying weights.
spatialcdf(Z, weights = NULL, normalise = FALSE, ..., W = NULL, Zname = NULL)
spatialcdf(Z, weights = NULL, normalise = FALSE, ..., W = NULL, Zname = NULL)
Z |
Spatial covariate.
A pixel image or a |
weights |
Spatial weighting for different locations.
A pixel image, a |
normalise |
Logical. Whether the weights should be normalised so that they sum to 1. |
... |
Arguments passed to |
W |
Optional window (object of class |
Zname |
Optional character string for the name of the covariate |
If weights
is missing or NULL
, it defaults to 1.
The values of the covariate Z
are computed on a grid of pixels. The weighted cumulative distribution
function of Z
values is computed, taking each value with weight
equal to the pixel area. The resulting function is such that
is the area of the region of space where
.
If weights
is a pixel image or a function, then the
values of weights
and of the covariate Z
are computed on a grid of pixels. The
weights
are multiplied by the pixel area.
Then the weighted empirical cumulative distribution function
of Z
values
is computed using ewcdf
. The resulting function
is such that
is the total weight (or weighted area)
of the region of space where
.
If weights
is a fitted point process model, then it should
be a Poisson process. The fitted intensity of the model,
and the value of the covariate Z
, are evaluated at the
quadrature points used to fit the model. The weights
are
multiplied by the weights of the quadrature points.
Then the weighted empirical cumulative distribution of Z
values
is computed using ewcdf
. The resulting function
is such that
is the expected number of points
in the point process that will fall in the region of space
where
.
If normalise=TRUE
, the function is normalised so that its
maximum value equals 1, so that it gives the cumulative
fraction of weight or cumulative fraction of points.
The result can be printed, plotted, and used as a function.
A cumulative distribution function object
belonging to the classes "spatialcdf"
,
"ewcdf"
, "ecdf"
(only if normalise=TRUE
)
and "stepfun"
.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
with(bei.extra, { plot(spatialcdf(grad)) if(require("spatstat.model")) { fit <- ppm(bei ~ elev) plot(spatialcdf(grad, predict(fit))) A <- spatialcdf(grad, fit) A(0.1) } }) plot(spatialcdf("x", W=letterR))
with(bei.extra, { plot(spatialcdf(grad)) if(require("spatstat.model")) { fit <- ppm(bei ~ elev) plot(spatialcdf(grad, predict(fit))) A <- spatialcdf(grad, fit) A(0.1) } }) plot(spatialcdf("x", W=letterR))
Given a spatial point pattern with numeric marks, compute a weighted median of the mark values, with spatially-varying weights that depend on distance to the data points.
## S3 method for class 'ppp' SpatialMedian(X, sigma = NULL, ..., type = 4, at = c("pixels", "points"), leaveoneout = TRUE, weights = NULL, edge = TRUE, diggle = FALSE, verbose = FALSE)
## S3 method for class 'ppp' SpatialMedian(X, sigma = NULL, ..., type = 4, at = c("pixels", "points"), leaveoneout = TRUE, weights = NULL, edge = TRUE, diggle = FALSE, verbose = FALSE)
X |
A spatial point pattern (object of class |
sigma |
Smoothing bandwidth, passed to |
... |
Further arguments passed to |
type |
Integer specifying the type of median
(using the convention of |
at |
Character string indicating whether to compute the median
at every pixel of a pixel image ( |
leaveoneout |
Logical value indicating whether to compute a leave-one-out
estimator. Applicable only when |
weights |
Optional vector of numeric weights attached to the points of |
edge , diggle
|
Arguments passed to |
verbose |
Logical value specifying whether to print progress reports during the calculation. |
The argument X
should be a spatial point pattern
(object of class "ppp"
) with numeric marks.
The algorithm computes the weighted median of the mark values at each desired spatial location, using spatially-varying weights which depend on distance to the data points.
Suppose the data points are at spatial locations
and have mark values
.
For a query location
, the smoothed median is defined
as the weighted median of the mark values
with weights
,
where
where is the smoothing kernel with bandwidth
sigma
If at="points"
and leaveoneout=TRUE
, then
a leave-one-out calculation is performed, which means that
when the query location is a data point ,
the value at the data point is ignored, and
the weighted median is computed from the values
for all
not equal to
.
If X
has a single column of marks:
If at="pixels"
(the default), the result is
a pixel image (object of class "im"
).
If at="points"
, the result is a numeric vector
of length equal to the number of points in X
.
If X
has a data frame of marks:
If at="pixels"
(the default), the result is a named list of
pixel images (object of class "im"
). There is one
image for each column of marks. This list also belongs to
the class "solist"
, for which there is a plot method.
If at="points"
, the result is a data frame
with one row for each point of X
,
and one column for each column of marks.
Entries are values of the interpolated function at the points of X
.
The return value has attributes
"sigma"
and "varcov"
which report the smoothing
bandwidth that was used.
The calculation of the median value depends on the argument
type
which is interpreted in the same way as for
quantile.default
. Currently, only types 1 and 4
are implemented.
If type=1
, the median is always
one of the mark values (one of the values in marks(x)
).
If type=4
(the default),
the median value is obtained by linearly interpolating
between mark values.
Note that the default values of type
in SpatialMedian.ppp
and SpatialQuantile.ppp
are different.
Adrian Baddeley [email protected].
Generic function SpatialMedian
.
SpatialQuantile
and SpatialQuantile.ppp
for other quantiles.
Smooth.ppp
for the spatially weighted average.
X <- longleaf if(!interactive()) { ## mark values rounded to nearest multiple of 10 to reduce check time marks(X) <- round(marks(X), -1) } Z <- SpatialMedian(X, sigma=30) ZX <- SpatialMedian(X, sigma=30, at="points")
X <- longleaf if(!interactive()) { ## mark values rounded to nearest multiple of 10 to reduce check time marks(X) <- round(marks(X), -1) } Z <- SpatialMedian(X, sigma=30) ZX <- SpatialMedian(X, sigma=30, at="points")
Compute a weighted median or weighted quantile of spatial data.
SpatialMedian(X, ...) SpatialQuantile(X, prob = 0.5, ...)
SpatialMedian(X, ...) SpatialQuantile(X, prob = 0.5, ...)
X |
A spatial data object. |
prob |
Probability for which the quantile is required. A single numeric value between 0 and 1. Default is to calculate the median. |
... |
Further arguments passed to methods. |
The functions SpatialMedian
and SpatialQuantile
are generic. They calculate spatially weighted medians
and quantiles of spatial data. The details depend on the class of
X
.
There are methods for spatial point patterns (class "ppp"
)
and possibly for other objects.
Adrian Baddeley [email protected].
Methods SpatialMedian.ppp
, SpatialQuantile.ppp
.
Smooth
for the spatially weighted average.
Given a spatial point pattern with numeric marks, compute a weighted quantile of the mark values, with spatially-varying weights that depend on distance to the data points.
## S3 method for class 'ppp' SpatialQuantile(X, prob = 0.5, sigma = NULL, ..., type = 1, at = c("pixels", "points"), leaveoneout = TRUE, weights = NULL, edge = TRUE, diggle = FALSE, verbose = FALSE)
## S3 method for class 'ppp' SpatialQuantile(X, prob = 0.5, sigma = NULL, ..., type = 1, at = c("pixels", "points"), leaveoneout = TRUE, weights = NULL, edge = TRUE, diggle = FALSE, verbose = FALSE)
X |
A spatial point pattern (object of class |
prob |
Probability for which the quantile is required. A single numeric value between 0 and 1. |
sigma |
Smoothing bandwidth, passed to |
... |
Further arguments passed to |
type |
Integer specifying the type of median
(using the convention of |
at |
Character string indicating whether to compute the quantile
at every pixel of a pixel image ( |
leaveoneout |
Logical value indicating whether to compute a leave-one-out
estimator. Applicable only when |
weights |
Optional vector of numeric weights attached to the points of |
edge , diggle
|
Arguments passed to |
verbose |
Logical value specifying whether to print progress reports during the calculation. |
The argument X
should be a spatial point pattern
(object of class "ppp"
) with numeric marks.
The algorithm computes the weighted quantile of the mark values at each desired spatial location, using spatially-varying weights which depend on distance to the data points.
Suppose the data points are at spatial locations
and have mark values
.
For a query location
, the smoothed quantile is defined
as the weighted quantile of the mark values
with weights
,
where
where is the smoothing kernel with bandwidth
sigma
.
If at="points"
and leaveoneout=TRUE
, then
a leave-one-out calculation is performed, which means that
when the query location is a data point ,
the value at the data point is ignored, and
the weighted quantile is computed from the values
for all
not equal to
.
The calculation of the quantile value depends on the argument
type
which is interpreted in the same way as for
quantile.default
. Currently, only types 1 and 4
are implemented.
If type=1
(the default), the quantile value is
one of the mark values (one of the values in marks(x)
).
If type=4
, the quantile value is obtained by linearly interpolating
between mark values.
Note that the default values of type
in SpatialQuantile.ppp
and SpatialMedian.ppp
are different.
If X
has a single column of marks:
If at="pixels"
(the default), the result is
a pixel image (object of class "im"
).
If at="points"
, the result is a numeric vector
of length equal to the number of points in X
.
If X
has a data frame of marks:
If at="pixels"
(the default), the result is a named list of
pixel images (object of class "im"
). There is one
image for each column of marks. This list also belongs to
the class "solist"
, for which there is a plot method.
If at="points"
, the result is a data frame
with one row for each point of X
,
and one column for each column of marks.
Entries are values of the interpolated function at the points of X
.
The return value has attributes
"sigma"
and "varcov"
which report the smoothing
bandwidth that was used.
Adrian Baddeley [email protected].
SpatialMedian.ppp
, SpatialMedian
.
X <- longleaf if(!interactive()) { ## mark values rounded to nearest multiple of 10 to reduce check time marks(X) <- round(marks(X), -1) } Z <- SpatialQuantile(X, prob=0.25, sigma=30) ZX <- SpatialQuantile(X, prob=0.25, sigma=30, at="points")
X <- longleaf if(!interactive()) { ## mark values rounded to nearest multiple of 10 to reduce check time marks(X) <- round(marks(X), -1) } Z <- SpatialQuantile(X, prob=0.25, sigma=30) ZX <- SpatialQuantile(X, prob=0.25, sigma=30, at="points")
Create an object that represents a spatial function which has been evaluated or sampled at an irregular set of points.
ssf(loc, val)
ssf(loc, val)
loc |
The spatial locations at which the function has been evaluated.
A point pattern (object of class |
val |
The function values at these locations.
A numeric vector with one entry for each point of |
An object of class "ssf"
represents a real-valued or
vector-valued function that has been evaluated or sampled at an
irregular set of points. An example would be a spatial covariate
that has only been measured at certain locations.
An object of this class also inherits the class "ppp"
,
and is essentially the same as a marked point pattern, except
for the class membership which enables it to be
handled in a different way.
There are methods for plot
, print
etc; see
plot.ssf
and methods.ssf
.
Use unmark
to extract only the point
locations, and marks.ssf
to extract only the function values.
Object of class "ssf"
.
Adrian Baddeley [email protected]
plot.ssf
,
methods.ssf
,
Smooth.ssf
,
with.ssf
,
[.ssf
.
ssf(cells, nndist(cells, k=1:3))
ssf(cells, nndist(cells, k=1:3))
Draw the Stienen diagram of a point pattern, or compute the region covered by the Stienen diagram.
stienen(X, ..., bg = "grey", border = list(bg = NULL)) stienenSet(X, edge=TRUE)
stienen(X, ..., bg = "grey", border = list(bg = NULL)) stienenSet(X, edge=TRUE)
X |
Point pattern (object of class |
... |
Arguments passed to |
bg |
Fill colour for circles. |
border |
Either a list of arguments passed to |
edge |
Logical value indicating whether to include the circles at the border of the diagram. |
The Stienen diagram of a point pattern (Stienen, 1982) is formed by drawing a circle around each point of the pattern, with diameter equal to the nearest-neighbour distance for that point. These circles do not overlap. If two points are nearest neighbours of each other, then the corresponding circles touch.
stienenSet(X)
computes the union of these circles and
returns it as a window (object of class "owin"
).
stienen(X)
generates a plot of the Stienen diagram of
the point pattern X
. By default, circles are shaded in grey
if they lie inside the window of X
, and are not shaded
otherwise.
The plotting function stienen
returns NULL
.
The return value of stienenSet
is a window (object of class
"owin"
).
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Stienen, H. (1982) Die Vergroeberung von Karbiden in reinen Eisen-Kohlenstoff Staehlen. Dissertation, RWTH Aachen.
Y <- stienenSet(cells) stienen(redwood) stienen(redwood, border=list(bg=NULL, lwd=2, cols="red"))
Y <- stienenSet(cells) stienen(redwood) stienen(redwood, border=list(bg=NULL, lwd=2, cols="red"))
Perform a studentised permutation test for a difference between groups of point patterns.
studpermu.test(X, formula, summaryfunction = Kest, ..., rinterval = NULL, nperm = 999, use.Tbar = FALSE, minpoints = 20, rsteps = 128, r = NULL, arguments.in.data = FALSE)
studpermu.test(X, formula, summaryfunction = Kest, ..., rinterval = NULL, nperm = 999, use.Tbar = FALSE, minpoints = 20, rsteps = 128, r = NULL, arguments.in.data = FALSE)
X |
Data. Either a |
formula |
Formula describing the grouping, when |
summaryfunction |
Summary function applicable to point patterns. |
... |
Additional arguments passed to |
rinterval |
Interval of distance values |
nperm |
Number of random permutations for the test. |
use.Tbar |
Logical value indicating choice of test statistic.
If |
minpoints |
Minimum permissible number of points in a point pattern for inclusion in the test calculation. |
rsteps |
Number of discretisation steps in the |
r |
Optional vector of distance values as the argument for
|
arguments.in.data |
Logical. If |
This function performs the studentized permutation test of Hahn (2012) for a difference between groups of point patterns.
The first argument X
should be either
Each element of X
will be interpreted as a group of
point patterns, assumed to be replicates of the same point process.
One column of the hyperframe should contain point patterns,
and another column should contain a factor indicating the
grouping. The argument formula
should be a formula in the
R language specifying the grouping: it should be of the form
P ~ G
where P
is the name of the column of point
patterns, and G
is the name of the factor.
A group needs to contain at least two point patterns with at least
minpoints
points in each pattern.
The function returns an object of class "htest"
and "studpermutest"
that can be printed and plotted.
The printout shows the test result and -value.
The plot shows the summary functions for the
groups (and the group means if requested).
Object of class "studpermutest"
.
Ute Hahn.
Modified for spatstat
by
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Hahn, U. (2012) A studentized permutation test for the comparison of spatial point patterns. Journal of the American Statistical Association 107 (498), 754–764.
np <- if(interactive()) 99 else 19 testpyramidal <- studpermu.test(pyramidal, Neurons ~ group, nperm=np) testpyramidal
np <- if(interactive()) 99 else 19 testpyramidal <- studpermu.test(pyramidal, Neurons ~ group, nperm=np) testpyramidal
Evaluate the distance between two linear subspaces using the measure proposed by Li, Zha and Chiaromonte (2005).
subspaceDistance(B0, B1)
subspaceDistance(B0, B1)
B0 |
Matrix whose columns are a basis for the first subspace. |
B1 |
Matrix whose columns are a basis for the second subspace. |
This algorithm calculates the maximum absolute value of the
eigenvalues of where
are the projection
matrices onto the subspaces generated by
B0,B1
.
This measure of distance was proposed by Li, Zha and Chiaromonte
(2005). See also Xia (2007).
A single numeric value.
Matlab original by Yongtao Guan, translated to R by Suman Rakshit.
Guan, Y. and Wang, H. (2010) Sufficient dimension reduction for spatial point processes directed by Gaussian random fields. Journal of the Royal Statistical Society, Series B, 72, 367–387.
Li, B., Zha, H. and Chiaromonte, F. (2005) Contour regression: a general approach to dimension reduction. Annals of Statistics 33, 1580–1616.
Xia, Y. (2007) A constructive approach to the estimation of dimension reduction directions. Annals of Statistics 35, 2654–2690.
Given a point pattern and a spatial covariate that has some predictive value for the point pattern, compute a confidence interval for the optimal value of the threshold that should be used to convert the covariate to a binary predictor.
thresholdCI(X, Z, confidence = 0.95, nsim = 1000, parametric = FALSE)
thresholdCI(X, Z, confidence = 0.95, nsim = 1000, parametric = FALSE)
X |
Point pattern (object of class |
Z |
Spatial covariate with numerical values.
Either a pixel image (object of class |
confidence |
Confidence level. A number between 0 and 1. |
nsim |
Number of bootstrap simulations to perform. |
parametric |
Logical value specifying whether to use the parametric bootstrap. |
The spatial covariate Z
is assumed to have some utility as a
predictor of the point pattern X
.
This code computes a bootstrap confidence interval
for the best threshold value for converting the
numerical predictor to a binary predictor, for use in
techniques such as Weights of Evidence.
A matrix containing upper and lower limits for the
threshold z
and the corresponding upper and lower limits for
the fraction of area of the study region.
Adrian Baddeley [email protected].
Baddeley, A., Brown, W., Milne, R.K., Nair, G., Rakshit, S., Lawrence, T., Phatak, A. and Fu, S.C. (2021) Optimal thresholding of predictors in mineral prospectivity analysis. Natural Resources Research 30 923–969.
gold <- rescale(murchison$gold, 1000, "km") faults <- rescale(murchison$faults, 1000, "km") distfault <- distfun(faults) Nsim <- if(interactive()) 250 else 25 thresholdCI(gold, distfault, nsim=Nsim)
gold <- rescale(murchison$gold, 1000, "km") faults <- rescale(murchison$faults, 1000, "km") distfault <- distfun(faults) Nsim <- if(interactive()) 250 else 25 thresholdCI(gold, distfault, nsim=Nsim)
Given a point pattern and a spatial covariate that has some predictive value for the point pattern, determine the optimal value of the threshold for converting the covariate to a binary predictor.
thresholdSelect(X, Z, method = c("Y", "LL", "AR", "t", "C"), Zname)
thresholdSelect(X, Z, method = c("Y", "LL", "AR", "t", "C"), Zname)
X |
Point pattern (object of class |
Z |
Spatial covariate with numerical values.
Either a pixel image (object of class |
method |
Character string (partially matched) specifying the method to be used to select the optimal threshold value. See Details. |
Zname |
Optional character string giving a short name for the covariate. |
The spatial covariate Z
is assumed to have some utility as a
predictor of the point pattern X
.
This code chooses the best threshold value for converting the
numerical predictor
Z
to a binary predictor, for use in
techniques such as Weights of Evidence.
The best threshold is selected by maximising the criterion
specified by the argument method
. Options are:
method="Y"
(the default): the Youden criterion
method="LL"
: log-likelihood
method="AR"
: the Akman-Raftery criterion
method="t"
: the Studentised Weights-of-Evidence contrast
method="C"
: the Weights-of-Evidence contrast
These criteria are explained in Baddeley et al (2021).
A single numerical value giving the selected bandwidth.
The result also belongs to the class "bw.optim"
(see bw.optim.object
)
which can be plotted to show the criterion used to select
the threshold.
Adrian Baddeley [email protected].
Baddeley, A., Brown, W., Milne, R.K., Nair, G., Rakshit, S., Lawrence, T., Phatak, A. and Fu, S.C. (2021) Optimal thresholding of predictors in mineral prospectivity analysis. Natural Resources Research 30 923–969.
gold <- rescale(murchison$gold, 1000, "km") faults <- rescale(murchison$faults, 1000, "km") distfault <- distfun(faults) z <- thresholdSelect(gold, distfault) z plot(z, xlim=c(0, 20))
gold <- rescale(murchison$gold, 1000, "km") faults <- rescale(murchison$faults, 1000, "km") distfault <- distfun(faults) z <- thresholdSelect(gold, distfault) z plot(z, xlim=c(0, 20))
Extract the pixel values of a pixel image at each point along a linear transect.
transect.im(X, ..., from="bottomleft", to="topright", nsample=512, click=FALSE, add=FALSE, curve=NULL)
transect.im(X, ..., from="bottomleft", to="topright", nsample=512, click=FALSE, add=FALSE, curve=NULL)
X |
A pixel image (object of class |
... |
Ignored. |
from , to
|
Optional. Start point and end point of the transect.
Pairs of |
nsample |
Integer. Number of sample locations along the transect. |
click |
Optional.
Logical value.
If |
add |
Logical. If |
curve |
Optional. A specification of a curved transect. See the section on Curved Transect. |
The pixel values of the image X
along a line segment
will be extracted. The result is a function table ("fv"
object)
which can be plotted directly.
If click=TRUE
, then the user is prompted to click two points on
the plot of X
. These endpoints define the transect.
Otherwise, the transect is defined by the endpoints
from
and to
. The default is a diagonal transect from
bottom left to top right of the frame.
An object of class "fv"
which can be plotted.
If curve
is given, then the transect will be a curve.
The argument curve
should be a list with the following
arguments:
A function in the R language with one argument t
.
A numeric vector of length 2 giving the range of values
of the argument t
.
(Optional) a character string giving the symbolic name
of the function argument t
; defaults to "t"
.
(Optional) a character string giving a short
description of the function argument t
; defaults to
"curve parameter"
.
The function f
must return a 2-column matrix or data frame
specifying the spatial coordinates (x,y)
of locations along the
curve, determined by the values of the input argument t
.
Adrian Baddeley [email protected] and Rolf Turner [email protected]
Z <- bei.extra$elev plot(transect.im(Z))
Z <- bei.extra$elev plot(transect.im(Z))
Computes the third order summary statistic
of a spatial point pattern.
Tstat(X, ..., r = NULL, rmax = NULL, correction = c("border", "translate"), ratio = FALSE, verbose=TRUE)
Tstat(X, ..., r = NULL, rmax = NULL, correction = c("border", "translate"), ratio = FALSE, verbose=TRUE)
X |
The observed point pattern,
from which an estimate of |
... |
Ignored. |
r |
Optional. Vector of values for the argument |
rmax |
Optional. Numeric. The maximum value of |
correction |
Optional. A character vector containing any selection of the
options |
ratio |
Logical.
If |
verbose |
Logical. If |
This command calculates the
third-order summary statistic for a spatial point patterns,
defined by Schladitz and Baddeley (2000).
The definition of is similar to the definition of Ripley's
function
, except that
counts pairs of
points while
counts triples of points.
Essentially
is a rescaled cumulative
distribution function of the diameters of triangles in the
point pattern. The diameter of a triangle is the length of its
longest side.
An object of class "fv"
, see fv.object
,
which can be plotted directly using plot.fv
.
If the number of points is large, the algorithm can take a very long time
to inspect all possible triangles. A rough estimate
of the total computation time will be printed at the beginning
of the calculation. If this estimate seems very large,
stop the calculation using the user interrupt signal, and
call Tstat
again, using rmax
to restrict the
range of r
values,
thus reducing the number of triangles to be inspected.
Adrian Baddeley [email protected]
Schladitz, K. and Baddeley, A. (2000) A third order point process characteristic. Scandinavian Journal of Statistics 27 (2000) 657–671.
plot(Tstat(redwood))
plot(Tstat(redwood))
This command estimates the variance of
any summary statistic (such as the -function)
by spatial subdivision of a single point pattern dataset.
varblock(X, fun = Kest, blocks = quadrats(X, nx = nx, ny = ny), ..., nx = 3, ny = nx, confidence=0.95)
varblock(X, fun = Kest, blocks = quadrats(X, nx = nx, ny = ny), ..., nx = 3, ny = nx, confidence=0.95)
X |
Point pattern dataset (object of class |
fun |
Function that computes the summary statistic. |
blocks |
Optional. A tessellation that specifies the division of the space into blocks. |
... |
Arguments passed to |
nx , ny
|
Optional. Number of rectangular blocks
in the |
confidence |
Confidence level, as a fraction between 0 and 1. |
This command computes an estimate of the variance of
the summary statistic fun(X)
from a single point pattern
dataset X
using a subdivision method.
It can be used to plot confidence intervals
for the true value of a summary function such as the -function.
The window containing X
is divided into pieces by
an nx * ny
array of rectangles
(or is divided into pieces of more general shape,
according to the argument blocks
if it is present).
The summary statistic fun
is applied to each of the
corresponding sub-patterns of X
as described below.
Then the pointwise
sample mean, sample variance and sample standard deviation
of these summary statistics are computed. Then
pointwise confidence intervals are computed, for the specified level
of confidence, defaulting to 95 percent.
The variance is estimated by equation (4.21) of Diggle (2003, page 52).
This assumes that the point pattern X
is stationary.
For further details see Diggle (2003, pp 52–53).
The estimate of the summary statistic
from each block is computed as follows.
For most functions fun
,
the estimate from block B
is computed by finding the subset of X
consisting of
points that fall inside B
,
and applying fun
to these points, by calling fun(X[B])
.
However if fun
is the -function
Kest
,
or any function which has an argument called domain
,
the estimate for each block B
is computed
by calling fun(X, domain=B)
. In the case of the
-function this means that the estimate from block
B
is computed by counting pairs of
points in which the first point lies in B
,
while the second point may lie anywhere.
A function value table (object of class "fv"
)
that contains the result of fun(X)
as well as
the sample mean, sample variance and sample standard deviation
of the block estimates, together with
the upper and lower two-standard-deviation confidence limits.
If the blocks are too small, there may be insufficient data
in some blocks, and the function fun
may report an error.
If this happens, you need to take larger blocks.
An error message about incompatibility may occur.
The different function estimates may be incompatible in some cases,
for example, because they use different default edge corrections
(typically because the tiles of the tessellation are not the same kind
of geometric object as the window of X
, or because the default
edge correction depends on the number of points). To prevent
this, specify the choice of edge correction,
in the correction
argument to fun
, if it has one.
An alternative to varblock
is Loh's mark bootstrap
lohboot
.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
Diggle, P.J. (2003) Statistical analysis of spatial point patterns, Second edition. Arnold.
tess
,
quadrats
for basic manipulation.
lohboot
for an alternative bootstrap technique.
v <- varblock(amacrine, Kest, nx=4, ny=2) v <- varblock(amacrine, Kcross, nx=4, ny=2) if(interactive()) plot(v, iso ~ r, shade=c("hiiso", "loiso"))
v <- varblock(amacrine, Kest, nx=4, ny=2) v <- varblock(amacrine, Kcross, nx=4, ny=2) if(interactive()) plot(v, iso ~ r, shade=c("hiiso", "loiso"))
Given a spatial object (such as a point pattern or pixel image) in two dimensions, these functions extract the window in which the object is defined.
## S3 method for class 'quadrattest' Window(X, ...)
## S3 method for class 'quadrattest' Window(X, ...)
X |
A spatial object. |
... |
Ignored. |
These are methods for the generic function Window
which extract the spatial window in which the object X
is defined.
An object of class "owin"
(see owin.object
)
specifying an observation window.
Adrian Baddeley [email protected], Rolf Turner [email protected] and Ege Rubak [email protected].
Window
,
Window.ppp
,
Window.psp
.
A <- quadrat.test(cells, 4) Window(A)
A <- quadrat.test(cells, 4) Window(A)
Evaluate an R expression in a
function value table (object of class "fv"
).
## S3 method for class 'fv' with(data, expr, ..., fun = NULL, enclos=NULL)
## S3 method for class 'fv' with(data, expr, ..., fun = NULL, enclos=NULL)
data |
A function value table (object of class |
expr |
The expression to be evaluated. An R language
expression, which may involve the names of columns in |
... |
Ignored. |
fun |
Logical value, specifying whether the result
should be interpreted as another function ( |
enclos |
An environment in which to search for variables that are
not found in |
This is a method for the generic command with
for an object of class "fv"
(function value table).
An object of class "fv"
is a convenient way of storing and
plotting several different estimates of the same function. It is
effectively a data frame with extra attributes.
See fv.object
for further explanation.
This command makes it possible to perform computations that involve
different estimates of the same function. For example we use it to compute
the arithmetic difference between two different edge-corrected
estimates of the function of a point pattern.
The argument expr
should be an R language expression. The expression
may involve
the name of any column in data
, referring to
one of the estimates of the function;
the symbol .
which stands for all
the available estimates of the function;
the symbol .y
which stands for the recommended
estimate of the function (in an "fv"
object, one of the
estimates is always identified as the recommended estimate);
the symbol .x
which stands for the argument of the function;
global constants or functions.
See the Examples. The expression should be capable of handling vectors and matrices.
The interpretation of the argument fun
is as follows:
If fun=FALSE
, the result of evaluating the expression
expr
will be returned as a numeric vector, matrix or
data frame.
If fun=TRUE
, then the result of evaluating expr
will be interpreted as containing the values of a new function.
The return value will be an object of class "fv"
.
(This can only happen if the result has the right dimensions.)
The default is fun=TRUE
if the result of evaluating
expr
has more than one column, and fun=FALSE
otherwise.
To perform calculations involving several objects of
class "fv"
, use eval.fv
.
A function value table (object of class "fv"
)
or a numeric vector or data frame.
Adrian Baddeley [email protected]
and Rolf Turner [email protected]
with
,
fv.object
,
eval.fv
,
Kest
# compute 4 estimates of the K function X <- runifrect(42) K <- Kest(X) plot(K) # derive 4 estimates of the L function L(r) = sqrt(K(r)/pi) L <- with(K, sqrt(./pi)) plot(L) # compute 4 estimates of V(r) = L(r)/r V <- with(L, ./.x) plot(V) # compute the maximum absolute difference between # the isotropic and translation correction estimates of K(r) D <- with(K, max(abs(iso - trans)))
# compute 4 estimates of the K function X <- runifrect(42) K <- Kest(X) plot(K) # derive 4 estimates of the L function L(r) = sqrt(K(r)/pi) L <- with(K, sqrt(./pi)) plot(L) # compute 4 estimates of V(r) = L(r)/r V <- with(L, ./.x) plot(V) # compute the maximum absolute difference between # the isotropic and translation correction estimates of K(r) D <- with(K, max(abs(iso - trans)))
Given a spatially sampled function, evaluate an expression involving the function values.
apply.ssf(X, ...) ## S3 method for class 'ssf' with(data, ...)
apply.ssf(X, ...) ## S3 method for class 'ssf' with(data, ...)
X , data
|
A spatially sampled function (object of class |
... |
Arguments passed to |
An object of class "ssf"
represents a
function (real- or vector-valued) that has been
sampled at a finite set of points.
It contains a data frame
which provides the function values
at the sample points.
In with.ssf
, the expression specified by ...
will be evaluated in this dataframe.
In apply.ssf
, the dataframe will be subjected to
the apply
operator using the additional arguments
...
.
If the result of evaluation
is a data frame with one row for each data point,
or a numeric vector with one entry for each data point,
then the result will be an object of class "ssf"
containing this information. Otherwise, the result will be
a numeric vector.
An object of class "ssf"
or a numeric vector.
Adrian Baddeley [email protected].
a <- ssf(cells, data.frame(d=nndist(cells), i=1:npoints(cells))) with(a, i/d)
a <- ssf(cells, data.frame(d=nndist(cells), i=1:npoints(cells))) with(a, i/d)