Skip to content
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

Uninformative error when calling posterior_predict with ndraws greater than the number of samples #1370

Closed
andrjohns opened this issue Jun 28, 2022 · 2 comments

Comments

@andrjohns
Copy link
Contributor

From this post on the forum, calling posterior_predict and requesting ndraws greater than the number of post-warmup draws in the model gives an error from the sample.int function (reprex below).

It would probably be better to have an input validation step for the ndraws value:

Reprex:

library(brms)
#> Loading required package: Rcpp
#> Loading 'brms' package (version 2.17.0). Useful instructions
#> can be found by typing help('brms'). A more detailed introduction
#> to the package is available through vignette('brms_overview').
#> 
#> Attaching package: 'brms'
#> The following object is masked from 'package:stats':
#> 
#>     ar
fit <- brm(time ~ age, data = kidney,
           iter = 100, chains = 1,
           backend = "cmdstanr")
#> Start sampling
#> Running MCMC with 1 chain...
#> 
#> Chain 1 WARNING: There aren't enough warmup iterations to fit the 
#> Chain 1          three stages of adaptation as currently configured. 
#> Chain 1          Reducing each adaptation stage to 15%/75%/10% of 
#> Chain 1          the given number of warmup iterations: 
#> Chain 1            init_buffer = 7 
#> Chain 1            adapt_window = 38 
#> Chain 1            term_buffer = 5 
#> Chain 1 Iteration:  1 / 100 [  1%]  (Warmup) 
#> Chain 1 Iteration: 51 / 100 [ 51%]  (Sampling) 
#> Chain 1 Iteration: 100 / 100 [100%]  (Sampling) 
#> Chain 1 finished in 0.1 seconds.

pp <- posterior_predict(fit, ndraws = 200)
#> Error in sample.int(length(x), size, replace, prob): cannot take a sample larger than the population when 'replace = FALSE'

Created on 2022-06-28 by the reprex package (v2.0.1)

paul-buerkner added a commit that referenced this issue Jun 29, 2022
@paul-buerkner
Copy link
Owner

Thank you. Fixed now.

@andrjohns
Copy link
Contributor Author

Speedy as always, thanks Paul!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants