KAMP univariate variance
kamp_variance.Rd
Computes the KAMP (K-function Adjusted for Marked Permutations) variance for a given spatial point pattern. Also returns the KAMP expectation, z-statistic, and p-value.
Note: this a matrix-based implementation of the KAMP variance that
does not use the spatstat
package. It is a wrapper around the
kamp_variance_helper
function that calculates the KAMP variance at
one radius and maps it over a vector of radii.
Usage
kamp_variance(
ppp_obj,
rvals = c(0, 0.05, 0.075, 0.1, 0.15, 0.2),
correction = "trans",
marksvar1 = "immune"
)
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
- var
Variance of K under the permutation null distribution
- pval
P-value, calculated using the formula: pnorm(-z)
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 variance
kamp_result <- kamp_variance(marked_pp, marksvar1 = "immune")
print(kamp_result)
}
#> Error in map(.x, .f, ...): ℹ In index: 1.
#> Caused by error in `kamp_variance_helper()`:
#> ! unused argument (marksvar1 = marksvar1)