R/dist_fun2.R

Defines functions dist_fun2

Documented in dist_fun2

dist_fun2 <-
function(d, tau, dist_fun, breaks=numeric(0), ...) {
  breaks <- sort(breaks)
  breaks[breaks==0] <- .Machine$double.eps
  for (i in which(duplicated(breaks))) {
    breaks[i] <- breaks[i-1] + 10*.Machine$double.eps
  }
  if (any(is.infinite(breaks)))
    stop("breaks must be finite")
  if (length(breaks) != length(tau)-1L)
    stop("length(breaks) must equal length(tau)-1")
#  if (length(breaks) != length(unique(breaks)))
#    stop("values in breaks must be unique")
  h <- 1
  for (i in seq_len(length(breaks))) {
    h <- c(h,
      h[length(h)] * dist_fun(breaks[i], tau[i], ...) /
        dist_fun(breaks[i], tau[i+1L]), ...)
  }
  h[is.na(h)] <- 0
  j <- cut(d, c(0, breaks, Inf), labels=FALSE, include.lowest=TRUE)
  dist_fun(d, tau[j], ...) * h[j]
}

Try the bSims package in your browser

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

bSims documentation built on Oct. 7, 2021, 9:13 a.m.