Skip to contents

Computes the KAMP (K-function Adjusted for Marked Permutations) expectation for a given spatial point pattern. This function calculates Ripley's K using both the traditional Ripley's K method (based on Kcross) and the KAMP-adjusted CSR baseline (based on Kest).

The KAMP-adjusted CSR represents a more robust baseline for K (compared to traditional CSR) that accounts for spatial clustering or inhomogeneity in a point pattern compared to the traditional CSR assumption, while avoiding the computational burden of permuting the point pattern.

Notes:

This function uses the spatstat package under the hood, which automatically uses border correction when the number of points in the point pattern is more than 3000.

See ?Kcross and ?Kest for more details on the K calculation methods.

See kamp_expectation_mat for the matrix-based implementation.

Usage

kamp_expectation(
  ppp_obj,
  rvals = c(0, 0.05, 0.075, 0.1, 0.15, 0.2),
  correction = "trans",
  marksvar1 = "immune"
)

Arguments

ppp_obj

A point pattern object from the spatstat.geom package.

rvals

Vector of radii at which to calculate the KAMP expectation. Defaults to c(0, 0.05, 0.075, 0.1, 0.15, 0.2).

correction

Type of edge correction method to be used and passed to Kcross and Kest. Defaults to translational edge correction.

marksvar1

Identifies subset of marked points. Defaults to immune.

Value

A dataframe with the following columns:

r

The radius at which K was calculated.

k

The observed K value from Kcross

theo_csr

The theoretical K under CSR from Kcross

kamp_csr

The adjusted CSR representing the permuted expectation.

kamp

The difference between observed K and KAMP CSR

Details

Compute KAMP Expectation

Examples

if (requireNamespace("spatstat.geom", quietly = TRUE)) {
  # simulates a simple spatial point pattern with two types
  win <- spatstat.geom::owin(c(0, 1), c(0, 1))
  pp <- spatstat.random::rpoispp(lambda = 100, win = win)
  marks <- sample(c("immune", "background"), pp$n, replace = TRUE)
  marked_pp <- spatstat.geom::ppp(pp$x, pp$y, window = win, marks = factor(marks))

  # computes KAMP expectation
  kamp_result <- kamp_expectation(marked_pp, marksvar1 = "immune")
  print(kamp_result)
}
#> # A tibble: 6 × 5
#>       r      k theo_csr kamp_csr    kamp
#>   <dbl>  <dbl>    <dbl>    <dbl>   <dbl>
#> 1 0     0       0        0       0      
#> 2 0.05  0.0111  0.00785  0.00854 0.00256
#> 3 0.075 0.0208  0.0177   0.0182  0.00256
#> 4 0.1   0.0381  0.0314   0.0306  0.00749
#> 5 0.15  0.0768  0.0707   0.0737  0.00316
#> 6 0.2   0.133   0.126    0.129   0.00382