The $summary() method runs summarise_draws() from the posterior package and returns the output. For MCMC, only post-warmup draws are included in the summary.

There is also a $print() method that prints the same summary stats but removes the extra formatting used for printing tibbles and returns the fitted model object itself. The $print() method may also be faster than $summary() because it is designed to only compute the summary statistics for the variables that will actually fit in the printed output whereas $summary() will compute them for all of the specified variables in order to be able to return them to the user. See Examples.

summary(variables = NULL, ...)

Arguments

variables

(character vector) The variables to include.

...

Optional arguments to pass to posterior::summarise_draws().

Value

The $summary() method returns the tibble data frame created by posterior::summarise_draws().

The $print() method returns the fitted model object itself (invisibly), which is the standard behavior for print methods in R.

See also

Examples

# \dontrun{ fit <- cmdstanr_example("logistic") fit$summary()
#> # A tibble: 105 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 lp__ -65.9 -65.6 1.41 1.24 -68.7 -64.3 1.00 2184. #> 2 alpha 0.376 0.378 0.218 0.220 0.00751 0.730 1.00 3633. #> 3 beta[1] -0.663 -0.653 0.246 0.245 -1.09 -0.263 1.00 4022. #> 4 beta[2] -0.269 -0.263 0.228 0.226 -0.649 0.107 1.00 3949. #> 5 beta[3] 0.676 0.673 0.265 0.271 0.244 1.12 1.00 3975. #> 6 log_lik[1] -0.517 -0.511 0.0992 0.0990 -0.692 -0.367 1.00 3507. #> 7 log_lik[2] -0.404 -0.384 0.147 0.140 -0.665 -0.196 1.00 4695. #> 8 log_lik[3] -0.498 -0.466 0.219 0.205 -0.906 -0.205 1.00 3889. #> 9 log_lik[4] -0.453 -0.432 0.156 0.151 -0.746 -0.230 1.00 3814. #> 10 log_lik[5] -1.18 -1.16 0.278 0.281 -1.66 -0.756 1.00 4117. #> # … with 95 more rows, and 1 more variable: ess_tail <dbl>
fit$print()
#> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> lp__ -65.95 -65.64 1.41 1.24 -68.75 -64.27 1.00 2184 3071 #> alpha 0.38 0.38 0.22 0.22 0.01 0.73 1.00 3633 3074 #> beta[1] -0.66 -0.65 0.25 0.25 -1.09 -0.26 1.00 4021 2815 #> beta[2] -0.27 -0.26 0.23 0.23 -0.65 0.11 1.00 3948 3214 #> beta[3] 0.68 0.67 0.27 0.27 0.24 1.12 1.00 3974 3343 #> log_lik[1] -0.52 -0.51 0.10 0.10 -0.69 -0.37 1.00 3506 2773 #> log_lik[2] -0.40 -0.38 0.15 0.14 -0.67 -0.20 1.00 4694 3405 #> log_lik[3] -0.50 -0.47 0.22 0.20 -0.91 -0.21 1.00 3889 3133 #> log_lik[4] -0.45 -0.43 0.16 0.15 -0.75 -0.23 1.00 3814 3282 #> log_lik[5] -1.18 -1.16 0.28 0.28 -1.66 -0.76 1.00 4117 3034 #> #> # showing 10 of 105 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option)
fit$print(max_rows = 2) # same as print(fit, max_rows = 2)
#> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> lp__ -65.95 -65.64 1.41 1.24 -68.75 -64.27 1.00 2184 3071 #> alpha 0.38 0.38 0.22 0.22 0.01 0.73 1.00 3633 3074 #> #> # showing 2 of 105 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option)
# include only certain variables fit$summary("beta")
#> # A tibble: 3 × 10 #> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 beta[1] -0.663 -0.653 0.246 0.245 -1.09 -0.263 1.00 4022. 2815. #> 2 beta[2] -0.269 -0.263 0.228 0.226 -0.649 0.107 1.00 3949. 3215. #> 3 beta[3] 0.676 0.673 0.265 0.271 0.244 1.12 1.00 3975. 3343.
fit$print(c("alpha", "beta[2]"))
#> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> alpha 0.38 0.38 0.22 0.22 0.01 0.73 1.00 3633 3074 #> beta[2] -0.27 -0.26 0.23 0.23 -0.65 0.11 1.00 3948 3214
# include all variables but only certain summaries fit$summary(NULL, c("mean", "sd"))
#> # A tibble: 105 × 3 #> variable mean sd #> <chr> <dbl> <dbl> #> 1 lp__ -65.9 1.41 #> 2 alpha 0.376 0.218 #> 3 beta[1] -0.663 0.246 #> 4 beta[2] -0.269 0.228 #> 5 beta[3] 0.676 0.265 #> 6 log_lik[1] -0.517 0.0992 #> 7 log_lik[2] -0.404 0.147 #> 8 log_lik[3] -0.498 0.219 #> 9 log_lik[4] -0.453 0.156 #> 10 log_lik[5] -1.18 0.278 #> # … with 95 more rows
# can use functions created from formulas # for example, calculate Pr(beta > 0) fit$summary("beta", prob_gt_0 = ~ mean(. > 0))
#> # A tibble: 3 × 2 #> variable prob_gt_0 #> <chr> <dbl> #> 1 beta[1] 0.00175 #> 2 beta[2] 0.116 #> 3 beta[3] 0.997
# }