Skip to content

weightsMatrix does not work as expected in variancePartition or dream #114

@lucagaessler

Description

@lucagaessler

Hi @GabrielHoffman!

I have been (further) applying both variancePartition() and dream() to mass spectrometry-based proteomics data and it works quite nicely! Since voom() assumes RNAseq data as input, I tried to provide manually calculated weights to the modelling process. According to the documentation, this should be possible via the weightsMatrix argument. Unfortunately, it does not seem to work for me in either function above - the results are the same with or without providing the weights.

Is this feature not implemented yet or did I maybe misunderstand something? Any help would be highly appreciated!

I took the example from your vignette to reproduce the behaviour:

library("variancePartition")
#> Loading required package: ggplot2
#> Loading required package: limma
#> Loading required package: BiocParallel
#> 
#> Attaching package: 'variancePartition'
#> The following objects are masked from 'package:limma':
#> 
#>     eBayes, topTable

# load simulated data:
# geneExpr: matrix of gene expression values
# info: information/metadata about each sample

data(varPartData)

form <- ~ (1 | Individual) + (1 | Tissue) + Age + Height

# Specify custom weights
# In this example the weights are simulated from a
# uniform distribution and are not meaningful.
weights <- matrix(runif(length(geneExpr)), nrow = nrow(geneExpr))

weights_input <- weights[1:4, ]

# Specify custom weights
res_weights <- fitExtractVarPartModel(geneExpr[1:4, ], form, info,
                                      useWeights = TRUE,
                                      weightsMatrix = weights_input)

res_no_weights <- fitExtractVarPartModel(geneExpr[1:4, ], form, info,
                                         useWeights = FALSE)

identical(res_weights, res_no_weights)
#> [1] TRUE

sessionInfo()
#> R version 4.4.3 (2025-02-28)
#> Platform: aarch64-apple-darwin20
#> Running under: macOS Sequoia 15.7.1
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> time zone: Europe/Stockholm
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] variancePartition_1.39.4 BiocParallel_1.40.2      limma_3.62.2            
#> [4] ggplot2_4.0.0           
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.2.1    dplyr_1.1.4         farver_2.1.2       
#>  [4] S7_0.2.0            bitops_1.0-9        fastmap_1.2.0      
#>  [7] reprex_2.1.1        digest_0.6.37       lifecycle_1.0.4    
#> [10] statmod_1.5.1       magrittr_2.0.4      compiler_4.4.3     
#> [13] rlang_1.1.6         tools_4.4.3         yaml_2.3.10        
#> [16] knitr_1.50          plyr_1.8.9          RColorBrewer_1.1-3 
#> [19] KernSmooth_2.23-26  withr_3.0.2         purrr_1.1.0        
#> [22] numDeriv_2016.8-1.1 BiocGenerics_0.52.0 grid_4.4.3         
#> [25] aod_1.3.3           caTools_1.18.3      scales_1.4.0       
#> [28] gtools_3.9.5        iterators_1.0.14    MASS_7.3-65        
#> [31] cli_3.6.5           mvtnorm_1.3-3       rmarkdown_2.29     
#> [34] reformulas_0.4.2    generics_0.1.4      rstudioapi_0.17.1  
#> [37] reshape2_1.4.4      minqa_1.2.8         stringr_1.5.2      
#> [40] splines_4.4.3       parallel_4.4.3      matrixStats_1.5.0  
#> [43] vctrs_0.6.5         boot_1.3-31         Matrix_1.7-3       
#> [46] pbkrtest_0.5.5      tidyr_1.3.1         glue_1.8.0         
#> [49] nloptr_2.2.1        codetools_0.2-20    stringi_1.8.7      
#> [52] gtable_0.3.6        EnvStats_3.1.0      lme4_1.1-37        
#> [55] lmerTest_3.1-3      tibble_3.3.0        remaCor_0.0.20     
#> [58] pillar_1.11.1       htmltools_0.5.8.1   gplots_3.2.0       
#> [61] R6_2.6.1            Rdpack_2.6.4        evaluate_1.0.3     
#> [64] lattice_0.22-6      Biobase_2.66.0      rbibutils_2.3      
#> [67] backports_1.5.0     RhpcBLASctl_0.23-42 broom_1.0.10       
#> [70] fANCOVA_0.6-1       corpcor_1.6.10      Rcpp_1.1.0         
#> [73] nlme_3.1-167        xfun_0.51           fs_1.6.6           
#> [76] pkgconfig_2.0.3

Created on 2025-11-12 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions