method_plot: Graphic display of marginal posterior probability...

plot.mcmcOutputR Documentation

Graphic display of marginal posterior probability distributions

Description

Plot the posterior probability distribution(s) for the nodes of a mmcmcOutput object. postPlot is equivalent to plot(mcmcOutput(object)).

Note the new argument center with options to display the mean, median or mode; this replaces the showMode argument. The argument CRImass replaces credMass.

Usage

## S3 method for class 'mcmcOutput'
plot(x, params, layout=c(3,3),
    center = c("mean", "median", "mode"), CRImass=0.95,
    compVal = NULL, ROPE = NULL, HDItextPlace = 0.7,
    showCurve = FALSE, shadeHDI = NULL, ...)


postPlot(object, params, layout=c(3,3),
    center = c("mean", "median", "mode"), CRImass=0.95,
    compVal = NULL, ROPE = NULL, HDItextPlace = 0.7,
    showCurve = FALSE, shadeHDI = NULL, ...)

Arguments

x

An object of class mcmcOutput.

object

An object of any class that can be coerced to class mcmcOutput.

params

An optional vector of column numbers or names; names are partially matched, so params="alpha" will match all of alpha, alpha0, alpha[1], alphanew; negative indices indicate parameters to exclude, positive and negative indices cannot be mixed.

layout

a length-2 vector with the maximum number of rows and columns to display in the plotting frame.

center

the statistic to use to represent the central tendency.

CRImass

the probability mass to include in credible intervals; set this to NULL to suppress plotting of credible intervals.

compVal

a single value for comparison with those plotted; the same value will be used for all the plots.

ROPE

a two element vector, such as c(-1, 1), specifying the limits of the Region Of Practical Equivalence; the same value will be used for all the plots.

HDItextPlace

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

showCurve

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

shadeHDI

specifies a colour to shade the area under the curve corresponding to the HDI; NULL for no shading. Ignored if showCurve = FALSE. Use colours() to see a list of possible colours.

...

graphical parameters and the breaks parameter for the histogram.

Details

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

plotPost1.jpg

plotPost2.jpg

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

Value

Returns nothing. Used for its plotting side-effect.

Author(s)

Mike Meredith, based on code by John Kruschke.

See Also

For details of the HDI calculation, see hdi.

Examples

# Use the example data set
data(mcmcListExample)
mco <- mcmcOutput(mcmcListExample)
plot(mco)
plot(mco, "p")   # plots p[1,1], p[2,2] and psi
plot(mco, "p[")  # plots p[1,1] and p[2,2], not psi

# Generate some data
normal <- rnorm(1e5, 2, 1)
postPlot(normal)
postPlot(normal, col='wheat', border='magenta')
postPlot(normal, CRImass=0.8, compVal=0, ROPE=c(-0.2,0.2),
    xlab="Response variable")
postPlot(normal, center="mode", showCurve=TRUE, compVal=5.5)

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

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


mcmcOutput documentation built on Nov. 18, 2022, 1:08 a.m.