Create a draws object supported by the posterior package. These methods are just wrappers around CmdStanR's $draws() method provided for convenience.

# S3 method for CmdStanMCMC
as_draws(x, ...)

# S3 method for CmdStanMLE
as_draws(x, ...)

# S3 method for CmdStanLaplace
as_draws(x, ...)

# S3 method for CmdStanVB
as_draws(x, ...)

# S3 method for CmdStanGQ
as_draws(x, ...)

# S3 method for CmdStanPathfinder
as_draws(x, ...)

Arguments

x

A CmdStanR fitted model object.

...

Optional arguments passed to the $draws() method (e.g., variables, inc_warmup, etc.).

Details

To subset iterations, chains, or draws, use the posterior::subset_draws() method after creating the draws object.

Examples

# \dontrun{
fit <- cmdstanr_example()
as_draws(fit)
#> # A draws_array: 1000 iterations, 4 chains, and 105 variables
#> , , variable = lp__
#> 
#>          chain
#> iteration   1   2   3   4
#>         1 -66 -65 -65 -64
#>         2 -67 -67 -65 -68
#>         3 -66 -65 -65 -66
#>         4 -65 -66 -64 -66
#>         5 -64 -67 -65 -66
#> 
#> , , variable = alpha
#> 
#>          chain
#> iteration     1    2    3    4
#>         1 0.792 0.30 0.38 0.38
#>         2 0.061 0.54 0.49 0.14
#>         3 0.538 0.23 0.47 0.29
#>         4 0.446 0.10 0.37 0.41
#>         5 0.253 0.68 0.46 0.56
#> 
#> , , variable = beta[1]
#> 
#>          chain
#> iteration     1     2     3     4
#>         1 -0.93 -0.46 -0.99 -0.75
#>         2 -0.60 -0.87 -0.93 -0.84
#>         3 -0.67 -0.51 -0.45 -0.41
#>         4 -0.90 -0.78 -0.75 -0.19
#>         5 -0.63 -0.57 -0.45 -0.62
#> 
#> , , variable = beta[2]
#> 
#>          chain
#> iteration     1      2     3      4
#>         1 -0.26  0.031 -0.15 -0.195
#>         2  0.12 -0.226 -0.36 -0.386
#>         3 -0.02 -0.199 -0.15 -0.548
#>         4 -0.31 -0.013 -0.20 -0.084
#>         5 -0.12 -0.615 -0.09 -0.610
#> 
#> # ... with 995 more iterations, and 101 more variables

# posterior's as_draws_*() methods will also work
posterior::as_draws_rvars(fit)
#> # A draws_rvars: 1000 iterations, 4 chains, and 4 variables
#> $lp__: rvar<1000,4>[1] mean ± sd:
#> [1] -66 ± 1.5 
#> 
#> $alpha: rvar<1000,4>[1] mean ± sd:
#> [1] 0.37 ± 0.22 
#> 
#> $beta: rvar<1000,4>[3] mean ± sd:
#> [1] -0.67 ± 0.25  -0.28 ± 0.23   0.69 ± 0.27 
#> 
#> $log_lik: rvar<1000,4>[100] mean ± sd:
#>   [1] -0.518 ± 0.101  -0.398 ± 0.148  -0.500 ± 0.222  -0.445 ± 0.153 
#>   [5] -1.183 ± 0.289  -0.593 ± 0.195  -0.637 ± 0.127  -0.278 ± 0.133 
#>   [9] -0.697 ± 0.172  -0.743 ± 0.237  -0.280 ± 0.126  -0.492 ± 0.240 
#>  [13] -0.655 ± 0.213  -0.361 ± 0.174  -0.279 ± 0.109  -0.275 ± 0.087 
#>  [17] -1.594 ± 0.288  -0.481 ± 0.109  -0.232 ± 0.075  -0.112 ± 0.078 
#>  [21] -0.211 ± 0.087  -0.571 ± 0.151  -0.330 ± 0.138  -0.135 ± 0.065 
#>  [25] -0.451 ± 0.123  -1.520 ± 0.340  -0.307 ± 0.123  -0.446 ± 0.086 
#>  [29] -0.722 ± 0.230  -0.699 ± 0.193  -0.489 ± 0.165  -0.425 ± 0.111 
#>  [33] -0.406 ± 0.128  -0.062 ± 0.048  -0.583 ± 0.188  -0.325 ± 0.130 
#>  [37] -0.702 ± 0.230  -0.309 ± 0.149  -0.178 ± 0.110  -0.684 ± 0.132 
#>  [41] -1.131 ± 0.261  -0.937 ± 0.201  -0.413 ± 0.266  -1.175 ± 0.188 
#>  [45] -0.359 ± 0.118  -0.578 ± 0.131  -0.301 ± 0.128  -0.324 ± 0.083 
#>  [49] -0.319 ± 0.081  -1.288 ± 0.331  -0.288 ± 0.094  -0.832 ± 0.146 
#>  [53] -0.402 ± 0.132  -0.371 ± 0.142  -0.381 ± 0.136  -0.320 ± 0.188 
#>  [57] -0.660 ± 0.121  -0.954 ± 0.356  -1.371 ± 0.345  -0.976 ± 0.161 
#>  [61] -0.543 ± 0.100  -0.872 ± 0.317  -0.115 ± 0.071  -0.899 ± 0.250 
#>  [65] -2.024 ± 0.609  -0.509 ± 0.139  -0.276 ± 0.081  -1.059 ± 0.239 
#>  [69] -0.437 ± 0.086  -0.642 ± 0.235  -0.608 ± 0.213  -0.460 ± 0.173 
#>  [73] -1.496 ± 0.368  -0.947 ± 0.199  -1.139 ± 0.392  -0.373 ± 0.140 
#>  [77] -0.876 ± 0.143  -0.490 ± 0.174  -0.767 ± 0.193  -0.537 ± 0.197 
#>  [81] -0.160 ± 0.100  -0.220 ± 0.138  -0.344 ± 0.082  -0.275 ± 0.092 
#>  [85] -0.129 ± 0.074  -1.136 ± 0.323  -0.821 ± 0.130  -0.776 ± 0.248 
#>  [89] -1.289 ± 0.322  -0.258 ± 0.136  -0.383 ± 0.131  -1.501 ± 0.351 
#>  [93] -0.736 ± 0.220  -0.318 ± 0.088  -0.389 ± 0.113  -1.575 ± 0.284 
#>  [97] -0.432 ± 0.101  -1.058 ± 0.374  -0.690 ± 0.144  -0.392 ± 0.098 
#> 
posterior::as_draws_list(fit)
#> # A draws_list: 1000 iterations, 4 chains, and 105 variables
#> 
#> [chain = 1]
#> $lp__
#>  [1] -66 -67 -66 -65 -64 -65 -65 -66 -64 -66
#> 
#> $alpha
#>  [1] 0.792 0.061 0.538 0.446 0.253 0.343 0.387 0.827 0.506 0.713
#> 
#> $`beta[1]`
#>  [1] -0.93 -0.60 -0.67 -0.90 -0.63 -0.71 -0.64 -0.60 -0.73 -0.96
#> 
#> $`beta[2]`
#>  [1] -0.26  0.12 -0.02 -0.31 -0.12 -0.46 -0.44 -0.39 -0.32 -0.22
#> 
#> 
#> [chain = 2]
#> $lp__
#>  [1] -65 -67 -65 -66 -67 -67 -67 -67 -67 -72
#> 
#> $alpha
#>  [1]  0.303  0.538  0.227  0.104  0.678  0.596 -0.041  0.769  0.340  0.948
#> 
#> $`beta[1]`
#>  [1] -0.46 -0.87 -0.51 -0.78 -0.57 -0.50 -0.57 -0.67 -0.60 -0.47
#> 
#> $`beta[2]`
#>  [1]  0.03060 -0.22607 -0.19885 -0.01303 -0.61503 -0.63211  0.00036 -0.41151
#>  [9] -0.46209 -0.88087
#> 
#> # ... with 990 more iterations, and 2 more chains, and 101 more variables
# }