Skip to contents

Extract and return the model summary using cmdstanr::summary().

Usage

get_summary(model_output, variables = NULL)

Arguments

model_output

List. Model output generated by run_model().

variables

Character vector. Specific variables (e.g., "strata_raw[1]") or variable types (e.g., "strata_raw") for which to calculate metrics. If NULL (default) all variables are returned.

Value

A data frame of model summary statistics.

See also

Other model assessment functions: get_convergence(), get_model_vars()

Examples

# Temporarily suppress convergence warning for legibility
# "The ESS has been capped to avoid unstable estimates."
opts <- options(warn = -1)

# Using the example model for Pacific Wrens

get_summary(pacific_wren_model)
#> # A tibble: 10,917 × 10
#>    variable         mean   median     sd    mad       q5      q95  rhat ess_bulk
#>    <chr>           <dbl>    <dbl>  <dbl>  <dbl>    <dbl>    <dbl> <dbl>    <dbl>
#>  1 lp__         -1.44e+4 -1.44e+4 36.0   33.6   -1.45e+4 -1.44e+4 1.00      26.9
#>  2 strata_raw[… -9.51e-1 -9.96e-1  0.514  0.625 -1.71e+0 -1.67e-1 1.03      64.1
#>  3 strata_raw[… -2.70e-1 -2.49e-1  0.231  0.162 -6.31e-1  4.68e-2 1.00      64.1
#>  4 strata_raw[… -1.33e-1 -1.86e-1  0.570  0.605 -9.74e-1  7.05e-1 0.966     64.1
#>  5 strata_raw[…  1.53e+0  1.57e+0  0.279  0.266  1.08e+0  2.03e+0 0.981     56.4
#>  6 strata_raw[… -2.25e-1 -1.75e-1  0.260  0.216 -5.83e-1  1.38e-1 1.01      52.3
#>  7 strata_raw[…  1.24e+0  1.27e+0  0.607  0.647  2.96e-1  2.04e+0 1.24      64.1
#>  8 strata_raw[… -9.12e-1 -9.86e-1  0.485  0.448 -1.49e+0 -1.33e-1 1.01      30.7
#>  9 strata_raw[…  1.82e+0  1.82e+0  0.390  0.387  1.27e+0  2.42e+0 1.03      54.7
#> 10 strata_raw[… -9.54e-1 -8.51e-1  0.334  0.301 -1.51e+0 -5.56e-1 0.987     64.1
#> # ℹ 10,907 more rows
#> # ℹ 1 more variable: ess_tail <dbl>
get_summary(pacific_wren_model, variables = "strata_raw")
#> # A tibble: 19 × 10
#>    variable      mean median    sd   mad      q5     q95  rhat ess_bulk ess_tail
#>    <chr>        <dbl>  <dbl> <dbl> <dbl>   <dbl>   <dbl> <dbl>    <dbl>    <dbl>
#>  1 strata_raw… -0.951 -0.996 0.514 0.625 -1.71   -0.167  1.03      64.1     49.6
#>  2 strata_raw… -0.270 -0.249 0.231 0.162 -0.631   0.0468 1.00      64.1     49.6
#>  3 strata_raw… -0.133 -0.186 0.570 0.605 -0.974   0.705  0.966     64.1     43.9
#>  4 strata_raw…  1.53   1.57  0.279 0.266  1.08    2.03   0.981     56.4     28.0
#>  5 strata_raw… -0.225 -0.175 0.260 0.216 -0.583   0.138  1.01      52.3     37.7
#>  6 strata_raw…  1.24   1.27  0.607 0.647  0.296   2.04   1.24      64.1     18.9
#>  7 strata_raw… -0.912 -0.986 0.485 0.448 -1.49   -0.133  1.01      30.7     22.4
#>  8 strata_raw…  1.82   1.82  0.390 0.387  1.27    2.42   1.03      54.7     28.0
#>  9 strata_raw… -0.954 -0.851 0.334 0.301 -1.51   -0.556  0.987     64.1     43.9
#> 10 strata_raw… -0.414 -0.423 0.388 0.333 -1.15    0.204  1.10      64.1     56.9
#> 11 strata_raw… -0.241 -0.200 0.253 0.220 -0.786   0.0617 0.966     62.5     22.4
#> 12 strata_raw…  0.358  0.336 0.242 0.207  0.0146  0.680  1.02      64.1     21.4
#> 13 strata_raw… -0.673 -0.605 0.329 0.255 -1.10   -0.196  0.983     64.1     30.7
#> 14 strata_raw… -0.966 -0.932 0.336 0.323 -1.48   -0.486  1.04      64.1     23.5
#> 15 strata_raw…  0.639  0.672 0.240 0.302  0.289   0.967  1.07      64.1     49.6
#> 16 strata_raw… -0.822 -0.808 0.456 0.385 -1.45   -0.210  1.06      64.1     37.7
#> 17 strata_raw… -0.689 -0.614 0.395 0.274 -1.27   -0.224  0.999     64.1     49.6
#> 18 strata_raw…  1.19   1.19  0.358 0.203  0.752   1.71   0.999     51.9     28.0
#> 19 strata_raw…  0.478  0.489 0.330 0.317 -0.0779  1.01   1.07      64.1     49.6
get_summary(pacific_wren_model, variables = "strata_raw[9]")
#> # A tibble: 1 × 10
#>   variable        mean median    sd   mad    q5    q95  rhat ess_bulk ess_tail
#>   <chr>          <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl>    <dbl>    <dbl>
#> 1 strata_raw[9] -0.954 -0.851 0.334 0.301 -1.51 -0.556 0.987     64.1     43.9

# Restore warnings
options(opts)