# Kinhom

##### Inhomogeneous K-function

Estimates the inhomogeneous $K$ function of a non-stationary point pattern.

- Keywords
- spatial, nonparametric

##### Usage

```
Kinhom(X, lambda, ..., r = NULL, breaks = NULL,
correction=c("border", "bord.modif", "isotropic", "translate"),
nlarge = 500, lambda2)
```

##### Arguments

- X
- The observed data point pattern,
from which an estimate of the inhomogeneous $K$ function
will be computed.
An object of class
`"ppp"`

or in a format recognised by`as.ppp()`

- lambda
- Values of the estimated intensity function.
Either a vector giving the intensity values
at the points of the pattern
`X`

, or a pixel image (object of class`"im"`

) giving the intensity values at all locations. - ...
- Ignored.
- r
- vector of values for the argument $r$ at which the inhomogeneous $K$ function should be evaluated. Not normally given by the user; there is a sensible default.
- breaks
- An alternative to the argument
`r`

. Not normally invoked by the user. See Details. - correction
- A character vector containing any selection of the
options
`"border"`

,`"bord.modif"`

,`"isotropic"`

,`"Ripley"`

or`"translate"`

. It specifies the edge correction(s) to be applied. - nlarge
- Optional. Efficiency threshold.
If the number of points exceeds
`nlarge`

, then only the border correction will be computed, using a fast algorithm. - lambda2
- Advanced use only. Matrix containing estimates of the products $\lambda(x_i)\lambda(x_j)$ of the intensities at each pair of data points $x_i$ and $x_j$.

##### Details

This computes a generalisation of the $K$ function
for inhomogeneous point patterns, proposed by
Baddeley, Moller and Waagepetersen (2000).
The ``ordinary'' $K$ function
(variously known as the reduced second order moment function
and Ripley's $K$ function), is
described under `Kest`

. It is defined only
for stationary point processes.
The inhomogeneous $K$ function
$K_{\rm inhom}(r)$
is a direct generalisation to nonstationary point processes.
Suppose $x$ is a point process with non-constant intensity
$\lambda(u)$ at each location $u$.
Define $K_{\rm inhom}(r)$ to be the expected
value, given that $u$ is a point of $x$,
of the sum of all terms
$1/\lambda(u)\lambda(x_j)$
over all points $x_j$
in the process separated from $u$ by a distance less than $r$.
This reduces to the ordinary $K$ function if
$\lambda()$ is constant.
If $x$ is an inhomogeneous Poisson process with intensity
function $\lambda(u)$, then
$K_{\rm inhom}(r) = \pi r^2$.

This allows us to inspect a point pattern for evidence of interpoint interactions after allowing for spatial inhomogeneity of the pattern. Values $K_{\rm inhom}(r) > \pi r^2$ are suggestive of clustering.

The argument `lambda`

must supply the
(estimated) values of the intensity function $\lambda$.
It may be either
[object Object],[object Object]

Edge corrections are used to correct bias in the estimation of $K_{\rm inhom}$. Each edge-corrected estimate of $K_{\rm inhom}(r)$ is of the form $$\widehat K_{\rm inhom}(r) = \sum_i \sum_j \frac{1{d_{ij} \le r} e(x_i,x_j,r)}{\lambda(x_i)\lambda(x_j)}$$ where $d_{ij}$ is the distance between points $x_i$ and $x_j$, and $e(x_i,x_j,r)$ is an edge correction factor. For the `border' correction, $$e(x_i,x_j,r) = \frac{1(b_i > r)}{\sum_j 1(b_j > r)/\lambda(x_j)}$$ where $b_i$ is the distance from $x_i$ to the boundary of the window. For the `modified border' correction, $$e(x_i,x_j,r) = \frac{1(b_i > r)}{\mbox{area}(W \ominus r)}$$ where $W \ominus r$ is the eroded window obtained by trimming a margin of width $r$ from the border of the original window. For the `translation' correction, $$e(x_i,x_j,r) = \frac 1 {\mbox{area}(W \cap (W + (x_j - x_i)))}$$ and for the `isotropic' correction, $$e(x_i,x_j,r) = \frac 1 {\mbox{area}(W) g(x_i,x_j)}$$ where $g(x_i,x_j)$ is the fraction of the circumference of the circle with centre $x_i$ and radius $||x_i - x_j||$ which lies inside the window.

If the point pattern `X`

contains more than about 1000 points,
the isotropic and translation edge corrections can be computationally
prohibitive. The computations for the border method are much faster,
and are statistically efficient when there are large numbers of
points. Accordingly, if the number of points in `X`

exceeds
the threshold `nlarge`

, then only the border correction will be
computed. Setting `nlarge=Inf`

will prevent this from happening.
Setting `nlarge=0`

is equivalent to selecting only the border
correction with `correction="border"`

.

The pair correlation function can also be applied to the
result of `Kinhom`

; see `pcf`

.

##### Value

- An object of class
`"fv"`

(see`fv.object`

). Essentially a data frame containing at least the following columns, r the vector of values of the argument $r$ at which the pair correlation function $g(r)$ has been estimated theo vector of values of $\pi r^2$, the theoretical value of $K_{\rm inhom}(r)$ for an inhomogeneous Poisson process - and containing additional columns
according to the choice specified in the
`correction`

argument. The additional columns are named`border`

,`trans`

and`iso`

and give the estimated values of $K_{\rm inhom}(r)$ using the border correction, translation correction, and Ripley isotropic correction, respectively.

##### References

Baddeley, A., Moller, J. and Waagepetersen, R. (2000)
Non- and semiparametric estimation of interaction in
inhomogeneous point patterns.
*Statistica Neerlandica* **54**, 329--350.

##### See Also

##### Examples

```
data(lansing)
# inhomogeneous pattern of maples
X <- unmark(split(lansing)$maple)
<testonly>sub <- sample(c(TRUE,FALSE), X$n, replace=TRUE, prob=c(0.1,0.9))
X <- X[sub , ]</testonly>
# (1) intensity function estimated by model-fitting
# Fit spatial trend: polynomial in x and y coordinates
fit <- ppm(X, ~ polynom(x,y,2), Poisson())
# predict intensity values at points themselves
lambda <- predict(fit, locations=X, type="trend")
# inhomogeneous K function
Ki <- Kinhom(X, lambda)
plot(Ki)
# (2) intensity function estimated by heavy smoothing
smo <- density.ppp(X, sigma=0.1)
# evaluate smoothed intensity at data points
lambda <- smo[X]
# inhomogeneous K function
Ki <- Kinhom(X, lambda)
plot(Ki)
# (3) simulated data: known intensity function
lamfun <- function(x,y) { 100 * x }
# inhomogeneous Poisson process
Y <- rpoispp(lamfun, 100, owin())
# evaluate intensity at points of pattern
lambda <- lamfun(Y$x, Y$y)
# inhomogeneous K function
Ki <- Kinhom(Y, lambda)
plot(Ki)
# How to make simulation envelopes:
# Example shows method (2)
smo <- density.ppp(X, sigma=0.1)
myKfun <- function(X, ..., lam) { Kinhom(X, lambda=lam[X], ...) }
Ken <- envelope(X, myKfun, nsim=99,
simulate=expression(rpoispp(smo)),
lam=smo, correction="trans")
plot(Ken)
```

*Documentation reproduced from package spatstat, version 1.9-1, License: GPL version 2 or newer*