weights.draws: Extract Weights from Draws Objects

View source: R/weight_draws.R

weights.drawsR Documentation

Extract Weights from Draws Objects

Description

Extract weights from draws objects, with one weight per draw. See weight_draws for details how to add weights to draws objects.

Usage

## S3 method for class '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.

See Also

weight_draws, resample_draws

Examples

x <- example_draws()

# sample some random weights for illustration
wts <- rexp(ndraws(x))
head(wts)

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

# extract weights
head(weights(x)) # defaults to normalized weights
head(weights(x, normalize=FALSE)) # recover original weights
head(weights(x, log=TRUE)) # get normalized log-weights

# add weights which are already on the log scale
log_wts <- log(wts)
head(log_wts)

x <- weight_draws(x, weights = log_wts, log = TRUE)
# extract weights
head(weights(x))
head(weights(x, log=TRUE, normalize = FALSE)) # recover original log_wts


posterior documentation built on Nov. 2, 2023, 5:56 p.m.