Learn R Programming

tidybayes (version 1.0.4)

tidy_draws: Get a sample of posterior draws from a model as a tibble

Description

Extract draws from a Bayesian fit into a wide-format data frame with a .chain, .iteration, and .draw column, as well as all variables as columns. While this function can be useful for quick glances at models (especially combined with gather_variables and median_qi), it is generally speaking not as useful as spread_draws or gather_draws for most applications, and is mainly used internally (see `Details`).

Usage

tidy_draws(model)

# S3 method for default tidy_draws(model)

# S3 method for mcmc.list tidy_draws(model)

# S3 method for stanfit tidy_draws(model)

# S3 method for stanreg tidy_draws(model)

# S3 method for runjags tidy_draws(model)

# S3 method for jagsUI tidy_draws(model)

# S3 method for brmsfit tidy_draws(model)

# S3 method for matrix tidy_draws(model)

# S3 method for MCMCglmm tidy_draws(model)

Arguments

model

A supported Bayesian model fit object. See tidybayes-models for a list of supported models.

Value

A data frame (actually, a tibble) with a .chain column, .iteration column, .draw column, and one column for every variable in model.

Details

In practice, apart from quick looks at a model you will probably not call this directly; spread_draws or gather_draws, which are build on top of this function, provide support for extracting variable dimensions are so are often more useful.

To provide support for new models in tidybayes, you must provide an implementation of this function or an implementation of as.mcmc.list (tidy_draws should work on any model with an implementation of as.mcmc.list)

See Also

spread_draws or gather_draws, which use this function internally and provides a friendly interface for extracting tidy data frames from model fits.

Examples

Run this code
# NOT RUN {
library(magrittr)

data(line, package = "coda")

line %>%
  tidy_draws()

# }

Run the code above in your browser using DataLab