New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory allocation error #995
Comments
I'm not sure we have any magic tricks, but it would be useful to know what the results of If your model is fairly simple, you may be able to use |
Here's a start at a reproducible example. So far it seems slow on my machine but not hugely memory-hungry. R is reporting 2.4GB of RAM use - I think but am not sure that TMB's memory use will be correctly charged to R? In any case, the total memory allocation on the machine is at about 20GB and doesn't seem to be blowing up. Does it cause problems for you? The error you're reporting above ("cannot allocate vector of size 47.1 Gb") doesn't seem consistent with what's happening here (although I haven't gotten to the end of the computation yet, maybe something bad will happen when the model gets finalized ...). Again, more details from
nt <- 2e4
nn <- 3e5
set.seed(101)
## counts with at least 2 times per individual
nt_id <- rpois(nt, lambda = mean(nn/nt)-2) + 2
nn2 <-sum(nt_id) ## close to nn
tvec <- lapply(nt_id, seq.int) |> unlist() |> factor()
idvec <- rep(seq_along(nt_id), times = nt_id)
dd <- (replicate(6, rnorm(nn2), simplify = FALSE)
|> as.data.frame()
|> setNames(c("y", paste0("x", 1:5)))
)
dd <- data.frame(dd, tvec, id = idvec)
library(glmmTMB)
library(peakRAM)
peakRAM(
glmmTMB(y ~ x1 + x2 + x3 + x4 + x5 + ar1(0 + tvec|id) + (1|id),
dispformula = ~ 0,
data = dd, verbose = TRUE)
) |
Thank you! One thing I noticed that was different between your code and mine was that I used Here's the traceback:
|
There should be no difference between Can you show us the output of |
I will try this again when I get a chance. I'm pretty sure I know what's happening, which is that at some point internally the machinery is trying to set up a dense matrix with dimensions equal to the length of the autocorrelation factor. This matrix is not actually needed by The simpler, hackier solution is to copy |
There's another similar issue here , causing |
I've copied remotes::install_github("bbolker/reformulas")
remotes::install_github("glmmTMB/glmmTMB/glmmTMB@reformulas") and see if you get the same error (you'll need development tools installed). You may run into problems a little further down the line based on the step that @kaskr mentions above, but if so we can add something to skip this step ... |
I'm trying to run a gaussian model with temporal autocorrelation. The data is GPS data, with observations from multiple animals once every hour. In total, there are 300000 data points, with the temporal autocorrelation factor having 20407 levels. I followed this vignette to add temporal autocorrelation, grouping by each animal, such that the autocorrelation parameter is ar1(date-time factor + 0|individual id). I have 5 other predictors other than the autocorrelation parameter. I have set the dispersion formula to zero in the model specification.
I'm running into a memory allocation issue, with the error "Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 't': cannot allocate vector of size 47.1 Gb". I know this is likely because the dataset is too large to run the model and my computer is running out of memory. I was wondering if there were workarounds to this problem other than reducing the size of my dataset.
Thank you!
The text was updated successfully, but these errors were encountered: