chain_diagnosis: Plots for assessing MCMC output.

Description Usage Arguments Value Notes See Also Examples

View source: R/diagnostics.R

Description

chain_diagnosis Generate plots to help assess the convergence of MCMC output.

Generate plots of chain traces (variable values vs. iteration), auto-correlation plots and 1D densities (histograms).

Usage

1
chain_diagnosis(chain, max.chain = 20, chatter = 0)

Arguments

chain

(list) containing output data from an MCMC, including

chatter

(integer) how verbose is the output? (0=quiet, 1=normal, 2=verbose)

max.chains

maximum no. chains to overlay on trace plot

Value

none

Notes

The input chain should be a list such as produced by gw_sampler or mh_sampler that contains the following:

theta

(array) n * ndim array of posterior samples n samples of ndim vectors of parameters

method

(string) name of MCMC method used

nchains

number of chain/walkers used

The plot for parameter i contains three panels.

Top: trace plots showing (in different colours) the trace of each chain or walker for the parameter. The thick black lines shows the trace of the mean of the chains/walkers (averaged at each iteration).

Bottom left: autocorrelations. Black shows the ACF for the mean of the chains/walkers. Blue shows the mean of the ACFs of each chain/walker.

Bottom right: historgram of parameter i over all chains/walkers.

See Also

gw_sampler, mh_sampler

Examples

1
2
3
4
5
6
7
my_posterior <- function(theta) {
  cov <- matrix(c(1,0.98,0.8,0.98,1.0,0.97,0.8,0.97,2.0), nrow = 3)
  logP <- mvtnorm::dmvnorm(theta, mean = c(-1, 2, 0), sigma = cov, log = TRUE)
  return(logP)
}
chain <- gw_sampler(my_posterior, theta.0 = c(0,0,0), nsteps = 10e4, burn.in = 1e4) 
chain_diagnosis(chain)

svdataman/tonic documentation built on Aug. 2, 2019, 3:21 p.m.