| Name | Last modified | Size | Description | |
|---|---|---|---|---|
| Parent Directory | - | |||
| README.html | 2020-09-03 00:40 | 13K | ||
The goal of tgstat is to provide fast and efficient implementation of certain R functions such as ‘cor’ and ‘dist’, along with specific statistical tools.
Various approaches are used to boost the performance, including multi-processing and use of optimized functions provided by the Basic Linear Algebra Subprograms (BLAS) library.
In order to install tgstat:
set.seed(seed=1)
rows = 3000
cols = 3000
vals<-sample(1:(rows*cols/2), rows*cols, replace=T)
m<-matrix(vals, nrow=rows, ncol=cols)
m_with_NAs <- m
m_with_NAs[sample(1:(rows*cols), rows*cols / 10)] <- NA
dim(m)
#> [1] 3000 3000Pearson correlation without BLAS, no NAs:
Same with BLAS:
# tgs_cor, with BLAS, no NAs, pearson
options(tgs_use.blas=T)
system.time(tgs_cor(m))
#> user system elapsed
#> 2.021 0.312 0.400Base R version:
Pearson correlation without BLAS, with NAs:
options(tgs_use.blas=F)
system.time(tgs_cor(m_with_NAs, pairwise.complete.obs=T))
#> user system elapsed
#> 63.072 1.317 1.443Same with BLAS:
options(tgs_use.blas=T)
system.time(tgs_cor(m_with_NAs, pairwise.complete.obs=T))
#> user system elapsed
#> 6.431 0.888 0.639Base R version:
system.time(cor(m_with_NAs, use="pairwise.complete.obs"))
#> user system elapsed
#> 238.613 0.164 239.340Distance without BLAS, no NAs:
Same with BLAS:
Base R:
BLAStgstat runs best when R is linked with an optimized BLAS implementation.
Many optimized BLAS implementations are available, both proprietary (e.g. Intel’s MKL, Apple’s vecLib) and opensource (e.g. OpenBLAS, ATLAS). Unfortunately, R often uses by default the reference BLAS implementation, which is known to have poor performance.
Having tgstat rely on the reference BLAS will result in very poor performance and is strongly discouraged. If your R implementation uses an optimized BLAS, set options(tgs_use.blas=TRUE) to allow tgstat to make BLAS calls. Otherwise, set options(tgs_use.blas=FALSE) (default) which instructs tgstat to avoid BLAS and instead rely only on its own optimization methods. If in doubt, it is possible to run one of tgstat CPU intensive functions (e.g. tgs_cor) and compare its run time under both options(tgs_use.blas=FALSE).
Exact instructions for linking R with an optimized BLAS library are system dependent and are out of scope of this document.