Learn R Programming

stppResid (version 1.1)

gridresid: Calculate grid-based residuals

Description

gridresid divides the space-time window into a grid of bins and calculates residuals within each bin for a specified conditional intensity model.

Usage

gridresid(X, cifunction, theta = NULL, lambda = NULL, grid = c(10, 10), gf = NULL, resid = c("raw", "pearson", "inverse"), algthm = c("cubature", "mc", "miser", "none"), n = 100, n.miser = 10000, tol = 1e-05, maxEval = 0, absError = 0, ints = NULL)

Arguments

X
A stpp object.
cifunction
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.
theta
Optional: A vector of parameters to be passed to cifunction.
lambda
Optional: A vector of conditional intensities at each point in X.
grid
A vector representing the number of columns and rows in the grid.
gf
Optional: A stgrid object.
resid
The residual type to be computed. The three types are raw, pearson, and inverse.
algthm
The algorithm used for estimating the integrals in each grid cell. The three algorithms are cubature, mc, miser, and none
n
Initial number of sample points in each grid cell for approximating integrals. The number of sample points are iteratively increased by n until some accuracy threshold is reached.
n.miser
The total number of sample points for estimating all integrals.
tol
The maximum tolerance.
maxEval
The maximum number of function evaluations needed (default 0 implies no limit).
absError
The maximum absolute error tolerated.
ints
An optional vector of integrals. Must be the same length as the number of rows in grid, and each element of ints should correspond to each row in grid.

Value

  • Prints to the screen the number of simulated points in each bin used to approximate the integrals. Outputs an object of class gridresid, which is a list of
  • XAn object of class stpp.
  • gridAn object of class stgrid.
  • residualsA vector of grid-based residuals. The order of the residuals corresponds with the order of the bins in grid.
  • nTotal number of points used for approximating all integrals.
  • integralVector of actual integral approximations in each grid cell.
  • mean.lambdaVector of the approximate final mean of lambda in each grid cell.
  • sd.lambdaVector of the approximate standard deviation of lambda in each grid cell.
  • If the miser algorithm is selected, the following is also returned:
  • app.ptsA data frame of the x,y, and t coordinates of a sample of 10,000 of the sampled points for integral approximation, along with the value of lambda (l).

Details

The grid-based residuals are well known residuals for temporal point processes, and purely spatial point processes (see Baddeley et al. (2005)), extended to space-time point processes in Clements et al. (2010). They consist of the raw residual, and rescaled versions of the raw residual called the pearson residual and the inverse residual.

The raw residual for bin i ($B_{i}$) is defined as the number of points in $B_{i}$ minus the expected number of points in $B_{i}$,

$$R(B_{i}) = N(B_{i}) - \int_{B_{i}} \hat{\lambda}(x) dx,$$

where $\hat{\lambda}(x)$ is the fitted conditional intesity model.

The pearson residual is defined as

$$R_{p}(B_{i}) = \sum_{x_{i} \in B_{i}}1/\sqrt{\hat{\lambda}(x_{i})} - \int_{B_{i}}\sqrt{\hat{\lambda}(x)} dx.$$

The inverse residual is defined as

$$R_{I}(B_{i}) = \sum_{x_{i} \in B_{i}}1/\hat{\lambda}(x_{i}) - \int_{B_{i}}I(\hat{\lambda}(x) > 0)dx.$$

If neither type of residual is specified, the default residual to be computed is the raw residual.

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 gridresid to calculate the conditional intensity at each observed point in X.

The integrals in $R(B_{i})$ are approximated using one of three algorithms: the adaptIntegrate function from the cubature pakcage, a simple Monte Carlo (mc) algorithm, or the miser algorithm. The default is cubature and should be the fastest approximation. The approximation continues until either the maximum number of evaluations is reached, the error is less than the absolute error, or is less than the tolerance times the integral.

The simple Monte Carlo iteratively adds n sample points to each grid 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 these two algorithms.

Passing gf will eliminate the need for gridresid to create a stgrid object. If neither grid or gf is specified, the default grid is 10 by 10.

References

Baddeley, A., Turner, R.,Moller, J., and Hazelton, M. (2005) Residual analysis for spatial point processes. Journal of the Royal Statistical Society, 67, 617--666.

Clements, R.A., Schoenberg, F.P., and Schorlemmer, D. (2011) Residual analysis methods for space-time point processes with applications to earthquake forecast models in California. Annals of Applied Statistics, 5, Number 4, 2549--2571.

See Also

make.grid

Examples

Run this code
#===> 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

gresiduals <- gridresid(X, ci1, theta = 3000)
plot(gresiduals)
gresiduals2 <- gridresid(X, ci2)
plot(gresiduals2)

Run the code above in your browser using DataLab