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

as_draws_matrix(x, ...)

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

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

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

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

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

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

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

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

draws_matrix(..., .nchains = 1)

is_draws_matrix(x)

Arguments

x

An object to convert to a draws_matrix object.

...

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

.nchains

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

Value

A draws_matrix object, which has classes c("draws_matrix", "draws", "matrix").

Details

Objects of class "draws_matrix" are matrices (2-D arrays) with dimensions "draw" and "variable". See Examples.

See also

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

Examples

x1 <- as_draws_matrix(example_draws())
class(x1)
#> [1] "draws_matrix" "draws"        "matrix"      
print(x1)
#> # A draws_matrix: 100 iterations, 4 chains, and 10 variables
#>     variable
#> draw   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
str(x1)
#>  'draws_matrix' num [1:400, 1:10] 2.01 1.46 5.81 6.85 1.81 ...
#>  - attr(*, "dimnames")=List of 2
#>   ..$ draw    : chr [1:400] "1" "2" "3" "4" ...
#>   ..$ variable: chr [1:10] "mu" "tau" "theta[1]" "theta[2]" ...
#>  - attr(*, "nchains")= int 4

x2 <- draws_matrix(a = rnorm(10), b = rnorm(10), c = 1)
class(x2)
#> [1] "draws_matrix" "draws"        "matrix"      
print(x2)
#> # A draws_matrix: 10 iterations, 1 chains, and 3 variables
#>     variable
#> draw     a     b c
#>   1   1.63  0.22 1
#>   2   0.43 -0.72 1
#>   3  -1.76  1.56 1
#>   4   0.94 -0.24 1
#>   5   1.57  0.63 1
#>   6   0.46  0.18 1
#>   7   0.71 -0.95 1
#>   8  -1.28  1.01 1
#>   9   1.87  0.08 1
#>   10 -0.15  1.05 1
str(x2)
#>  'draws_matrix' num [1:10, 1:3] 1.625 0.434 -1.765 0.936 1.571 ...
#>  - attr(*, "dimnames")=List of 2
#>   ..$ draw    : chr [1:10] "1" "2" "3" "4" ...
#>   ..$ variable: chr [1:3] "a" "b" "c"
#>  - attr(*, "nchains")= int 1