Learn R Programming

mcmcplots (version 0.2)

denplot: Density Plots for MCMC Parameters on a Single Plot

Description

This function plots densities for all parameters from an MCMC simulation on a single plot or plots densities for those parameters as indicated by the parms and regex.

Usage

denplot(mcmcout, parms = NULL, regex = NULL, random = NULL, xlim = NULL, ylim = NULL, auto.layout = TRUE, mar=c(2.0, 2.0, 1.5, 0.25)+0.1, col = mcmcplotsPalette(nchains), lty = 1, xlab = "", ylab = "", plot.title=NULL, main = NULL, 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.
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.
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.

Details

None.

References

None.

See Also

mcmcplot

Examples

Run this code
## 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 <- as.mcmc.list(lapply(1:3, function(i) 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)
denplot(fakemcmc, main="Density plots of fake data.  Yawn.")
denplot(fakemcmc, "gamma")
denplot(fakemcmc, "gamma", "alpha\\[[12]]$") # all gamma and alpha[1] and alpha[2]

## 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")

Run the code above in your browser using DataLab