drostlab / myTAI

Evolutionary Transcriptomics with R
https://drostlab.github.io/myTAI/
GNU General Public License v2.0
41 stars 17 forks source link

FlatLineTest `Error in gamma_MME[[3]] : subscript out of bounds. ` #31

Closed LotharukpongJS closed 1 year ago

LotharukpongJS commented 1 year ago

Describe the bug When running the FlatLineTest with a high number of permutations (>50 000), an error Error in gamma_MME[[3]] : subscript out of bounds. is returned. To my knowledge, this is not the case for the other permutation tests.

To Reproduce I first detected this issue with the tfStability() function when ran with the default test, TestStatistic = "FlatLineTest". One hundred thousand permutations were specified, i.e. permutations = 100000. Using the PhyloExpressionSetExample,

> tfStability(
+     PhyloExpressionSetExample,
+     transforms = c("log2", "rank"),
+     permutations = 100000
+ )
Proceeding with the FlatLineTest

[ Number of Eigen threads that are employed on your machine: 8 ]

[ Computing age assignment permutations for test statistic ... ]
[=========================================] 100%    69.2%   
[ Computing variances of permuted transcriptome signatures ... ]

Total runtime of your permutation test: 7.252  seconds.Error in gamma_MME[[3]] : subscript out of bounds

Then, I checked the FlatLineTest().

> FlatLineTest(myTAI::tf(PhyloExpressionSetExample, FUN = log2), permutations = 100000)

[ Number of Eigen threads that are employed on your machine: 8 ]

[ Computing age assignment permutations for test statistic ... ]
[=========================================] 100%   .8%   
[ Computing variances of permuted transcriptome signatures ... ]

Total runtime of your permutation test: 6.979  seconds.Error in gamma_MME[[3]] : subscript out of bounds

Meanwhile, this behaviour doesn't happen with a lower (but still high) number of permutations (permutations = 20000).

> FlatLineTest(myTAI::tf(PhyloExpressionSetExample, FUN = log2), permutations = 20000)

[ Number of Eigen threads that are employed on your machine: 8 ]

[ Computing age assignment permutations for test statistic ... ]
[=========================================] 100%   
[ Computing variances of permuted transcriptome signatures ... ]

Total runtime of your permutation test: 15.191  seconds.$p.value
[1] 2.192776e-33

$std.dev
[1] 0.05381242 0.05381653 0.05382267 0.05382233 0.05381785 0.05382214 0.05382146

$ks.test

    Asymptotic one-sample Kolmogorov-Smirnov test

data:  filtered_vars
D = 0.020072, p-value = 2.391e-07
alternative hypothesis: two-sided

Expected behaviour I would have expected the test to proceed ahead with 100,000 permutations just as it does with 20,000.

Screenshots or code I think issue relates to:

https://github.com/drostlab/myTAI/blob/3168e75d2ef0dd7602450421c7af5b940dd4766d/R/FlatLineTest.R#L151-L156

Session info:

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────── package version date (UTC) lib source bit 4.0.5 2022-11-15 [1] CRAN (R 4.2.0) bit64 4.0.5 2020-08-30 [1] CRAN (R 4.2.0) cachem 1.0.8 2023-05-01 [1] CRAN (R 4.2.0) callr 3.7.3 2022-11-02 [1] CRAN (R 4.2.0) cli 3.6.1 2023-03-23 [1] CRAN (R 4.2.0) codetools 0.2-19 2023-02-01 [1] CRAN (R 4.2.0) colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.2.0) crayon 1.5.2 2022-09-29 [1] CRAN (R 4.2.0) devtools 2.4.5 2022-10-11 [1] CRAN (R 4.2.0) digest 0.6.33 2023-07-07 [1] CRAN (R 4.2.0) dplyr 1.1.2 2023-04-20 [1] CRAN (R 4.2.0) ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0) evaluate 0.21 2023-05-05 [1] CRAN (R 4.2.0) fansi 1.0.4 2023-01-22 [1] CRAN (R 4.2.0) farver 2.1.1 2022-07-06 [1] CRAN (R 4.2.0) fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.2.0) fitdistrplus 1.1-11 2023-04-25 [1] CRAN (R 4.2.0) forcats 1.0.0 2023-01-29 [1] CRAN (R 4.2.0) foreach 1.5.2 2022-02-02 [1] CRAN (R 4.2.0) fs 1.6.3 2023-07-20 [1] CRAN (R 4.2.0) generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.0) ggplot2 3.4.2 2023-04-03 [1] CRAN (R 4.2.0) ggsci 3.0.0 2023-03-08 [1] CRAN (R 4.2.0) glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) gtable 0.3.3 2023-03-21 [1] CRAN (R 4.2.0) hms 1.1.3 2023-03-21 [1] CRAN (R 4.2.0) htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.2.0) htmlwidgets 1.6.2 2023-03-17 [1] CRAN (R 4.2.0) httpuv 1.6.11 2023-05-11 [1] CRAN (R 4.2.2) iterators 1.0.14 2022-02-05 [1] CRAN (R 4.2.0) knitr 1.43 2023-05-25 [1] CRAN (R 4.2.2) labeling 0.4.2 2020-10-20 [1] CRAN (R 4.2.0) later 1.3.1 2023-05-02 [1] CRAN (R 4.2.2) lattice 0.21-8 2023-04-05 [1] CRAN (R 4.2.0) lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.0) lubridate 1.9.2 2023-02-10 [1] CRAN (R 4.2.0) magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) MASS 7.3-60 2023-05-04 [1] CRAN (R 4.2.2) Matrix 1.5-4.1 2023-05-18 [1] CRAN (R 4.2.0) memoise 2.0.1 2021-11-26 [1] CRAN (R 4.2.0) mime 0.12 2021-09-28 [1] CRAN (R 4.2.0) miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.2.0) munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) myTAI 1.0.1.9000 2023-07-25 [1] Github (drostlab/myTAI@3168e75) pillar 1.9.0 2023-03-22 [1] CRAN (R 4.2.0) pkgbuild 1.4.2 2023-06-26 [1] CRAN (R 4.2.0) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) pkgload 1.3.2.1 2023-07-08 [1] CRAN (R 4.2.0) prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.2.0) processx 3.8.2 2023-06-30 [1] CRAN (R 4.2.0) profvis 0.3.8 2023-05-02 [1] CRAN (R 4.2.0) promises 1.2.0.1 2021-02-11 [1] CRAN (R 4.2.0) ps 1.7.5 2023-04-18 [1] CRAN (R 4.2.0) purrr 1.0.1 2023-01-10 [1] CRAN (R 4.2.0) R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) Rcpp 1.0.11 2023-07-06 [1] CRAN (R 4.2.0) readr 2.1.4 2023-02-10 [1] CRAN (R 4.2.0) remotes 2.4.2.1 2023-07-18 [1] CRAN (R 4.2.2) rlang 1.1.1 2023-04-28 [1] CRAN (R 4.2.0) rmarkdown 2.23 2023-07-01 [1] CRAN (R 4.2.0) rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.2.0) scales 1.2.1 2022-08-20 [1] CRAN (R 4.2.0) sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) shiny 1.7.4.1 2023-07-06 [1] CRAN (R 4.2.0) stringi 1.7.12 2023-01-11 [1] CRAN (R 4.2.0) stringr 1.5.0 2022-12-02 [1] CRAN (R 4.2.0) survival 3.5-5 2023-03-12 [1] CRAN (R 4.2.0) tibble 3.2.1 2023-03-20 [1] CRAN (R 4.2.0) tidyr 1.3.0 2023-01-24 [1] CRAN (R 4.2.0) tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.2.0) tidyverse 2.0.0 2023-02-22 [1] CRAN (R 4.2.0) timechange 0.2.0 2023-01-11 [1] CRAN (R 4.2.0) tzdb 0.4.0 2023-05-12 [1] CRAN (R 4.2.2) urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.2.0) usethis 2.2.2 2023-07-06 [1] CRAN (R 4.2.0) utf8 1.2.3 2023-01-31 [1] CRAN (R 4.2.0) vctrs 0.6.3 2023-06-14 [1] CRAN (R 4.2.0) vroom 1.6.3 2023-04-28 [1] CRAN (R 4.2.0) withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) xfun 0.39 2023-04-20 [1] CRAN (R 4.2.0) xtable 1.8-4 2019-04-21 [1] CRAN (R 4.2.0) yaml 2.3.7 2023-01-23 [1] CRAN (R 4.2.0)

[1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library



**Additional note:**
The total runtime report is wrong, in the condition when this error happens - these tests took much longer than the reported runtime. The reported runtime was correct (the moment it was printed on the screen) with `permutations = 20000`. By the way, I really like the progress bar.
HajkD commented 1 year ago

Dear @LotharukpongJS

Thank you so much for catching this!

@lavakin Would it be possible to have a closer look at this?

With many thanks and very best wishes, Hajk