Skip to content

Instantly share code, notes, and snippets.

@brshallo
Last active January 21, 2022 08:12
Show Gist options
  • Select an option

  • Save brshallo/88ba63b4f69f0347c2b483947efb9be3 to your computer and use it in GitHub Desktop.

Select an option

Save brshallo/88ba63b4f69f0347c2b483947efb9be3 to your computer and use it in GitHub Desktop.
copied from deprecated spatstat:::CDF.density() function
# copied from spatstat.utils::paren()
paren <- function (x, type = "(") {
if (length(x) == 0)
return(x)
if (identical(type, ""))
type <- "blank"
switch(type, `(` = {
out <- paste("(", x, ")", sep = "")
}, `[` = {
out <- paste("[", x, "]", sep = "")
}, `{` = {
out <- paste("{", x, "}", sep = "")
}, blank = {
out <- paste(x)
}, stop(paste("Unrecognised parenthesis type:", sQuote(type))))
out
}
# copied from spatstat.utils::prange()
prange <- function (r) {
stopifnot(length(r) == 2)
paren(paste(r, collapse = ", "), "[")
}
# copied from deprecated
CDF.density <- function (f, ..., warn = TRUE){
stopifnot(inherits(f, "density"))
if (warn && is.call(cl <- f$call) && any(c("from", "to") %in%
names(cl)))
warning(paste("Density was normalised within the computed range",
"of x values", prange(c(cl$from, cl$to))), call. = FALSE)
xx <- f$x
yy <- f$y
nn <- length(xx)
Fx <- cumsum(yy * c(0, diff(xx)))
Fx <- Fx/Fx[nn]
FF <- approxfun(xx, Fx, method = "linear", rule = 2)
return(FF)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment