K Function

using SpatialMultitaper, GeoStatsProcesses

import GLMakie as Mke

The K function is a second-order summary statistic for point processes. It is defined as the expected number of further points within a distance r of an arbitrary point, divided by the intensity of the process. For a homogeneous Poisson process, this is simply πr^2 in two dimensions. The K function can be estimated using the k_function function.

region = Box(Point(0, 0), Point(100, 100))
X = rand(PoissonProcess(0.01), region)
data = spatial_data(X, region)
tapers = sin_taper_family((4, 4), region)
nk = (100, 100)
kmax = (0.1, 0.1)
radii = 0:0.5:30
kfun = k_function(data, radii = radii, nk = nk, kmax = kmax, tapers = tapers)
K function of a 2 dimensional process
  between processes: 1 and 1
  evaluated at 0.0:0.5:30.0
  with values of type Vector{Float64}

We can then visualise the K function using Makie

Mke.lines(kfun)
Example block output

L functions

The L function is a transformation of the K function, defined as L(r) = sqrt(K(r)/π). This is usually easier to visualise, as for a homogeneous Poisson process, L(r) = r. We can compute the L function using the l_function function.

lfun = l_function(kfun)
L function of a 2 dimensional process
  between processes: 1 and 1
  evaluated at 0.0:0.5:30.0
  with values of type Vector{Float64}

and again plot this using Makie

Mke.lines(lfun)
Example block output

we can also plot the difference L(r) - r, which is often used to assess clustering or inhibition in the point process.

Mke.lines(centered_l_function(lfun))
Example block output

these functions can be computed from each other or directly from the data

lfun2 = l_function(data, radii = radii, nk = nk, kmax = kmax, tapers = tapers)
lfun.value == lfun2.value
true

This page was generated using Literate.jl.