Diagnostic plots {rstan} | R Documentation |
RStan Diagnostic plots
Description
Diagnostic plots for HMC and NUTS using ggplot2.
Usage
stan_diag(object,
information = c("sample","stepsize", "treedepth","divergence"),
chain = 0, ...)
stan_par(object, par, chain = 0, ...)
stan_rhat(object, pars, ...)
stan_ess(object, pars, ...)
stan_mcse(object, pars, ...)
Arguments
object |
A stanfit or stanreg object. |
information |
The information to be contained in the diagnostic plot. |
par , pars |
The name of a single scalar parameter ( |
chain |
If |
... |
For |
Details
stan_rhat
,stan_ess
,stan_mcse
Respectively, these plots show the distribution of the Rhat statistic, the ratio of effective sample size to total sample size, and the ratio of Monte Carlo standard error to posterior standard deviation for the estimated parameters. These plots are not intended to identify individual parameters, but rather to allow for quickly identifying if the estimated values of these quantities are desireable for all parameters.
stan_par
Calling
stan_par
generates three plots: (i) a scatterplot ofpar
vs. the accumulated log-posterior (lp__
), (ii) a scatterplot ofpar
vs. the average Metropolis acceptance rate (accept_stat
), and (iii) a violin plot showing the distribution ofpar
at each of the sampled step sizes (one per chain). For the scatterplots, red points are superimposed to indicate which (if any) iterations encountered a divergent transition. Yellow points indicate a transition that hit the maximum treedepth rather than terminated its evolution normally.stan_diag
The
information
argument is used to specify which plotsstan_diag
should generate:-
information='sample'
Histograms oflp__
andaccept_stat
, as well as a scatterplot showing their joint distribution. -
information='stepsize'
Violin plots showing the distributions oflp__
andaccept_stat
at each of the sampled step sizes (one per chain). -
information='treedepth'
Histogram oftreedepth
and violin plots showing the distributions oflp__
andaccept_stat
for each value oftreedepth
. -
information='divergence'
Violin plots showing the distributions oflp__
andaccept_stat
for iterations that encountered divergent transitions (divergent=1
) and those that did not (divergent=0
).
-
Value
For stan_diag
and stan_par
, a list containing the ggplot objects for
each of the displayed plots. For stan_rhat
, stan_ess
,
and stan_mcse
, a single ggplot object.
Note
For details about the individual diagnostics and sampler parameters and their interpretations see the Stan Modeling Language User's Guide and Reference Manual at https://mc-stan.org/documentation/.
See Also
List of RStan plotting functions
,
Plot options
Examples
## Not run:
fit <- stan_demo("eight_schools")
stan_diag(fit, info = 'sample') # shows three plots together
samp_info <- stan_diag(fit, info = 'sample') # saves the three plots in a list
samp_info[[3]] # access just the third plot
stan_diag(fit, info = 'sample', chain = 1) # overlay chain 1
stan_par(fit, par = "mu")
## End(Not run)