From: <li...@us...> - 2009-02-12 12:26:25
|
Revision: 101 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=101&view=rev Author: ligges Date: 2009-02-12 12:26:22 +0000 (Thu, 12 Feb 2009) Log Message: ----------- as.mcmc.list.bugs method implemented (contributed by Mike Meredith) Modified Paths: -------------- trunk/R2WinBUGS/NAMESPACE trunk/R2WinBUGS/R/bugs.sims.R trunk/R2WinBUGS/man/bugs.Rd Added Paths: ----------- trunk/R2WinBUGS/R/as.mcmc.list.bugs.R Modified: trunk/R2WinBUGS/NAMESPACE =================================================================== --- trunk/R2WinBUGS/NAMESPACE 2009-02-12 11:17:21 UTC (rev 100) +++ trunk/R2WinBUGS/NAMESPACE 2009-02-12 12:26:22 UTC (rev 101) @@ -15,4 +15,4 @@ S3method(print, bugs) S3method(plot, bugs) - +S3method(as.mcmc.list, bugs) Added: trunk/R2WinBUGS/R/as.mcmc.list.bugs.R =================================================================== --- trunk/R2WinBUGS/R/as.mcmc.list.bugs.R (rev 0) +++ trunk/R2WinBUGS/R/as.mcmc.list.bugs.R 2009-02-12 12:26:22 UTC (rev 101) @@ -0,0 +1,18 @@ +## Function as.mcmc.list.bugs contributed by Mike Meredith, 12 Feb 2009: +as.mcmc.list.bugs <- function(x, ...) { + if(!inherits(x, "bugs")) + stop("Method as.mcmc.list.bugs() is only intended for bugs objects.") + if(dim(x$sims.array)[2] != x$n.chains) + stop("Inconsistancy in bug object regarding the number of chains.") + mclis <- vector("list", x$n.chains) + strt <- x$n.burnin%/%x$n.thin + 1 + end <- x$n.iter%/%x$n.thin + ord <- order(dimnames(x$sims.array)[[3]]) + if(end - strt + 1 < nrow(x$sims.array[,1,ord])) end <- end + 1 + for(i in 1:x$n.chains) { + tmp1 <- x$sims.array[,i,ord] + rownames(tmp1) <- strt:end + mclis[[i]] <- mcmc(tmp1, strt, end, 1) + } + as.mcmc.list(mclis) +} Modified: trunk/R2WinBUGS/R/bugs.sims.R =================================================================== --- trunk/R2WinBUGS/R/bugs.sims.R 2009-02-12 11:17:21 UTC (rev 100) +++ trunk/R2WinBUGS/R/bugs.sims.R 2009-02-12 12:26:22 UTC (rev 101) @@ -123,7 +123,7 @@ if(DIC) { ## Read DIC from BUGS log LOG <- bugs.log("log.txt")$DIC - if(any(is.na(LOG))) { ## Something went wrong --> Use Gelmans tweak + if(any(is.na(LOG))) { ## Something went wrong --> Use Gelman's tweak deviance <- all$sims.array[, , dim(sims.array)[3], drop = FALSE] if(!is.R()) dimnames(deviance) <- NULL dim(deviance) <- dim(deviance)[1:2] Modified: trunk/R2WinBUGS/man/bugs.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.Rd 2009-02-12 11:17:21 UTC (rev 100) +++ trunk/R2WinBUGS/man/bugs.Rd 2009-02-12 12:26:22 UTC (rev 101) @@ -71,7 +71,10 @@ \item{codaPkg}{logical; if \code{FALSE} (default) a \code{bugs} object is returned, if \code{TRUE} file names of \pkg{WinBUGS} output are returned for easy access by the \pkg{coda} package through function - \code{\link{read.bugs}} (not used if \code{program="OpenBUGS"}).} + \code{\link{read.bugs}} (not used if \code{program="OpenBUGS"}). + A \code{bugs} object can be converted to an \code{mcmc.list} object as + used by the \pkg{coda} package with the method \code{\link[coda]{as.mcmc.list}} + (for which a method is provided by R2WinBUGS).} \item{bugs.directory}{directory that contains the \pkg{WinBUGS} executable. If the global option \code{R2WinBUGS.bugs.directory} is not \code{NULL}, it will be used as the default.} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |