# idw

##### Inverse-distance weighted smoothing of observations at irregular points

Performs spatial smoothing of numeric values observed at a set of irregular locations using inverse-distance weighting.

##### Usage

`idw(X, power=2, at="pixels", ...)`

##### Arguments

- X
A marked point pattern (object of class

`"ppp"`

).- power
Numeric. Power of distance used in the weighting.

- at
String specifying whether to compute the intensity values at a grid of pixel locations (

`at="pixels"`

) or only at the points of`X`

(`at="points"`

).- …
Arguments passed to

`as.mask`

to control the pixel resolution of the result.

##### Details

This function performs spatial smoothing of numeric values observed at a set of irregular locations.

Smoothing is performed by inverse distance weighting. If the observed values are \(v_1,\ldots,v_n\) at locations \(x_1,\ldots,x_n\) respectively, then the smoothed value at a location \(u\) is $$ g(u) = \frac{\sum_i w_i v_i}{\sum_i w_i} $$ where the weights are the inverse \(p\)-th powers of distance, $$ w_i = \frac 1 {d(u,x_i)^p} $$ where \(d(u,x_i) = ||u - x_i||\) is the Euclidean distance from \(u\) to \(x_i\).

The argument `X`

must be a marked point pattern (object
of class `"ppp"`

, see `ppp.object`

).
The points of the pattern are taken to be the
observation locations \(x_i\), and the marks of the pattern
are taken to be the numeric values \(v_i\) observed at these
locations.

The marks are allowed to be a data frame. Then the smoothing procedure is applied to each column of marks.

If `at="pixels"`

(the default), the smoothed mark value
is calculated at a grid of pixels, and the result is a pixel image.
The arguments `…`

control the pixel resolution.
See `as.mask`

.

If `at="points"`

, the smoothed mark values are calculated
at the data points only, using a leave-one-out rule (the mark value
at a data point is excluded when calculating the smoothed value
for that point).

An alternative to inverse-distance weighting is kernel smoothing,
which is performed by `Smooth.ppp`

.

##### Value

*If X has a single column of marks:*

If

`at="pixels"`

(the default), the result is a pixel image (object of class`"im"`

). Pixel values are values of the interpolated function.If

`at="points"`

, the result is a numeric vector of length equal to the number of points in`X`

. Entries are values of the interpolated function at the points of`X`

.

*If X has a data frame of marks:*

If

`at="pixels"`

(the default), the result is a named list of pixel images (object of class`"im"`

). There is one image for each column of marks. This list also belongs to the class`"solist"`

, for which there is a plot method.If

`at="points"`

, the result is a data frame with one row for each point of`X`

, and one column for each column of marks. Entries are values of the interpolated function at the points of`X`

.

##### See Also

`density.ppp`

,
`ppp.object`

,
`im.object`

.

See `Smooth.ppp`

for kernel smoothing
and `nnmark`

for nearest-neighbour interpolation.

To perform other kinds of interpolation, see also the `akima`

package.

##### Examples

```
# NOT RUN {
# data frame of marks: trees marked by diameter and height
data(finpines)
plot(idw(finpines))
idw(finpines, at="points")[1:5,]
# }
```

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