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

`gridresid`

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

1 |

`X` |
A “ |

`cifunction` |
A function returning the value of the conditional intensity at all points in |

`theta` |
Optional: A vector of parameters to be passed to |

`lambda` |
Optional: A vector of conditional intensities at each point in |

`grid` |
A vector representing the number of columns and rows in the grid. |

`gf` |
Optional: A “ |

`resid` |
The residual type to be computed. The three types are “ |

`algthm` |
The algorithm used for estimating the integrals in each grid cell. The three algorithms are “ |

`n` |
Initial number of sample points in each grid cell for approximating integrals. The number of sample points are iteratively increased by |

`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 |

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{λ}(x) dx,*

where *lambda_hat(x)* is the fitted conditional intesity model.

The `pearson`

residual is defined as

*R_{p}(B_{i}) = ∑_{x_{i} \in B_{i}}1/√{\hat{λ}(x_{i})} - \int_{B_{i}}√{\hat{λ}(x)} dx.*

The `inverse`

residual is defined as

*R_{I}(B_{i}) = ∑_{x_{i} \in B_{i}}1/\hat{λ}(x_{i}) - \int_{B_{i}}I(\hat{λ}(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.

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

`X ` |
An object of class “ |

`grid ` |
An object of class “ |

`residuals ` |
A vector of grid-based residuals. The order of the residuals corresponds with the order of the bins in |

`n` |
Total number of points used for approximating all integrals. |

`integral` |
Vector of actual integral approximations in each grid cell. |

`mean.lambda` |
Vector of the approximate final mean of lambda in each grid cell. |

`sd.lambda` |
Vector of the approximate standard deviation of lambda in each grid cell. |

If the `miser`

algorithm is selected, the following is also returned:

`app.pts` |
A 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). |

Robert Clements

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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ```
#===> 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
## Not run:
gresiduals <- gridresid(X, ci1, theta = 3000)
plot(gresiduals)
## End(Not run)
gresiduals2 <- gridresid(X, ci2)
plot(gresiduals2)
``` |

stppResid documentation built on May 29, 2017, 3:48 p.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.