R/ecdf.R

Defines functions ECDF

Documented in ECDF

#' Empirical cummulative distrubution function
#'
#' Calculates ecdf based on weibull plotting position
#'
#' @param x vector of values
#'
#' @keywords internal
#' @export
#'
#' @examples
#'
#' ECDF(round(rnorm(100)))
#'
ECDF <- function(x) {

  ## sort the values: x1 < x2 < x3 < ... < xN
  st <- sort(x)

  ## weibull plotting position
  aux <- data.table(p = rank(
    x = st,
    ties.method = 'first') / (length(st) + 1),
                    value = st,
                    key = 'value')

  J <- value <- NULL

  out <- aux[J(unique(value)),
             mult = 'last']

  structure(.Data = out)
}

Try the CoSMoS package in your browser

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

CoSMoS documentation built on May 30, 2021, 1:06 a.m.