mjskay / tidybayes

Bayesian analysis + tidy data + geoms (R package)
http://mjskay.github.io/tidybayes
GNU General Public License v3.0
712 stars 59 forks source link

Cholmod error with add_predicted_draws() #218

Closed teaguescott closed 3 years ago

teaguescott commented 4 years ago

Hi,

I am trying to create a tibble of posterior predictions with the function _add_predicteddraws() and keep running into this error:

Error in b %*% data$Zt : Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 105

I'm not sure how best to add a brief reprex here but can send you my code and data if it helps.

mjskay commented 4 years ago

If you can get a small reprex for it that would be easier, though by the sounds of the error it might be an issue that only crops up if you're running out of memory.

Can you say a bit more about the model and also give output of traceback()?

teaguescott commented 4 years ago

Seems like it probably has to do with memory (given what google tells me about that error).

It's a generalized linear mixed model run in rstanarm. The dataframe used for the model contains 149 rows, and there are four parameters used for the model with 12 groups. The posterior sample size is 16000. Two of these are numeric, two categorical. One of these categorical variables is included as a group level effect and contains three levels.

Here's the model:

 M <- stan_glmer(ml95 ~ 1 + cen_jDay * year + cen_jDay * NDVI_95 + (1 + br_stat|bird),
                           data = fin_akde,
                           family = Gamma(link = "log"),
                           control = list(adapt_delta = 0.99, max_treedepth = 15),
                           chains = 4, cores = 4, warmup = 4000, iter = 8000,
                           seed = 3)

Here's the traceback() output:

18: b %*% data$Zt
17: b %*% data$Zt
16: as.matrix(b %*% data$Zt)
15: pp_eta(object, data = dat, draws = draws)
14: posterior_linpred.stanreg(model, newdata = newdata, ...)
13: f_fitted_predicted(model, newdata = newdata, ...)
12: fitted_predicted_draws_brmsfit_(rstanarm::posterior_linpred, 
        model, newdata, output_name = value, ..., seed = seed, category = category, 
        re.form = re_formula, transform = transform, is_brms = FALSE)
11: fitted_draws.stanreg(model, newdata, value, ..., n = n, seed = seed, 
        re_formula = re_formula, category = category, dpar = dpar, 
        scale = scale)
10: fitted_draws(model, newdata, value, ..., n = n, seed = seed, 
        re_formula = re_formula, category = category, dpar = dpar, 
        scale = scale)
9: add_fitted_draws(., M3.021)
8: function_list[[k]](value)
7: withVisible(function_list[[k]](value))
6: freduce(value, `_function_list`)
5: `_fseq`(`_lhs`)
4: eval(quote(`_fseq`(`_lhs`)), env, env)
3: eval(quote(`_fseq`(`_lhs`)), env, env)
2: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1: fin_akde %>% data_grid(bird, year, cen_jDay, NDVI_95, br_stat) %>% 
       add_fitted_draws(M3.021)

I guess I'm just surprised that I'm running out of memory. I was playing around with other models that didn't include the second interaction parameter and the add_predicted_draws() and add_fitted_draws() functions ran just fine.

Figuring out a reprex might take me a bit of time... I can attach the dataframe used in the model if that helps.

mjskay commented 4 years ago

Thanks for the additional info. One thing to check would be to see if a call to posterior_linpred() instead of add_fitted_draws() yields the same error. If so I'd suggest raising the issue with rstanarm folks (probably on https://discourse.mc-stan.org/) as they'll better be able to help.

mjskay commented 3 years ago

Closing this issue as old; also looks like it was probably an rstanarm problem.