Learn R Programming

R2MLwiN (version 0.1-7)

sixway: Draws a sixway plot of MCMC diagnostics.

Description

This function produces a variety of diagnostic plots and statistics for MCMC chains.

Usage

sixway(chain, name=NULL, acf.maxlag=100, pacf.maxlag=10, ...)

Arguments

chain
A numeric vector, or mcmc object (in which case uses its thin argument, otherwise assumes thinning=1), storing the MCMC chain for a chosen parameter.
name
The parameter name. If name=NULL, the parameter name is "x" by default.
acf.maxlag
Maximum lag at which to calculate the auto-correlation function. acf.maxlag=100 by default.
pacf.maxlag
Maximum lag at which to calculate the partial auto-correlation function. pacf.maxlag=10 by default.
...
Other graphical parameters (see par for details).

Value

  • A variety of plots and statistics are displayed in an R graphic window, including the following:
  • trace plotthe plotted trajectory of an MCMC chain for a model parameter (only the stored chain iterations are plotted);
  • kernel density plotkernel density estimates are computed using density;
  • autocorrelation functionthe function acf is used to compute and plot estimates of the autocorrelation function;
  • partial autocorrelation functionthe function pacf computes and plots estimates of the partial autocorrelation function;
  • Monte Carlo standard errorthe estimated Monte Carlo standard error (MCSE) of the posterior estimate of the mean is plotted against the number of iterations;
  • accuracy diagnosticsthe box contains two contrasting accuracy diagnostics. The Raftery-Lewis diagnostic (raftery.diag) is a diagnostic based on a particular quantile of the distribution. The diagnostic Nhat is used to estimate the length of Markov chain required to estimate a particular quantile (e.g. the 2.5% and 97.5% quantiles) to a given accuracy. The Brooks-Draper diagnostic (BD) is a diagnostic based on the mean of the distribution; it is used to estimate the length of Markov chain required to produce a mean estimate to k(=2) significant figures with a given accuracy;
  • summary statisticsthis box provides summary statistics including the posterior mean, sd, mode, quantiles and the effective sample size (ESS) of the chain.

See Also

density,acf,pacf,raftery.diag,effectiveSize

Examples

Run this code
library(R2MLwiN)
## Modify the following paths as appropriate.
## MLwiN folder
mlwin = "C:/Program Files (x86)/MLwiN v2.27/"
## MLwiN sample worksheet folder
wspath=paste(mlwin,"/samples/",sep="")

## Example: Normal
formula="normexam~(0|cons+standlrt)+(2|cons+standlrt)+(1|cons)"
levID=c('school','student')
estoptions= list(EstM=1,resi.store.levs=2)
wsfile=paste(wspath,"tutorial.ws",sep="")
inputfile=paste(tempdir(),"/tutorial.dta",sep="")
ws2foreign(wsfile, foreignfile=inputfile, MLwiNPath=mlwin)
library(foreign);indata =read.dta(inputfile)
mymodel=runMLwiN(formula, levID, D="Normal", indata, estoptions,MLwiNPath=mlwin)

chain=mymodel["chains"][,"FP_standlrt"]
sixway(chain,"beta_1")

Run the code above in your browser using DataLab