paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.25k stars 177 forks source link

A more informative message when brmsfit contains only warmup samples #1625

Closed venpopov closed 3 months ago

venpopov commented 3 months ago

If you run a brms model with just warmup samples, and you call the model object (which calls the summary function), you get an error:

fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
    data = epilepsy,
    family = poisson(),
    warmup = 1000, 
    save_warmup = TRUE,
    iter = 1000)
fit1

#> Error in object$fit@stan_args[[1]] : subscript out of bounds

or a different error with the cmdstanr backend:

fit2 <- brm(count ~ zAge + zBase * Trt + (1|patient),
    data = epilepsy,
    family = poisson(),
    warmup = 1000,
    iter = 1000, 
    save_warmup = TRUE,
    backend = 'cmdstanr')
fit2

#> Error in `[.data.frame`(full_summary, , "Rhat") : 
#>  undefined columns selected

If you acces the fit slot, instead you get a more informative message:

fit1$fit
#> Stan model 'model_a52a580d3cb87237a8fc6e2875fe741c-202403181850-1-509462' does not contain samples after warmup.

It could be nice, though not high priority by any means, to give a similar message instead of throwing an error when you call the brmsfit object as well.

paul-buerkner commented 3 months ago

fixed