Learn R Programming

mcmcplots (version 0.2)

traplot: Traceplots of Multiple Parameters.

Description

This function produces trace plots from an MCMC simulation on a single plot for all parameters (by default) or those parameters indicated by the parms argument.

Usage

traplot(mcmcout, parms = NULL, regex = NULL, random = NULL, ylim = NULL,
auto.layout = TRUE, mar=c(2.0, 2.0, 1.5, 0.25)+0.1, col =
mcmcplotsPalette(nchains), lty = 1, main = NULL, style = c("gray", "plain"), ...)

Arguments

mcmcout
an object that can be coerced to an mcmc or mcmc.list object
parms
character vector specifying which subsets of parameters to plot. If NULL, mcmcplot will plot all parameters. Regular expressions are used to strip all numbers and punctuation out of the parameter names to find the parameters tha
regex
character vector of regular expressions denoting groups of parameters to plot.
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.
ylim
limits for the y-axis.
auto.layout
automatically creates a plot layout using mult.fig if TRUE.
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.
main
main title for the plots. Default is to use parameter names.
style
if "gray", then the plotting region is printed with a gray background, otherwise the default plotting region is used.
...
further arguments passed to the plotting 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)))))

## Plot traces of the fake MCMC output
traplot(fakemcmc)
traplot(fakemcmc, style="plain")
traplot(fakemcmc, "gamma")

## traplot 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)
traplot(schools.sim, "theta")

Run the code above in your browser using DataLab