R/rPopulationIndependenceK.R

Defines functions rPopulationIndependenceK

Documented in rPopulationIndependenceK

rPopulationIndependenceK <- function(
    X,
    ReferenceType,
    NeighborType,
    CheckArguments = TRUE) {

  if (CheckArguments) {
    CheckdbmssArguments()
  }

  # Eliminate useless points
  X.reduced <-
    (X[marks(X)$PointType == ReferenceType | marks(X)$PointType == NeighborType])
  RandomizedX <- X.reduced
  # Reduce the factor levels to two (factor eliminates the levels with no points)
  Marks <- factor(marks(X.reduced)$PointType)
  # The new point pattern has classical spatstat marks
  RandomizedX <- RandomizedX %mark% Marks
  # Split reference and neighbor points
  X.split <- split(RandomizedX)
  # Randomly shift the neighbors
  rshift(X.split, which = NeighborType) -> RandomizedX.split
  # Reunify the split point pattern
  RandomizedX.split ->  split(RandomizedX)
  # Reorganize the marks (add weight)
  PointWeight <- rep(1, RandomizedX$n)
  PointType   <- marks(RandomizedX)
  marks(RandomizedX) <- data.frame(PointWeight, PointType)
  class(RandomizedX) <- c("wmppp", "ppp")
  return(RandomizedX)
}

Try the dbmss package in your browser

Any scripts or data that you put into this service are public.

dbmss documentation built on June 8, 2025, 1:59 p.m.