plot_mcmc_path: Plot path of MCMC chains

View source: R/plot_mcmc_path.R

plot_mcmc_pathR Documentation

Plot path of MCMC chains

Description

This will produce a simple plot for visualizing the path of the variable steps (one variable moving at a time) or cycles (the movement of the variables after completing a cycle) for a list of MCMC chains stored as a list. The starting place of the chain *the first row of each chain) is denoted by a point. See Details.

Usage

plot_mcmc_path(
  x,
  ncycles = 10,
  palette = "RdYlBu",
  xlim,
  ylim,
  xlab = "var 1",
  ylab = "var 2",
  type = "step",
  ...
)

Arguments

x

A matrix with 2 columns or a list of 2 column matrices

ncycles

The number of cycles to plot

palette

a valid palette name (one of palette.pals()). The name is matched to the list of available palettes, ignoring upper vs. lower case, spaces, dashes, etc. in the matching.

xlim

x-axis limits

ylim

y-axis limits

xlab

x-axis label

ylab

y-axis label

type

Type of path to plot. "step" moves horizontally and vertically for each variable step within the MCMC cycles. "cycle" plots the variable movement for each completed MCMC cycle.

...

Additional parameters for the [graphics]{plot.default} function.

Details

The function currently only works for chains with two variables stored as a 2-column matrix or data frame. Each column contains the MCMC samples of each variable.

The paths are distinguished by using different line colors. By default, the "RdYlBu" palette from hcl.colors is used. It is unlikely this color scheme will work well for more than 5 chains.

Value

A plot.

Examples

x1 = cbind(rnorm(3), rchisq(3, df = 1))
x2 = cbind(rnorm(3), rchisq(3, df = 1))
x = list(x1, x2)
plot_mcmc_path(x)
# change point type
plot_mcmc_path(x, type = "cycle", pch = 20)

jfrench/bayesutils documentation built on April 10, 2023, 6:28 p.m.