GabrielHoffman / variancePartition

Quantify and interpret divers of variation in multilevel gene expression experiments
http://gabrielhoffman.github.io/variancePartition/
60 stars 14 forks source link

Error: missing value where TRUE/FALSE needed with categorical variables #104

Closed ecrusu closed 1 month ago

ecrusu commented 1 month ago

Hi! I've been testing the package but every time I try to add a categorical variable to the formula, I get the following error:

Error in if (inherits(possibleError, "error") && grep("the fixed-effects model matrix is column rank deficient",  : 
  missing value where TRUE/FALSE needed

It has happened with real data but also with mock data. Design formulas with only one metadata categorical column throw the error. It did not happen though with the tutorial data from https://www.bioconductor.org/packages/release/bioc/vignettes/variancePartition/inst/doc/variancePartition.html.

The package seems extremely promising but I can't seem to make it work with my data. Thank you very much for your time.

Here's a reproducible example:

colnames_vector <- paste0("col", 1:68)

# Create mock sample info
variable1 <- c("B", "B", "A", "B", "A", "B", "B", "B", "A", "A", "B", "B", "B", 
               "B", "B", "A", "B", "B", "B", "B", 
               "B", "B", "B", "B", "A", "A", "B", "B", "B", "A", "B", "B", "A", 
               "A", "B", "B", "B", "B", "B", "B", 
               "A", "A", "B", "B", "A", "B", "B", "B", "B", "A", "A", "B", "B", 
               "B", "B", "B", "B", "A", "B", "B", 
               "B", "B", "B", "A", "B", "B", "B", "B")
variable2 <- c(67, 81, 61, 78, 87, 86, 78, 64, 76, 77, 82, 79, 78, 66, 77, 73, 74, 84, 66, 68, 
               88, 89, 85, 92, 83, 85, 87, 86, 88, 92, 95, 83, 71, 62, 76, 85, 78, 68, 80, 83, 
               86, 80, 67, 89, 63, 58, 66, 80, 69, 95, 79, 64, 87, 77, 79, 87, 76, 78, 59, 85, 
               79, 76, 74, 73, 73, 78, 70, 80)

mock_sampleinfo <- data.frame(variable1 = variable1, variable2 = variable2, 
                              row.names = colnames_vector)
mock_sampleinfo$variable1 <- as.factor(mock_sampleinfo$variable1)

# Mock expression info
num_rows <- 11649
mock_df <- data.frame(lapply(1:length(colnames_vector), function(x) rnorm(num_rows)))
colnames(mock_df) <- colnames_vector

form <- ~ (1 | variable1)
varPart <- fitExtractVarPartModel(mock_df, form, mock_sampleinfo)

Session info output:

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8   
 [6] LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C           LC_TELEPHONE=C        
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] variancePartition_1.24.1 BiocParallel_1.28.3      edgeR_3.36.0             limma_3.50.3            
 [5] BiocManager_1.30.25      dplyr_1.1.4              scales_1.3.0             ggplot2_3.5.1           
 [9] enrichplot_1.14.2        DOSE_3.20.1              ggridges_0.5.6           org.Hs.eg.db_3.14.0     
[13] AnnotationDbi_1.56.2     IRanges_2.28.0           S4Vectors_0.32.4         Biobase_2.54.0          
[17] BiocGenerics_0.40.0      ReactomePA_1.38.0       

loaded via a namespace (and not attached):
  [1] shadowtext_0.1.4       backports_1.5.0        fastmatch_1.1-4        plyr_1.8.9             igraph_2.0.3          
  [6] lazyeval_0.2.2         splines_4.1.2          GenomeInfoDb_1.30.1    digest_0.6.37          foreach_1.5.2         
 [11] yulab.utils_0.1.7      GOSemSim_2.20.0        viridis_0.6.5          GO.db_3.14.0           fansi_1.0.6           
 [16] magrittr_2.0.3         checkmate_2.3.2        memoise_2.0.1          doParallel_1.0.17      aod_1.3.3             
 [21] Biostrings_2.62.0      graphlayouts_1.1.1     prettyunits_1.2.0      colorspace_2.1-1       blob_1.2.4            
 [26] rappdirs_0.3.3         ggrepel_0.9.6          rbibutils_2.3          crayon_1.5.3           RCurl_1.98-1.16       
 [31] jsonlite_1.8.8         graph_1.72.0           scatterpie_0.2.4       lme4_1.1-35.3          iterators_1.0.14      
 [36] ape_5.8                glue_1.7.0             polyclip_1.10-7        gtable_0.3.5           zlibbioc_1.40.0       
 [41] XVector_0.34.0         graphite_1.40.0        pheatmap_1.0.12        DBI_1.2.3              Rcpp_1.0.13           
 [46] viridisLite_0.4.2      progress_1.2.3         gridGraphics_0.5-1     tidytree_0.4.6         bit_4.0.5             
 [51] reactome.db_1.77.0     httr_1.4.7             fgsea_1.20.0           gplots_3.1.3.1         RColorBrewer_1.1-3    
 [56] pkgconfig_2.0.3        farver_2.1.2           locfit_1.5-9.9         utf8_1.2.4             ggplotify_0.1.2       
 [61] tidyselect_1.2.1       rlang_1.1.4            reshape2_1.4.4         munsell_0.5.1          tools_4.1.2           
 [66] cachem_1.1.0           cli_3.6.3              generics_0.1.3         RSQLite_2.3.7          broom_1.0.5           
 [71] stringr_1.5.1          fastmap_1.2.0          ggtree_3.13.1          RhpcBLASctl_0.23-42    bit64_4.0.5           
 [76] fs_1.6.4               tidygraph_1.3.1        caTools_1.18.2         purrr_1.0.2            KEGGREST_1.34.0       
 [81] ggraph_2.2.1           nlme_3.1-152           aplot_0.2.3            DO.db_2.9              compiler_4.1.2        
 [86] pbkrtest_0.5.2         rstudioapi_0.16.0      png_0.1-8              treeio_1.18.1          tibble_3.2.1          
 [91] tweenr_2.0.3           stringi_1.8.4          lattice_0.20-45        Matrix_1.4-0           nloptr_2.0.3          
 [96] vctrs_0.6.5            pillar_1.9.0           lifecycle_1.0.4        Rdpack_2.6.1           data.table_1.16.0     
[101] bitops_1.0-8           patchwork_1.3.0        qvalue_2.26.0          R6_2.5.1               renv_1.0.7            
[106] KernSmooth_2.23-20     gridExtra_2.3          codetools_0.2-18       boot_1.3-28            MASS_7.3-54           
[111] gtools_3.9.5           withr_3.0.1            GenomeInfoDbData_1.2.7 parallel_4.1.2         hms_1.1.3             
[116] grid_4.1.2             ggfun_0.1.6            tidyr_1.3.1            minqa_1.2.6            ggforce_0.4.2   
bk1n commented 1 month ago

Same issue I had - see #102 , had to upgrade my R version to 4.4.1 with newer version of BiocManager to get latest version of variancePartition

GabrielHoffman commented 1 month ago

That version of R and variancePartition is very very old. Did a new version resolve this?

Gabriel

ecrusu commented 1 month ago

Yes! The new version works just fine. Thanks!