Learn R Programming

posterior (version 1.6.0)

draws_df: The draws_df format

Description

The as_draws_df() methods convert objects to the draws_df format. The draws_df() function creates an object of the draws_df format based on a set of numeric vectors. See Details.

Usage

as_draws_df(x, ...)

# S3 method for default as_draws_df(x, ...)

# S3 method for data.frame as_draws_df(x, ...)

# S3 method for draws_df as_draws_df(x, ...)

# S3 method for draws_matrix as_draws_df(x, ...)

# S3 method for draws_array as_draws_df(x, ...)

# S3 method for draws_list as_draws_df(x, ...)

# S3 method for draws_rvars as_draws_df(x, ...)

# S3 method for mcmc as_draws_df(x, ...)

# S3 method for mcmc.list as_draws_df(x, ...)

draws_df(..., .nchains = 1)

is_draws_df(x)

Value

A draws_df object, which has classes c("draws_df", "draws", class(tibble::tibble())).

Arguments

x

An object to convert to a draws_df object.

...

For as_draws_df(): Arguments passed to individual methods (if applicable). For draws_df(): Named arguments containing numeric vectors each defining a separate variable.

.nchains

(positive integer) The number of chains. The default is 1.

Details

Objects of class "draws_df" are tibble data frames. They have one column per variable as well as additional metadata columns ".iteration", ".chain", and ".draw". The difference between the ".iteration" and ".draw" columns is that the former is relative to the MCMC chain while the latter ignores the chain information and has all unique values. See Examples.

If a data.frame-like object is supplied to as_draws_df that contains columns named ".iteration" or ".chain", they will be treated as iteration and chain indices, respectively. See Examples.

See Also

Other formats: draws, draws_array(), draws_list(), draws_matrix(), draws_rvars()

Examples

Run this code
x1 <- as_draws_df(example_draws())
class(x1)
print(x1)
str(x1)

x2 <- draws_df(a = rnorm(10), b = rnorm(10), c = 1)
class(x2)
print(x2)
str(x2)

# the difference between iteration and draw is clearer when contrasting
# the head and tail of the data frame
print(head(x1), reserved = TRUE, max_variables = 2)
print(tail(x1), reserved = TRUE, max_variables = 2)

# manually supply chain information
xnew <- data.frame(mu = rnorm(10), .chain = rep(1:2, each = 5))
xnew <- as_draws_df(xnew)
print(xnew)

Run the code above in your browser using DataLab