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,
rvec = c(0, 0.05, 0.075, 0.1, 0.15, 0.2),
correction = "trans",
markvar1 = "immune1",
markvar2 = "immune2",
thin_pct = 0
)
Arguments
- ppp_obj
A point pattern object from the
spatstat.geom
package.- 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).
- correction
Type of edge correction method. Defaults to translational.
- 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".
- thin_pct
Percentage that determines how much to thin the amount of points in the point pattern object. Default is 0.
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_fundiff
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, markvar1 = "immune1", markvar2 = "immune2")
print(result)
}
#> Error in map(.x, .f, ...): ℹ In index: 1.
#> Caused by error in `kamp_expectation_biv_mat_helper()`:
#> ! unused arguments (markvar1 = markvar1, markvar2 = markvar2)