devresid divides the space-time window into a grid of bins and calculates the deviance residuals within each bin between two competing conditional intensity models.devresid(X, cifunction1, cifunction2, theta1 = NULL, theta2 = NULL,
lambda1 = NULL, lambda2 = NULL, grid = c(10, 10), gf = NULL, algthm1 =
c("cubature", "mc", "miser", "none"), algthm2 = c("cubature", "mc", "miser", "none"),
n = 100, n1.miser = 10000, n2.miser = 10000, tol = 1e-05, maxEval = 0,
absError = 0, ints1 = NULL, ints2 = NULL)stppX, according to model 1 (cifunction1). The function should take arguments X and an optional vector of parameters theta1.X, according to model 2 (cifunction2) which should be different than model 1 (cifunction1). The function should take arguments Xcifunction1.cifunction2.cifunction1 at each point in X.cifunction2 at each point in X.stgridcubaturemcmisernonecubaturemcmisernonen until some accuracy threshold is reached.miser algorithm is selected.miser algorithm is selected.grid, and each element of ints1 should correspond to each row in grid.grid, and each element of ints2 should correspond to each row in grid.Outputs an object of class devresid
stppstgridgrid.miser algorithm is selected, the following is also returned:$$R_{D}(B_i) = \sum_{i:(x_{i})\in B_{i}} log \hat{\lambda}_{1}(x_{i}) - \int_{B_{i}} \hat{\lambda}_{1}(x_{i}) dx - \left(\sum_{i:(x_{i})\in B_{i}} log \hat{\lambda}_{2}(x_{i}) - \int_{B_{i}} \hat{\lambda}_{2}(x_{i}) dx\right),$$ where $\hat{\lambda}(x)$ is the fitted conditional intensity model.
The conditional intensity functions, cifunction1 and cifunction2, should take X as their first argument, and an optional theta as their 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. Both cifunction1 and cifunction2 are required. lambda1 and lambda2 are optional, and if passed will eliminate the need for devresid to calculate the conditional intensities 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 n1.miser and/or n2.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 n1.miser/n2.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 ints1 and/or ints2 eliminates the need for approximating the integrals using either of these two algorithms.
Passing gf will eliminate the need for devresid to create a stgridgrid or gf is specified, the default grid is 10 by 10.
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.
make.grid#===> 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
deviance <- devresid(X, ci1, ci2, theta1 = 3000)
#===> plot results <===#
plot(deviance)Run the code above in your browser using DataLab