# diagnose.ppm

##### Diagnostic Plots for Fitted Point Process Model

Given a point process model fitted to a point pattern, produce diagnostic plots based on residuals.

- Keywords
- spatial

##### Usage

```
diagnose.ppm(object, ..., type="raw", which="all", sigma=NULL,
rbord=reach(object), cumulative=TRUE,
plot.it=TRUE,
plot.neg="image", plot.smooth="imagecontour", plot.sd,
rv = NULL, plot.sd, spacing=0.1,
srange=NULL, monochrome=FALSE)
```

##### Arguments

- object
- The fitted point process model (an object of class
`"ppm"`

) for which diagnostics should be produced. This object is usually obtained from`ppm`

. - type
- String indicating the type of residuals or weights to be used.
Current options are
`"eem"`

for the Stoyan-Grabarnik exponential energy weights,`"raw"`

for the raw residuals,`"inverse"`

for the inverse-lam - which
- Character string or vector indicating the choice(s) of
plots to be generated. Options are
`"all"`

,`"marks"`

,`"smooth"`

,`"x"`

,`"y"`

and`"sum"`

. Multiple choices may be g - sigma
- Bandwidth for kernel smoother in
`"smooth"`

option. - ...
- Extra arguments, controlling either the resolution of the smoothed image
(passed to
`ksmooth.ppp`

) or the appearance of the plots (passed to`plot.default`

). - rbord
- Width of border to avoid edge effects.
The diagnostic calculations
will be confined to those points of the data pattern which are
at least
`rbord`

units away from the edge of the window. - cumulative
- Logical flag indicating whether the lurking variable plots
for the $x$ and $y$ coordinates will be the plots of
cumulative sums of marks (
`cumulative=TRUE`

) or the plots of marginal integrals of the smoothed residual field ( - plot.it
- Logical value indicating whether
plots should be shown. If
`plot.it=FALSE`

, the computed diagnostic quantities are returned without plotting them. - plot.neg
- One of
`"discrete"`

or`"image"`

indicating how the density part of the residual measure should be plotted. - plot.smooth
- One of
`"image"`

,`"persp"`

,`"contour"`

or`"imagecontour"`

indicating how the smoothed residual field should be plotted. - plot.sd
- Logical value indicating whether
error bounds should be added to the
`"x"`

and`"y"`

plots. The default is`TRUE`

for Poisson models and`FALSE`

for non-Poisson models. See Details. - rv
- Usually absent.
If this argument is present, the values of the residuals will not be
calculated from the fitted model
`object`

but will instead be taken directly from this vector. - spacing
- The spacing between plot panels (when a four-panel plot is generated) expressed as a fraction of the width of the window of the point pattern.
- srange
- Vector of length 2 that will be taken as giving the range of values of the smoothed residual field, when generating an image plot of this field. This is useful if you want to generate diagnostic plots for two different fitted models using the
- monochrome
- Flag indicating whether images should be displayed in greyscale (suitable for publication) or in colour (suitable for the screen). The default is to display in colour.

##### Details

This function generates several diagnostic plots for a
fitted point process model.
The plots display the residuals from the fitted model
(Baddeley et al, 2005)
or alternatively the `exponential energy marks' (Stoyan and Grabarnik, 1991).
These plots can be used to
assess goodness-of-fit, to identify outliers in the data,
and to reveal departures from the fitted model.
See also the companion function `qqplot.ppm`

.

The argument `object`

must be a fitted point process model
(object of class `"ppm"`

) typically produced by the maximum
pseudolikelihood fitting algorithm `ppm`

).

The argument `type`

selects the type of residual or weight
that will be computed. Current options are:

[object Object],[object Object]

The argument `which`

selects the type of plot that is
produced. Options are:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

The argument `rbord`

ensures there are no edge
effects in the computation of the residuals. The diagnostic calculations
will be confined to those points of the data pattern which are
at least `rbord`

units away from the edge of the window.
The value of `rbord`

should be greater than or equal to
the range of interaction permitted in the model.

The argument `rv`

would normally be used only by experts.
It enables the user to substitute arbitrary values for the
residuals or marks, overriding the usual calculations.
If `rv`

is present, then instead of calculating the residuals from
the fitted model, the algorithm takes the entries of the vector
`rv`

to be the values of the residuals or marks,
and plots them in the manner appropriate to the type of residual
or mark selected by `type`

. The length of `rv`

must equal
the number of points in the original data point pattern
(if `type="eem"`

) or the number of quadrature (data and dummy)
points used to fit the model (if `type="raw"`

,
`type="inverse"`

or `type="pearson"`

).

The return value is an object of class `"diagppm"`

.
There are methods for `plot`

and `print`

for such objects.
See the Examples.
See also the companion function `qqplot.ppm`

which produces a
Q-Q plot of the residuals.

##### Value

- An object of class
`"diagppm"`

which contains the coordinates needed to reproduce the selected plots. This object can be plotted using`plot.diagppm`

and printed using`print.diagppm`

.

##### synopsis

diagnose.ppm(object, ..., type="raw", which="all", sigma=NULL, rbord=reach(object), cumulative=TRUE, plot.it=TRUE, rv = NULL, compute.sd=TRUE, compute.cts=TRUE, typename)

##### References

Baddeley, A., Turner, R., Moller, J. and Hazelton, M. (2005) Residual analysis for spatial point processes. Journal of the Royal Statistical Society, Series B. to appear.

Stoyan, D. and Grabarnik, P. (1991)
Second-order characteristics for stochastic structures connected with
Gibbs point processes.
*Mathematische Nachrichten*, 151:95--100.

##### See Also

##### Examples

```
data(cells)
fit <- ppm(cells, ~x, Strauss(r=0.15), rbord=0.15)
diagnose.ppm(fit, rbord=0.15)
diagnose.ppm(fit, type="pearson", rbord=0.15)
diagnose.ppm(fit, rbord=0.15, which="marks")
diagnose.ppm(fit, rbord=0.15, type="raw", plot.neg="discrete")
# save the diagnostics and plot them later
u <- diagnose.ppm(fit, rbord=0.15, plot.it=FALSE)
plot(u)
plot(u, which="marks")
```

*Documentation reproduced from package spatstat, version 1.7-11, License: GPL version 2 or newer*