Learn R Programming

mcmcplots (version 0.2)

denoverplot: Overlaying Densities for Parameters from two MCMC Simulations.

Description

This function determines which parameters are in common from two different MCMC simulations and plots overlaying density estimates of the parameters in common. This function can be used in debugging MCMC code by comparing distributions of parameters from the development MCMC code and a reference MCMC simulation.

Usage

denoverplot(mcmc1, mcmc2, parms = NULL, regex = NULL, random = NULL, auto.layout = TRUE, legend = TRUE, mar = c(2.0, 2.0, 1.5, 0.25)+0.1, col = mcmcplotsPalette(2), lty = 1, plot.title = NULL, main = NULL, style = c("gray", "plain"), ...)

Arguments

mcmc1
object that can be coerced to an mcmc object.
mcmc2
object that can be coerced to an mcmc object.
parms
character vector specifying which subsets of parameters to plot. If NULL and regex=NULL, denoverplot will plot all common parameters mcmc1 and mcmc2. Regular expressions are used to strip a
regex
character vector of regular expressions denoting groups of parameters to plot.
random
integer specifying how many parameters from each group will be randomly selected for plotting. This argument is useful when mcmcout has a large number of parameters (e.g., from a hierarchical model). If NULL, mcmcplot
auto.layout
logical specifying whether the mult.fig function from the sfsmisc package should be used to construct the plotting region.
legend
if TRUE an extra plot in the plotting region is used as a legend.
mar
argument passed to multi.fig if auto.layout=TRUE
col
colors for plotting the densites.
lty
line types for plotting densities. Argument is recylced to be of length 2.
main
character vector of titles to put over each individual plot. If NULL, then the names of the parameters are used.
plot.title
title to put in the outer margin. Default is no title.
style
if "gray", then the plotting region is printed with a gray background, otherwise the default plotting region is used.
...
additional arguments passed to the denoverplot function.

Value

  • Creates a plot.

Details

None.

References

None.

See Also

denplot

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)))))
fakemcmc2 <- as.mcmc.list(lapply(1:3, function(i) mcmc(matrix(rnorm(nc*nr, rep(means, each=nr)), nrow=nr, dimnames=list(NULL,pnames)))))

## Plot the fake MCMC output
denoverplot(fakemcmc, fakemcmc2)
denoverplot(fakemcmc, fakemcmc2, style="plain")
denoverplot(fakemcmc, fakemcmc2, main="Comparison of densities of fake data")

Run the code above in your browser using DataLab