From a shinystan object get rhat, effective sample size, posterior quantiles, means, standard deviations, sampler diagnostics, etc.

retrieve(sso, what, ...)

Arguments

sso

A shinystan object.

what

What do you want to get? See Details, below.

...

Optional arguments, in particular pars to specify parameter names (by default all parameters will be used). For NUTS sampler parameters only (e.g. stepsize, treedepth) inc_warmup can also be specified to include/exclude warmup iterations (the default is FALSE). See Details, below.

Details

The argument what can take on the values below. 'Args: arg' means that arg can be specified in ... for this value of what.

"rhat", "Rhat", "r_hat", or "R_hat"

returns: Rhat statistics. Args: pars

"N_eff", "n_eff", "neff", "Neff", "ess", or "ESS"

returns: Effective sample sizes. Args: pars

"mean"

returns: Posterior means. Args: pars

"sd"

returns: Posterior standard deviations. Args: pars

"se_mean" or "mcse"

returns: Monte Carlo standard error. Args: pars

"median"

returns: Posterior medians. Args: pars.

"quantiles" or any string with "quant" in it (not case sensitive)

returns: 2.5%, 25%, 50%, 75%, 97.5% posterior quantiles. Args: pars.

"avg_accept_stat" or any string with "accept" in it (not case sensitive)

returns: Average value of "accept_stat" (which itself is the average acceptance probability over the NUTS subtree). Args: inc_warmup

"prop_divergent" or any string with "diverg" in it (not case sensitive)

returns: Proportion of divergent iterations for each chain. Args: inc_warmup

"max_treedepth" or any string with "tree" or "depth" in it (not case sensitive)

returns: Maximum treedepth for each chain. Args: inc_warmup

"avg_stepsize" or any string with "step" in it (not case sensitive)

returns: Average stepsize for each chain. Args: inc_warmup

Note

Sampler diagnostics (e.g. "avg_accept_stat") only available for models originally fit using Stan.

Examples

# Using example shinystan object 'eight_schools' sso <- eight_schools retrieve(sso, "rhat")
#> mu theta[1] theta[2] theta[3] theta[4] #> 1.000408 1.000543 1.001548 1.000518 1.000856 #> theta[5] theta[6] theta[7] theta[8] tau #> 1.001214 1.000248 1.003489 1.000177 1.007904 #> log-posterior #> 1.021784
retrieve(sso, "mean", pars = c('theta[1]', 'mu'))
#> theta[1] mu #> 12.463055 8.364435
retrieve(sso, "quantiles")
#> 2.5% 25% 50% 75% 97.5% #> mu -2.353100 5.1145147 8.235383 11.634226 18.832640 #> theta[1] -2.337721 6.8603573 11.307956 17.105685 33.069280 #> theta[2] -5.005552 3.8081126 8.045067 12.246303 21.681474 #> theta[3] -12.142390 1.6861830 6.638008 11.265691 21.997043 #> theta[4] -5.856721 3.9138352 8.075504 11.992252 21.604468 #> theta[5] -9.304029 0.6588147 5.189271 9.009807 16.282473 #> theta[6] -9.278113 1.9676098 6.449365 10.557170 19.452161 #> theta[7] -1.449085 6.8776511 10.931001 15.700186 26.912940 #> theta[8] -7.994186 4.1264315 8.722433 13.589607 27.326509 #> tau 1.411547 4.0011385 6.474779 10.155257 22.018404 #> log-posterior -28.093941 -22.2340468 -19.269627 -15.908783 -8.326459
retrieve(sso, "max_treedepth") # equivalent to retrieve(sso, "depth"), retrieve(sso, "tree"), etc.
#> chain1 chain2 chain3 chain4 #> 5 6 6 5
retrieve(sso, "prop_divergent")
#> chain1 chain2 chain3 chain4 #> 0.019 0.004 0.018 0.024
retrieve(sso, "prop_divergent", inc_warmup = TRUE)
#> chain1 chain2 chain3 chain4 #> 0.0285 0.0245 0.0280 0.0310