R/defaultwin.R

Defines functions default.clipwindow default.expand

Documented in default.clipwindow default.expand

#
#
#  defaultwin.R
#
#   $Revision: 1.11 $   $Date: 2022/01/03 05:43:45 $
#

default.expand <- function(object, m=2, epsilon=1e-6, w=Window(object)) {
  stopifnot(inherits(object, c("ppm", "rmhmodel")))
  # no expansion necessary if model is Poisson
  if(is.poisson(object))
    return(.no.expansion)
  # default is no expansion if model is nonstationary
  if(!is.stationary(object))
    return(.no.expansion)
  
# Redundant since a non-expandable model is non-stationary
#  if(!is.expandable(object))
#    return(.no.expansion)
  
  # rule is to expand data window by distance d = m * reach
  rr <- reach(object, epsilon=epsilon)
  if(!is.finite(rr))
    return(rmhexpand())
  if(!is.numeric(m) || length(m) != 1 || m < 1)
    stop("m should be a single number >= 1")
  mr <- m * rr
  rule <- rmhexpand(distance = mr)
  # 
  if(is.owin(w)) {
    # apply rule to window
    wplus <- expand.owin(w, rule)
    # save as new expansion rule
    rule <- rmhexpand(wplus)
  }
  return(rule)
}

default.clipwindow <- function(object, epsilon=1e-6) {
  stopifnot(inherits(object, c("ppm", "rmhmodel")))
  # data window
  w <- as.owin(object)
  if(is.null(w)) return(NULL)
  # interaction range of model
  rr <- reach(object, epsilon=epsilon)
  if(!is.finite(rr))
    return(NULL)
  if(rr == 0)
    return(w)
  else
    return(erosion(w, rr))
}

  

Try the spatstat.random package in your browser

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

spatstat.random documentation built on Oct. 22, 2023, 1:17 a.m.