chainsPlot {basicMCMCplots}R Documentation

Compare trace plots from multiple MCMC chains

Description

Overlays trace plots from each MCMC chain, for each parameter

Usage

chainsPlot(
  samplesList,
  var = NULL,
  ind = NULL,
  burnin = NULL,
  scale = FALSE,
  line = NULL,
  ncols = NULL,
  width = 7,
  height = NULL,
  legend = !is.null(names(samplesList)),
  legend.location = "topright",
  cex = 1,
  traceplot = TRUE,
  densityplot = TRUE,
  file = NULL
)

Arguments

samplesList

List of arrays of MCMC samples from different chains

var

Parameter names to plot

ind

Indices of MCMC samples to plot

burnin

Number of initial samples to discard from each MCMC chain (default: 0)

scale

Logical, whether to normalize each posterior chain (default: FALSE)

line

Numeric vector of true parameter values for adding lines to plots

ncols

Number of columns in grid of parameter traceplots or densityplots

width

Width of the plot

height

Height of the plot

legend

Logical, whether to include a legend of chain names

legend.location

Legend location

cex

Expansion coefficient for text (default: 1)

traceplot

Logical, whether to generate posterior trace plots (default: TRUE)

densityplot

Logical, whether to generate posterior density plots (default: TRUE)

file

Filename for saving figure to a file

Examples

samples1 <- cbind(rnorm(1000, 1), rgamma(1000, 1), rpois(1000, 1))
colnames(samples1) <- c('alpha', 'beta', 'gamma')
samples2 <- cbind(rnorm(1000, 2), rgamma(1000, 2), rpois(1000, 2))
colnames(samples2) <- c('alpha', 'beta', 'gamma')
samplesList <- list(chain1 = samples1, chain2 = samples2)

chainsPlot(samplesList)

chainsPlot(samplesList, densityplot = FALSE, burnin = 500)

chainsPlot(samplesList, traceplot = FALSE, legend.location = 'topleft', cex = 0.7)


[Package basicMCMCplots version 0.2.7 Index]