Compute quantiles
Usage
fast_quantile(x, prob = 0.5, na.rm = FALSE, ...)
fast_median(x, na.rm = FALSE, ...)
fast_mvquantile(x, prob = 0.5, na.rm = FALSE, ...)
fast_mvmedian(x, na.rm = FALSE, ...)
Value
fast_quantile
and fast_median
calculate univariate
quantiles (single-value return); fast_mvquantile
and fast_mvmedian
calculate multivariate quantiles (for each column, result lengths equal to
the number of columns).
Examples
fast_quantile(runif(1000), 0.1)
#> [1] 0.0865877
fast_median(1:100)
#> [1] 50.5
x <- matrix(rnorm(100), ncol = 2)
fast_mvquantile(x, 0.2)
#> [1] -0.8459934 -1.2524877
fast_mvmedian(x)
#> [1] 0.10661071 -0.08524222
# Compare speed for vectors (usually 30% faster)
x <- rnorm(10000)
microbenchmark::microbenchmark(
fast_median = fast_median(x),
base_median = median(x),
# bioc_median = Biobase::rowMedians(matrix(x, nrow = 1)),
times = 100, unit = "milliseconds"
)
#> Unit: milliseconds
#> expr min lq mean median uq max neval
#> fast_median 0.079118 0.1255945 0.1380520 0.143613 0.1545830 0.179164 100
#> base_median 0.148106 0.1646465 0.1735709 0.172126 0.1804565 0.275423 100
# Multivariate cases
# (5~7x faster than base R)
# (3~5x faster than Biobase rowMedians)
x <- matrix(rnorm(100000), ncol = 20)
microbenchmark::microbenchmark(
fast_median = fast_mvmedian(x),
base_median = apply(x, 2, median),
# bioc_median = Biobase::rowMedians(t(x)),
times = 10, unit = "milliseconds"
)
#> Unit: milliseconds
#> expr min lq mean median uq max neval
#> fast_median 0.673204 0.708470 0.7407105 0.722504 0.740700 0.971500 10
#> base_median 2.673792 2.768899 2.8122961 2.789762 2.813431 3.121515 10