draws-brms: Transform 'brmsfit' to 'draws' objects

draws-brmsR Documentation

Transform brmsfit to draws objects

Description

Transform a brmsfit object to a format supported by the posterior package.

Usage

## S3 method for class 'brmsfit'
as_draws(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)

## S3 method for class 'brmsfit'
as_draws_matrix(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)

## S3 method for class 'brmsfit'
as_draws_array(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)

## S3 method for class 'brmsfit'
as_draws_df(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)

## S3 method for class 'brmsfit'
as_draws_list(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)

## S3 method for class 'brmsfit'
as_draws_rvars(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)

Arguments

x

A brmsfit object or another R object for which the methods are defined.

variable

A character vector providing the variables to extract. By default, all variables are extracted.

regex

Logical; Should variable should be treated as a (vector of) regular expressions? Any variable in x matching at least one of the regular expressions will be selected. Defaults to FALSE.

inc_warmup

Should warmup draws be included? Defaults to FALSE.

...

Arguments passed to individual methods (if applicable).

Details

To subset iterations, chains, or draws, use the subset_draws method after transforming the brmsfit to a draws object.

See Also

draws subset_draws

Examples

## Not run: 
fit <- brm(count ~ zAge + zBase * Trt + (1|patient),
           data = epilepsy, family = poisson())

# extract posterior draws in an array format
(draws_fit <- as_draws_array(fit))
posterior::summarize_draws(draws_fit)

# extract only certain variables
as_draws_array(fit, variable = "r_patient")
as_draws_array(fit, variable = "^b_", regex = TRUE)

# extract posterior draws in a random variables format
as_draws_rvars(fit)

## End(Not run)


brms documentation built on Sept. 23, 2024, 5:08 p.m.