Density Plots for MCMC Parameters on a Single Plot

Description

Creates a plot of densities for specified parameters from an MCMC simulation in a single plot or plots densities for those parameters as indicated by the parms and regex.

Usage

1
2
3
4
5
denplot(mcmcout, parms = NULL, regex = NULL, random = NULL,
leaf.marker="[\\[_]", ci = NULL, xlim = NULL,
ylim = NULL, auto.layout = TRUE, mar=c(2.0, 2.0, 1.5, 0.25) + 0.1, col =
NULL, lty = 1, xlab = "", ylab = "", plot.title = NULL, main = NULL,
greek = FALSE, collapse = FALSE, style=c("gray", "plain"), ...)

Arguments

mcmcout

an object that can be coerced to an mcmc or mcmc.list object

parms

a vector of character strings that identifies which variables in mcmcout should be plotted. If parms and regex are both NULL, all parameters will be plotted.

regex

a vector of character strings with regular expressions that identify which variables in mcmcout should be plotted.

random

an integer indicating the maximum number of parameters to randomly select for plotting from each group of parameters as specified by the parms argument.

leaf.marker

a regular expression with a character class that marks the beginning of the “leaf” portion of a parameter name. The default character class includes [ and _

ci

if non NULL, plots (100*ci)% credible interval limits on the density plots. The default (NULL) is not to plot the intervals.

xlim

limits of the x-axis.

ylim

limits of the y-axis.

auto.layout

if TRUE, denplot automatically creates a plot layout using mult.fig from the sfsmisc package.

mar

argument passed to multi.fig if auto.layout=TRUE

col

colors to be used in plotting the densities.

lty

line types to be used in plotting.

xlab

label for the x-axis.

ylab

label for the y-axis.

plot.title

title to put in the outer margin. Default is no title.

main

character vector of titles for each individual plot. If NULL, then the names of the parameters are used.

greek

if TRUE, the names of greek letters in the labels will be displayed as greek characters on the plot.

collapse

if TRUE, all parallel chains are collapsed into one chain before plotting. If FALSE, parallel chains are plotted with colors as specified in col.

style

if "gray", then the plotting region is printed with a gray background, otherwise the default plotting region is used.

...

further arguments to be passed to the plotting function.

Value

Creates a plot.

Author(s)

S. McKay Curtis

See Also

mcmcplot, parms2plot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Create fake MCMC output
nc <- 10; nr <- 1000
pnames <- c(paste("alpha[", 1:5, "]", sep=""), paste("gamma[", 1:5, "]", sep=""))
means <- rpois(10, 20)
fakemcmc <- coda::as.mcmc.list(
    lapply(1:3,
           function(i) coda::mcmc(matrix(rnorm(nc*nr, rep(means,each=nr)),
                                         nrow=nr, dimnames=list(NULL,pnames)))))

## Plot densities of the fake MCMC output
denplot(fakemcmc)
denplot(fakemcmc, style="plain")
denplot(fakemcmc, collapse=TRUE, greek=TRUE, ci=0.95)
denplot(fakemcmc, xlim=range(unlist(fakemcmc)),
        plot.title="Density plots of fake data. Yawn.")
denplot(fakemcmc, "gamma")
denplot(fakemcmc, "gamma", "alpha\\[[12]]$") # all gamma and alpha[1] and alpha[2]

## What happens with NULL varnames?
coda::varnames(fakemcmc) <- NULL
denplot(fakemcmc)

## Not run: 
## denplot works on bugs objects too
library(R2WinBUGS)
example("openbugs", "R2WinBUGS")
## from the help file for openbugs:
schools.sim <- bugs(data, inits, parameters, model.file,
                    n.chains = 3, n.iter = 5000,
                    program = "openbugs", working.directory = NULL)
denplot(schools.sim, "theta")

## End(Not run)