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.
as_draws_df(x, ...) # S3 method for default as_draws_df(x, ...) # S3 method for data.frame as_draws_df(x, .iteration = NULL, .chain = NULL, ...) # 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 mcmc as_draws_df(x, ...) # S3 method for mcmc.list as_draws_df(x, ...) draws_df(..., .nchains = 1) is_draws_df(x)
x | An object to convert to a |
---|---|
... | For |
.iteration | Optional name of a column in the supplied |
.chain | Optional name of a column in the supplied |
.nchains | Number of chains (default is |
A draws_df
object, which has classes
c("draws_df", "draws", class(tibble::tibble()))
.
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.
Other formats:
draws_array()
,
draws_list()
,
draws_matrix()
,
draws
#> [1] "draws_df" "draws" "tbl_df" "tbl" "data.frame"print(x1)#> # A draws_df: 100 iterations, 4 chains, and 10 variables #> mu tau theta[1] theta[2] theta[3] theta[4] theta[5] theta[6] #> 1 2.01 2.8 3.96 0.271 -0.74 2.1 0.923 1.7 #> 2 1.46 7.0 0.12 -0.069 0.95 7.3 -0.062 11.3 #> 3 5.81 9.7 21.25 14.931 1.83 1.4 0.531 7.2 #> 4 6.85 4.8 14.70 8.586 2.67 4.4 4.758 8.1 #> 5 1.81 2.8 5.96 1.156 3.11 2.0 0.769 4.7 #> 6 3.84 4.1 5.76 9.909 -1.00 5.3 5.889 -1.7 #> 7 5.47 4.0 4.03 4.151 10.15 6.6 3.741 -2.2 #> 8 1.20 1.5 -0.28 1.846 0.47 4.3 1.467 3.3 #> 9 0.15 3.9 1.81 0.661 0.86 4.5 -1.025 1.1 #> 10 7.17 1.8 6.08 8.102 7.68 5.6 7.106 8.5 #> # ... with 390 more draws, and 2 more variables #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'}str(x1)#> tibble [400 × 13] (S3: draws_df/draws/tbl_df/tbl/data.frame) #> $ mu : num [1:400] 2.01 1.46 5.81 6.85 1.81 ... #> $ tau : num [1:400] 2.77 6.98 9.68 4.79 2.85 ... #> $ theta[1] : num [1:400] 3.962 0.124 21.251 14.7 5.96 ... #> $ theta[2] : num [1:400] 0.271 -0.069 14.931 8.586 1.156 ... #> $ theta[3] : num [1:400] -0.743 0.952 1.829 2.675 3.109 ... #> $ theta[4] : num [1:400] 2.1 7.28 1.38 4.39 1.99 ... #> $ theta[5] : num [1:400] 0.923 -0.062 0.531 4.758 0.769 ... #> $ theta[6] : num [1:400] 1.65 11.26 7.16 8.1 4.66 ... #> $ theta[7] : num [1:400] 3.32 9.62 14.8 9.49 1.21 ... #> $ theta[8] : num [1:400] 4.85 -8.64 -1.74 5.28 -4.54 ... #> $ .chain : int [1:400] 1 1 1 1 1 1 1 1 1 1 ... #> $ .iteration: int [1:400] 1 2 3 4 5 6 7 8 9 10 ... #> $ .draw : int [1:400] 1 2 3 4 5 6 7 8 9 10 ...#> [1] "draws_df" "draws" "tbl_df" "tbl" "data.frame"print(x2)#> # A draws_df: 10 iterations, 1 chains, and 3 variables #> a b c #> 1 0.862 1.07 1 #> 2 -0.243 -0.67 1 #> 3 -0.206 1.11 1 #> 4 0.019 -0.25 1 #> 5 0.030 -1.18 1 #> 6 0.550 -0.98 1 #> 7 -2.274 1.07 1 #> 8 2.683 0.13 1 #> 9 -0.361 0.49 1 #> 10 0.213 -1.70 1 #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'}str(x2)#> tibble [10 × 6] (S3: draws_df/draws/tbl_df/tbl/data.frame) #> $ a : num [1:10] 0.8621 -0.2432 -0.2061 0.0192 0.0296 ... #> $ b : num [1:10] 1.074 -0.665 1.114 -0.246 -1.178 ... #> $ c : num [1:10] 1 1 1 1 1 1 1 1 1 1 #> $ .chain : int [1:10] 1 1 1 1 1 1 1 1 1 1 #> $ .iteration: int [1:10] 1 2 3 4 5 6 7 8 9 10 #> $ .draw : int [1:10] 1 2 3 4 5 6 7 8 9 10# 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)#> # A draws_df: 6 iterations, 1 chains, and 10 variables #> mu tau .chain .iteration .draw #> 1 2.0 2.8 1 1 1 #> 2 1.5 7.0 1 2 2 #> 3 5.8 9.7 1 3 3 #> 4 6.8 4.8 1 4 4 #> 5 1.8 2.8 1 5 5 #> 6 3.8 4.1 1 6 6 #> # ... with 8 more variables#> # A draws_df: 6 iterations, 1 chains, and 10 variables #> mu tau .chain .iteration .draw #> 1 NA NA NA 1 1 #> 2 NA NA NA 2 2 #> 3 NA NA NA 3 3 #> 4 NA NA NA 4 4 #> 5 NA NA NA 5 5 #> 6 NA NA NA 6 6 #> # ... with 8 more variables