resample_draws {posterior} | R Documentation |
Resample draws
objects
Description
Resample draws
objects according to provided weights, for example weights
obtained through importance sampling.
Usage
resample_draws(x, ...)
## S3 method for class 'draws'
resample_draws(x, weights = NULL, method = "stratified", ndraws = NULL, ...)
## S3 method for class 'rvar'
resample_draws(x, ...)
Arguments
x |
(draws) A |
... |
Arguments passed to individual methods (if applicable). |
weights |
(numeric vector) A vector of positive weights of length
|
method |
(string) The resampling method to use:
Currently, |
ndraws |
(positive integer) The number of draws to be returned. By
default |
Details
Upon usage of resample_draws()
, chains will automatically be merged
due to subsetting of individual draws (see subset_draws
for details).
Also, weights stored in the draws
object will be removed in the process,
as resampling invalidates existing weights.
Value
A draws
object of the same class as x
.
References
Kitagawa, G., Monte Carlo Filter and Smoother for Non-Gaussian Nonlinear ' State Space Models, Journal of Computational and Graphical Statistics, 5(1):1-25, 1996.
See Also
Examples
x <- as_draws_df(example_draws())
# random weights for justr for demonstration
w <- runif(ndraws(x), 0, 10)
# use default stratified sampling
x_rs <- resample_draws(x, weights = w)
summarise_draws(x_rs, default_summary_measures())
# use simple random sampling
x_rs <- resample_draws(x, weights = w, method = "simple")
summarise_draws(x_rs, default_summary_measures())