Skip to content

Commit

Permalink
update weight_draws doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Jun 11, 2020
1 parent de8cd76 commit 8df28a4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
34 changes: 13 additions & 21 deletions R/weight_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@
#' x <- example_draws()
#'
#' # sample some random weights for illustration
#' weights <- rexp(ndraws(x))
#' wts <- rexp(ndraws(x))
#' head(wts)
#'
#' # add weights
#' x <- weight_draws(x, weights = weights)
#' x <- weight_draws(x, weights = wts)
#'
#' # extract weights
#' head(weights(x))
#' 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_weights <- log(weights)
#' x <- weight_draws(x, weights = log_weights, log = TRUE)
#' 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
#'
#' @export
weight_draws <- function(x, weights, ...) {
Expand Down Expand Up @@ -112,22 +119,7 @@ weight_draws.draws_list <- function(x, weights, log = FALSE, ...) {
#'
#' @seealso [`weight_draws`], [`resample_draws`]
#'
#' @examples
#' x <- example_draws()
#'
#' # sample some random weights for illustration
#' weights <- rexp(ndraws(x))
#'
#' # add weights
#' x <- weight_draws(x, weights = weights)
#'
#' # return normalized weights
#' weights <- weights(x)
#' head(weights)
#'
#' # return normalized log weights
#' log_weights <- weights(x, log = TRUE)
#' head(log_weights)
#' @inherit weight_draws examples
#'
#' @export
weights.draws <- function(object, log = FALSE, normalize = TRUE, ...) {
Expand Down
17 changes: 12 additions & 5 deletions man/weight_draws.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions man/weights.draws.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8df28a4

Please sign in to comment.