KAMP bivariate expectation (Matrix Implementation)
kamp_expectation_biv_mat.Rd
Computes the KAMP (K-function Adjusted for Marked Permutations) expectation for bivariate point patterns using a matrix-based approach. Note that this is slower.
See kamp_expectation_biv
for the spatstat
-based implementation of the KAMP
bivariate expectation.
Usage
kamp_expectation_biv_mat(
ppp_obj,
rvals = c(0, 0.05, 0.075, 0.1, 0.15, 0.2),
correction = "trans",
marksvar1 = "immune1",
marksvar2 = "immune2"
)
Arguments
- ppp_obj
A point pattern object from the
spatstat.geom
package.- correction
Type of edge correction method. Defaults to translational.
- rvec
Vector of radii at which to calculate the KAMP expectation. Defaults to c(0, 0.05, 0.075, 0.1, 0.15, 0.2).
- markvar1
Variable used to mark the points in the point pattern object for the first type. Default is "immune1".
- markvar2
Variable used to mark the points in the point pattern object for the second type. Default is "immune2".
Value
A dataframe with the following columns:
- r
The radius at which K was calculated.
- k
The observed K value
- theo_csr
The theoretical K under CSR
- kamp_csr
The adjusted CSR representing the KAMP permuted expectation.
- kamp
The difference between observed K and KAMP CSR
Examples
if (requireNamespace("spatstat.geom", quietly = TRUE) &&
requireNamespace("spatstat.random", quietly = TRUE)) {
# Simulates a window
win <- spatstat.geom::owin(c(0, 1), c(0, 1))
# Generates 200 total points
pp <- spatstat.random::rpoispp(lambda = 200, win = win)
# Assigns three marks: immune1, immune2, and background
marks <- sample(c("immune1", "immune2", "background"), pp$n, replace = TRUE, prob = c(0.3, 0.3, 0.4))
# Creates marked point pattern
marked_pp <- spatstat.geom::ppp(pp$x, pp$y, window = win, marks = factor(marks))
# Computes KAMP expectation
result <- kamp_expectation_biv_mat(marked_pp, marksvar1 = "immune1", marksvar2 = "immune2")
print(result)
}
#> Error in map(.x, .f, ...): ℹ In index: 1.
#> Caused by error in `kamp_expectation_biv_mat_helper()`:
#> ! could not find function "kamp_expectation_biv_mat_helper"