draws_df {posterior} | R Documentation |
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, ...)
## Default S3 method:
as_draws_df(x, ...)
## S3 method for class 'data.frame'
as_draws_df(x, ...)
## S3 method for class 'draws_df'
as_draws_df(x, ...)
## S3 method for class 'draws_matrix'
as_draws_df(x, ...)
## S3 method for class 'draws_array'
as_draws_df(x, ...)
## S3 method for class 'draws_list'
as_draws_df(x, ...)
## S3 method for class 'draws_rvars'
as_draws_df(x, ...)
## S3 method for class 'mcmc'
as_draws_df(x, ...)
## S3 method for class 'mcmc.list'
as_draws_df(x, ...)
draws_df(..., .nchains = 1)
is_draws_df(x)
Arguments
x |
An object to convert to a |
... |
For |
.nchains |
(positive integer) The number of chains. The default is |
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.
Value
A draws_df
object, which has classes
c("draws_df", "draws", class(tibble::tibble()))
.
See Also
Other formats:
draws
,
draws_array()
,
draws_list()
,
draws_matrix()
,
draws_rvars()
Examples
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)