# Kest

##### K-function

Estimates the reduced second moment function $K(r)$ from a point pattern in a window of arbitrary shape.

- Keywords
- spatial

##### Usage

```
Kest(X)
Kest(X, r)
Kest(X, breaks)
```

##### Arguments

- X
- The observed point pattern,
from which an estimate of $K(r)$ will be computed.
An object of class
`"ppp"`

, or data in any format acceptable to`as.ppp()`

. - r
- vector of values for the argument $r$ at which $K(r)$ should be evaluated. There is a sensible default.
- breaks

##### Details

The $K$ function (variously called ``Ripley's K-function''
and the ``reduced second moment function'')
of a stationary point process $X$ is defined so that
$\lambda K(r)$ equals the expected number of
additional random points within a distance $r$ of a
typical random point of $X$. Here $\lambda$
is the intensity of the process,
i.e. the expected number of points of $X$ per unit area.
The $K$ function is determined by the
second order moment properties of $X$.
An estimate of $K$ derived from a spatial point pattern dataset
can be used in exploratory data analysis and formal inference
about the pattern (Cressie, 1991; Diggle, 1983; Ripley, 1988).
In exploratory analyses, the estimate of $K$ is a useful statistic
summarising aspects of inter-point ``dependence'' and ``clustering''.
For inferential purposes, the estimate of $K$ is usually compared to the
true value of $K$ for a completely random (Poisson) point process,
which is $K(r) = \pi r^2$.
Deviations between the empirical and theoretical $K$ curves
may suggest spatial clustering or spatial regularity.
This routine `Kest`

estimates the $K$ function
of a stationary point process, given observation of the process
inside a known, bounded window.
The argument `X`

is interpreted as a point pattern object
(of class `"ppp"`

, see `ppp.object`

) and can
be supplied in any of the formats recognised by
`as.ppp()`

.

The estimation of $K$ is hampered by edge effects arising from the unobservability of points of the random pattern outside the window. An edge correction is needed to reduce bias (Baddeley, 1998; Ripley, 1988). The correction implemented here is the border method or ``reduced sample'' estimator (Ripley, 1988). Although this is less efficient than some alternative corrections, it has the advantage that it can be computed for a window of arbitrary shape.

Note that the estimator assumes the process is stationary (spatially
homogeneous). For inhomogeneous point patterns, see
`Kinhom`

.

The estimator `Kest`

ignores marks.
Its counterparts for multitype point patterns
are `Kcross`

, `Kdot`

,
and for general marked point patterns
see `Kmulti`

.

Some writers, particularly Stoyan (1994, 1995) advocate the use of
the ``pair correlation function''
$$g(r) = \frac{K'(r)}{2\pi r}$$
where $K'(r)$ is the derivative of $K(r)$.
See `pcf`

on how to estimate this function.

##### Value

- A data frame containing
r the vector of values of the argument $r$ at which the function $K$ has been estimated border the ``reduced sample'' or ``border corrected'' estimator of $K(r)$ theo the theoretical value $K(r) = \pi r^2$ for a stationary Poisson process

##### synopsis

Kest(X, r=NULL, breaks=NULL, slow, both, ...)

##### Warnings

The estimator of $K(r)$ is approximately unbiased for each fixed $r$. Bias increases with $r$ and depends on the window geometry. For a rectangular window it is prudent to restrict the $r$ values to a maximum of $1/4$ of the smaller side length of the rectangle. Bias may become appreciable for point patterns consisting of fewer than 15 points. While $K(r)$ is always a non-decreasing function, the estimator of $K$ is not guaranteed to be non-decreasing. This is rarely a problem in practice.

##### References

Baddeley, A.J. Spatial sampling and censoring.
In O.E. Barndorff-Nielsen, W.S. Kendall and
M.N.M. van Lieshout (eds)
*Stochastic Geometry: Likelihood and Computation*.
Chapman and Hall, 1998.
Chapter 2, pages 37--78.
Cressie, N.A.C. *Statistics for spatial data*.
John Wiley and Sons, 1991.

Diggle, P.J. *Statistical analysis of spatial point patterns*.
Academic Press, 1983.

Ripley, B.D. *Statistical inference for spatial processes*.
Cambridge University Press, 1988.

Stoyan, D, Kendall, W.S. and Mecke, J. (1995)
*Stochastic geometry and its applications*.
2nd edition. Springer Verlag.

Stoyan, D. and Stoyan, H. (1994) Fractals, random shapes and point fields: methods of geometrical statistics. John Wiley and Sons.

##### See Also

`Fest`

,
`Gest`

,
`Jest`

,
`pcf`

,
`reduced.sample`

,
`Kcross`

,
`Kdot`

,
`Kinhom`

,
`Kmulti`

##### Examples

```
library(spatstat)
pp <- runifpoint(50)
Kpp <- Kest(pp)
plot(Kpp$r, Kpp$border, type="l", xlab="r", ylab="K(r)", ylim=c(0,1),
main = "K-function")
r <- Kpp$r
lines(r, Kpp$theo, lty=2)
legend(0.5, 2, c("empirical (border correction)", "Poisson process"), lty=c(1,2))
data(cells)
K <- Kest(cells)
plot(K$r, K$border, type="l")
plot(border ~ r, type="l", data=K)
# restrict the plot to values of r less than 0.1
plot(border ~ r, type="l", data=K[K$r <= 0.1, ])
plot(border ~ r, type="l", data=K, subset=(r <= 0.1))
```

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