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)
}
#> # A tibble: 6 × 7
#> r k theo_csr kamp_csr kamp var pvalue
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0 0 0 0 0 0 NaN
#> 2 0.05 0.00508 0.00785 0.00655 -0.00147 0.00000324 0.794
#> 3 0.075 0.0149 0.0177 0.0162 -0.00133 0.00000636 0.701
#> 4 0.1 0.0360 0.0314 0.0343 0.00177 0.0000170 0.334
#> 5 0.15 0.0651 0.0707 0.0673 -0.00223 0.0000385 0.640
#> 6 0.2 0.121 0.126 0.124 -0.00309 0.0000868 0.630