tessresid: Calculate tessellation residuals

Description Usage Arguments Details Value Author(s) See Also Examples


tessresid divides the space-time window into bins using a Voronoi tessellation and calculates residuals within each bin for a specified conditional intensity model.


tessresid(X, cifunction, theta = NULL, algthm = c("mc", "miser", "none"), 
n = 100, n.miser = 10000, ints = NULL)



A “stpp” object.


A function returning the value of the conditional intensity at all points in X. The function should take arguments X and an optional vector of parameters theta.


Optional: A vector of parameters to be passed to cifunction.


The algorithm used for estimating the integrals in each tessellation cell. The three algorithms are “mc”, “miser”, and “none


Initial number of sample points in each grid tessellation for approximating integrals. The number of sample points are iteratively increased by n until some accuracy threshold is reached.


The total number of sample points for estimating all integrals.


An optional vector of integrals. Must be the same length as the number of tessellation cells, and each element of ints should correspond to each cell in the tile.list that is returned using the deldir function, which can be called separately.


Tessellation residuals are residuals calculated in bins that are created by dividing up the spatial window using a Voronoi tessellation. Because the bins are based on a tessellation, each bin contains at most one point. The residual in bin i (V_i) is defined by

R_{T}(V_{i}) = ≤ft(1 - \int_{V_{i}}\hat{λ}(x)dx\right)/√{\int_{V_{i}}\hat{λ}(x)dx},

where lambda_hat(x) is the fitted conditional intensity model.

The conditional intensity function, cifunction, should take X as the first argument, and an optional theta as the second argument, and return a vector of conditional intensity estimates with length equal to the number of points in X, i.e. the length of X$x. cifunction is required, while lambda is optional. lambda eliminates the need for tessresid to calculate the conditional intensity at each observed point in X.

The integrals in R_{T}(V_{i}) are approximated using one of two algorithms: a simple Monte Carlo (mc) algorithm, or the MISER algorithm. The simple Monte Carlo iteratively adds n sample points to each tessellation cell to approximate the integral, and the iteration stops when some threshold in the accuracy of the approximation is reached. The MISER algorithm samples a total number of n.miser points in a recursive way, sampling the points in locations that have the highest variance. This part can be very slow and the approximations can be very inaccurate. For highest accuracy these algorithms will require a very large n or n.miser depending on the complexity of the conditional intensity functions (some might say ~1 billion sample points are needed for a good approximation).

Passing the argument ints eliminates the need for approximating the integrals using either of the two algorithms here. However, the tile.list must first be obtained in order to assure that each element of ints corresponds to the correct cell. The tile.list can be obtained, either by using the deldir function separately, or by using tessresid with one of the included algorithms first (the tile.list is returned along with the residuals). tessresid can then be called again with ints included and algthm = “none”.

Note that if miser is selected, and if the points in the point pattern are very densely clustered, the integral in some cells may end up being approximated based on only the observed point in the point pattern that is contained in that cell. This happens because the cells in these clusters of points will be very small, and so it may be likely that sampled points based on the MISER algorithm will miss these cells entirely. For this reason, the simple Monte Carlo algorithm might be preferred.


Outputs an object of class “tessresid”, which is a list of


An object of class “stpp”.


An object of type “tile.list”, which is itself a list with one entry for each point in X. Each entry is a list of

pt: x and y coordinates of the point.

x: x coordinates of the vertices of the tessellation cell.

y: y coordinates of the vertices of the tessellation cell.


A vector of tessellation residuals. The order of the residuals corresponds with the order of the cells in tile.list.


Robert Clements

See Also

gridresid, deldir, tile.list


#===> load simulated data <===#
X <- stpp(simdata$x, simdata$y, simdata$t)

#===> define two conditional intensity functions <===#
ci1 <- function(X, theta){theta*exp(-2*X$x - 2*X$y - 2*X$t)} #correct model

ci2 <- function(X, theta = NULL){rep(250, length(X$x))} #homogeneous Poisson model

## Not run: 
tsresiduals <- tessresid(X, ci1, theta = 3000)
tsresiduals2 <- tessresid(X, ci2)
#===> plot results <===#

## End(Not run)

Search within the stppResid package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.