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 realistic 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.

Note: this is a slower, matrix-based implementation of the KAMP expectation

See get_kamp_expectation for the faster implementation that utilizes functions in spatstat

Usage

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

Arguments

ppp_obj

A point pattern object of class "ppp" from the spatstat package.

rvals

A vector of radii at which to calculate the KAMP expectation.

correction

Type of edge correction. Defaults to translational.

marksvar1

The variable used to mark the points in the point pattern object. Defaults to "immune".

p_thin

Percentage that determines how much to thin the amount of points in the point pattern object. Defaults to 0.

Value

A dataframe with the following columns:

r

The radius at which K was calculated.

k

The observed K value calculated using matrices

theo_csr

The theoretical K under CSR

kamp_csr

The adjusted CSR representing the permuted expectation.

kamp_fundiff

The difference between observed K and KAMP CSR

Details

Computes KAMP Expectation using matrices

Examples

if (requireNamespace("spatstat.geom", quietly = TRUE)) {
# simulate 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))
# compute KAMP expectation using matrix method
kamp_result_mat <- kamp_expectation_mat(marked_pp, marksvar1 = "immune")
print(kamp_result_mat)
}
#> Error in map(.x, .f, ...):  In index: 1.
#> Caused by error in `kamp_expectation_mat_helper()`:
#> ! unused argument (marksvar1 = marksvar1)