Partial K function

The partial K function is an extension of the K function that allows us to account for the effect of other types of points on the points of interest. It is particularly useful in multitype point patterns, where we want to understand the spatial distribution of one type of point while considering the influence of other types.

using SpatialMultitaper, GeoStatsProcesses

import GLMakie as Mke

Consider an example where we have three types of points, generated by first making points of type X, and then translating these points randomly to create points of type Y and Z.

region = Box(Point(0, 0), Point(100, 100))
X = rand(PoissonProcess(0.01), region)
function random_translate(p, sigma = 1)
    shift = sigma * randn()
    θ = 2π * rand()
    Translate(shift * cos(θ), shift * sin(θ))(p)
end
Y = PointSet(random_translate.(X))
Z = PointSet(random_translate.(X))

data = spatial_data((X, Y, Z), region)
Spatial data in 2 dimensions
  processes: 1:3
  region: Box(min: (x: 0.0 m, y: 0.0 m), max: (x: 100.0 m, y: 100.0 m))
  with values of type Tuple{PointSet{𝔼{2}, CoordRefSystems.Cartesian2D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}, PointSet{𝔼{2}, CoordRefSystems.Cartesian2D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}, PointSet{𝔼{2}, CoordRefSystems.Cartesian2D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}}

We can then compute the L function as before, but also the partial L function, which accounts for the effect of the other types of points.

tapers = sin_taper_family((4, 4), region)
nk = 100
kmax = 0.1
radii = 0:0.1:30
lfun = l_function(data, radii = radii, nk = nk, kmax = kmax, tapers = tapers)
par_lfun = partial_l_function(data, radii = radii, nk = nk, kmax = kmax, tapers = tapers)
partial L function of a 2 dimensional process
  between processes: 1:3 and 1:3
  evaluated at 0.0:0.1:30.0
  with values of type Vector{StaticArraysCore.SMatrix{3, 3, Float64, 9}}

If we look at the L function between types Y and Z, we see that it indicates clustering between these two types of points, as the curve is above the diagonal line. However, the partial L function, which accounts for the effect of type 1 points, shows that there is actually no clustering between types Y and Z when the effect of type X is accounted for.

fig = Mke.Figure()
ax = Mke.Axis(fig[1, 1], title = "L function vs partial", xlabel = "r", ylabel = "K(r)")
Mke.ablines!(ax, 0, 1; color = :black, linestyle = :dash)
Mke.lines!(ax, lfun[2, 3], label = "L function")
Mke.lines!(ax, par_lfun[2, 3], label = "Partial L function")
Mke.axislegend(ax; position = :lt)
fig
Example block output

This page was generated using Literate.jl.