View source: R/resample_draws.R
resample_draws | R Documentation |
draws
objectsResample draws
objects according to provided weights, for example weights
obtained through importance sampling.
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, ...)
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 |
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.
A draws
object of the same class as x
.
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.
resample_draws()
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())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.