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")
#> Model executable is up to date!
fit$summary()
#> # A tibble: 105 x 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.45 1.22 -68.8 -64.3 1.00 2041. #> 2 alpha 0.379 0.381 0.220 0.220 0.0269 0.753 1.00 4096. #> 3 beta[1] -0.659 -0.655 0.250 0.252 -1.08 -0.261 1.00 3764. #> 4 beta[2] -0.273 -0.271 0.225 0.216 -0.646 0.0888 1.00 4440. #> 5 beta[3] 0.681 0.677 0.261 0.259 0.271 1.12 1.00 4279. #> 6 log_lik… -0.517 -0.510 0.0988 0.0989 -0.686 -0.367 1.00 3990. #> 7 log_lik… -0.403 -0.385 0.146 0.135 -0.677 -0.200 1.00 4584. #> 8 log_lik… -0.499 -0.466 0.220 0.204 -0.891 -0.210 1.00 4330. #> 9 log_lik… -0.450 -0.432 0.152 0.150 -0.726 -0.238 1.00 4179. #> 10 log_lik… -1.18 -1.16 0.282 0.284 -1.68 -0.756 1.00 4453. #> # … 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.59 1.45 1.22 -68.80 -64.29 1.00 2040 2693 #> alpha 0.38 0.38 0.22 0.22 0.03 0.75 1.00 4096 2697 #> beta[1] -0.66 -0.65 0.25 0.25 -1.08 -0.26 1.00 3764 2833 #> beta[2] -0.27 -0.27 0.22 0.22 -0.65 0.09 1.00 4440 2925 #> beta[3] 0.68 0.68 0.26 0.26 0.27 1.12 1.00 4279 2926 #> log_lik[1] -0.52 -0.51 0.10 0.10 -0.69 -0.37 1.00 3989 2987 #> log_lik[2] -0.40 -0.39 0.15 0.13 -0.68 -0.20 1.00 4583 2861 #> log_lik[3] -0.50 -0.47 0.22 0.20 -0.89 -0.21 1.00 4329 3207 #> log_lik[4] -0.45 -0.43 0.15 0.15 -0.73 -0.24 1.00 4178 3105 #> log_lik[5] -1.18 -1.16 0.28 0.28 -1.68 -0.76 1.00 4452 3084 #> #> # showing 10 of 105 rows (change via 'max_rows' argument)
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.59 1.45 1.22 -68.80 -64.29 1.00 2040 2693 #> alpha 0.38 0.38 0.22 0.22 0.03 0.75 1.00 4096 2697 #> #> # showing 2 of 105 rows (change via 'max_rows' argument)
# include only certain variables fit$summary("beta")
#> # A tibble: 3 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 beta[1] -0.659 -0.655 0.250 0.252 -1.08 -0.261 1.00 3764. 2834. #> 2 beta[2] -0.273 -0.271 0.225 0.216 -0.646 0.0888 1.00 4440. 2926. #> 3 beta[3] 0.681 0.677 0.261 0.259 0.271 1.12 1.00 4279. 2926.
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.03 0.75 1.00 4096 2697 #> beta[2] -0.27 -0.27 0.22 0.22 -0.65 0.09 1.00 4440 2925
# include all variables but only certain summaries fit$summary(NULL, c("mean", "sd"))
#> # A tibble: 105 x 3 #> variable mean sd #> <chr> <dbl> <dbl> #> 1 lp__ -65.9 1.45 #> 2 alpha 0.379 0.220 #> 3 beta[1] -0.659 0.250 #> 4 beta[2] -0.273 0.225 #> 5 beta[3] 0.681 0.261 #> 6 log_lik[1] -0.517 0.0988 #> 7 log_lik[2] -0.403 0.146 #> 8 log_lik[3] -0.499 0.220 #> 9 log_lik[4] -0.450 0.152 #> 10 log_lik[5] -1.18 0.282 #> # … 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 x 2 #> variable prob_gt_0 #> <chr> <dbl> #> 1 beta[1] 0.003 #> 2 beta[2] 0.112 #> 3 beta[3] 0.995
# }