The summarise_draws() (and summarize_draws()) methods provide a quick way to get a table of summary statistics and diagnostics. These methods will convert an object to a draws object if it isn't already. For convenience, a summary() method for draws and rvar objects are also provided as an alias for summarise_draws() if the input object is a draws or rvar object.

summarise_draws(.x, ...)

summarize_draws(.x, ...)

# S3 method for draws
summarise_draws(.x, ..., .args = list(), .cores = 1)

# S3 method for draws
summary(object, ...)

# S3 method for rvar
summarise_draws(.x, ...)

# S3 method for rvar
summary(object, ...)

default_summary_measures()

default_convergence_measures()

default_mcse_measures()

Arguments

.x, object

(draws) A draws object or one coercible to a draws object.

...

Name-value pairs of summary or diagnostic functions. The provided names will be used as the names of the columns in the result unless the function returns a named vector, in which case the latter names are used. The functions can be specified in any format supported by as_function(). See Examples.

.args

(named list) Optional arguments passed to the summary functions.

.cores

(positive integer) The number of cores to use for computing summaries for different variables in parallel. Coerced to integer if possible, otherwise errors. The default is .cores = 1, in which case no parallelization is implemented. By default, a socket cluster is used on Windows and forks otherwise.

Value

The summarise_draws() methods return a tibble data frame. The first column ("variable") contains the variable names and the remaining columns contain summary statistics and diagnostics.

The functions default_summary_measures(), default_convergence_measures(), and default_mcse_measures() return character vectors of names of the default measures.

Details

The default summary functions used are the ones specified by default_summary_measures() and default_convergence_measures():

default_summary_measures()

default_convergence_measures()

The var() function should not be used to compute variances due to its inconsistent behavior with matrices. Instead, please use distributional::variance().

See also

diagnostics for a list of available diagnostics and links to their individual help pages.

Examples

x <- example_draws("eight_schools") class(x)
#> [1] "draws_array" "draws" "array"
str(x)
#> 'draws_array' num [1:100, 1:4, 1:10] 2.01 1.46 5.81 6.85 1.81 ... #> - attr(*, "dimnames")=List of 3 #> ..$ iteration: chr [1:100] "1" "2" "3" "4" ... #> ..$ chain : chr [1:4] "1" "2" "3" "4" #> ..$ variable : chr [1:10] "mu" "tau" "theta[1]" "theta[2]" ...
summarise_draws(x)
#> # A tibble: 10 x 10 #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 mu 4.18 4.16 3.40 3.57 -0.854 9.39 1.02 558. 322. #> 2 tau 4.16 3.07 3.58 2.89 0.309 11.0 1.01 246. 202. #> 3 theta[1] 6.75 5.97 6.30 4.87 -1.23 18.9 1.01 400. 254. #> 4 theta[2] 5.25 5.13 4.63 4.25 -1.97 12.5 1.02 564. 372. #> 5 theta[3] 3.04 3.99 6.80 4.94 -10.3 11.9 1.01 312. 205. #> 6 theta[4] 4.86 4.99 4.92 4.51 -3.57 12.2 1.02 695. 252. #> 7 theta[5] 3.22 3.72 5.08 4.38 -5.93 10.8 1.01 523. 306. #> 8 theta[6] 3.99 4.14 5.16 4.81 -4.32 11.5 1.02 548. 205. #> 9 theta[7] 6.50 5.90 5.26 4.54 -1.19 15.4 1.00 434. 308. #> 10 theta[8] 4.57 4.64 5.25 4.89 -3.79 12.2 1.02 355. 146.
summarise_draws(x, "mean", "median")
#> # A tibble: 10 x 3 #> variable mean median #> <chr> <dbl> <dbl> #> 1 mu 4.18 4.16 #> 2 tau 4.16 3.07 #> 3 theta[1] 6.75 5.97 #> 4 theta[2] 5.25 5.13 #> 5 theta[3] 3.04 3.99 #> 6 theta[4] 4.86 4.99 #> 7 theta[5] 3.22 3.72 #> 8 theta[6] 3.99 4.14 #> 9 theta[7] 6.50 5.90 #> 10 theta[8] 4.57 4.64
summarise_draws(x, mean, mcse = mcse_mean)
#> # A tibble: 10 x 3 #> variable mean mcse #> <chr> <dbl> <dbl> #> 1 mu 4.18 0.150 #> 2 tau 4.16 0.213 #> 3 theta[1] 6.75 0.319 #> 4 theta[2] 5.25 0.202 #> 5 theta[3] 3.04 0.447 #> 6 theta[4] 4.86 0.189 #> 7 theta[5] 3.22 0.232 #> 8 theta[6] 3.99 0.222 #> 9 theta[7] 6.50 0.250 #> 10 theta[8] 4.57 0.273
summarise_draws(x, ~quantile(.x, probs = c(0.4, 0.6)))
#> # A tibble: 10 x 3 #> variable `40%` `60%` #> <chr> <dbl> <dbl> #> 1 mu 3.41 5.35 #> 2 tau 2.47 3.96 #> 3 theta[1] 4.95 7.01 #> 4 theta[2] 4.32 6.13 #> 5 theta[3] 2.54 5.33 #> 6 theta[4] 3.78 6.11 #> 7 theta[5] 2.69 4.69 #> 8 theta[6] 2.92 5.47 #> 9 theta[7] 4.81 7.33 #> 10 theta[8] 3.50 5.92
# using default_*_meaures() summarise_draws(x, default_summary_measures())
#> # A tibble: 10 x 7 #> variable mean median sd mad q5 q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 mu 4.18 4.16 3.40 3.57 -0.854 9.39 #> 2 tau 4.16 3.07 3.58 2.89 0.309 11.0 #> 3 theta[1] 6.75 5.97 6.30 4.87 -1.23 18.9 #> 4 theta[2] 5.25 5.13 4.63 4.25 -1.97 12.5 #> 5 theta[3] 3.04 3.99 6.80 4.94 -10.3 11.9 #> 6 theta[4] 4.86 4.99 4.92 4.51 -3.57 12.2 #> 7 theta[5] 3.22 3.72 5.08 4.38 -5.93 10.8 #> 8 theta[6] 3.99 4.14 5.16 4.81 -4.32 11.5 #> 9 theta[7] 6.50 5.90 5.26 4.54 -1.19 15.4 #> 10 theta[8] 4.57 4.64 5.25 4.89 -3.79 12.2
summarise_draws(x, default_convergence_measures())
#> # A tibble: 10 x 4 #> variable rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> #> 1 mu 1.02 558. 322. #> 2 tau 1.01 246. 202. #> 3 theta[1] 1.01 400. 254. #> 4 theta[2] 1.02 564. 372. #> 5 theta[3] 1.01 312. 205. #> 6 theta[4] 1.02 695. 252. #> 7 theta[5] 1.01 523. 306. #> 8 theta[6] 1.02 548. 205. #> 9 theta[7] 1.00 434. 308. #> 10 theta[8] 1.02 355. 146.
summarise_draws(x, default_mcse_measures())
#> # A tibble: 10 x 6 #> variable mcse_mean mcse_median mcse_sd mcse_q5 mcse_q95 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 mu 0.150 0.319 0.149 0.551 0.415 #> 2 tau 0.213 0.250 0.156 0.114 0.964 #> 3 theta[1] 0.319 0.262 0.233 0.820 1.36 #> 4 theta[2] 0.202 0.213 0.166 0.676 0.848 #> 5 theta[3] 0.447 0.346 0.329 2.18 0.623 #> 6 theta[4] 0.189 0.287 0.154 0.956 0.449 #> 7 theta[5] 0.232 0.139 0.213 1.62 0.736 #> 8 theta[6] 0.222 0.421 0.195 1.16 0.432 #> 9 theta[7] 0.250 0.270 0.178 0.458 0.622 #> 10 theta[8] 0.273 0.372 0.241 0.997 1.29
# compute variance of variables summarise_draws(x, var = distributional::variance)
#> # A tibble: 10 x 17 #> variable var.1 var.2 var.3 var.4 var.5 var.6 var.7 var.8 var.9 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 mu 12.1 0.652 -0.288 -0.153 0.652 17.5 -0.157 -1.46 -0.288 #> 2 tau 11.9 -2.40 -0.0611 -0.799 -2.40 13.1 -1.27 -0.304 -0.0611 #> 3 theta[1] 46.4 0.805 -3.43 0.782 0.805 42.6 -9.72 -1.65 -3.43 #> 4 theta[2] 27.0 -0.132 0.00865 -1.52 -0.132 26.6 -5.31 -2.10 0.00865 #> 5 theta[3] 44.9 -8.23 -3.24 -3.66 -8.23 36.2 -2.01 0.194 -3.24 #> 6 theta[4] 22.8 0.266 -1.42 -1.74 0.266 27.6 -2.15 0.593 -1.42 #> 7 theta[5] 30.9 0.879 0.840 -4.10 0.879 29.8 2.34 -0.505 0.840 #> 8 theta[6] 34.8 0.754 -3.73 -3.03 0.754 24.9 0.0602 0.939 -3.73 #> 9 theta[7] 30.5 2.41 -0.968 -1.16 2.41 34.8 -2.53 -3.50 -0.968 #> 10 theta[8] 25.7 1.01 -3.63 -1.32 1.01 33.1 0.314 -4.44 -3.63 #> # ... with 7 more variables: var.10 <dbl>, var.11 <dbl>, var.12 <dbl>, #> # var.13 <dbl>, var.14 <dbl>, var.15 <dbl>, var.16 <dbl>
# illustrate use of '.args' ws <- rexp(ndraws(x)) summarise_draws(x, weighted.mean, .args = list(w = ws))
#> # A tibble: 10 x 2 #> variable weighted.mean #> <chr> <dbl> #> 1 mu 4.14 #> 2 tau 4.22 #> 3 theta[1] 7.41 #> 4 theta[2] 5.03 #> 5 theta[3] 3.35 #> 6 theta[4] 4.77 #> 7 theta[5] 2.87 #> 8 theta[6] 3.33 #> 9 theta[7] 6.67 #> 10 theta[8] 4.73