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, ...)

Arguments

object

(draws) A draws object.

log

(logical) Should the weights be returned on the log scale? Defaults to FALSE.

normalize

(logical) Should the weights be normalized to sum to 1 on the standard scale? Defaults to TRUE.

...

Arguments passed to individual methods (if applicable).

Value

A vector of weights, with one weight per draw.

Examples

x <- example_draws()

# sample some random weights for illustration
wts <- rexp(ndraws(x))
head(wts)
#> [1] 1.9344030 0.7445487 2.1868616 0.8625128 0.5622111 1.3747321

# add weights
x <- weight_draws(x, weights = wts)

# extract weights
head(weights(x)) # defaults to normalized weights
#> [1] 0.004921318 0.001894208 0.005563598 0.002194320 0.001430322 0.003497458
head(weights(x, normalize=FALSE)) # recover original weights
#> [1] 1.9344030 0.7445487 2.1868616 0.8625128 0.5622111 1.3747321
head(weights(x, log=TRUE)) # get normalized log-weights
#> [1] -5.314179 -6.268955 -5.191510 -6.121883 -6.549856 -5.655719

# add weights which are already on the log scale
log_wts <- log(wts)
head(log_wts)
#> [1]  0.6597987 -0.2949770  0.7824675 -0.1479052 -0.5758779  0.3182589

x <- weight_draws(x, weights = log_wts, log = TRUE)
# extract weights
head(weights(x))
#> [1] 0.004921318 0.001894208 0.005563598 0.002194320 0.001430322 0.003497458
head(weights(x, log=TRUE, normalize = FALSE)) # recover original log_wts
#> [1]  0.6597987 -0.2949770  0.7824675 -0.1479052 -0.5758779  0.3182589