1cumuplot <- function(x, probs=c(0.025,0.5,0.975), ylab="", lty=c(2,1), 2 lwd=c(1,2), type="l", ask, 3 auto.layout=TRUE, col=1, ...) 4{ 5 if (missing(ask)) { 6 ask <- if (is.R()) { 7 dev.interactive() 8 } 9 else { 10 interactive() 11 } 12 } 13 cquantile <- function(z, probs) 14 { 15 ## Calculates cumulative quantile of a vector 16 cquant <- matrix(0, nrow=length(z), length(probs)) 17 for(i in seq(along=z)) # for loop proved faster than apply here 18 if (is.R()) { 19 cquant[i,] <- quantile(z[1:i], probs=probs, names=FALSE) 20 }else{ 21 cquant[i,] <- quantile(z[1:i], probs=probs) 22 } 23 cquant <- as.data.frame(cquant) 24 names(cquant) <- paste(formatC(100*probs,format="fg",width=1,digits=7), 25 "%", sep="") # just like quantile.default 26 return(cquant) 27 } 28 29 oldpar <- NULL 30 on.exit(par(oldpar)) 31 if (auto.layout) { 32 oldpar <- par(mfrow = set.mfrow(Nchains = nchain(x), 33 Nparms = nvar(x))) 34 } 35 36 if (!is.mcmc.list(x)) 37 x <- mcmc.list(as.mcmc(x)) 38 39 Iterations <- as.vector(time(x)) 40 for (i in 1:nchain(x)) { 41 for (j in 1:nvar(x)) { 42 Y <- cquantile(as.matrix(x[[i]])[,j], probs=probs) 43 if (!is.R()) Y <- as.matrix(Y) 44 matplot(Iterations, Y, ylab=ylab, lty=lty, lwd=lwd, type=type, 45 col=col, ...) 46 title(paste(varnames(x)[j], ifelse(is.null(chanames(x)), 47 "", ":"), chanames(x)[i], sep = "")) 48 if (i == 1 & j == 1) 49 oldpar <- c(oldpar, par(ask=ask)) 50 } 51 } 52} 53 54 55