# parres

##### Partial Residuals for Point Process Model

Computes the smoothed partial residuals, a diagnostic for transformation of a covariate in a Poisson point process model.

##### Usage

```
parres(model, covariate, ...,
smooth.effect=FALSE, subregion=NULL,
bw = "nrd0", adjust=1, from = NULL, to = NULL, n = 512,
bw.input = c("points", "quad"), bw.restrict=FALSE, covname)
```

##### Arguments

- model
- Fitted point process model (object of class
`"ppm"`

). - covariate
- The covariate of interest.
Either a character string matching the name of one of
the canonical covariates in the model, or one of the names
`"x"`

or`"y"`

referring to the Cartesian coordinates, or one of the names of - smooth.effect
- Logical. Determines the choice of algorithm. See Details.
- subregion
- Optional. A window (object of class
`"owin"`

) specifying a subset of the spatial domain of the data. The calculation will be confined to the data in this subregion. - bw
- Smoothing bandwidth or bandwidth rule
(passed to
`density.default`

). - adjust
- Smoothing bandwidth adjustment factor
(passed to
`density.default`

). - n, from, to
- Arguments passed to
`density.default`

to control the number and range of values at which the function will be estimated. - ...
- Additional arguments passed to
`density.default`

. - bw.input
- Character string specifying the input data used for automatic bandwidth selection.
- bw.restrict
- Logical value, specifying whether bandwidth selection is performed using
data from the entire spatial domain or from the
`subregion`

. - covname
- Optional. Character string to use as the name of the covariate.

##### Details

This command computes the smoothed partial residual diagnostic
(Baddeley, Chang, Song and Turner, 2012)
for the transformation of a covariate
in a Poisson point process model.
The argument `model`

must be a fitted Poisson point process model.
The diagnostic works in two different ways:
[object Object],[object Object]
Alternatively `covariate`

can be one of the character strings
`"x"`

or `"y"`

signifying the Cartesian coordinates.
The behaviour here depends on whether the coordinate was one of the
canonical covariates in the model.

If there is more than one canonical covariate in the model
that depends on the specified `covariate`

, then
the covariate effect is computed using all these canonical covariates.
For example in a log-quadratic model which includes the terms `x`

and
`I(x^2)`

, the quadratic effect involving both these terms
will be computed.

There are two choices for the algorithm.
If `smooth.effect=TRUE`

, the fitted covariate effect (according
to `model`

) is added to the point process residuals, then
smoothing is applied to these values. If `smooth.effect=FALSE`

,
the point process residuals are smoothed first, and then the fitted
covariate effect is added to the result.

The smoothing bandwidth is controlled by the arguments
`bw`

, `adjust`

, `bw.input`

and `bw.restrict`

.
If `bw`

is a numeric value, then
the bandwidth is taken to be `adjust * bw`

.
If `bw`

is a string representing a bandwidth selection rule
(recognised by `density.default`

)
then the bandwidth is selected by this rule.

The data used for automatic bandwidth selection are
specified by `bw.input`

and `bw.restrict`

.
If `bw.input="points"`

(the default) then bandwidth selection is
based on the covariate values at the points of the original point
pattern dataset to which the model was fitted.
If `bw.input="quad"`

then bandwidth selection is
based on the covariate values at every quadrature point used to
fit the model.
If `bw.restrict=TRUE`

then the bandwidth selection is performed
using only data from inside the `subregion`

.

##### Value

- A function value table (object of class
`"fv"`

) containing the values of the smoothed partial residual, the estimated variance, and the fitted effect of the covariate. Also belongs to the class`"parres"`

which has methods for`print`

and`plot`

.

##### Slow computation

In a large dataset, computation can be very slow if the default
settings are used, because the smoothing bandwidth is selected
automatically. To avoid this, specify a numerical value
for the bandwidth `bw`

. One strategy is to use a coarser
subset of the data to select `bw`

automatically.
The selected bandwidth can be read off the print output for
`parres`

.

##### References

Baddeley, A., Chang, Y.-M., Song, Y. and Turner, R. (2013)
Residual diagnostics for covariate effects in
spatial point process models.
*Journal of Computational and Graphical Statistics*,
**22**, 886--905.

##### See Also

##### Examples

```
X <- rpoispp(function(x,y){exp(3+x+2*x^2)})
model <- ppm(X, ~x+y)
tra <- parres(model, "x")
plot(tra)
plot(parres(model, "x", subregion=square(0.5)))
model2 <- ppm(X, ~x+I(x^2)+y)
plot(parres(model2, "x"))
Z <- setcov(owin())
plot(parres(model2, Z))
```

*Documentation reproduced from package spatstat, version 1.41-1, License: GPL (>= 2)*