This report benchmark the performance of weightedMedian() against alternative methods.
> rvector <- function(n, mode = c("logical", "double", "integer"), range = c(-100, +100), na_prob = 0) {
+ mode <- match.arg(mode)
+ if (mode == "logical") {
+ x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+ } else {
+ x <- runif(n, min = range[1], max = range[2])
+ }
+ storage.mode(x) <- mode
+ if (na_prob > 0)
+ x[sample(n, size = na_prob * n)] <- NA
+ x
+ }
> rvectors <- function(scale = 10, seed = 1, ...) {
+ set.seed(seed)
+ data <- list()
+ data[[1]] <- rvector(n = scale * 100, ...)
+ data[[2]] <- rvector(n = scale * 1000, ...)
+ data[[3]] <- rvector(n = scale * 10000, ...)
+ data[[4]] <- rvector(n = scale * 1e+05, ...)
+ data[[5]] <- rvector(n = scale * 1e+06, ...)
+ names(data) <- sprintf("n = %d", sapply(data, FUN = length))
+ data
+ }
> data <- rvectors(mode = "double")
> data <- data[1:3]
> x <- data[["n = 1000"]]
> w <- runif(length(x))
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 5411121 289.0 7916910 422.9 7916910 422.9
Vcells 10941647 83.5 39038428 297.9 94934136 724.3
> stats <- microbenchmark(weightedMedian = weightedMedian(x, w = w, ties = "mean", na.rm = FALSE),
+ `limma::weighted.median` = limma_weighted.median(x, w = w, na.rm = FALSE), `cwhmisc::w.median` = cwhmisc_w.median(x,
+ w = w), `laeken::weightedMedian` = laeken_weightedMedian(x, w = w), unit = "ms")
Table: Benchmarking of weightedMedian(), limma::weighted.median(), cwhmisc::w.median() and laeken::weightedMedian() on n = 1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
1 | weightedMedian | 0.049771 | 0.0621750 | 0.0690443 | 0.0660595 | 0.0739120 | 0.133834 |
2 | limma::weighted.median | 0.079686 | 0.0893280 | 0.1032444 | 0.0982745 | 0.1141630 | 0.232075 |
3 | cwhmisc::w.median | 0.111127 | 0.1232115 | 0.1336499 | 0.1292615 | 0.1430555 | 0.190786 |
4 | laeken::weightedMedian | 0.153300 | 0.1737255 | 0.1964686 | 0.1845090 | 0.2110095 | 0.626636 |
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
1 | weightedMedian | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 |
2 | limma::weighted.median | 1.601053 | 1.436719 | 1.495336 | 1.487666 | 1.544580 | 1.734051 |
3 | cwhmisc::w.median | 2.232766 | 1.981689 | 1.935712 | 1.956743 | 1.935484 | 1.425542 |
4 | laeken::weightedMedian | 3.080107 | 2.794138 | 2.845543 | 2.793073 | 2.854875 | 4.682188 |
Figure: Benchmarking of weightedMedian(), limma::weighted.median(), cwhmisc::w.median() and laeken::weightedMedian() on n = 1000 data. Outliers are displayed as crosses. Times are in milliseconds.
> x <- data[["n = 10000"]]
> w <- runif(length(x))
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 5409434 288.9 7916910 422.9 7916910 422.9
Vcells 10542162 80.5 39038428 297.9 94934136 724.3
> stats <- microbenchmark(weightedMedian = weightedMedian(x, w = w, ties = "mean", na.rm = FALSE),
+ `limma::weighted.median` = limma_weighted.median(x, w = w, na.rm = FALSE), `cwhmisc::w.median` = cwhmisc_w.median(x,
+ w = w), `laeken::weightedMedian` = laeken_weightedMedian(x, w = w), unit = "ms")
Table: Benchmarking of weightedMedian(), limma::weighted.median(), cwhmisc::w.median() and laeken::weightedMedian() on n = 10000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
2 | limma::weighted.median | 0.550082 | 0.5588770 | 0.6009897 | 0.5618375 | 0.583609 | 1.030887 |
1 | weightedMedian | 0.564641 | 0.5769645 | 0.6158315 | 0.5815415 | 0.604659 | 0.949171 |
4 | laeken::weightedMedian | 0.651894 | 0.6599555 | 0.7142915 | 0.6664945 | 0.711960 | 1.147676 |
3 | cwhmisc::w.median | 0.679045 | 0.6990925 | 0.7443819 | 0.7056445 | 0.730986 | 1.213795 |
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
2 | limma::weighted.median | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.0000000 |
1 | weightedMedian | 1.026467 | 1.032364 | 1.024695 | 1.035071 | 1.036069 | 0.9207323 |
4 | laeken::weightedMedian | 1.185085 | 1.180860 | 1.188525 | 1.186276 | 1.219926 | 1.1132898 |
3 | cwhmisc::w.median | 1.234443 | 1.250888 | 1.238593 | 1.255958 | 1.252527 | 1.1774278 |
Figure: Benchmarking of weightedMedian(), limma::weighted.median(), cwhmisc::w.median() and laeken::weightedMedian() on n = 10000 data. Outliers are displayed as crosses. Times are in milliseconds.
> x <- data[["n = 100000"]]
> w <- runif(length(x))
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 5409515 288.9 7916910 422.9 7916910 422.9
Vcells 10632728 81.2 39038428 297.9 94934136 724.3
> stats <- microbenchmark(weightedMedian = weightedMedian(x, w = w, ties = "mean", na.rm = FALSE),
+ `limma::weighted.median` = limma_weighted.median(x, w = w, na.rm = FALSE), `cwhmisc::w.median` = cwhmisc_w.median(x,
+ w = w), `laeken::weightedMedian` = laeken_weightedMedian(x, w = w), unit = "ms")
Table: Benchmarking of weightedMedian(), limma::weighted.median(), cwhmisc::w.median() and laeken::weightedMedian() on n = 100000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
2 | limma::weighted.median | 4.682831 | 4.821213 | 5.121895 | 4.903404 | 5.097217 | 8.068642 |
4 | laeken::weightedMedian | 5.063243 | 5.322617 | 5.911933 | 5.506824 | 5.925829 | 13.300783 |
3 | cwhmisc::w.median | 5.972863 | 6.166059 | 6.894042 | 6.306785 | 6.878705 | 15.306226 |
1 | weightedMedian | 6.812815 | 6.883257 | 7.137748 | 6.954033 | 7.214968 | 8.906691 |
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
2 | limma::weighted.median | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 |
4 | laeken::weightedMedian | 1.081236 | 1.104000 | 1.154247 | 1.123061 | 1.162562 | 1.648454 |
3 | cwhmisc::w.median | 1.275481 | 1.278943 | 1.345994 | 1.286205 | 1.349502 | 1.897002 |
1 | weightedMedian | 1.454850 | 1.427702 | 1.393576 | 1.418205 | 1.415472 | 1.103865 |
Figure: Benchmarking of weightedMedian(), limma::weighted.median(), cwhmisc::w.median() and laeken::weightedMedian() on n = 100000 data. Outliers are displayed as crosses. Times are in milliseconds.
R version 4.1.1 Patched (2021-08-10 r80727)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS
Matrix products: default
BLAS: /home/hb/software/R-devel/R-4-1-branch/lib/R/lib/libRblas.so
LAPACK: /home/hb/software/R-devel/R-4-1-branch/lib/R/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] microbenchmark_1.4-7 matrixStats_0.60.0 ggplot2_3.3.5
[4] knitr_1.33 R.devices_2.17.0 R.utils_2.10.1
[7] R.oo_1.24.0 R.methodsS3_1.8.1-9001 history_0.0.1-9000
loaded via a namespace (and not attached):
[1] Biobase_2.52.0 httr_1.4.2 splines_4.1.1
[4] bit64_4.0.5 network_1.17.1 assertthat_0.2.1
[7] highr_0.9 stats4_4.1.1 blob_1.2.2
[10] GenomeInfoDbData_1.2.6 robustbase_0.93-8 pillar_1.6.2
[13] RSQLite_2.2.8 lattice_0.20-44 limma_3.48.3
[16] glue_1.4.2 digest_0.6.27 XVector_0.32.0
[19] colorspace_2.0-2 Matrix_1.3-4 XML_3.99-0.7
[22] pkgconfig_2.0.3 zlibbioc_1.38.0 genefilter_1.74.0
[25] purrr_0.3.4 ergm_4.1.2 xtable_1.8-4
[28] scales_1.1.1 tibble_3.1.4 annotate_1.70.0
[31] KEGGREST_1.32.0 farver_2.1.0 generics_0.1.0
[34] IRanges_2.26.0 ellipsis_0.3.2 cachem_1.0.6
[37] withr_2.4.2 BiocGenerics_0.38.0 mime_0.11
[40] survival_3.2-13 magrittr_2.0.1 crayon_1.4.1
[43] statnet.common_4.5.0 memoise_2.0.0 laeken_0.5.1
[46] fansi_0.5.0 R.cache_0.15.0 MASS_7.3-54
[49] R.rsp_0.44.0 progressr_0.8.0 tools_4.1.1
[52] lifecycle_1.0.0 S4Vectors_0.30.0 trust_0.1-8
[55] munsell_0.5.0 tabby_0.0.1-9001 AnnotationDbi_1.54.1
[58] Biostrings_2.60.2 compiler_4.1.1 GenomeInfoDb_1.28.1
[61] rlang_0.4.11 grid_4.1.1 RCurl_1.98-1.4
[64] cwhmisc_6.6 rstudioapi_0.13 rappdirs_0.3.3
[67] startup_0.15.0-9000 labeling_0.4.2 bitops_1.0-7
[70] base64enc_0.1-3 boot_1.3-28 gtable_0.3.0
[73] DBI_1.1.1 markdown_1.1 R6_2.5.1
[76] lpSolveAPI_5.5.2.0-17.7 rle_0.9.2 dplyr_1.0.7
[79] fastmap_1.1.0 bit_4.0.4 utf8_1.2.2
[82] parallel_4.1.1 Rcpp_1.0.7 vctrs_0.3.8
[85] png_0.1-7 DEoptimR_1.0-9 tidyselect_1.1.1
[88] xfun_0.25 coda_0.19-4
Total processing time was 7.56 secs.
To reproduce this report, do:
html <- matrixStats:::benchmark('weightedMedian')
Copyright Henrik Bengtsson. Last updated on 2021-08-25 22:52:58 (+0200 UTC). Powered by RSP.