plotPost {BEST}R Documentation

Graphic display of a posterior probability distribution


Plot the posterior probability distribution for a single parameter from a vector of samples, typically from an MCMC process, with appropriate summary statistics.


plotPost(paramSampleVec, credMass = 0.95, compVal = NULL, ROPE = NULL,
  HDItextPlace = 0.7, showMode = FALSE, showCurve = FALSE, 
  mainColor="skyblue", comparisonColor="darkgreen", ROPEColor = "darkred",



A vector of samples drawn from the target distribution.


the probability mass to include in credible intervals, or NULL to suppress plotting of credible intervals.


a value for comparison with those plotted.


a two element vector, such as c(-1, 1), specifying the limits of the Region Of Practical Equivalence.


a value in [0,1] that controls the horizontal position of the labels at the ends of the HDI bar.


logical: if TRUE, the mode is displayed instead of the mean.


logical: if TRUE, the posterior density will be represented by a kernel density function instead of a histogram.


an optional color name such as "skyblue" or a RGB specification such as "#87CEEB" that controls the color of the histograms and posterior prediction lines.


an optional color name such as "darkgreen" or a RGB specification such as "#013220" that controls the color used to display compVal.


an optional color name such as "darkred" or a RGB specification such as "#8B0000" that controls the color used to display the ROPE.


graphical parameters and the breaks parameter for the histogram.


The data are plotted either as a histogram (above) or, if showCurve = TRUE, as a fitted kernel density curve (below). Either the mean or the mode of the distribution is displayed, depending on the parameter showMode. The Highest Density Interval (HDI) is shown as a horizontal bar, with labels for the ends of the interval.



If values for a ROPE are supplied, these are shown as vertical dashed lines (dark red by default), together with the percentage of probability mass within the ROPE. If a comparison value (compVal) is supplied, this is shown as a vertical dotted line (green by default), together with the probability mass below and above this value.


Returns an object of class histogram invisibly. Used for its plotting side-effect.


John Kruschke, modified by Mike Meredith

See Also

For details of the HDI calculation, see hdi.


# Generate some data
tst <- rnorm(1e5, 3, 1)
plotPost(tst, credMass=0.8, ROPE=c(-1,1), xlab="Response variable")
plotPost(tst, showMode=TRUE, showCurve=TRUE, compVal=5.5)

# Custom colors
plotPost(tst, mainColor='wheat', border='magenta')
plotPost(tst, credMass=0.8, compVal=0, ROPE=c(-1,1), xlab="Response variable",
  comparisonColor="#880088", ROPEColor = "darkblue")
plotPost(tst, showMode=TRUE, showCurve=TRUE, compVal=5.5,
  mainColor=2, comparisonColor=4)

# For integers:
tst <- rpois(1e5, 12)

# A severely bimodal distribution:
tst2 <- c(rnorm(1e5), rnorm(5e4, 7))
plotPost(tst2)                  # A valid 95% CrI, but not HDI
plotPost(tst2, showCurve=TRUE)  # Correct 95% HDI

[Package BEST version 0.5.4 Index]