Open NathanSiemers opened 2 years ago
btw, removing the offset parameter in the glm_gp call doesn't change anything.
Hey, sorry for the delay. I was at a workshop this week. I did take a briefly this afternoon while waiting for my flight and tried the code below to reproduce the issue, but my version finished successfully.
library(glmGamPoi)
model_matrix <- cbind(1, rnorm(5))
true_Beta <- cbind(rnorm(n = 30), rnorm(n = 30, mean = 3))
sf <- exp(rnorm(n = 5, mean = 0.7))
model_matrix
#> [,1] [,2]
#> [1,] 1 1.1480341
#> [2,] 1 -0.6869605
#> [3,] 1 -2.1089572
#> [4,] 1 0.1170987
#> [5,] 1 1.0913436
Y <- matrix(rnbinom(n = 30 * 5, mu = sf * exp(true_Beta %*% t(model_matrix)), size = 1/2.4),
nrow = 30, ncol = 5)
options(DelayedArray.block.size = 1e9)
DelayedArray::setAutoBlockSize(1e9)
#> automatic block size set to 1e+09 bytes (was 1e+08)
DelayedArray::setAutoBlockShape('last-dim-grows-first')
#> automatic block shape set to "last-dim-grows-first" (was "hypercube")
Y_h5 <- HDF5Array::writeHDF5Array(Y)
lmf <- glm_gp(
Y_h5,
model_matrix,
on_disk = TRUE,
verbose = TRUE,
offset = 0
)
#> Calculate Size Factors (normed_sum)
#> Make initial dispersion estimate
#> Make initial beta estimate
#> Estimate beta
#> Estimate dispersion
#> Fit dispersion trend
#> Shrink dispersion estimates
#> Estimate beta again
compare.treat = test_de( lmf, c(0,1), verbose = TRUE )
#> Fit reduced model
#> Calculate quasi likelihood ratio
#> Prepare results
Created on 2022-04-01 by the reprex package (v2.0.1)
I will have to take a more detailed look what's the difference between your code/data and my version next week. But thanks for making such a detailed bug report, I am sure we will able to figure out what is going wrong here :)
Best, Constantin
Just wondering if there has been any updates on this issue? I have been having a similiar issue as well. Worth noting: when I pass a matrix (sparse or not) to glm_gp with on_disk=T I have the same issue (think it is suppose to make it a HDF5Array internally, yes?), while if I first make the HDF5Array object then feed it in I do not have the issue, so that work around works for me (in case others need such a work around).
Hi Sean,
thanks for sharing your experience and the work-around. If you have a reproducible example (https://reprex.tidyverse.org/), I will try to take a look and figure out why the internal conversion fails.
Until then, I endorse your suggestion to manually create a HDF5Array
object and call glmGamPoi
with that :)
Hello Constantin,
Thank you for this code, I've been using and learning more about it for several months. I'm working with some large data sets and using glmGamPoi to perform modeling and hypothesis testing.
I've been able to create full models from HDF5Array input data sets and on_disk = TRUE. I did need to adjust the chunk size params to get this to occur in finite time. However, the on-disk version of the model output cannot be queried with test_de. Performing such test gives the error:
Error in combine_size_factors_and_offset(offset, size_factors, Y, verbose = verbose) : length(offset) == 1 || length(offset) == n_samples is not TRUE
(seems to be coming from estimate_size_factors.R)
If I run the same model with a realized input matrix and on_disk = FALSE, everything works as expected. I wonder if test_de can't determine the right dimensions or related parameters for on_disk models and is instead throwing this error?
It could be a general bug, it could be a problem that only shows up when one alters default H5 temp file paths, etc? But I've looked, and I think the on-disk model objects have hard-coded locations for data contained within them.... Hmm.
Attached is the log file (docx). You can get a full tgz of the code and input data at the link below. I've tried to make this an MRE, but even very truncated the singlecellexperiment file is a little big.
Thanks, Nathan Siemers mre.glmgampoi.bug.docx
tgz file: https://drive.google.com/file/d/1fYN4F7TtFpwgC6yqYZDP_rDHBiV4XU5H/view?usp=sharing