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)
stpp
X
. The function should take arguments X
and an optional vector of parameters theta
.cifunction
.mc
miser
none
n
until some accuracy threshold is reached.ints
should correspond to each cell in the tile.list
that is returned using the deldir
function, whichtessresid
stpp
tile.list
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.
tile.list
.$$R_{T}(V_{i}) = \left(1 - \int_{V_{i}}\hat{\lambda}(x)dx\right)/\sqrt{\int_{V_{i}}\hat{\lambda}(x)dx},$$
where $\hat{\lambda}(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.
gridresid
, deldir
, tile.list
#===> load simulated data <===#
data(simdata)
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
tsresiduals <- tessresid(X, ci1, theta = 3000)
tsresiduals2 <- tessresid(X, ci2)
#===> plot results <===#
plot(tsresiduals)
plot(tsresiduals2)
Run the code above in your browser using DataLab