Title: | Gliding Box Lacunarity and Other Metrics for 2D Random Closed Sets |
---|---|
Description: | Functions for estimating the gliding box lacunarity (GBL), covariance, and pair-correlation of a random closed set (RACS) in 2D from a binary coverage map (e.g. presence-absence land cover maps). Contains a number of newly-developed covariance-based estimators of GBL (Hingee et al., 2019) <doi:10.1007/s13253-019-00351-9> and balanced estimators, proposed by Picka (2000) <http://www.jstor.org/stable/1428408>, for covariance, centred covariance, and pair-correlation. Also contains methods for estimating contagion-like properties of RACS and simulating 2D Boolean models. Binary coverage maps are usually represented as raster images with pixel values of TRUE, FALSE or NA, with NA representing unobserved pixels. A demo for extracting such a binary map from a geospatial data format is provided. Binary maps may also be represented using polygonal sets as the foreground, however for most computations such maps are converted into raster images. The package is based on research conducted during the author's PhD studies. |
Authors: | Kassel Liam Hingee |
Maintainer: | Kassel Liam Hingee <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1-7 |
Built: | 2024-10-29 04:01:48 UTC |
Source: | https://github.com/kasselhingee/lacunaritycovariance |
This function estimates the centred covariance of a stationary RACS. Available estimators are the plug-in moment centred covariance estimator, two 'balanced' estimators suggested by Picka (2000), and a third 'balanced' estimator inspired by one of Picka's pair-correlation estimators.
cencovariance( xi, obswin = NULL, setcov_boundarythresh = NULL, estimators = "all", drop = FALSE ) cencovariance.cvchat( cvchat, cpp1 = NULL, phat = NULL, setcov_boundarythresh = NULL, estimators = "all", drop = FALSE )
cencovariance( xi, obswin = NULL, setcov_boundarythresh = NULL, estimators = "all", drop = FALSE ) cencovariance.cvchat( cvchat, cpp1 = NULL, phat = NULL, setcov_boundarythresh = NULL, estimators = "all", drop = FALSE )
xi |
An observation of a RACS of interest as a full binary map (as an |
obswin |
If |
setcov_boundarythresh |
To avoid instabilities caused by dividing by very small quantities, if the set covariance of the observation window
is smaller than |
estimators |
A list of strings specifying estimators to use.
See details.
|
drop |
If TRUE and one estimator selected then the returned value will be a single |
cvchat |
The plug-in moment estimate of covariance as an |
cpp1 |
Picka's reduced window estimate of coverage probability as an |
phat |
The usual estimate of coverage probability,
which is the observed foreground area in |
The centred covariance of a stationary RACS is
The estimators available are (see (Section 3.4, Hingee, 2019) for more information):
plugin
the plug-in moment centred
covariance estimator
mattfeldt
an estimator inspired by an
'intrinsically' balanced pair-correlation estimator from Picka (1997) that was
later studied in an isotropic situation by Mattfeldt and Stoyan
(Mattfeldt and Stoyan, 2000)
pickaint
Picka's 'intrinsically' balanced
centred covariance estimator (Picka, 2000).
pickaH
Picka's
'additively' balanced centred covariance estimator (Picka, 2000).
Currently computes centred covariance using racscovariance
.
If drop = TRUE
and only one estimator is requested then a
im
object containing the centred covariance estimate is returned. Otherwise a
named imlist
of im
objects containing the centred covariance
estimates for each requested estimator.
cencovariance()
: Centred covariance estimates from a binary map.
cencovariance.cvchat()
: Generates centred covariances estimates from
a plug-in moment estimate of covariance, Picka's reduced window estimate of coverage probability,
and the plug-in moment estimate of coverage probability.
If these estimates already exist, then cencovariance.cvchat
saves significant computation time over cencovariance
.
Kassel Liam Hingee
Hingee, K.L. (2019) Spatial Statistics of Random Closed Sets for Earth Observations. PhD: Perth, Western Australia: University of Western Australia. Submitted.
Mattfeldt, T. and Stoyan, D. (2000) Improved estimation of the pair correlation function of random sets. Journal of Microscopy, 200, 158-173.
Picka, J.D. (1997) Variance-Reducing Modifications for Estimators of Dependence in Random Sets. Ph.D.: Illinois, USA: The University of Chicago.
Picka, J.D. (2000) Variance reducing modifications for estimators of standardized moments of random sets. Advances in Applied Probability, 32, 682-700.
xi <- heather$coarse obswin <- Frame(xi) cencovariance(xi, obswin, estimators = "all")
xi <- heather$coarse obswin <- Frame(xi) cencovariance(xi, obswin, estimators = "all")
Calculates the disc-state contagion landscape metric as described in (Hingee, 2016; Hingee, 2019). The disc-state contagion landscape metric describes the entropy (mixing) between four possible states of a disc:
the disc is completely
contained in
the disc does not intersect
the centre of the disc is in but the disc is not contained in
the disc intersects but the centre is outside
Disc-state contagion is a function of the disc radius.
The main difference to classical contagion (O'Neill, 1988) is that disc-state contagion
is based on the spherical contact distribution instead of pixel neighbours.
One impact of this design is that the distance with which to quantify the
mixing between and the background may be chosen by the user by
choosing the disc radius (for classical contagion this distance is fixed by
the map resolution).
Note: to create fv
objects the function copies about 20 lines of code from the spatstat collection of packages.
contagdiscstate(XiH, XicH, p, normalise = FALSE)
contagdiscstate(XiH, XicH, p, normalise = FALSE)
XiH |
Conditional spherical contact distribution function for |
XicH |
Conditional spherical contact distribution for the complement of
|
p |
The coverage probability of |
normalise |
Optional. If TRUE |
XiH
should be a function of radius that contains (estimates of) the
probability of a disc of radius not intersecting
if the
disc's centre is not in
Similarly XicH
should be (an estimate of) the
probability of a disc being fully contained in given its centre
is in
These can both be obtained using Hest
in
spatstat. For XicH
take care to apply Hest
to the complement
of with the observation window
.
If normalise
is TRUE
then the result is divided by
and increased by 1 so that contagion will always be between 0
and 1.
If XiH
is an fv
object then an fv
object is returned.
If XiH
is a vector then the returned object is a vector the same length as XiH
with each element
corresponding to the contagion at each r
value of XiH
.
Hingee, K.L. (2016) Statistics for patch observations. International Archives of the Photogrammetry, Remote Sensing and Spatial Information Sciences pp. 235-242. Prague: ISPRS.
Hingee, K.L. (2019) Spatial Statistics of Random Closed Sets for Earth Observations. PhD: Perth, Western Australia: University of Western Australia. Submitted.
O'Neill, R.V., Krummel, J.R., Gardner, R.H., Sugihara, G., Jackson, B., DeAngelis, D.L., et al. (1988) Indices of landscape pattern. Landscape Ecology, 1, 153-162.
xi <- heather$coarse obswindow <- Frame(heather$coarse) p <- coverageprob(xi, Frame(xi)) xiH <- Hest(xi, W = obswindow) #Sph. Contact Distrution Estimate xicH <- Hest(complement.owin(xi), W = obswindow) #Conditional Core Prob. Estimate contagion <- contagdiscstate(xiH, xicH, p)
xi <- heather$coarse obswindow <- Frame(heather$coarse) p <- coverageprob(xi, Frame(xi)) xiH <- Hest(xi, W = obswindow) #Sph. Contact Distrution Estimate xicH <- Hest(complement.owin(xi), W = obswindow) #Conditional Core Prob. Estimate contagion <- contagdiscstate(xiH, xicH, p)
Function for calculating the classic pixel-adjacency contagion landscape metric from a binary map (O'Neill, 1988).
contagpixelgrid(xi, obswin, normalise = FALSE) adjacency(xi, obswin = NULL)
contagpixelgrid(xi, obswin, normalise = FALSE) adjacency(xi, obswin = NULL)
xi |
A raster binary map (as an |
obswin |
If |
normalise |
If |
The unnormalised contagion landscape metric of categorical map is defined as
where is the probability of
randomly selected adjacent pixels being in class
and class
respectively, and
is the number of classes.
Here as
xi
is a binary map and we have defined 'adjacent'
pixels using the 4-neighbourhood regime.
Contagion is calculated from an adjacency matrix created using the function adjacency
.
The adjacency matrix is a 2 by 2 table containing the number of pairs of neighbouring pixels (where order matters) such that:
Second pixel in xi |
Second pixel not in xi |
|
First pixel in xi |
- | - |
First pixel not in xi |
- | - |
The computed pixel-adjacency contagion value. If normalise
is TRUE
then the value will be between 0 and 1. Otherwise the value will be negative.
contagpixelgrid()
: Pixel-adjacency contagion landscape metric of a binary map.
adjacency()
: Calculates the adjacency matrix used in the pixel contagion
Will fail if map is either all foreground or all background.
O'Neill, R.V., Krummel, J.R., Gardner, R.H., Sugihara, G., Jackson, B., DeAngelis, D.L., et al. (1988) Indices of landscape pattern. Landscape Ecology, 1, 153-162.
xi <- heather$coarse obswin <- owin(xrange = c(0,7),yrange=c(0,16)) adjmat <- adjacency(xi,obswin) pixeladjcontagion <- contagpixelgrid(xi,obswin)
xi <- heather$coarse obswin <- owin(xrange = c(0,7),yrange=c(0,16)) adjmat <- adjacency(xi,obswin) pixeladjcontagion <- contagpixelgrid(xi,obswin)
Computes the proportion of the observation window that is foreground, which is the usual estimate for the coverage probability of a stationary RACS from a binary map.
coverageprob(xi, obswin = NULL) coveragefrac(xi, obswin = NULL) cp(xi, obswin = NULL)
coverageprob(xi, obswin = NULL) coveragefrac(xi, obswin = NULL) cp(xi, obswin = NULL)
xi |
An observation of a RACS of interest as a full binary map (as an |
obswin |
The window of observation (not necessarily rectangular) also as an |
The coverage probability of a stationary RACS is the probability that an arbitrary point is covered by the RACS.
Given a binary map, xi
, of a realisation of stationary RACS in a window
,
this function computes the fraction of
covered by foreground,
which is an estimate of the coverage probability.
See (Chiu et al., 2013, Section 6.4.2) for more details.
If xi
is an im
object then xi
must be an image of 1s, 0s and NAs
representing inside the set, outside the set and outside the observation window respectively.
coverageprob
will not accept a obswin
argument if xi
is an im
object.
An estimate of the coverage probability
Kassel Liam Hingee
Chiu, S.N., Stoyan, D., Kendall, W.S. and Mecke, J. (2013) Stochastic Geometry and Its Applications, 3rd ed. Chichester, United Kingdom: John Wiley & Sons.
xi <- heather$coarse obswindow <- Frame(heather$coarse) cp <- coverageprob(xi, obswindow)
xi <- heather$coarse obswindow <- Frame(heather$coarse) cp <- coverageprob(xi, obswindow)
This function provides estimates of coverage probability from subsets of the observation window, which are a key component of balanced estimators of covariance, centred covariance, pair-correlation and gliding box lacunarity.
cppicka(xi, obswin = NULL, setcov_boundarythresh = NULL)
cppicka(xi, obswin = NULL, setcov_boundarythresh = NULL)
xi |
An observation of a RACS of interest as a full binary map (as an |
obswin |
If |
setcov_boundarythresh |
To avoid instabilities caused by dividing by very small quantities, if the set covariance of the observation window
is smaller than |
The plug-in moment covariance estimator (plugincvc
) uses less of the observation window than the usual coverage probability estimators.
Picka (1997, 2000) created new 'balanced' estimators of centred covariance and pair-correlation
that accounted for this difference.
A key component of Picka's estimators is an estimate of the coverage probability from the subregion of the binary map that is
the intersection between and
shifted by vector
, where
is the observation window (p.~687, Picka, 2000).
If we treat
and
as indicator functions representing the foreground and observation window respectively,
this coverage probability estimator used by Picka is
cppicka
produces these estimates for an array of vectors using fast Fourier transforms.
An im
object. Pixel values correspond to estimates of the coverage probability
from the subregion of the observation window, , that is the intersection of
and
shifted by vector
, where
is the pixel location.
Kassel Liam Hingee
Picka, J.D. (1997) Variance-Reducing Modifications for Estimators of Dependence in Random Sets. Ph.D.: Illinois, USA: The University of Chicago.
Picka, J.D. (2000) Variance reducing modifications for estimators of standardized moments of random sets. Advances in Applied Probability, 32, 682-700.
xi <- heather$coarse obswindow <- Frame(heather$coarse) cp <- coverageprob(xi, obswindow) cpp1 <- cppicka(xi, obswindow)
xi <- heather$coarse obswindow <- Frame(heather$coarse) cp <- coverageprob(xi, obswindow) cpp1 <- cppicka(xi, obswindow)
Estimates gliding box lacunarity (GBL) for square boxes using all estimators described in (Hingee et al., 2017).
It calls the functions gblc
, gblg
, gblcc
and gblemp
.
gbl( xi, boxwidths, estimators = c("GBLcc.pickaH"), obswin = NULL, includenormed = FALSE, setcov_boundarythresh = 1e-06 ) gbl.cvchat( boxwidths, estimators = c("GBLg.mattfeldt", "GBLg.pickaint", "GBLg.pickaH", "GBLcc.mattfeldt", "GBLcc.pickaint", "GBLc"), phat = NULL, cvchat = NULL, cpp1 = NULL )
gbl( xi, boxwidths, estimators = c("GBLcc.pickaH"), obswin = NULL, includenormed = FALSE, setcov_boundarythresh = 1e-06 ) gbl.cvchat( boxwidths, estimators = c("GBLg.mattfeldt", "GBLg.pickaint", "GBLg.pickaH", "GBLcc.mattfeldt", "GBLcc.pickaint", "GBLc"), phat = NULL, cvchat = NULL, cpp1 = NULL )
xi |
An observation of a RACS of interest as a full binary map (as an |
boxwidths |
A list of box widths |
estimators |
A vector of estimator names - see details for possible names. |
obswin |
If |
includenormed |
A logical value. If TRUE then GBL estimates normalised by the GBL values at zero will be included in a returned list of |
setcov_boundarythresh |
To avoid instabilities caused by dividing by very small quantities, if the set covariance of the observation window
is smaller than |
phat |
The fraction of foreground area in the observation window, which is the usual estimator of coverage probability given by |
cvchat |
The plug-in moment covariance estimate (often from |
cpp1 |
Picka's estimate of coverage probability for subsets of the observation window. See |
As empirical GBL is one of the GBL estimators available through this function, non-square boxes are not allowed.
To estimate GBL for non-square boxes use gblcc
or gblg
directly.
If xi
is an owin
object then obswin
and xi
are converted
into an im
object using as.im
The estimators available are
"GBLc"
The unmodified (unbalanced) covariance estimator provided by gblc
"GBLemp"
Empirical gliding box lacunarity (Allain and Cloitre, 1991). Calls gblemp
"GBLcc.mattfeldt"
See help for gblcc
"GBLcc.pickaint"
See help for gblcc
"GBLcc.pickaH"
See help for gblcc
The default, GBLcc.pickaH, is a method based on centred covariance. Centred covariance approaches zero for large vectors, and are thus easier to integrate with the set covariance of the boxes.
The set covariance of the boxes is computed empirically using spatstat's setcov
function, which converts into a binary pixel mask using
as.mask
defaults. Computation speed can be increased by setting a small default number of pixels, npixel
, in spatstat's global options (accessed through spatstat.options
), however fewer pixels also decreases the accuracy of the GBL computation.
An fv
object.
gbl()
: computes GBL estimates from a binary map.
gbl.cvchat()
: computes covariance-based estimator of GBL from the plug-in moment estimate of covariance,
Picka's reduced window coverage probability estimates (see cppicka
) and the usual coverage probability estimate, phat
.
Allain, C. and Cloitre, M. (1991) Characterizing the lacunarity of random and deterministic fractal sets. Physical Review A, 44, 3552-3558.
Hingee K, Baddeley A, Caccetta P, Nair G (2019). Computation of lacunarity from covariance of spatial binary maps. Journal of Agricultural, Biological and Environmental Statistics, 24, 264-288. DOI: 10.1007/s13253-019-00351-9.
xi <- as.im(heather$coarse, value = TRUE, na.replace = FALSE) boxwidths <- seq(1, 10, by = 0.5) # reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^5) gblests <- gbl(xi, boxwidths, estimators = "GBLcc.pickaH") spatstat.options(oldopt)
xi <- as.im(heather$coarse, value = TRUE, na.replace = FALSE) boxwidths <- seq(1, 10, by = 0.5) # reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^5) gblests <- gbl(xi, boxwidths, estimators = "GBLcc.pickaH") spatstat.options(oldopt)
Can be used to estimate the gliding box lacunarity (GBL) of a stationary RACS from a binary map using the plug-in moment covariance covariance estimator (Hingee et al., 2019). It can also calculate the GBL of a RACS from a given covariance function and coverage probability.
gblc( boxes, covariance = NULL, p = NULL, xiim = NULL, integrationMethod = "cubature" )
gblc( boxes, covariance = NULL, p = NULL, xiim = NULL, integrationMethod = "cubature" )
boxes |
Either a list of side lengths for square boxes or a list of |
covariance |
A |
p |
The coverage probability. Typically estimated by the fraction of the observation window covered by the set of interest. |
xiim |
A binary coverage map as an |
integrationMethod |
The integration method used by |
Computes a numerical approximation of
where is each of the sets (often called a box) specified by
boxes
,
is the set covariance of
,
is the area of
,
is the coverage probability of a stationary RACS, and
is the covariance of a stationary RACS.
This can be used to compute the GBL from model parameters by passing
gblc
the
covariance and coverage probability of the model.
The set covariance of is computed empirically using spatstat's
setcov
function, which converts into a binary pixel mask using
as.mask
defaults. Computation speed can be increased by setting a small default number of pixels, npixel
, in spatstat's global options (accessed through spatstat.options
), however fewer pixels also decreases the accuracy of the GBL computation.
The default method of integration for the above integral is cubature::cubintegrate()
from the cubature package.
The 'harmonisesum
' method is known to produce numerical artefacts (Section 6.2 of (Hingee et al., 2019))
If a binary map is supplied then and
are estimated using
the usual coverage probability estimator and the plug-in moment covariance estimator, respectively
(see
coverageprob
and plugincvc
).
If boxes
is a list of numerical values then GBL is estimated
for square boxes with side length given by boxes
.
The returned object is then an fv
object containing estimates of GBL,
box mass variance and box mass mean.
If boxes
is a list of owin
objects then gblc
returns a
dataframe with columns corresponding to estimates of GBL, box mass variance and box mass mean.
Note if NA
or NaN
values in the covariance
object are used then gblc
will return NA
or NaN
.
Hingee K, Baddeley A, Caccetta P, Nair G (2019). Computation of lacunarity from covariance of spatial binary maps. Journal of Agricultural, Biological and Environmental Statistics, 24, 264-288. DOI: 10.1007/s13253-019-00351-9.
xi <- heather$coarse # reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^5) covar <- plugincvc(xi, Frame(xi)) p <- area(xi) / area(Frame(xi)) sidelengths <- seq(0.3, 14, by = 1) # compute GBL estimate for square boxes from estimated covariance gblest <- gblc(sidelengths, covar, p) # compute GBL estimate for boxes that are discs discboxes <- lapply(sidelengths / 2, disc) discgbls <- gblc(discboxes, covar, p) # compute GBL estimates from binary map xiim <- as.im(xi, na.replace = 0) gblest <- gblc(sidelengths, xiim = xiim) spatstat.options(oldopt)
xi <- heather$coarse # reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^5) covar <- plugincvc(xi, Frame(xi)) p <- area(xi) / area(Frame(xi)) sidelengths <- seq(0.3, 14, by = 1) # compute GBL estimate for square boxes from estimated covariance gblest <- gblc(sidelengths, covar, p) # compute GBL estimate for boxes that are discs discboxes <- lapply(sidelengths / 2, disc) discgbls <- gblc(discboxes, covar, p) # compute GBL estimates from binary map xiim <- as.im(xi, na.replace = 0) gblest <- gblc(sidelengths, xiim = xiim) spatstat.options(oldopt)
Estimates the gliding box lacunarity (GBL) of a stationary RACS using centred covariance estimates (Hingee et al., 2017). The centred covariance and coverage probability can be provided or estimated from binary map.
gblcc( boxes, cencovar = NULL, p = NULL, xiim = NULL, estimator = "pickaH", integrationMethod = "harmonisesum" ) gblcc.inputcovar(boxes, cencovar, p, integrationMethod = "harmonisesum")
gblcc( boxes, cencovar = NULL, p = NULL, xiim = NULL, estimator = "pickaH", integrationMethod = "harmonisesum" ) gblcc.inputcovar(boxes, cencovar, p, integrationMethod = "harmonisesum")
boxes |
Either a list of side lengths for square boxes or a list of |
cencovar |
A |
p |
The coverage probability. Typically estimated by the fraction of the observation window covered by the set of interest. |
xiim |
An observation of a stationary RACS as an |
estimator |
If an observation |
integrationMethod |
The integration method used by |
If we denote the estimated centred covariance by
and coverage probability
then
the estimate of GBL is
where is each of the sets (often called a box) specified by
boxes
,
is the set covariance of
,
is the area of
,
is the coverage probability of a stationary RACS.
The set covariance of is computed empirically using spatstat's
setcov
function, which converts into a binary pixel mask using
as.mask
defaults. Computation speed can be increased by setting a small default number of pixels, npixel
, in spatstat's global options (accessed through spatstat.options
), however fewer pixels also decreases the accuracy of the GBL computation.
If boxes
is a list of numerical values then GBL is estimated for square boxes with side length given by boxes
.
The returned object is then an fv
object containing estimates of GBL, box mass variance and box mass mean.
If boxes
is a list of owin
objects then gblcc
returns a dataframe of with columns corresponding to estimates of GBL, box mass variance and box mass mean.
Note if NA
or NaN
values in the covariance
object are used then gblc
will return NA
or NaN
instead of an GBL value.
gblcc.inputcovar()
: GBL estimates from already estimated centred covariance.
Hingee K, Baddeley A, Caccetta P, Nair G (2019). Computation of lacunarity from covariance of spatial binary maps. Journal of Agricultural, Biological and Environmental Statistics, 24, 264-288. DOI: 10.1007/s13253-019-00351-9.
xi <- heather$coarse cencovar <- cencovariance(xi, obswin = Frame(xi), estimators = c("pickaH"), drop = TRUE) p <- area(xi) / area(Frame(xi)) sidelengths <- seq(0.3, 14, by = 1) # reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^5) # compute GBL estimate for square boxes from estimated centred covariance gblccest <- gblcc(sidelengths, cencovar, p) # compute GBL estimate for boxes that are discs discboxes <- lapply(sidelengths / 2, disc) discgbls <- gblcc(discboxes, cencovar, p) # compute GBL estimates from binary map xiim <- as.im(xi, na.replace = 0) gblccest <- gblcc(sidelengths, xiim = xiim, estimator = "pickaH") spatstat.options(oldopt)
xi <- heather$coarse cencovar <- cencovariance(xi, obswin = Frame(xi), estimators = c("pickaH"), drop = TRUE) p <- area(xi) / area(Frame(xi)) sidelengths <- seq(0.3, 14, by = 1) # reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^5) # compute GBL estimate for square boxes from estimated centred covariance gblccest <- gblcc(sidelengths, cencovar, p) # compute GBL estimate for boxes that are discs discboxes <- lapply(sidelengths / 2, disc) discgbls <- gblcc(discboxes, cencovar, p) # compute GBL estimates from binary map xiim <- as.im(xi, na.replace = 0) gblccest <- gblcc(sidelengths, xiim = xiim, estimator = "pickaH") spatstat.options(oldopt)
Calculates empirical gliding box lacunarity of a binary map, which was proposed by Allain and Cloitre (1991).
gblemp(boxwidths, xiim, obswin = Frame(xiim)) gbltrad(boxwidths, xiim, obswin = Frame(xiim))
gblemp(boxwidths, xiim, obswin = Frame(xiim)) gbltrad(boxwidths, xiim, obswin = Frame(xiim))
boxwidths |
A list of suggested box widths in the same units as |
xiim |
An image of pixels valued either |
obswin |
Optional observation window. The observation window used for the estimator will be the intersection of |
Calculates empirical gliding box lacunarity (Allain and Cloitre, 1991) for a given range of square box sizes,
where is a box that has a random location in the observation window and
is the (random) area of the foreground in
.
This is an estimate of the gliding box lacunarity of a RACS (Hingee et al., 2017).
The algorithm uses the pixel locations in xiim
as an array of box centre locations to compute
the mean and variance of the area in a random box of a given size.
Locations where the box is not completely within the observation window are ignored.
An fv
object containing empirical GBL, variance of the area in the box and mean of the area in the box.
The box widths (labelled s
) are always odd multiples of the pixel width.
gbltrad()
: An alias of gblemp
used in past versions of this package. This alias may be removed in future versions.
The box side lengths are rounded such that they are an odd number of pixels across.
gblemp
uses the roll_sum
function in RcppRoll to operate, so RcppRoll must be installed to run gblemp
.
Allain, C. and Cloitre, M. (1991) Characterizing the lacunarity of random and deterministic fractal sets. Physical Review A, 44, 3552-3558.
Hingee K, Baddeley A, Caccetta P, Nair G (2019). Computation of lacunarity from covariance of spatial binary maps. Journal of Agricultural, Biological and Environmental Statistics, 24, 264-288. DOI: 10.1007/s13253-019-00351-9.
xiim <- as.im(heather$coarse, na.replace = 0) boxwidths <- seq(0.2, 14, by = 0.2) #in units of xiim gblest <- gblemp(boxwidths, xiim)
xiim <- as.im(heather$coarse, na.replace = 0) boxwidths <- seq(0.2, 14, by = 0.2) #in units of xiim gblest <- gblemp(boxwidths, xiim)
Estimates the gliding box lacunarity (GBL) of a stationary RACS by estimating pair-correlation from a binary map (Hingee et al., 2017). It can also calculate the GBL of a RACS from a provided pair-correlation function.
gblg(boxes, paircorr = NULL, xiim = NULL, integrationMethod = "cubature")
gblg(boxes, paircorr = NULL, xiim = NULL, integrationMethod = "cubature")
boxes |
Either a list of side lengths for square boxes or a list of |
paircorr |
A |
xiim |
An observation of a stationary RACS as an |
integrationMethod |
The integration method used by |
If we denote the estimated pair-correlation by then the estimate of GBL is
where is each of the sets (often called a box) specified by
boxes
,
is the set covariance of
,
is the area of
,
is the coverage probability of a stationary RACS.
This can be used to compute the GBL from model parameters by passing
gblc
the
covariance and coverage probability of the model.
If the xiim
argument to gblg
is used then pair correlation is estimated from xiim
using paircorr
and the pickaH
estimator.
The set covariance of is computed empirically using spatstat's
setcov
function, which converts into a binary pixel mask using
as.mask
defaults. Computation speed can be increased by setting a small default number of pixels, npixel
, in spatstat's global options (accessed through spatstat.options
), however fewer pixels also decreases the accuracy of the GBL computation.
The default integration method for this function uses cubature::cubintegrate()
from the cubature package.
The 'harmonisesum' integration method is known to produce numerical artefacts (Section 6.2 of (Hingee et al., 2019))
If boxes
is a list of numerical values then GBL is estimated for square boxes with side length given by boxes
.
The returned object is then an fv
object containing estimates of GBL.
If boxes
is a list of owin
objects then gblg
returns a dataframe of with columns corresponding to estimates of GBL.
Note that if any values in the paircorr
object needed for gblg
are NA
or NaN
then gblg
will return NA
or NaN
, respectively.
Hingee K, Baddeley A, Caccetta P, Nair G (2019). Computation of lacunarity from covariance of spatial binary maps. Journal of Agricultural, Biological and Environmental Statistics, 24, 264-288. DOI: 10.1007/s13253-019-00351-9.
xi <- as.im(heather$coarse, na.replace = 0, eps = 4 * heather$coarse$xstep) sidelengths <- seq(0.3, 14, by = 3) # reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^4) # compute GBL estimates from binary map xiim <- as.im(xi, na.replace = 0) gblgest <- gblg(sidelengths, xiim = xiim) spatstat.options(oldopt)
xi <- as.im(heather$coarse, na.replace = 0, eps = 4 * heather$coarse$xstep) sidelengths <- seq(0.3, 14, by = 3) # reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^4) # compute GBL estimates from binary map xiim <- as.im(xi, na.replace = 0) gblgest <- gblg(sidelengths, xiim = xiim) spatstat.options(oldopt)
Given two functions, f and g, that map from 2D space to 1D, and values of f and g represented as im
objects
then innerprod.im
computes the (function space) inner product
innerprod.im( A, B, outsideA = NA, outsideB = NA, na.replace = TRUE, method = "cubature" )
innerprod.im( A, B, outsideA = NA, outsideB = NA, na.replace = TRUE, method = "cubature" )
A |
An |
B |
An |
outsideA |
The value of |
outsideB |
The value of |
na.replace |
Logical. If TRUE NA values in |
method |
Either "cubature" or "harmonisesum". The former uses |
This function uses the package cubature to integrate the multiple of the two images. If cubature is not available then it harmonises the two input images, multiplies them together and returns the
integral of the resulting image.
outsideA
and outsideB
are used to determine result if the inner product requires
values outside the domain of A or B. For example if outsideA=0
and the
domain of B
is larger than A
's domain then the inner product
can still be computed. However if A
is NA
outside (e.g. not
known/not provided) and the domain of B
is larger than A
's
domain then the inner product can not be computed and the returned value is NA
The harmonisesum
method appears to perform well when used by gblcc()
, but produces numerical artefacts when used by gblc()
and gblg()
. The cubature
method takes longer to compute and is more accurate for functions (A or B) that are non-zero for large vectors. This makes it suitable for use by gblc()
and gblg()
.
If the inner product can be computed then returns sum(A
* B
), otherwise returns NA
.
xi <- heather$coarse covar <- plugincvc(xi, Frame(xi)) B <- setcov(square(1)) innerprod.im(covar, B, outsideB = 0)
xi <- heather$coarse covar <- plugincvc(xi, Frame(xi)) B <- setcov(square(1)) innerprod.im(covar, B, outsideB = 0)
im
object is a binary mapTests whether xi
is a binary map.
The pixel values must be of logical type (TRUE
, FALSE
and NA
only), or numerical (1, 0 or NA
).
isbinarymap(xi, requiretrue = FALSE)
isbinarymap(xi, requiretrue = FALSE)
xi |
an image object |
requiretrue |
Logical. If TRUE then |
Logical value. TRUE
if xi
is a binary map. Otherwise FALSE
.
If requiretrue = TRUE
and xi
is not a binary map then an error will occur.
# The following return TRUE isbinarymap(as.im(heather$coarse, na.value = 0)) isbinarymap(as.im(heather$coarse, na.value = FALSE, value = TRUE)) # The following return FALSE isbinarymap(as.im(heather$coarse, na.value = 0.2, value = 1)) isbinarymap(as.im(heather$coarse, na.value = 0, value = 1.5))
# The following return TRUE isbinarymap(as.im(heather$coarse, na.value = 0)) isbinarymap(as.im(heather$coarse, na.value = FALSE, value = TRUE)) # The following return FALSE isbinarymap(as.im(heather$coarse, na.value = 0.2, value = 1)) isbinarymap(as.im(heather$coarse, na.value = 0, value = 1.5))
Estimates the pair-correlation function of a stationary RACS. The plug-in moment pair-correlation estimator and three 'balanced' estimators suggested by Picka (2000) are available.
paircorr( xi, obswin = NULL, setcov_boundarythresh = NULL, estimators = "all", drop = FALSE ) paircorr.cvchat( cvchat, cpp1 = NULL, phat = NULL, estimators = "all", drop = FALSE )
paircorr( xi, obswin = NULL, setcov_boundarythresh = NULL, estimators = "all", drop = FALSE ) paircorr.cvchat( cvchat, cpp1 = NULL, phat = NULL, estimators = "all", drop = FALSE )
xi |
An observation of a RACS of interest as a full binary map (as an |
obswin |
If |
setcov_boundarythresh |
To avoid instabilities caused by dividing by very small quantities, if the set covariance of the observation window
is smaller than |
estimators |
A list of strings specifying estimators to use.
See details.
|
drop |
If TRUE and one estimator selected then the returned value will be a single |
cvchat |
The plug-in moment estimate of covariance as an |
cpp1 |
Picka's reduced window estimate of coverage probability as an |
phat |
The plug-in moment estimate of coverage probability,
which is the observed foreground area in |
The pair-correlation of a stationary RACS is
The estimators available are (see (Hingee, 2019) for more information):
plugin
the plug-in moment pair-correlation estimator which is , where
and
are
the plug-in moment estimate of covariance and the usual estimate of coverage probability, respectively.
mattfeldt
an 'intrinsically' balanced pair-correlation estimator suggested by Picka (1997).
A similar isotropic pair-correlation estimator was later studied by Mattfeldt and Stoyan (2000).
pickaint
Picka's 'intrinsically' balanced pair-correlation estimator (Picka, 2000).
pickaH
Picka's 'additively' balanced pair-correlation estimator (Picka, 2000).
If drop = TRUE
and a single estimator is requested then an
im
object containing the pair-correlation estimate is returned. Otherwise a
named imlist
of im
objects containing the pair-correlation
estimates for each requested estimator.
paircorr()
: Estimates pair-correlation from a binary map.
paircorr.cvchat()
: Generates pair-correlation estimates from
the plug-in moment estimates of covariance, Picka's reduced window estimate of coverage probability,
and the coverage fraction (which is an unbiased estimate of the coverage probability).
If these estimates already exist then paircorr.cvchat
can save significant computation time.
Kassel Liam Hingee
Hingee, K.L. (2019) Spatial Statistics of Random Closed Sets for Earth Observations. PhD: Perth, Western Australia: University of Western Australia. Submitted.
Mattfeldt, T. and Stoyan, D. (2000) Improved estimation of the pair correlation function of random sets. Journal of Microscopy, 200, 158-173.
Picka, J.D. (1997) Variance-Reducing Modifications for Estimators of Dependence in Random Sets. Ph.D.: Illinois, USA: The University of Chicago.
Picka, J.D. (2000) Variance reducing modifications for estimators of standardized moments of random sets. Advances in Applied Probability, 32, 682-700.
xi <- as.im(heather$coarse, na.replace = 0, eps = 4 * heather$coarse$xstep) # Estimate pair correlation from a binary map pclns_directest <- paircorr(xi, estimators = "all") phat <- coverageprob(xi) cvchat <- plugincvc(xi) cpp1 <- cppicka(xi) # Compute pair correlation estimates from estimates covariance, # coverage probability and Picka's reduced-window coverage probability. pclns_fromcvc <- paircorr.cvchat(cvchat, cpp1, phat, estimators = "all")
xi <- as.im(heather$coarse, na.replace = 0, eps = 4 * heather$coarse$xstep) # Estimate pair correlation from a binary map pclns_directest <- paircorr(xi, estimators = "all") phat <- coverageprob(xi) cvchat <- plugincvc(xi) cpp1 <- cppicka(xi) # Compute pair correlation estimates from estimates covariance, # coverage probability and Picka's reduced-window coverage probability. pclns_fromcvc <- paircorr.cvchat(cvchat, cpp1, phat, estimators = "all")
Places subsets (grains) of two dimension space randomly on a given point pattern. This is useful for simulating germ-grain models such as Boolean models. Also described here are functions for computing summary properties of the a list of grains.
placegrainsfromlib( pp, grainlib, replace = TRUE, prob = NULL, w = NULL, xy = NULL ) meanarea.grainlib( grainlib, weights = rep(1/length(grainlib), length(grainlib)) ) meansetcov.grainlib( grainlib, weights = rep(1/length(grainlib), length(grainlib)), xy ) covar.grainlib(lambda, grainlib, weights, xy)
placegrainsfromlib( pp, grainlib, replace = TRUE, prob = NULL, w = NULL, xy = NULL ) meanarea.grainlib( grainlib, weights = rep(1/length(grainlib), length(grainlib)) ) meansetcov.grainlib( grainlib, weights = rep(1/length(grainlib), length(grainlib)), xy ) covar.grainlib(lambda, grainlib, weights, xy)
pp |
A point pattern (in |
grainlib |
A list of grains as |
replace |
passed directly to |
prob |
A list of probability weights for each grain in the library. Passed directly to |
w |
Optional desired observation window. If this is non-null then any grains with Frame outside the Frame of |
xy |
An |
weights |
Probability of selecting each grain in the library |
lambda |
Intensity of germs of a Boolean model - for computing the covariance of a Boolean model that has grain distribution given by |
Germ-grain models have two components, a point process (called germs) and a process that creates
grains that are centred on the germs.
The point process of germs can be easily simulated using a number of spatstat functions
(e.g. rpoispp
for Boolean models).
To simulate a germ-grain model in a window the germ process must be simulated in a larger window
because grains centred outside
can intersect
.
The result must then be cropped to
to achieve a realisation of the germ-grain process within
.
placegrainsfromlib
randomly samples from a library of grains (grainlib
) and places these on the points in pp
.
Sampling of the grain is independent of the location of the point in pp
.
It can be used to simulate the grain process in some germ-grain models.
Returns an owin
object.
placegrainsfromlib()
: Place grains randomly from a list of grains.
meanarea.grainlib()
: Compute mean area of a random grain given by the library
meansetcov.grainlib()
: Computes the mean of the set covariance of the grains in grainlib
.
xy
is required because the set covariance function must rasterise the owin
objects.
covar.grainlib()
: Compute the covariance of a Boolean model with random grain given by the library
Kassel Liam Hingee
# Simulate a germ-grain model where germs are a Poisson point process # and grains are randomly selected from 3 different disc sizes. grainlib <- solist(disc(radius = 1), disc(radius = 1.9), disc(radius = 0.2)) bufferdist <- 2 #chosen to be larger than the largest radius in library w <- owin(xrange = c(0, 10), yrange = c(0, 10)) # Simulate the germ process in the window plus a buffer region around window pp <- rpoispp(lambda = 0.1, win = dilation(w, bufferdist), nsim = 1, drop = TRUE) xi_withbuffer <- placegrainsfromlib(pp, grainlib) # Simulation of germ-grain model is the part within the window xi <- intersect.owin(xi_withbuffer, w) # Computation of properties from parameters lambda <- 0.1 discr <- 10 weights <- c(0.9999, 0.0001) grainlib <- solist(disc(r = discr), disc(r = 2*discr)) meanarea.grainlib(grainlib, weights) truecovar <- covar.grainlib(lambda, grainlib, weights, xy = as.mask(w, eps = 2))
# Simulate a germ-grain model where germs are a Poisson point process # and grains are randomly selected from 3 different disc sizes. grainlib <- solist(disc(radius = 1), disc(radius = 1.9), disc(radius = 0.2)) bufferdist <- 2 #chosen to be larger than the largest radius in library w <- owin(xrange = c(0, 10), yrange = c(0, 10)) # Simulate the germ process in the window plus a buffer region around window pp <- rpoispp(lambda = 0.1, win = dilation(w, bufferdist), nsim = 1, drop = TRUE) xi_withbuffer <- placegrainsfromlib(pp, grainlib) # Simulation of germ-grain model is the part within the window xi <- intersect.owin(xi_withbuffer, w) # Computation of properties from parameters lambda <- 0.1 discr <- 10 weights <- c(0.9999, 0.0001) grainlib <- solist(disc(r = discr), disc(r = 2*discr)) meanarea.grainlib(grainlib, weights) truecovar <- covar.grainlib(lambda, grainlib, weights, xy = as.mask(w, eps = 2))
This function computes the plug-in moment covariance estimate of a stationary RACS from a binary map.
For a stationary RACS, , the covariance
for a vector
is the probability of two points separated by a vector
are covered by
plugincvc(xi, obswin = NULL, setcov_boundarythresh = NULL)
plugincvc(xi, obswin = NULL, setcov_boundarythresh = NULL)
xi |
An observation of a RACS of interest as a full binary map (as an |
obswin |
If |
setcov_boundarythresh |
To avoid instabilities caused by dividing by very small quantities, if the set covariance of the observation window
is smaller than |
The plug-in moment covariance estimator is (Serra, 1982)
where is the set covariance of the observation window
and
is the set covariance of the foreground within
.
plugincvc
uses Fourier transforms to calculate the set covariance (using the setcov
of the foreground and observation window.
Vectors with small are eliminated using
setcov_boundarythresh
as division by small values is numerically unstable.
A SpatStat im
object containing the estimated covariance.
Kassel Liam Hingee
Serra, J.P. (1982) Image Analysis and Mathematical Morphology. London; New York: Academic Press.
xi <- as.im(heather$coarse, na.replace = 0) covar <- plugincvc(xi)
xi <- as.im(heather$coarse, na.replace = 0) covar <- plugincvc(xi)
Estimates the covariance of a stationary RACS. The plug-in moment covariance estimator and newer balanced estimators based on (Picka, 1997; Picka, 2000) are available.
racscovariance( xi, obswin = NULL, setcov_boundarythresh = NULL, estimators = "all", drop = FALSE ) racscovariance.cvchat( cvchat, cpp1 = NULL, phat = NULL, estimators = "all", drop = FALSE )
racscovariance( xi, obswin = NULL, setcov_boundarythresh = NULL, estimators = "all", drop = FALSE ) racscovariance.cvchat( cvchat, cpp1 = NULL, phat = NULL, estimators = "all", drop = FALSE )
xi |
A binary map. Either an |
obswin |
The observation window as an |
setcov_boundarythresh |
To avoid instabilities caused by dividing by very small quantities, if the set covariance of the observation window
is smaller than |
estimators |
A list of strings specifying covariance estimators to use.
See details.
Passing |
drop |
If TRUE and one estimator is selected then the returned value will be a single |
cvchat |
The plug-in moment estimate of covariance as an |
cpp1 |
Picka's reduced window estimate of coverage probability as an |
phat |
The classical estimate of coverage probability,
which is the observed area in |
The covariance of a RACS is also known as the two-point coverage probability, and is
closely related to the semivariogram.
The covariance of a stationary RACS given a vector
is
the probability that two points separated by a vector
are covered by
.
Given a vector , the plug-in moment covariance estimate from a binary map is the volume of the set of points,
, such that both
and
are observed to be in the foreground
relative to the volume of points,
, for which both
and
are in the observation window (Hingee, 2019).
Picka (1997, 2000) suggested a number of improvements to centred
covariance estimation (see
cencovariance
) that 'balanced' the
data used to estimate covariance with the data used to estimate coverage
probability. These lead to covariance estimators that give
estimates for the covariance of that are a constant offset from
covariance estimates for the complement of
(note the constant offset
depends on the coverage probability), which
appears to avoid some surprising behaviour that the plug-in moment covariance estimator
suffers (Hingee, 2019).
These estimators are called
pickaint
and pickaH
in this package.
Another improved estimator, inspired by an 'intrinsic modification' briefly mentioned by Picka (1997)
for pair-correlation estimators, is also available.
We have called this estimator mattfeldt
as a similar isotropic estimator for pair-correlation
was studied by Mattfeldt and Stoyan (2000).
The estimators available are (see (Hingee, 2019) for more information):
plugin
the plug-in moment covariance estimator
mattfeldt
an estimator inspired by an
'intrinsically' balanced pair-correlation estimator from Picka that was later studied in an
isotropic situation by Mattfeldt and Stoyan (2000)
pickaint
an estimator inspired by an
'intrinsically' balanced centred covariance estimator from Picka (2000).
pickaH
an estimator inspired by the
'additively' balanced centred covariance estimator from Picka (2000).
If drop = TRUE
and only one estimator is requested then
an im
object containing the covariance estimate.
Otherwise a named imlist
of covariance estimates corresponding to each requested estimator.
racscovariance()
: Estimates covariance from a binary map.
racscovariance.cvchat()
: Computes covariance estimates from
a plug-in moment estimate of covariance, Picka's reduced window estimate of coverage probability,
and the usual estimate of coverage probability.
If these estimates already exist then racscovariance.cvchat
can save significant computation time.
Kassel Liam Hingee
Hingee, K.L. (2019) Spatial Statistics of Random Closed Sets for Earth Observations. PhD: Perth, Western Australia: University of Western Australia. Submitted.
Mattfeldt, T. and Stoyan, D. (2000) Improved estimation of the pair correlation function of random sets. Journal of Microscopy, 200, 158-173.
Picka, J.D. (1997) Variance-Reducing Modifications for Estimators of Dependence in Random Sets. Ph.D.: Illinois, USA: The University of Chicago.
Picka, J.D. (2000) Variance reducing modifications for estimators of standardized moments of random sets. Advances in Applied Probability, 32, 682-700.
xi <- heather$coarse obswin <- Frame(xi) # Estimate from a binary map balancedcvchats_direct <- racscovariance(xi, obswin = obswin, estimators = "all") phat <- coverageprob(xi, obswin = obswin) cvchat <- plugincvc(xi, obswin) cpp1 <- cppicka(xi, obswin = Frame(heather$coarse)) harmonised <- harmonise.im(cvchat = cvchat, cpp1 = cpp1) cvchat <- harmonised$cvchat cpp1 <- harmonised$cpp1 # Compute balanced estimate of covariance from other estimates balancedcvchats_fromplugincvc <- racscovariance.cvchat(cvchat, cpp1, phat, estimators = "pickaH", drop = TRUE)
xi <- heather$coarse obswin <- Frame(xi) # Estimate from a binary map balancedcvchats_direct <- racscovariance(xi, obswin = obswin, estimators = "all") phat <- coverageprob(xi, obswin = obswin) cvchat <- plugincvc(xi, obswin) cpp1 <- cppicka(xi, obswin = Frame(heather$coarse)) harmonised <- harmonise.im(cvchat = cvchat, cpp1 = cpp1) cvchat <- harmonised$cvchat cpp1 <- harmonised$cpp1 # Compute balanced estimate of covariance from other estimates balancedcvchats_fromplugincvc <- racscovariance.cvchat(cvchat, cpp1, phat, estimators = "pickaH", drop = TRUE)
Functions for simulating a Boolean model with grains that are discs of fixed constant radius (the abbreviation 'bdd' is short for Boolean model with Deterministic Discs). A Boolean model is a two stage model, first the locations (called germs) of grains are randomly distributed according to a Poisson point process, then a random grain is placed on each germ independently. Introductions to Boolean models are available in many stochastic geometry books (Chiu et al., 2013). Also described here are functions for calculating the coverage probability, germ intensity, and covariance from model parameters for a Boolean model with deterministic discs.
rbdd(lambda, discr, window, seed = NULL) bddcoverageprob(lambda, discr) bddlambda(coverp, discr) bdddiscr(coverp, lambda) bddcovar.iso(r, lambda, discr) bddcovar(xrange, yrange, eps, lambda, discr)
rbdd(lambda, discr, window, seed = NULL) bddcoverageprob(lambda, discr) bddlambda(coverp, discr) bdddiscr(coverp, lambda) bddcovar.iso(r, lambda, discr) bddcovar(xrange, yrange, eps, lambda, discr)
lambda |
Intensity of the germ process (which is a Poisson point process) |
discr |
Radius of the discs |
window |
The window to simulate in (an |
seed |
Optional input (default in NULL). Is an integer passed to
|
coverp |
Coverage probability of the Boolean model |
r |
is the radius to calculate covariance |
xrange |
range of x values for |
yrange |
range of y values for |
eps |
list of length 2 of the steps between samples points in x and y respectively for |
See Functions section.
rbdd()
: Returns an owin
that is a set generated by simulating a Boolean
model with specified intensity and disc radius.
The window information is not contained in this object.
If the simulated set is empty then an empty owin
object is returned.
The point process of germs is generated using spatstat's rpoispp
.
bddcoverageprob()
: Returns the true coverage probability given the intensity and disc radius.
bddlambda()
: Returns the germ intensity given coverage probability and disc radius.
bdddiscr()
: Returns the disc radius given coverage probability and germ intensity.
bddcovar.iso()
: Returns the true covariance of points separated by a distance r
given the intensity, lambda
and disc radius discr
of the model.
bddcovar()
: Returns an image of the covariance as calculated from disc radius and intensity.
The returned object of rbdd
is an owin
specifying the realisation of the Boolean model within the simulation window. The simulation window is not included, thus the object returned by rbdd
can have much smaller extent than the simulation window (e.g. when the simulated set is empty).
Chiu, S.N., Stoyan, D., Kendall, W.S. and Mecke, J. (2013) Stochastic Geometry and Its Applications, 3rd ed. Chichester, United Kingdom: John Wiley & Sons.
# Simulate Boolean model with discs of radius 10. # The coverage probability is very close to 0.5. discr <- 10 w <- owin(xrange = c(0, 100), c(0, 100)) lambda <- 2.2064E-3 xi <- rbdd(lambda, discr, w) # Compute properties of Boolean model from parameters cp <- bddcoverageprob(lambda, discr) cvc <- bddcovar(c(-10, 10), c(-10, 10), c(0.2, 0.2), lambda, discr)
# Simulate Boolean model with discs of radius 10. # The coverage probability is very close to 0.5. discr <- 10 w <- owin(xrange = c(0, 100), c(0, 100)) lambda <- 2.2064E-3 xi <- rbdd(lambda, discr, w) # Compute properties of Boolean model from parameters cp <- bddcoverageprob(lambda, discr) cvc <- bddcovar(c(-10, 10), c(-10, 10), c(0.2, 0.2), lambda, discr)
Functions for simulating a Boolean model with grains that are deterministic rectangles. A Boolean model is a two stage model, first the locations (called germs) of grains are randomly distributed according to a Poisson point process, then a random grain is placed on each germ independently. An introduction can be found in (Chiu et al., 2013). Also described in this help file are functions for calculating the coverage probability and covariance.
rbdr(lambda, grain, win, seed = NULL) bdrcoverageprob(lambda, grain) bdrcovar(lambda, grain, xy)
rbdr(lambda, grain, win, seed = NULL) bdrcoverageprob(lambda, grain) bdrcovar(lambda, grain, xy)
lambda |
Intensity of the germ process (which is a Poisson point process) |
grain |
Rectangle object specifying the grain |
win |
The window to simulate in (an |
seed |
Optional input (default in NULL). Is an integer passed to |
xy |
A raster object that specifies the pixel coordinates of the desired covariance image. |
Depends on the function used (see Functions section).
rbdr()
: Returns an owin
that is a set generated by simulating a Boolean
model with a specified intensity and fixed rectangular grain.
The window information is not contained in this object.
If the simulated set is empty then an empty owin
object is returned.
The point process of germs is generated using spatstat's rpoispp
.
bdrcoverageprob()
: Returns the true coverage probability given the intensity and grain.
bdrcovar()
: Returns an image of the covariance as calculated from disc radius and intensity.
The returned object of rbdr
is only the foreground of a binary map and thus can have much smaller extent than the simulation window (e.g. when the simulated set is empty).
Chiu, S.N., Stoyan, D., Kendall, W.S. and Mecke, J. (2013) Stochastic Geometry and Its Applications, 3rd ed. Chichester, United Kingdom: John Wiley & Sons.
grain <- owin(xrange = c(-5, 5), yrange = c(-5, 5)) win <- owin(xrange = c(0, 100), c(0, 100)) lambda <- 4.2064E-3 xi <- rbdr(lambda, grain, win) cp_theoretical <- bdrcoverageprob(lambda, grain) xy <- as.mask(dilationAny(win, win), eps = c(1, 1)) cvc_theoretical <- bdrcovar(lambda, grain, xy)
grain <- owin(xrange = c(-5, 5), yrange = c(-5, 5)) win <- owin(xrange = c(0, 100), c(0, 100)) lambda <- 4.2064E-3 xi <- rbdr(lambda, grain, win) cp_theoretical <- bdrcoverageprob(lambda, grain) xy <- as.mask(dilationAny(win, win), eps = c(1, 1)) cvc_theoretical <- bdrcovar(lambda, grain, xy)
Simulates a Boolean model of discs with log normal radii by first simulating a Poisson point process and then placing discs of random radii around each point (the radii are generated using a log normal distribution).
rblnd(obswin, bufferdist, lambda, meanlog, sdlog, seed = NULL)
rblnd(obswin, bufferdist, lambda, meanlog, sdlog, seed = NULL)
obswin |
An |
bufferdist |
A distance to expand |
lambda |
Intensity of the Poisson point process, passed to rpoispp. It could be either a single positive number, or any other object that rpoispp can understand. |
meanlog |
For the distribution of radii. The logarithm of the distribution is set to have mean |
sdlog |
For the distribution of radii. The logarithm of the distribution is set to have standard deviation |
seed |
Optional input (default is |
The point process needs to be simulated in a larger region than the desired observation window to account for the possibility of discs that intersect the observation window, but have germs outside the observation window.
The point process of germs is generated using spatstat's rpoispp
.
Returns an owin
object cropped to obswin
.
A good choice of bufferdist
is required and will be sensitive to the distribution of radii.
w <- owin(xrange = c(0, 10), yrange = c(0, 10)) xi <- rblnd(w, 2, 0.3, -1, 0.2)
w <- owin(xrange = c(0, 10), yrange = c(0, 10)) xi <- rblnd(w, 2, 0.3, -1, 0.2)
Functions for simulation and computing theoretical values of a Boolean model with identically shaped grains with size given by a truncated Pareto distribution.
rbpto(lambda, grain, win, xm, alpha, lengthscales, seed = NULL, xy = NULL) bpto.coverageprob(lambda, grain, xm, alpha, lengthscales = 1:500) bpto.germintensity(coverp, grain, xm, alpha, lengthscales = 1:500) bpto.covar(lambda, grain, xm, alpha, lengthscales = 1:500, xy)
rbpto(lambda, grain, win, xm, alpha, lengthscales, seed = NULL, xy = NULL) bpto.coverageprob(lambda, grain, xm, alpha, lengthscales = 1:500) bpto.germintensity(coverp, grain, xm, alpha, lengthscales = 1:500) bpto.covar(lambda, grain, xm, alpha, lengthscales = 1:500, xy)
lambda |
Intensity of the germ process (which is a Poisson point process) |
grain |
A single |
win |
The window to simulate in (an |
xm |
A parameter governing the shape of the Pareto distribution used - see details |
alpha |
A parameter governing the shape of the Pareto distribution used
|
lengthscales |
A list of scales of the |
seed |
Optional input (default in NULL). Is an integer passed to
|
xy |
A raster object that specifies pixel coordinates of the final
simulated binary map. It is used the same way as |
coverp |
Coverage probability of the Boolean model. |
The parameters xm
and alpha
are such that the CDF of the Pareto distribution is .
The distribution of grains scales is a step-function approximation to the CDF with steps at
lengthscales
.
An owin
object.
rbpto()
: Simulate Boolean model with grain size distributed according to a truncated Pareto distribution.
bpto.coverageprob()
: The coverage probability of the Boolean model with grain size distributed according to a truncated Pareto distribution.
bpto.germintensity()
: The germ intensity of the Boolean model with grain size distributed according to a truncated Pareto distribution.
bpto.covar()
: The covariance of the Boolean model with grain size distributed according to a truncated Pareto distribution.
xy
is required to specify resolution and offset of pixel grid.
lambda <- 0.2 win <- square(r = 10) grain <- disc(r = 0.2) xm <- 0.01 alpha <- 2 lengthscales <- seq(1, 5, by = 0.1) xi <- rbpto(lambda, grain, win, xm, alpha, lengthscales = lengthscales) # Compute properties of the Boolean model from parameters bpto.coverageprob(lambda, grain, xm, alpha, lengthscales = lengthscales) covar <- bpto.covar(lambda, grain, xm, alpha, lengthscales = lengthscales, xy = as.mask(win, eps = 2))
lambda <- 0.2 win <- square(r = 10) grain <- disc(r = 0.2) xm <- 0.01 alpha <- 2 lengthscales <- seq(1, 5, by = 0.1) xi <- rbpto(lambda, grain, win, xm, alpha, lengthscales = lengthscales) # Compute properties of the Boolean model from parameters bpto.coverageprob(lambda, grain, xm, alpha, lengthscales = lengthscales) covar <- bpto.covar(lambda, grain, xm, alpha, lengthscales = lengthscales, xy = as.mask(win, eps = 2))
Estimates many second order properties of RACS, gliding box lacunarity, covariance, centred covariance, and pair-correlation. This can be faster than computing estimates of multiple second order properties separately as Fourier transforms of the binary map are not repeated.
secondorderprops( xiim, gblargs = NULL, covarargs = NULL, cencovarargs = NULL, paircorrargs = NULL, returnrotmean = FALSE )
secondorderprops( xiim, gblargs = NULL, covarargs = NULL, cencovarargs = NULL, paircorrargs = NULL, returnrotmean = FALSE )
xiim |
A spatstat |
gblargs |
A list of named arguments passed to |
covarargs |
A list of named arguments passed to |
cencovarargs |
A list of named arguments passed to |
paircorrargs |
A list of named arguments passed to |
returnrotmean |
Logical. If FALSE the anisotropic estimates of covariance and pair-correlation will be returned as |
A named list of estimated properties. When multiple estimators have been requested for the same property, then the entry in the list is itself a list, with each entry corresponding to a different estimator.
The user interface for this function is substantially more stretched the knowledge of the author, Kassel Hingee. Therefore, there is greater chance of encountering bugs. Kassel Hingee apologises for any bugs you encounter, and requests to be informed (thank you!).
xiim <- as.im(heather$coarse, value = TRUE, na.replace = FALSE) gblargs = list(boxwidths = seq(1, 10, by = 1), estimators = c("GBLemp", "GBLcc.pickaH")) covarargs = list(estimators = "all") cencovarargs = list(estimators = "pickaH") paircorrargs = list(estimators = "pickaH") returnrotmean = TRUE secondests <- secondorderprops(xiim, gblargs = gblargs, covarargs = covarargs, cencovarargs = cencovarargs, paircorrargs = paircorrargs, returnrotmean = FALSE)
xiim <- as.im(heather$coarse, value = TRUE, na.replace = FALSE) gblargs = list(boxwidths = seq(1, 10, by = 1), estimators = c("GBLemp", "GBLcc.pickaH")) covarargs = list(estimators = "all") cencovarargs = list(estimators = "pickaH") paircorrargs = list(estimators = "pickaH") returnrotmean = TRUE secondests <- secondorderprops(xiim, gblargs = gblargs, covarargs = covarargs, cencovarargs = cencovarargs, paircorrargs = paircorrargs, returnrotmean = FALSE)
im
objectsThis function assumes that im
objects are each realisations of the same (stochastic) object.
It returns pointwise summaries such as observed sample mean and sample variance.
## S3 method for class 'imlist' summary(object, ..., harmonizeobject = TRUE)
## S3 method for class 'imlist' summary(object, ..., harmonizeobject = TRUE)
object |
A list of |
... |
Ignored |
harmonizeobject |
If TRUE (default) the pixel dimensions of the images will be harmonized. Otherwise the object will be tested for compatibility. |
A list im
objects containing the pointwise mean, variance and maxima and minima.
Kassel Hingee
# reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^4) obspatterns <- replicate(3, rbdd(10, 0.05, window = square(1)), simplify = FALSE) ims <- solapply(obspatterns, function(x) racscovariance(x, obswin = square(1), estimators = "pickaH", drop = TRUE)) summ <- summary.imlist(ims, harmonizeobject = FALSE) spatstat.options(oldopt)
# reduce resolution in setcov() for faster (less accurate) computation oldopt <- spatstat.options() spatstat.options("npixel" = 2^4) obspatterns <- replicate(3, rbdd(10, 0.05, window = square(1)), simplify = FALSE) ims <- solapply(obspatterns, function(x) racscovariance(x, obswin = square(1), estimators = "pickaH", drop = TRUE)) summ <- summary.imlist(ims, harmonizeobject = FALSE) spatstat.options(oldopt)