Kolmogorov_dist function

One-Sample Kolmogorov Distance

One-Sample Kolmogorov Distance

To calculate the one-sample Kolmogorov distance between observations and a distribution.

Kolmogorov_dist(x, null, alternative = c("two.sided", "less", "greater"), ...)

Arguments

  • x: numeric vector , observations xx
  • null: cumulative distribution function
  • alternative: character scalar, alternative hypothesis, either 'two.sided' (default), 'less', or 'greater'
  • ...: additional arguments of null

Returns

Function Kolmogorov_dist() returns a numeric scalar.

Details

Function Kolmogorov_dist() is different from ks.test in the following aspects

  • Ties in observations are supported. The step function of empirical distribution is inspired by ecdf . This is superior than (0:(n - 1))/n in ks.test .
  • Discrete distribution (with discrete observation) is supported.
  • Discrete distribution (with continuous observation) is not supported yet. This will be an easy modification in future.
  • Only the one-sample Kolmogorov distance, not the one-sample Kolmogorov test, is returned, to speed up the calculation.

Examples

# from ?stats::ks.test x1 = rnorm(50) ks.test(x1+2, y = pgamma, shape = 3, rate = 2) Kolmogorov_dist(x1+2, null = pgamma, shape = 3, rate = 2) # exactly the same # discrete distribution x2 <- rnbinom(n = 1e2L, size = 500, prob = .4) suppressWarnings(ks.test(x2, y = pnbinom, size = 500, prob = .4)) # warning on ties Kolmogorov_dist(x2, null = pnbinom, size = 500, prob = .4) # wont be the same
  • Maintainer: Tingting Zhan
  • License: GPL-2
  • Last published: 2025-03-15

Useful links