## This produces multiple acf plots on top of each other for each chain, ## not unlike the winbugs output. ## It assumes a one variable MCMC object. overlayedacfplot <- function(x, ...,main=paste("Autocorrelation for ",substitute(x))) { if (all(is.na(x))) { warn("Missing data, not calculating ",main) } else { for (ichain in 1:nchain(x)) { xacf <- acf(as.ts.mcmc(x[[ichain]]),plot=FALSE) if (ichain == 1) { plot(xacf$lag,xacf$acf,type="h", ylab="Autocorrelation", xlab="Lag", ylim=c(-1,1), main=main, ...) } else { points(xacf$lag,xacf$acf,type="h",col=ichain) } } } } traceAutoplot <- function(x,smooth=TRUE, ...) { if (all(is.na(x))) { warn("Missing data, not traceplots for ",substitute(x)) } else { oldpar <- par(mfrow = c(nvar(x),2)) on.exit(par(oldpar)) for (ivar in 1:nvar(x)) { avar <- x[, ivar, drop = FALSE] traceplot(avar, smooth = smooth, ...) overlayedacfplot(avar,...,main=paste("Autocorrelation for ",varnames(x)[ivar])) } invisible(x) } } ## This is the usual collection of coda plots I like to apply to a model. "grandPlots" <- function(param, ...) { if (!all(is.na(param))) { plot(param, ...) try(gelman.plot(param, transform=TRUE, ...)) try(autocorr.plot(param, ...)) } }