Extract weights from draws
objects, with one weight per draw.
See weight_draws
for details how to add weights to draws
objects.
# S3 method for draws
weights(object, log = FALSE, normalize = TRUE, ...)
(draws) A draws
object.
(logical) Should the weights be returned on the log scale?
Defaults to FALSE
.
(logical) Should the weights be normalized to sum to 1 on
the standard scale? Defaults to TRUE
.
Arguments passed to individual methods (if applicable).
A vector of weights, with one weight per draw.
x <- example_draws()
# sample some random weights for illustration
wts <- rexp(ndraws(x))
head(wts)
#> [1] 0.61086446 0.33461334 0.02989975 0.36790580 2.15576680 0.24003173
# add weights
x <- weight_draws(x, weights = wts)
# extract weights
head(weights(x)) # defaults to normalized weights
#> [1] 1.574879e-03 8.626719e-04 7.708502e-05 9.485037e-04 5.557816e-03
#> [6] 6.188295e-04
head(weights(x, normalize=FALSE)) # recover original weights
#> [1] 0.61086446 0.33461334 0.02989975 0.36790580 2.15576680 0.24003173
head(weights(x, log=TRUE)) # get normalized log-weights
#> [1] -6.453577 -7.055476 -9.470602 -6.960625 -5.192550 -7.387681
# add weights which are already on the log scale
log_wts <- log(wts)
head(log_wts)
#> [1] -0.4928802 -1.0947796 -3.5099051 -0.9999283 0.7681465 -1.4269842
x <- weight_draws(x, weights = log_wts, log = TRUE)
# extract weights
head(weights(x))
#> [1] 1.574879e-03 8.626719e-04 7.708502e-05 9.485037e-04 5.557816e-03
#> [6] 6.188295e-04
head(weights(x, log=TRUE, normalize = FALSE)) # recover original log_wts
#> [1] -0.4928802 -1.0947796 -3.5099051 -0.9999283 0.7681465 -1.4269842