Extract the values of sampler diagnostics for each iteration and chain of MCMC.

sampler_diagnostics(inc_warmup = FALSE)

Arguments

inc_warmup

(logical) Should warmup draws be included? Defaults to FALSE.

Value

A 3-D draws_array object (iteration x chain x variable). The variables for Stan's default MCMC algorithm are "accept_stat__", "stepsize__", "treedepth__", "n_leapfrog__", "divergent__", "energy__".

See also

Examples

# \dontrun{ fit <- cmdstanr_example("logistic")
#> Model executable is up to date!
sampler_diagnostics <- fit$sampler_diagnostics() str(sampler_diagnostics)
#> 'draws_array' num [1:1000, 1:4, 1:6] 0.936 0.942 0.996 0.979 0.859 ... #> - attr(*, "dimnames")=List of 3 #> ..$ iteration: chr [1:1000] "1" "2" "3" "4" ... #> ..$ chain : chr [1:4] "1" "2" "3" "4" #> ..$ variable : chr [1:6] "accept_stat__" "stepsize__" "treedepth__" "n_leapfrog__" ...
library(posterior) as_draws_df(sampler_diagnostics)
#> # A draws_df: 1000 iterations, 4 chains, and 6 variables #> accept_stat__ stepsize__ treedepth__ n_leapfrog__ divergent__ energy__ #> 1 0.94 0.68 3 7 0 67 #> 2 0.94 0.68 3 7 0 69 #> 3 1.00 0.68 3 7 0 66 #> 4 0.98 0.68 3 7 0 67 #> 5 0.86 0.68 3 7 0 69 #> 6 0.90 0.68 2 7 0 71 #> 7 0.96 0.68 2 7 0 69 #> 8 1.00 0.68 3 7 0 68 #> 9 0.82 0.68 3 7 0 70 #> 10 1.00 0.68 3 7 0 70 #> # ... with 3990 more draws #> # ... hidden reserved variables {'.chain', '.iteration', '.draw'}
# }