R/pvaldistance.R

Defines functions pvaldistance

Documented in pvaldistance

pvaldistance <- function(x, method = c('ks', 'cvm'), dist.to = c('uniform')) {
    stopifnot(is.numeric(x), is.character(method), is.character(dist.to))

    method  <- match.arg(method)
    dist.to <- match.arg(dist.to)

    if (dist.to == 'uniform') {
        x   <- sort(as.vector(x))
        num <- length(x)

        switch(method,
            ks  = max(abs(sweep(x      = cbind(c(0.0, x), c(x, 1.0)),
                                MARGIN = 1L,
                                STATS  = seq.int(0.0, 1.0, 1.0 / num)))),
            cvm = sum((seq_len(num) / num - 0.5 / num - x)^2.0) + 1.0 / (12.0 * num)
        )
    } else {
        NA_real_
    }
}

Try the bootruin package in your browser

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

bootruin documentation built on May 2, 2019, 10:23 a.m.