tessdev divides the space-time window into cells using a Voronoi tessellation and calculates the deviance residuals within each cell between two competing conditional intensity models.tessdev(X, cifunction1, cifunction2, theta1 = NULL, theta2 = NULL,
lambda1 = NULL, lambda2 = NULL, algthm1 = c("mc", "miser", "none"),
algthm2 = c("mc", "miser", "none"), n = 100, n1.miser = 10000,
n2.miser = 10000, 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.mcmisernonemcmisernonen until some accuracy threshold is reached.miser algorithm is selected.miser algorithm is selected.ints1 should correspond to each cell in the tile.list that is returned using the deldir fuints2 should correspond to each cell in the tile.list that is returned using the deldir fuOutputs an object of class tessdev
stpptile.listtile.list.algthm = mcmc algorithm:miser algorithm is selected, then a list of the following elements are also included for each model that uses the miser algorithm:$$R_{TD}(V_{i}) = \left(1 - \int_{V_{i}}\hat{\lambda}_{1}(x)dx\right)/\sqrt{\int_{V_{i}}\hat{\lambda}_{1}(x)dx}-\left(1 - \int_{V_{i}}\hat{\lambda}_{2}(x)dx\right)/\sqrt{\int_{V_{i}}\hat{\lambda}_{2}(x)dx},$$ 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_{TD}(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 arguments ints1 and/or ints2 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 ints1 and/or ints2 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 ints1 and/or ints2 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.
tessresid#===> 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 <- tessdev(X, ci1, ci2, theta1 = 3000)
#===> plot results <===#
plot(deviance)Run the code above in your browser using DataLab