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.46 1.24 -68.9 -64.3 1.00 2044. #> 2 alpha 0.371 0.369 0.221 0.215 0.0108 0.739 1.00 4090. #> 3 beta[1] -0.667 -0.661 0.243 0.243 -1.07 -0.279 1.00 4136. #> 4 beta[2] -0.284 -0.283 0.222 0.219 -0.652 0.0858 1.00 3682. #> 5 beta[3] 0.675 0.671 0.270 0.277 0.243 1.12 1.00 4106. #> 6 log_lik… -0.520 -0.515 0.101 0.0986 -0.697 -0.365 1.00 4126. #> 7 log_lik… -0.405 -0.387 0.150 0.144 -0.680 -0.197 1.00 4192. #> 8 log_lik… -0.509 -0.476 0.219 0.208 -0.918 -0.215 1.00 3766. #> 9 log_lik… -0.445 -0.424 0.153 0.149 -0.726 -0.231 1.00 3764. #> 10 log_lik… -1.17 -1.15 0.279 0.280 -1.66 -0.748 1.00 4560. #> # … 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.94 -65.59 1.46 1.24 -68.88 -64.29 1.00 2044 2715 #> alpha 0.37 0.37 0.22 0.22 0.01 0.74 1.00 4090 3028 #> beta[1] -0.67 -0.66 0.24 0.24 -1.07 -0.28 1.00 4135 2836 #> beta[2] -0.28 -0.28 0.22 0.22 -0.65 0.09 1.00 3682 2922 #> beta[3] 0.68 0.67 0.27 0.28 0.24 1.12 1.00 4106 2984 #> log_lik[1] -0.52 -0.51 0.10 0.10 -0.70 -0.37 1.00 4126 3037 #> log_lik[2] -0.40 -0.39 0.15 0.14 -0.68 -0.20 1.00 4192 2991 #> log_lik[3] -0.51 -0.48 0.22 0.21 -0.92 -0.21 1.00 3766 3168 #> log_lik[4] -0.44 -0.42 0.15 0.15 -0.73 -0.23 1.00 3764 2935 #> log_lik[5] -1.17 -1.15 0.28 0.28 -1.66 -0.75 1.00 4559 3086 #> #> # 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.94 -65.59 1.46 1.24 -68.88 -64.29 1.00 2044 2715 #> alpha 0.37 0.37 0.22 0.22 0.01 0.74 1.00 4090 3028 #> #> # 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 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.667 -0.661 0.243 0.243 -1.07 -0.279 1.00 4136. 2837. #> 2 beta[2] -0.284 -0.283 0.222 0.219 -0.652 0.0858 1.00 3682. 2922. #> 3 beta[3] 0.675 0.671 0.270 0.277 0.243 1.12 1.00 4106. 2985.
fit$print(c("alpha", "beta[2]"))
#> variable mean median sd mad q5 q95 rhat ess_bulk ess_tail #> alpha 0.37 0.37 0.22 0.22 0.01 0.74 1.00 4090 3028 #> beta[2] -0.28 -0.28 0.22 0.22 -0.65 0.09 1.00 3682 2922
# 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.46 #> 2 alpha 0.371 0.221 #> 3 beta[1] -0.667 0.243 #> 4 beta[2] -0.284 0.222 #> 5 beta[3] 0.675 0.270 #> 6 log_lik[1] -0.520 0.101 #> 7 log_lik[2] -0.405 0.150 #> 8 log_lik[3] -0.509 0.219 #> 9 log_lik[4] -0.445 0.153 #> 10 log_lik[5] -1.17 0.279 #> # … 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.00275 #> 2 beta[2] 0.101 #> 3 beta[3] 0.995
# }