R/KinhomEnvelope.R

Defines functions KinhomEnvelope

Documented in KinhomEnvelope

KinhomEnvelope <-
function(X, r = NULL, NumberOfSimulations = 100, Alpha = 0.05, 
         ReferenceType = "", lambda = NULL, SimulationType = "RandomPosition", 
         Global = FALSE, verbose = interactive()) {

  CheckdbmssArguments()
  
  # Estimate intensity if it has not been provided.
  if (is.null(lambda)) {
    if (ReferenceType == "") {
      X.reduced <- X
    } else {
      X.reduced <- X[X$marks$PointType==ReferenceType]
    }
    lambda <- spatstat.explore::density.ppp(X.reduced, sigma=bw.diggle(X.reduced))
  }
  
  # Choose the null hypothesis
  SimulatedPP <- switch (SimulationType,
                         RandomPosition = expression(rpoispp(lambda)),
                         RandomLocation = expression(rRandomLocation(X, CheckArguments = FALSE)),
                         RandomLabeling = expression(rRandomLabeling(X, CheckArguments = FALSE)),
                         PopulationIndependence = expression(rPopulationIndependenceM(X, ReferenceType = ReferenceType, CheckArguments = FALSE))
                         )
  if (is.null(SimulatedPP))
    stop(paste("The null hypothesis", sQuote(SimulationType), "has not been recognized."))
  # local envelope, keep extreme values for lo and hi (nrank=1)
  Envelope <- envelope(X, fun=Kinhomhat, nsim=NumberOfSimulations, nrank=1,
                       r=r, ReferenceType=ReferenceType, lambda=lambda, 
                       CheckArguments = FALSE,
                       simulate=SimulatedPP, verbose=verbose, savefuns=TRUE
                       )
  attr(Envelope, "einfo")$H0 <- switch (SimulationType,
                                        RandomPosition = "Random Position",
                                        RandomLocation = "Random Location",
                                        )
  # Calculate confidence intervals
  Envelope <- FillEnvelope(Envelope, Alpha, Global)
  # Return the envelope
  return (Envelope)
}

Try the dbmss package in your browser

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

dbmss documentation built on May 31, 2023, 8:30 p.m.