MCMCdiagnostics.Rd
Plots of Rhat statistics, ratios of effective sample size to total sample size, and autocorrelation of MCMC draws. See the Plot Descriptions section, below, for details. For models fit using the NoUTurnSampler, see also MCMCnuts for additional MCMC diagnostic plots.
mcmc_rhat(rhat, ..., size = NULL) mcmc_rhat_hist(rhat, ..., binwidth = NULL, breaks = NULL) mcmc_rhat_data(rhat, ...) mcmc_neff(ratio, ..., size = NULL) mcmc_neff_hist(ratio, ..., binwidth = NULL, breaks = NULL) mcmc_neff_data(ratio, ...) mcmc_acf(x, pars = character(), regex_pars = character(), ..., facet_args = list(), lags = 20, size = NULL) mcmc_acf_bar(x, pars = character(), regex_pars = character(), ..., facet_args = list(), lags = 20)
rhat  A vector of Rhat estimates. 

...  Currently ignored. 
size  An optional value to override 
binwidth  Passed to 
breaks  Passed to 
ratio  A vector of ratios of effective sample size estimates to
total sample size. See 
x  A 3D array, matrix, list of matrices, or data frame of MCMC draws.
The MCMCoverview page provides details on how to specify each these
allowed inputs. It is also possible to use an object with an

pars  An optional character vector of parameter names. If neither

regex_pars  An optional regular expression to use for
parameter selection. Can be specified instead of 
facet_args  A named list of arguments (other than 
lags  The number of lags to show in the autocorrelation plot. 
The plotting functions return a ggplot object that can be further
customized using the ggplot2 package. The functions with suffix
_data()
return the data that would have been drawn by the plotting
function.
mcmc_rhat()
, mcmc_rhat_hist()
Rhat values as either points or a histogram. Values are colored using different shades (lighter is better). The chosen thresholds are somewhat arbitrary, but can be useful guidelines in practice.
light: below 1.05 (good)
mid: between 1.05 and 1.1 (ok)
dark: above 1.1 (too high)
mcmc_neff()
, mcmc_neff_hist()
Ratios of effective sample size to total sample size as either points or a histogram. Values are colored using different shades (lighter is better). The chosen thresholds are somewhat arbitrary, but can be useful guidelines in practice.
light: between 0.5 and 1 (high)
mid: between 0.1 and 0.5 (good)
dark: below 0.1 (low)
mcmc_acf()
, mcmc_acf_bar()
Grid of autocorrelation plots by chain and parameter. The lags
argument
gives the maximum number of lags at which to calculate the autocorrelation
function. mcmc_acf()
is a line plot whereas mcmc_acf_bar()
is a
barplot.
Stan Development Team. Stan Modeling Language Users Guide and Reference Manual. https://mcstan.org/users/documentation/
Gelman, A. and Rubin, D. B. (1992). Inference from iterative simulation using multiple sequences. Statistical Science. 7(4), 457472.
The Visual MCMC Diagnostics vignette.
MCMCnuts for additional MCMC diagnostic plots for models fit using the NoUTurnSampler.
Other MCMC: MCMCcombos
,
MCMCdistributions
,
MCMCintervals
, MCMCnuts
,
MCMCoverview
, MCMCparcoord
,
MCMCrecover
,
MCMCscatterplots
,
MCMCtraces
#> [1] 250 4 4dimnames(x)#> $Iteration #> NULL #> #> $Chain #> [1] "chain:1" "chain:2" "chain:3" "chain:4" #> #> $Parameter #> [1] "alpha" "sigma" "beta[1]" "beta[2]" #>#>mcmc_rhat(rhat)# fake neff ratio values to use for demonstration ratio < c(runif(100, 0, 1)) mcmc_neff_hist(ratio)#>mcmc_neff(ratio)#>#>#>#>#>#>#>#>#># intentionally use small 'iter' so there are some # problems with rhat and neff for demonstration fit < stan_glm(mpg ~ ., data = mtcars, iter = 50, refresh = 0)#> Warning: There were 1 chains where the estimated Bayesian Fraction of Missing Information was low. See #> http://mcstan.org/misc/warnings.html#bfmilow#> Warning: Examine the pairs() plot to diagnose sampling problems#> Warning: The largest Rhat is 2, indicating chains have not mixed. #> Running the chains for more iterations may help. See #> http://mcstan.org/misc/warnings.html#rhat#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable. #> Running the chains for more iterations may help. See #> http://mcstan.org/misc/warnings.html#bulkess#> Warning: Tail Effective Samples Size (ESS) is too low, indicatingposterior variances and tail quantiles may be unreliable. #> Running the chains for more iterations may help. See #> http://mcstan.org/misc/warnings.html#tailess#> Warning: Markov chains did not converge! Do not analyze results!mcmc_neff(ratios, size = 3)# there's a small enough number of parameters in the # model that we can display their names on the yaxis mcmc_neff(ratios) + yaxis_text(hjust = 1)# can also look at autocorrelation draws < as.array(fit) mcmc_acf(draws, pars = c("wt", "cyl"), lags = 10)#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable. #> Running the chains for more iterations may help. See #> http://mcstan.org/misc/warnings.html#bulkess#> Warning: Tail Effective Samples Size (ESS) is too low, indicatingposterior variances and tail quantiles may be unreliable. #> Running the chains for more iterations may help. See #> http://mcstan.org/misc/warnings.html#tailess