PeteHaitch / DelayedMatrixStats

A port of the matrixStats API to work with DelayedMatrix objects from the DelayedArray package
Other
15 stars 7 forks source link

colVars yields incorrect results with vector center= #64

Closed LTLA closed 4 years ago

LTLA commented 4 years ago
set.seed(10000)
x <- matrix(runif(1000), ncol=10)
m <- colMeans(x)

library(MatrixGenerics)
colVars(x, center=m)
##  [1] 0.10691336 0.08324853 0.08741220 0.08187569 0.07997174 0.08929123
##  [7] 0.10014618 0.07568508 0.08539892 0.09346779

library(DelayedMatrixStats)
setAutoBlockSize(1000)
colVars(DelayedArray(x) + 0, center=m)
##   [1] 0.106913356 0.156154275 0.115199456 0.075587988 0.083750943 0.139545792
##   [7] 0.140249351 0.115283190 0.150080970 0.090407341 0.034007615 0.083248535
##  [13] 0.042293715 0.002682247 0.010845202 0.066640051 0.067343610 0.042377449
##  [19] 0.077175230 0.017501601 0.079126099 0.128367019 0.087412199 0.047800731
##  [25] 0.055963686 0.111758535 0.112462094 0.087495933 0.122293714 0.062620085
##  [31] 0.113201059 0.162441978 0.121487159 0.081875691 0.090038646 0.145833495
##  [37] 0.146537054 0.121570893 0.156368673 0.096695044 0.103134155 0.152375075
##  [43] 0.111420256 0.071808788 0.079971743 0.135766591 0.136470150 0.111503989
##  [49] 0.146301770 0.086628141 0.056658797 0.105899716 0.064944897 0.025333429
##  [55] 0.033496384 0.089291233 0.089994792 0.065028631 0.099826411 0.040152782
##  [61] 0.066810184 0.116051104 0.075096284 0.035484817 0.043647772 0.099442620
##  [67] 0.100146179 0.075180018 0.109977799 0.050304170 0.067315245 0.116556164
##  [73] 0.075601345 0.035989877 0.044152832 0.099947681 0.100651240 0.075685079
##  [79] 0.110482859 0.050809230 0.042231303 0.091472222 0.050517403 0.010905935
##  [85] 0.019068890 0.074863739 0.075567298 0.050601137 0.085398917 0.025725289
##  [91] 0.109973808 0.159214728 0.118259908 0.078648440 0.086811395 0.142606244
##  [97] 0.143309803 0.118343642 0.153141423 0.093467794

Your colblock_APPLY statement fails to split the vector center in a corresponding manner to the blocks of x.

PeteHaitch commented 4 years ago

Thanks. I'll fix before the next release

PeteHaitch commented 4 years ago

Reminder to self, this is still an issue. With the changes in https://github.com/HenrikBengtsson/matrixStats/issues/183 (not yet on CRAN) we're at least getting an error rather than a nonsense result:

set.seed(10000)
x <- matrix(runif(1000), ncol=10)
m <- colMeans(x)

suppressPackageStartupMessages(library(MatrixGenerics))
colVars(x, center=m)
#>  [1] 0.08013967 0.09265077 0.08367831 0.09274660 0.08362152 0.10039803
#>  [7] 0.08663035 0.07936689 0.08234544 0.07701829

suppressPackageStartupMessages(library(DelayedMatrixStats))
setAutoBlockSize(1000)
#> automatic block size set to 1000 bytes (was 1e+08)
colVars(DelayedArray(x), center=m)
#>  [1] 0.08013967 0.09265077 0.08367831 0.09274660 0.08362152 0.10039803
#>  [7] 0.08663035 0.07936689 0.08234544 0.07701829
colVars(DelayedArray(x) + 0, center=m)
#> Error in FUN(block, ...): Argument 'center' should be of the same length as number of rows of 'x': 10 != 1

Created on 2020-10-17 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.2 (2020-06-22) #> os macOS Catalina 10.15.7 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Melbourne #> date 2020-10-17 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib #> assertthat 0.2.1 2019-03-21 [1] #> backports 1.1.10 2020-09-15 [1] #> BiocGenerics * 0.35.4 2020-06-04 [1] #> callr 3.5.1 2020-10-13 [1] #> cli 2.1.0 2020-10-12 [1] #> crayon 1.3.4 2017-09-16 [1] #> DelayedArray * 0.15.16 2020-10-06 [1] #> DelayedMatrixStats * 1.11.2 2020-10-17 [1] #> desc 1.2.0 2018-05-01 [1] #> devtools 2.3.2 2020-09-18 [1] #> digest 0.6.25 2020-02-23 [1] #> ellipsis 0.3.1 2020-05-15 [1] #> evaluate 0.14 2019-05-28 [1] #> fansi 0.4.1 2020-01-08 [1] #> fs 1.5.0 2020-07-31 [1] #> glue 1.4.2 2020-08-27 [1] #> highr 0.8 2019-03-20 [1] #> htmltools 0.5.0 2020-06-16 [1] #> IRanges * 2.23.10 2020-06-13 [1] #> knitr 1.30 2020-09-22 [1] #> lattice 0.20-41 2020-04-02 [1] #> magrittr 1.5 2014-11-22 [1] #> Matrix * 1.2-18 2019-11-27 [1] #> MatrixGenerics * 1.1.7 2020-10-17 [1] #> matrixStats * 0.57.0-9000 2020-10-17 [1] #> memoise 1.1.0 2017-04-21 [1] #> pkgbuild 1.1.0 2020-07-13 [1] #> pkgload 1.1.0 2020-05-29 [1] #> prettyunits 1.1.1 2020-01-24 [1] #> processx 3.4.4 2020-09-03 [1] #> ps 1.4.0 2020-10-07 [1] #> R6 2.4.1 2019-11-12 [1] #> Rcpp 1.0.5 2020-07-06 [1] #> remotes 2.2.0 2020-07-21 [1] #> rlang 0.4.8 2020-10-08 [1] #> rmarkdown 2.4 2020-09-30 [1] #> rprojroot 1.3-2 2018-01-03 [1] #> S4Vectors * 0.27.14 2020-10-09 [1] #> sessioninfo 1.1.1 2018-11-05 [1] #> sparseMatrixStats 1.1.10 2020-10-06 [1] #> stringi 1.5.3 2020-09-09 [1] #> stringr 1.4.0 2019-02-10 [1] #> testthat 2.3.2 2020-03-02 [1] #> usethis 1.6.3 2020-09-17 [1] #> withr 2.3.0 2020-09-22 [1] #> xfun 0.18 2020-09-29 [1] #> yaml 2.2.1 2020-02-01 [1] #> source #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> Bioconductor #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> Bioconductor #> Github (PeteHaitch/DelayedMatrixStats@5a0b1a0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> Bioconductor #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> Github (Bioconductor/MatrixGenerics@fe8c0cc) #> Github (HenrikBengtsson/matrixStats@5f5fd7a) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> Bioconductor #> CRAN (R 4.0.0) #> Bioconductor #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```
PeteHaitch commented 4 years ago

Confirming fixed by #65 (using CRAN version of matrixStats)

set.seed(10000)
x <- matrix(runif(1000), ncol=10)
m <- colMeans(x)

suppressPackageStartupMessages(library(MatrixGenerics))
colVars(x, center=m)
#>  [1] 0.08013967 0.09265077 0.08367831 0.09274660 0.08362152 0.10039803
#>  [7] 0.08663035 0.07936689 0.08234544 0.07701829

suppressPackageStartupMessages(library(DelayedMatrixStats))
setAutoBlockSize(1000)
#> automatic block size set to 1000 bytes (was 1e+08)
colVars(DelayedArray(x), center=m)
#>  [1] 0.08013967 0.09265077 0.08367831 0.09274660 0.08362152 0.10039803
#>  [7] 0.08663035 0.07936689 0.08234544 0.07701829
colVars(DelayedArray(x) + 0, center=m)
#>  [1] 0.08013967 0.09265077 0.08367831 0.09274660 0.08362152 0.10039803
#>  [7] 0.08663035 0.07936689 0.08234544 0.07701829

Created on 2020-10-18 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.2 (2020-06-22) #> os macOS Catalina 10.15.7 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Melbourne #> date 2020-10-18 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib #> assertthat 0.2.1 2019-03-21 [1] #> backports 1.1.10 2020-09-15 [1] #> BiocGenerics * 0.35.4 2020-06-04 [1] #> callr 3.5.1 2020-10-13 [1] #> cli 2.1.0 2020-10-12 [1] #> crayon 1.3.4 2017-09-16 [1] #> DelayedArray * 0.15.16 2020-10-06 [1] #> DelayedMatrixStats * 1.11.3 2020-10-18 [1] #> desc 1.2.0 2018-05-01 [1] #> devtools 2.3.2 2020-09-18 [1] #> digest 0.6.26 2020-10-17 [1] #> ellipsis 0.3.1 2020-05-15 [1] #> evaluate 0.14 2019-05-28 [1] #> fansi 0.4.1 2020-01-08 [1] #> fs 1.5.0 2020-07-31 [1] #> glue 1.4.2 2020-08-27 [1] #> highr 0.8 2019-03-20 [1] #> htmltools 0.5.0 2020-06-16 [1] #> IRanges * 2.23.10 2020-06-13 [1] #> knitr 1.30 2020-09-22 [1] #> lattice 0.20-41 2020-04-02 [1] #> magrittr 1.5 2014-11-22 [1] #> Matrix * 1.2-18 2019-11-27 [1] #> MatrixGenerics * 1.1.7 2020-10-17 [1] #> matrixStats * 0.57.0 2020-09-25 [1] #> memoise 1.1.0 2017-04-21 [1] #> pkgbuild 1.1.0 2020-07-13 [1] #> pkgload 1.1.0 2020-05-29 [1] #> prettyunits 1.1.1 2020-01-24 [1] #> processx 3.4.4 2020-09-03 [1] #> ps 1.4.0 2020-10-07 [1] #> R6 2.4.1 2019-11-12 [1] #> Rcpp 1.0.5 2020-07-06 [1] #> remotes 2.2.0 2020-07-21 [1] #> rlang 0.4.8 2020-10-08 [1] #> rmarkdown 2.4 2020-09-30 [1] #> rprojroot 1.3-2 2018-01-03 [1] #> S4Vectors * 0.27.14 2020-10-09 [1] #> sessioninfo 1.1.1 2018-11-05 [1] #> sparseMatrixStats 1.1.11 2020-10-16 [1] #> stringi 1.5.3 2020-09-09 [1] #> stringr 1.4.0 2019-02-10 [1] #> testthat 2.3.2 2020-03-02 [1] #> usethis 1.6.3 2020-09-17 [1] #> withr 2.3.0 2020-09-22 [1] #> xfun 0.18 2020-09-29 [1] #> yaml 2.2.1 2020-02-01 [1] #> source #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> Bioconductor #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> Bioconductor #> Github (PeteHaitch/DelayedMatrixStats@15a4059) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> Bioconductor #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> Github (Bioconductor/MatrixGenerics@fe8c0cc) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> Bioconductor #> CRAN (R 4.0.0) #> Bioconductor #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> CRAN (R 4.0.0) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.2) #> CRAN (R 4.0.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```