From: <snt...@us...> - 2010-08-06 14:07:47
|
Revision: 161 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=161&view=rev Author: snthomas99 Date: 2010-08-06 14:07:38 +0000 (Fri, 06 Aug 2010) Log Message: ----------- updates to documentation and some bug fixes Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/NAMESPACE trunk/R2OpenBUGS/R/bugs.R trunk/R2OpenBUGS/R/bugs.script.R trunk/R2OpenBUGS/man/R2WinBUGS-package.Rd trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/bugs.run.Rd trunk/R2OpenBUGS/man/bugs.script.Rd Removed Paths: ------------- trunk/R2OpenBUGS/R/openbugs.R trunk/R2OpenBUGS/man/openbugs.Rd Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/DESCRIPTION 2010-08-06 14:07:38 UTC (rev 161) @@ -1,21 +1,19 @@ -Package: R2WinBUGS -Title: Running WinBUGS and OpenBUGS from R / S-PLUS -Date: 2010-03-18 -Version: 2.1-17 -Author: originally written by Andrew Gelman <ge...@st...>; +Package: R2OpenBUGS +Title: Running OpenBUGS from R / S-PLUS +Date: 2010-08-5 +Version: 1.0-0 +Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. With considerable contributions by Gregor Gorjanc <gre...@bf...> and Jouni Kerman <ke...@st...>. - Ported to S-PLUS by Insightful Corp. + Ported to S-PLUS by Insightful Corp. Adapted to R2OpenBUGS from R2WinBUGS by Neal Thomas. Description: Using this package, it is possible to call a BUGS model, summarize inferences and convergence in a table and graph, and save the simulations in arrays for easy access - in R / S-PLUS. In S-PLUS, the openbugs functionality and the windows emulation - functionality is not yet available. -Depends: R (>= 2.5.0), coda (>= 0.11-0) -Suggests: BRugs (>= 0.3-2) -SystemRequirements: WinBUGS 1.4 + in R / S-PLUS. +Depends: R (>= 2.9.2), coda (>= 0.11-0) +SystemRequirements: OpenBUGS >=3.1 URL: http://www.stat.columbia.edu/~gelman/bugsR/ Maintainer: Uwe Ligges <li...@st...> License: GPL-2 Modified: trunk/R2OpenBUGS/NAMESPACE =================================================================== --- trunk/R2OpenBUGS/NAMESPACE 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/NAMESPACE 2010-08-06 14:07:38 UTC (rev 161) @@ -9,7 +9,6 @@ read.bugs, bugs.log, monitor, - openbugs, as.bugs.array, write.model) Modified: trunk/R2OpenBUGS/R/bugs.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.R 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/R/bugs.R 2010-08-06 14:07:38 UTC (rev 161) @@ -17,15 +17,16 @@ if(.Platform$OS.type != "windows" & useWINE==FALSE){ if(debug)stop("The debug option is not available with linux/unix") if(save.history)("History plots (save.history) is not available with linux/unix") - }else{ - if(!file.exists(OpenBUGS.pgm)) - stop("OpenBUGS executable was not found" ) } if (missing(OpenBUGS.pgm) && !is.null(bugs.pgm <- getOption("R2OpenBUGS.pgm"))) { # requested by Jouni Kerman OpenBUGS.pgm<- bugs.pgm } + + if((.Platform$OS.type == "windows" | useWINE) & !file.exists(OpenBUGS.pgm)) + stop("OpenBUGS executable was not found" ) + ## Is OpenBUGS.pgm defined in Windows (where second character is : ## i.e. C:\Program...) or Unix style path? if(useWINE && (substr(OpenBUGS.pgm, 2, 2) == ":")) { Modified: trunk/R2OpenBUGS/R/bugs.script.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.script.R 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/R/bugs.script.R 2010-08-06 14:07:38 UTC (rev 161) @@ -36,7 +36,7 @@ function(x, useWINE, newWINE, WINEPATH) {native2win(x, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH)}) - initlist <- paste("modelInits(", 1:n.chains, ", '", inits, "')\n", sep="") + initlist <- paste("modelInits(", "'", inits, "',",1:n.chains,")\n", sep="") savelist <- paste("samplesSet(", parameters.to.save, ")\n", sep="") summarylist <- paste("summarySet(", parameters.to.save, ")\n", sep="") Deleted: trunk/R2OpenBUGS/R/openbugs.R =================================================================== --- trunk/R2OpenBUGS/R/openbugs.R 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/R/openbugs.R 2010-08-06 14:07:38 UTC (rev 161) @@ -1,114 +0,0 @@ -openbugs <- function(data, inits, parameters.to.save, model.file="model.txt", - n.chains = 3, n.iter = 2000, n.burnin = floor(n.iter/2), - n.thin = max(1, floor(n.chains *(n.iter - n.burnin) / n.sims)), n.sims = 1000, - DIC = TRUE, bugs.directory = "c:/Program Files/OpenBUGS/", - working.directory=NULL, digits = 5, over.relax = FALSE, seed=NULL) -{ - if(!is.R()) - stop("OpenBUGS is not yet available in S-PLUS") - if(!require("BRugs")) - stop("BRugs is required") - - ## switching from bugs() to BRugsFit() notation - modelFile <- model.file - numChains <- n.chains - nBurnin <- n.burnin - nIter <- n.iter - n.burnin - nThin <- n.thin - if(DIC) parameters.to.save <- c(parameters.to.save, "deviance") - parametersToSave <- parameters.to.save - - ## Move to working drirectory or temporary directory when NULL - if(is.null(working.directory)) { - working.directory <- tempdir() - inTempDir <- TRUE - } - savedWD <- getwd() - setwd(working.directory) - on.exit(setwd(savedWD)) - - if(inTempDir && basename(model.file) == model.file) - try(file.copy(file.path(savedWD, model.file), model.file, overwrite = TRUE)) - if(!file.exists(modelFile)) { - stop(modelFile, " does not exist") - } - if(file.info(modelFile)$isdir) { - stop(modelFile, " is a directory, but a file is required") - } - ## kludge to add carriage-returns (line-feeds?) to the model file - if(!length(grep("\r\n", readChar(modelFile, 10^3)))) { - message("Carriage returns added to model file ", modelFile) - model <- readLines(modelFile) - try(writeLines(model, modelFile)) - } - BRugs::modelCheck(modelFile) - if(!(is.vector(data) && is.character(data) && all(file.exists(data)))) { - data <- BRugs::bugsData(data, digits = digits) - } - if(inTempDir && all(basename(data) == data)) - try(file.copy(file.path(savedWD, data), data, overwrite = TRUE)) - BRugs::modelData(data) - BRugs::modelCompile(numChains) - if(!is.null(seed)) BRugs::modelSetRN(seed) - if(missing(inits) || is.null(inits)) { - BRugs::modelGenInits() - } else { - if(is.list(inits) || is.function(inits) || (is.character(inits) && - !any(file.exists(inits)))) { - inits <- BRugs::bugsInits(inits = inits, numChains = numChains, - digits = digits) - } - if(inTempDir && all(basename(inits) == inits)) - try(file.copy(file.path(savedWD, inits), inits, overwrite = TRUE)) - BRugs::modelInits(inits) - BRugs::modelGenInits() - } - BRugs::samplesSetThin(nThin) - ## set the adaptive phases - -## We do no longer have any Registry.txt file availabe, -## hence not resetting the adaptive phase any more. -## People should move to BRugs directly. -# adaptivelines <- scan(system.file("OpenBUGS", "Bugs", "Rsrc", -# "Registry.txt", package="BRugs"), -# what="character", quiet = TRUE) -# factories <- sub(".adaptivePhase", "", -# adaptivelines[grep("adaptivePhase",adaptivelines)]) -# sapply(factories, BRugs::modelSetAP, max(0, nBurnin-1)) - if(getOption("BRugsVerbose")){ - cat("Sampling has been started ...\n") - flush.console() - } - BRugs::modelUpdate(nBurnin, overRelax = over.relax) - ## BRugs::samplesSetThin(nThin) - if(DIC) { - BRugs::dicSet() - on.exit(BRugs::dicClear(), add = TRUE) - } - BRugs::samplesSet(parametersToSave) - BRugs::modelUpdate(nIter, overRelax = over.relax) - params <- sort.name(BRugs::samplesMonitors("*"), parametersToSave) - samples <- sapply(params, BRugs::samplesSample) - n.saved.per.chain <- nrow(samples)/numChains - samples.array <- array(samples, c(n.saved.per.chain, numChains, ncol(samples))) - dimnames(samples.array)[[3]] <- dimnames(samples)[[2]] - if(DIC) { - DICOutput <- BRugs::dicStats() - } else { - DICOutput <- NULL - } - bugs.output <- as.bugs.array(sims.array=samples.array, - model.file=modelFile, program="OpenBUGS", - DIC=DIC, DICOutput=DICOutput, - n.iter=n.iter, n.burnin=n.burnin, n.thin=n.thin) - bugs.output -} - -## sorter called by openbugs() to save the parameters in the specified order -sort.name <- function(a, b){ - ## sort the scalar parameter names in the vector "a" according to the - ## ordering of their stems in the shorter vector "b" - bracket.pos <- regexpr("\\[", a) - a.stem <- substr(a, 1, ifelse(bracket.pos>0, bracket.pos-1, nchar(a))) - a[order(match(a.stem, b))] -} Modified: trunk/R2OpenBUGS/man/R2WinBUGS-package.Rd =================================================================== --- trunk/R2OpenBUGS/man/R2WinBUGS-package.Rd 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/man/R2WinBUGS-package.Rd 2010-08-06 14:07:38 UTC (rev 161) @@ -1,37 +1,35 @@ -\name{R2WinBUGS-package} -\alias{R2WinBUGS-package} -\alias{R2WinBUGS} +\name{R2OpenBUGS-package} +\alias{R2OpenBUGS-package} +\alias{R2OpenBUGS} \docType{package} -\title{Running WinBUGS and OpenBUGS from R / S-PLUS} +\title{Running OpenBUGS from R / S-PLUS} \description{ -\pkg{R2WinBUGS} package provides possiblity to call a \pkg{BUGS} model, +\pkg{R2OpenBUGS} Call a \pkg{BUGS} model, summarize inferences and convergence in a table and graph, and save the -simulations in arrays for easy access in \R / S-PLUS. In S-PLUS, the -\pkg{OpenBUGS} functionality and the windows emulation functionality is -not yet available. The main command is \code{\link{bugs}}. +simulations in arrays for easy access in \R / S-PLUS. The main command is \code{\link{bugs}}. } \details{ -The following are sources of information on \pkg{R2WinBUGS} package: +The following are sources of information on \pkg{R2OpenBUGS} package: \tabular{ll}{ - DESCRIPTION file\tab \code{library(help="R2WinBUGS")}\cr + DESCRIPTION file\tab \code{library(help="R2OpenBUGS")}\cr \tab \cr - This file\tab \code{package?R2WinBUGS}\cr + This file\tab \code{package?R2OpenBUGS}\cr \tab \cr - Vignette\tab \code{vignette("R2WinBUGS")}\cr + Vignette\tab \code{vignette("R2OpenBUGS")}\cr \tab \cr Some help files\tab \code{\link{bugs}}\cr \tab \code{\link{write.model}}\cr \tab \code{\link{print.bugs}}\cr \tab \code{\link{plot.bugs}}\cr \tab \cr - News\tab \code{file.show(system.file("NEWS", package="R2WinBUGS"))}\cr + News\tab \code{file.show(system.file("NEWS", package="R2OpenBUGS"))}\cr } } Modified: trunk/R2OpenBUGS/man/bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.Rd 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/man/bugs.Rd 2010-08-06 14:07:38 UTC (rev 161) @@ -3,21 +3,22 @@ \title{Run WinBUGS and OpenBUGS from R or S-PLUS} \description{The \code{bugs} function takes data and starting values as - input. It automatically writes a \pkg{WinBUGS} script, calls the model, and + input. It automatically writes a \pkg{OpenBUGS} script, calls the model, and saves the simulations for easy access in \R or S-PLUS.} \usage{ -bugs(data, inits, parameters.to.save, model.file="model.bug", - n.chains=3, n.iter=2000, n.burnin=floor(n.iter/2), - n.thin=max(1, floor(n.chains * (n.iter - n.burnin) / n.sims)), - n.sims = 1000, bin=(n.iter - n.burnin) / n.thin, +bugs(data, inits, parameters.to.save, n.iter, model.file="model.bug", + n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, - bugs.directory="c:/Program Files/WinBUGS14/", - program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), - working.directory=NULL, clearWD=FALSE, - useWINE=.Platform$OS.type != "windows", WINE=NULL, - newWINE=TRUE, WINEPATH=NULL, bugs.seed=NULL, summary.only=FALSE, - save.history=!summary.only, over.relax = FALSE) + OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, + paste("C:/Program Files/OpenBUGS/OpenBUGS", + version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), + version='311', + working.directory=NULL, + clearWD=FALSE, useWINE=FALSE, WINE=NULL, + newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, + save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), + over.relax = FALSE) } \arguments{ @@ -38,7 +39,7 @@ parameters to save which should be monitored} \item{model.file}{file containing the model written in \pkg{WinBUGS} code. The extension can be either \file{.bug} or \file{.txt}. - If the extension is \file{.bug} and \code{program=="WinBUGS"}, + If the extension is \file{.bug} and \code{program=="OpenBUGS"}, a copy of the file with extension \file{.txt} will be created in the \code{bugs()} call and removed afterwards. Note that similarly named \file{.txt} files will be overwritten. @@ -50,41 +51,37 @@ \item{n.burnin}{length of burn in, i.e. number of iterations to discard at the beginning. Default is \code{n.iter/2}, that is, discarding the first half of the simulations.} - \item{n.thin}{thinning rate. Must be a positive integer. Set - \code{n.thin} > 1 to save memory and computation time if - \code{n.iter} is large. Default is \code{max(1, floor(n.chains * - (n.iter-n.burnin) / 1000))} which will only thin if there are at - least 2000 simulations.} - \item{n.sims}{The approximate number of simulations to keep after thinning.} - \item{bin}{number of iterations between saving of results - (i.e. the coda files are saved after each \code{bin} iterations); - default is to save only at the end.} - \item{debug}{if \code{FALSE} (default), \pkg{WinBUGS} is closed automatically - when the script has finished running, otherwise \pkg{WinBUGS} remains open - for further investigation} + \item{n.thin}{Thinning rate. Must be a positive integer. The default is + \code{n.thin} = 1. The thinning is implemented in the OpenBUGS update phase, so + thinned samples are never stored, and they are not counted in \ocde{n.burnin} or + \oode{n.iter}. Setting \ocde{n.thin}=2, doubles the number of iterations OpenBUGS + performs, but does not change \ocde{n.iter} or \ocde{n.burnin}. Thinning implemented + in this manner is not captured in summaries created by packages such as \pkg{coda}.} + \item{debug}{if \code{FALSE} (default), \pkg{OpenBUGS} is closed automatically + when the script has finished running, otherwise \pkg{OpenBUGS} remains open + for further investigation. The debug option is not available for linux execution.} \item{DIC}{logical; if \code{TRUE} (default), compute deviance, pD, - and DIC. This is done in \pkg{WinBUGS} directly using the rule \code{pD = + and DIC. This is done in \pkg{OpenBUGS} directly using the rule \code{pD = Dbar - Dhat}. If there are less iterations than required for the adaptive phase, the rule \code{pD=var(deviance) / 2} is used.} - \item{digits}{number of significant digits used for \pkg{WinBUGS} input, see + \item{digits}{number of significant digits used for \pkg{OpenBUGS} input, see \code{\link{formatC}}} \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}}. 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}, + (for which a method is provided by R2OpenBUGS).} + \item{OpenBUGS.pgm}{ For Windows or WINE execution, the full path to the OpenBUGS + executable. For linux execution, the full path to the OpenBUGS shell script (not + required if OpenBUGS is in the user's PATH variable). + If the global option \code{R2OpenBUGS.bugs.directory} is not \code{NULL}, it will be used as the default.} - \item{program}{the program to use, either - \code{winbugs}/\code{WinBUGS} or \code{openbugs}/\code{OpenBUGS}, - the latter makes use of function \code{\link{openbugs}} and requires - the CRAN package \pkg{BRugs}. The \code{openbugs}/\code{OpenBUGS} - choice is not available in S-PLUS.} + \item{version}{The version of OpenBUGS to use. \ocde{version} is ignored + with linux execution or if \code{OpenBUGS.pgm} is specified.} \item{working.directory}{sets working directory during execution of - this function; \pkg{WinBUGS}' in- and output will be stored in this + this function; \pkg{OpenBUGS}' in- and output will be stored in this directory; if \code{NULL}, a temporary working directory via \code{\link{tempdir}} is used.} \item{clearWD}{logical; indicating whether the files \file{data.txt}, @@ -92,23 +89,21 @@ and \file{coda[1:nchains].txt} should be removed after \pkg{WinBUGS} has finished. If set to \code{TRUE}, this argument is only respected if \code{codaPkg=FALSE}.} - \item{useWINE}{logical; attempt to use the Wine emulator to run - \pkg{WinBUGS}, defaults to \code{FALSE} on Windows, and \code{TRUE} - otherwise. Not available in S-PLUS.} - \item{WINE}{character, path to \file{wine} binary file, it is + \pkg{OpenBUGS}. Default is \code{FALSE}.} + \item{WINE}{Character, path to \file{wine} binary file, it is tried hard (by a guess and the utilities \code{which} and \code{locate}) to get the information automatically if not given.} \item{newWINE}{Use new versions of Wine that have \file{winepath} utility} - \item{WINEPATH}{character, path to \file{winepath} binary file, it is + \item{WINEPATH}{Character, path to \file{winepath} binary file, it is tried hard (by a guess and the utilities \code{which} and \code{locate}) to get the information automatically if not given.} - \item{bugs.seed}{random seed for \pkg{WinBUGS} (default is no seed)} + \item{bugs.seed}{Random seed for \pkg{OpenBUGS}}. \item{summary.only}{If \code{TRUE}, only a parameter summary for very quick analyses is given, temporary created files are not removed in that case.} \item{save.history}{If \code{TRUE} (the default), trace plots are generated at the end.} - \item{over.relax}{If \code{TRUE}, over-relaxed form of MCMC is used if available from WinBUGS.} + \item{over.relax}{If \code{TRUE}, over-relaxed form of MCMC is used if available from OpenBUGS.} } \details{ @@ -119,36 +114,34 @@ \item Go into \R / S-PLUS. \item Prepare the inputs for the \code{bugs} function and run it (see Example section). - \item A \pkg{WinBUGS} window will pop up and \R / S-PLUS will freeze - up. The model will now run in \pkg{WinBUGS}. It might take awhile. You - will see things happening in the Log window within \pkg{WinBUGS}. When - \pkg{WinBUGS} is done, its window will close and \R / S-PLUS will work + \item An \pkg{OpenBUGS} window will pop up and \R / S-PLUS will freeze + up. The model will now run in \pkg{OpenBUGS}. It might take awhile. You + will see things happening in the Log window within \pkg{OpenBUGS}. When + \pkg{OpenBUGS} is done, its window will close and \R / S-PLUS will work again. \item If an error message appears, re-run with \code{debug=TRUE}. } BUGS version support: \itemize{ - \item{\pkg{WinBUGS} 1.4.*}{default} - \item{\pkg{OpenBUGS} 2.*}{via argument \code{program="OpenBUGS"}} + \item{\pkg{OpenBUGS} >3.1}{} } Operation system support: \itemize{ \item{\pkg{MS Windows}}{no problem} - \item{\pkg{Linux}, \pkg{Mac OS X} and \pkg{Unix} in - general}{possible with Wine emulation via \code{useWINE=TRUE}, but - only for \pkg{WinBUGS} 1.4.*} + \item{\pkg{Linux, intel processors}}{GUI display and graphics not available.} + \item{\pkg{Mac OS X} and \pkg{Unix} in + general}{possible with Wine emulation via \code{useWINE=TRUE}} } If \code{useWINE=TRUE} is used, all paths (such as \code{working.directory} and \code{model.file}, must be given in native (Unix) style, but \code{bugs.directory} can be given in - Windows path style (e.g. \dQuote{c:/Program Files/WinBUGS14/}) or + Windows path style (e.g. \dQuote{c:/Program Files/OpenBUGS/}) or native (Unix) style (e.g. \dQuote{/path/to/wine/folder/dosdevices/c:/Program - Files/WinBUGS14}). This is done to achieve greatest portability with - default argument value for \code{bugs.directory}. + Files/OpenBUGS}). }. } @@ -193,7 +186,7 @@ \item{indexes.short}{indexes of \code{root.short}} \item{last.values}{list of simulations from the most recent iteration; they can be used as starting points if you wish to run - \pkg{WinBUGS} for further iterations} + \pkg{OpenBUGS} for further iterations} \item{pD}{an estimate of the effective number of parameters, for calculations see the section \dQuote{Arguments}.} \item{DIC}{\code{mean(deviance) + pD}} @@ -211,14 +204,14 @@ \author{Andrew Gelman, \email{ge...@st...}, \url{http:/www.stat.columbia.edu/~gelman/bugsR/}; modifications and packaged by Sibylle Sturtz, \email{st...@st...}, - and Uwe Ligges.} + Uwe Ligges. and Neal Thomas} \seealso{\code{\link{print.bugs}}, \code{\link{plot.bugs}}, as well as \pkg{coda} and \pkg{BRugs} packages} \examples{ # An example model file is given in: -model.file <- system.file(package="R2WinBUGS", "model", "schools.txt") +model.file <- system.file(package="R2OpenBUGS", "model", "schools.txt") # Let's take a look: file.show(model.file) @@ -249,8 +242,7 @@ ## You may need to edit "bugs.directory", ## also you need write access in the working directory: schools.sim <- bugs(data, inits, parameters, model.file, - n.chains=3, n.iter=5000, - bugs.directory="c:/Program Files/WinBUGS14/") + n.chains=3, n.iter=5000) print(schools.sim) plot(schools.sim) } Modified: trunk/R2OpenBUGS/man/bugs.run.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.run.Rd 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/man/bugs.run.Rd 2010-08-06 14:07:38 UTC (rev 161) @@ -1,20 +1,19 @@ \name{bugs.run} \alias{bugs.run} -\title{Calling WinBUGS} +\title{Calling OpenBUGS} -\description{Updates the lengths of the adaptive phases in the - \pkg{WinBUGS} registry (using \code{\link{bugs.update.settings}}), - calls \pkg{WinBUGS} and runs it with \file{script.txt} - intended for +\description{ + Calls \pkg{OpenBUGS} and runs it with \file{script.txt} - intended for internal use} \usage{ -bugs.run(n.burnin, bugs.directory, - useWINE=.Platform$OS.type != "windows", WINE=NULL, +bugs.run(n.burnin, OpenBUGS.pgm, + useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL) } \arguments{ \item{n.burnin}{length of burn in} - \item{bugs.directory}{directory that contains the \pkg{WinBUGS} executable} + \item{OpenBUGS.pgm}{Full path to the \pkg{OpenBUGS} executable or shell script} \item{useWINE}{as in \code{\link{bugs}} meta function} \item{WINE}{as in \code{\link{bugs}} meta function} \item{newWINE}{as in \code{\link{bugs}} meta function} @@ -22,7 +21,7 @@ } \value{Nothing, but has side effects as documented in - \code{\link{bugs.update.settings}} and calls \pkg{WinBUGS}.} + \code{\link{bugs.update.settings}} and calls \pkg{OpenBUGS}.} \seealso{The main function to be called by the user is \code{\link{bugs}}.} \keyword{internal} Modified: trunk/R2OpenBUGS/man/bugs.script.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.script.Rd 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/man/bugs.script.Rd 2010-08-06 14:07:38 UTC (rev 161) @@ -1,42 +1,46 @@ \name{bugs.script} \alias{bugs.script} -\title{Writes script for running WinBUGS} +\title{Writes script for running OpenBUGS} -\description{Write file \file{script.txt} for \pkg{WinBUGS} to read - +\description{Write file \file{script.txt} for \pkg{OpenBUGS} to read - intended for internal use} \usage{ -bugs.script(parameters.to.save, n.chains, n.iter, n.burnin, n.thin, - model.file, debug=FALSE, is.inits, bin, DIC=FALSE, - useWINE=.Platform$OS.type != "windows", newWINE=TRUE, WINEPATH=NULL, - bugs.seed=NULL, summary.only=FALSE, save.history=TRUE, - bugs.data.file, bugs.inits.files, over.relax = FALSE) +bugs.script(parameters.to.save, n.chains, n.iter, n.burnin, + n.thin, model.file, debug=FALSE, is.inits, + DIC=FALSE, useWINE=FALSE, + newWINE=TRUE, WINEPATH=NULL, bugs.seed=NULL, summary.only=FALSE, + save.history=(.Platform$OS.type = "windows" | useWINE=TRUE), + bugs.data.file, bugs.inits.files, + over.relax = FALSE) } \arguments{ \item{parameters.to.save}{parameters that should be monitored} \item{n.chains}{number of Markov chains} \item{n.iter}{number of total iterations (including burn in)} \item{n.burnin}{length of burn in} - \item{n.thin}{size of thinning parameter} - \item{model.file}{file containing the model written in \pkg{WinBUGS} code} - \item{debug}{if \code{FALSE}, \pkg{WinBUGS} is closed automatically, - otherwise \pkg{WinBUGS} remains open for further investigation} + \item{n.thin}{thinning parameter} + \item{model.file}{file containing the model written in \pkg{OpenBUGS} code} + \item{debug}{if \code{FALSE}, \pkg{OpenBUGS} is closed automatically, + otherwise \pkg{OpenBUGS} remains open for further investigation. With + \code{debug} = \code{TRUE}, no modelQuit() command is added to the + end of the script, which can cause an infinite loop with linux + execution.} \item{is.inits}{logical; whether initial values are given by the user - (\code{TRUE}) or have to be generated by \pkg{WinBUGS}} - \item{bin}{number of iterations between saving of results} + (\code{TRUE}) or have to be generated by \pkg{OpenBUGS}} \item{DIC}{logical; if \code{TRUE}, compute deviance, pD, and DIC - automatically in \pkg{WinBUGS}} + automatically in \pkg{OpenBUGS}} \item{useWINE}{as in \code{\link{bugs}} meta function} \item{newWINE}{as in \code{\link{bugs}} meta function} \item{WINEPATH}{as in \code{\link{bugs}} meta function} - \item{bugs.seed}{random seed for \pkg{WinBUGS} (default is no seed)} + \item{bugs.seed}{random seed for \pkg{OpenBUGS} (default is no seed specified)} \item{summary.only}{If \code{TRUE}, only a parameter summary for very quick analyses is given, temporary created files are not removed in that case.} \item{save.history}{If \code{TRUE} (the default), trace plots are generated at the end.} \item{bugs.data.file}{character name of the data file} \item{bugs.inits.files}{character vector of names of the inits files} - \item{over.relax}{If \code{TRUE}, over-relaxed form of MCMC is used if available from WinBUGS.} + \item{over.relax}{If \code{TRUE}, over-relaxed form of MCMC is used if available from OpenBUGS.} } \value{Nothing, but as a side effect, the script file \file{script.txt} Deleted: trunk/R2OpenBUGS/man/openbugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/openbugs.Rd 2010-07-25 02:45:16 UTC (rev 160) +++ trunk/R2OpenBUGS/man/openbugs.Rd 2010-08-06 14:07:38 UTC (rev 161) @@ -1,118 +0,0 @@ -\name{openbugs} -\alias{openbugs} -\title{Wrapper to run OpenBUGS} -\description{The \code{openbugs} function takes data and starting values - as input. It automatically calls the package \pkg{BRugs} and runs - something similar to \code{\link[BRugs]{BRugsFit}}. Not available in - S-PLUS.} - -\usage{ -openbugs(data, inits, parameters.to.save, - model.file = "model.txt", n.chains = 3, n.iter = 2000, - n.burnin = floor(n.iter/2), - n.thin = max(1, floor(n.chains * (n.iter - n.burnin) / n.sims)), - n.sims = 1000, DIC = TRUE, - bugs.directory = "c:/Program Files/OpenBUGS/", - working.directory = NULL, digits = 5, over.relax = FALSE, seed=NULL) -} - -\arguments{ - \item{data}{either a named list (names corresponding to variable names - in the \code{model.file}) of the data for the \pkg{OpenBUGS} model, - \emph{or} a vector or list of the names of the data objects used by - the model. If \code{data} is a one element character vector (such as \code{"data.txt"}), - it is assumed that data have already been written to the working directory into that file, - e.g. by the function \code{\link{bugs.data}}.} - \item{inits}{a list with \code{n.chains} elements; each element of the - list is itself a list of starting values for the \pkg{OpenBUGS} model, - \emph{or} a function creating (possibly random) initial values. - Alternatively, if \code{inits} are missing or \code{inits = NULL}, - initial values are generated by \pkg{OpenBUGS}.} - \item{parameters.to.save}{character vector of the names of the - parameters to save which should be monitored} - \item{model.file}{file containing the model written in \pkg{OpenBUGS} code. - The extension can be either \file{.bug} or \file{.txt}. If - \file{.bug}, a copy of the file with extension \file{.txt} will be - created in the \code{bugs()} call and removed afterwards. Note that - similarly named \file{.txt} files will be overwritten.} - \item{n.chains}{number of Markov chains (default: 3)} - \item{n.iter}{number of total iterations per chain (including burn in; - default: 2000)} - \item{n.burnin}{length of burn in, i.e. number of iterations to - discard at the beginning. Default is \code{n.iter/2}, that is, - discarding the first half of the simulations.} - \item{n.thin}{thinning rate. Must be a positive integer. Set - \code{n.thin} > 1 to save memory and computation time if - \code{n.iter} is large. Default is \code{max(1, floor(n.chains * - (n.iter-n.burnin) / 1000))} which will only thin if there are at - least 2000 simulations.} - \item{n.sims}{The approximate number of simulations to keep after thinning.} - \item{DIC}{logical; if \code{TRUE} (default), compute deviance, pD, and - DIC. This is done in \pkg{BRugs} directly.} - \item{digits}{number of significant digits used for \pkg{OpenBUGS} input, - see \code{\link{formatC}}} - \item{bugs.directory}{directory that contains the \pkg{OpenBUGS} executable - - currently unused} - \item{working.directory}{sets working directory during execution of - this function; \pkg{WinBUGS} in- and output will be stored in this - directory; if \code{NULL}, a temporary working directory via - \code{\link{tempdir}} is used.} - \item{over.relax}{If \code{TRUE}, over-relaxed form of MCMC is used if available from OpenBUGS.} - \item{seed}{random seed (default is no seed)} -} - -\value{A \code{\link{bugs}} object.} - -\author{Andrew Gelman, \email{ge...@st...}, - \url{http:/www.stat.columbia.edu/~gelman/bugsR/}; modifications and - packaged by Sibylle Sturtz, \email{st...@st...}, - and Uwe Ligges. -} - -\note{By default, BRugs (and hence \code{openbugs()}) is quite verbose. - This can be controlled for the whole BRugs package by the option \sQuote{BRugsVerbose} (see \code{\link{options}}) - which is set to \code{TRUE} by default. -} - -\seealso{\code{\link{bugs}} and the \pkg{BRugs} package} - -\examples{ -# An example model file is given in: -model.file <- system.file(package = "R2WinBUGS", "model", "schools.txt") -# Let's take a look: -file.show(model.file) - -# Some example data (see ?schools for details): -data(schools) -schools - -J <- nrow(schools) -y <- schools$estimate -sigma.y <- schools$sd -data <- list ("J", "y", "sigma.y") -inits <- function(){ - list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100), - sigma.theta = runif(1, 0, 100)) -} -## or alternatively something like: -# inits <- list( -# list(theta = rnorm(J, 0, 90), mu.theta = rnorm(1, 0, 90), -# sigma.theta = runif(1, 0, 90)), -# list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100), -# sigma.theta = runif(1, 0, 100)) -# list(theta = rnorm(J, 0, 110), mu.theta = rnorm(1, 0, 110), -# sigma.theta = runif(1, 0, 110))) - -parameters <- c("theta", "mu.theta", "sigma.theta") - -\dontrun{ -## both write access in the working directory and package BRugs required: -schools.sim <- bugs(data, inits, parameters, model.file, - n.chains = 3, n.iter = 5000, - program = "openbugs", working.directory = NULL) -print(schools.sim) -plot(schools.sim) -} -} -\keyword{interface} -\keyword{models} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2010-08-10 02:53:44
|
Revision: 165 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=165&view=rev Author: snthomas99 Date: 2010-08-10 02:53:35 +0000 (Tue, 10 Aug 2010) Log Message: ----------- Updated vignette and other doucmentation Modified Paths: -------------- trunk/R2OpenBUGS/R/bugs.script.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/inst/doc/bugs.tex trunk/R2OpenBUGS/man/as.bugs.array.Rd trunk/R2OpenBUGS/man/attach.all.Rd trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/bugs.data.Rd trunk/R2OpenBUGS/man/bugs.inits.Rd trunk/R2OpenBUGS/man/bugs.log.Rd trunk/R2OpenBUGS/man/bugs.script.Rd trunk/R2OpenBUGS/man/bugs.sims.Rd trunk/R2OpenBUGS/man/bugs.update.settings.Rd trunk/R2OpenBUGS/man/decode.parameter.name.Rd trunk/R2OpenBUGS/man/monitor.Rd trunk/R2OpenBUGS/man/read.bugs.Rd trunk/R2OpenBUGS/man/write.datafile.Rd trunk/R2OpenBUGS/man/write.model.Rd Added Paths: ----------- trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.Rnw Removed Paths: ------------- trunk/R2OpenBUGS/inst/doc/R2WinBUGS.Rnw Modified: trunk/R2OpenBUGS/R/bugs.script.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.script.R 2010-08-07 19:37:04 UTC (rev 164) +++ trunk/R2OpenBUGS/R/bugs.script.R 2010-08-10 02:53:35 UTC (rev 165) @@ -3,7 +3,7 @@ n.thin, model.file, debug=FALSE, is.inits, DIC=FALSE, useWINE=FALSE, newWINE=TRUE, WINEPATH=NULL, bugs.seed=NULL, summary.only=FALSE, - save.history=(.Platform$OS.type = "windows" | useWINE=TRUE), + save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), bugs.data.file, bugs.inits.files, over.relax = FALSE) { Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2010-08-07 19:37:04 UTC (rev 164) +++ trunk/R2OpenBUGS/inst/NEWS 2010-08-10 02:53:35 UTC (rev 165) @@ -1,3 +1,8 @@ +Changes to R2OpenBUGS: +===================== +First version 1.0.0 +- Converted R2WinBUGS to use OpenBUGS scripts. Eliminated BRugs calls. + Changes to R2WinBUGS: ===================== Copied: trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.Rnw (from rev 161, trunk/R2OpenBUGS/inst/doc/R2WinBUGS.Rnw) =================================================================== --- trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.Rnw (rev 0) +++ trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.Rnw 2010-08-10 02:53:35 UTC (rev 165) @@ -0,0 +1,495 @@ +%\VignetteIndexEntry{R2OpenBUGS} +\documentclass{Z} +\usepackage{RdRW,thumbpdf} +\newcommand{\WinBUGS}{{\proglang{WinBUGS}}{}} +\newcommand{\OpenBUGS}{{\proglang{OpenBUGS}}{}} +\newcommand{\RW}{{\pkg{R2WinBUGS}}{}} +\newcommand{\RO}{{\pkg{R2OpenBUGS}}{}} +\renewcommand{\R}{{\proglang{R}}{}} +\setlength{\textheight}{23.5cm} + +\title{\RO{}:\protect\linebreak A Package for Running \OpenBUGS{} from \R{}} +\author{Sibylle Sturtz\thanks{\email{st...@st...}}\\Fachbereich Statistik\\Universit\"at Dortmund\\Germany + \And + Uwe Ligges\thanks{\email{li...@st...}}\\Fachbereich Statistik\\Universit\"at Dortmund\\Germany + \And + Andrew Gelman\thanks{\email{ge...@st...}}\\Department of Statistics\\Columbia University\\USA +} +\Plainauthor{Sibylle Sturtz, Uwe Ligges, Andrew Gelman} +\Plaintitle{R2OpenBUGS: A Package for Running OpenBUGS from R} + +\Abstract{ +The \RO{} package provides convenient functions to call \OpenBUGS{} from \R{}. It +automatically writes the data and scripts in a format readable by \OpenBUGS{} for processing in batch mode, which +is possible since version 1.4. After the \OpenBUGS{} process has finished, it is possible either to read the +resulting data into \R{} by the package itself---which gives a compact graphical summary of inference and +convergence diagnostics---or to use the facilities of the \pkg{coda} package for further analyses of the +output. Examples are given to demonstrate the usage of this package. +} + +\Keywords{\R{}, \OpenBUGS{}, interface, MCMC} +\Plainkeywords{R, OpenBUGS, interface, MCMC} + +\begin{document} +An earlier version of this vignette has been published by the Journal of Statistical Software:\\ +Sturtz S, Ligges U, Gelman A (2005): +``\RW{}: A Package for Running \WinBUGS{} from \R{}.'' +{\em Journal of Statistical Software}, 12(3), 1--16. +\RO{} was adapted from \RW{} by Neal Thomas. + + +\section{Introduction}\label{Introduction} +The usage of Markov chain Monte Carlo (MCMC) methods became very popular within the last decade. \OpenBUGS{} +\citep[\textbf{B}ayesian inference \textbf{U}sing \textbf{G}ibbs \textbf{S}ampling, ][] +{Spiegelhalter;Thomas;Best:2003} is a popular software for analyzing complex statistical models using MCMC +methods. This software uses Gibbs sampling \citep{Geman;Geman:1984,Gelfand;Smith:1990,Casella;George:1992} and the +Metropolis algorithm \citep{Metropolis;Rosenbluth;Rosenbluth;Teller;Teller:1953} +to generate a Markov chain by sampling from full conditional +distributions. +The \OpenBUGS{} software is available for free +at \url{http://www.OpenBUGS.info}. +An introduction to MCMC methods is given in \cite{Gilks;Richardson;Spiegelhalter:1996}. + +Using \OpenBUGS{}, the user must specify the model to run, and to load data and initial values for a specified +number of Markov chains. Then it is possible to run the Markov chain(s) and to save the results for the parameters +the user is interested in. Summary statistics of these data, convergence diagnostics, kernel estimates +etc.\ are available as well. +Nevertheless, some users of this software might be interested in saving the output and reading it into \R{} +\citep{RCore:2004} for further analyses. +\OpenBUGS{} comes with the ability to run the software in batch mode using scripts. + +The \RO{} package makes use of this feature and provides the tools to call \OpenBUGS{} +directly after data manipulation in \R{}. Furthermore, it is possible to +work with the results after importing them back into \R{} again, for example to create posterior predictive simulations or, more generally, graphical displays of data and posterior simulations \citep{gelman:2004}. +Embedding in R can also be useful for frequently changed data or processing a bunch of data sets, +because it is much more convenient to use some \R{} functions (possibly within a loop) +rather than using ``copy \& paste'' to update data in \OpenBUGS{} each time; however difficulties have been encountered in this area because both \R{} and \OpenBUGS{} can lock up RAM in the Windows operating system. + +\R{} is a ``language for data analysis and graphics'' and an open source and +freely available statistical software package implementing that language, see \url{http://www.R-project.org/}. +Historically, \R{} is an implementation of the award-winning \proglang{S} +language and system \citep{becker:1984r,becker:1988r,chambers:1992,chambers:1998}. +\R{} and \RO{} are available from \emph{CRAN} (Comprehensive \R{} Archive Network), +i.e., \url{http://CRAN.R-Project.org} or one of its mirrors. +\RO{} could be ported to the commercial \proglang{S} implementation +\textsc{S-Plus}. Minor adaptions would be needed since \textsc{S-Plus} +lacks some of \R{}'s functions and capabilities. +If an internet connection is available, \RO{} can be installed by typing +\verb+install.packages("R2OpenBUGS")+ at the \R{} command prompt. +Do not forget to load the package with \verb+library("R2OpenBUGS")+. + +The package \pkg{coda} by \cite{Plummer;Best;Cowles;Vines:2004} is very useful for the analysis of \OpenBUGS{}' +output, the reader might want to install this package as well. The CRAN package \pkg{boa} (Bayesian Output +Analysis Program) by \cite{Smith:2004} has similar aims. +\proglang{JAGS} (Just Another Gibbs Sampler) +by \cite{Plummer:2003} is a program for analysis of Bayesian hierarchical models using Gibbs sampling that aims for +the same functionality as classic \proglang{BUGS}. \proglang{JAGS} is developed to work closely together with \R{} and +the \pkg{coda} package. + +%% Revision 2005-01-10 end + +In this paper, we give two examples, involving educational testing experiments in schools (cf.~Section~\ref{School}), +and incidence of childhood leukaemia depending on benzene emissions (cf.~Section~\ref{Leukaemia}). Details on the +functions of \RO{} are given in Section~\ref{Programming}. These functions automatically write the data and a +script in a format readable by \OpenBUGS{} for processing in batch mode, and call \OpenBUGS{} from \R{}. After the +\OpenBUGS{} process has finished, it is possible either to read the resulting data into \R{} by the package itself +or to use the facilities of the \pkg{coda} package for further analyses of the output. In Section~\ref{Example2}, +we demonstrate how to apply the functions provided by \RO{} on the examples' data, and how to analyze the output +both with package \pkg{coda} and with \RO{}'s methods to \verb+plot()+ and \verb+print()+ the output. + + +\section{Examples}\label{Examples} +In this Section, we introduce two examples which will be continued in Section~\ref{Example2}. + +\subsection{Schools data}\label{School} +The Scholastic Aptitude Test (SAT) measures the aptitude of high-schoolers in order to help colleges to make +admissions decisions. It is divided into two parts, verbal (SAT-V) and mathematical (SAT-M). +Our data comes from the SAT-V (Scholastic Aptitude Test-Verbal) on eight different high schools, from an experiment conducted in the late 1970s. +SAT-V is a standard multiple choice test administered by the Educational Testing Service. +This Service was interested in the effects of coaching programs for each of the selected schools. + +The study included coached and uncoached pupils, about sixty in each of the eight different schools; see +\cite{Rubin:1981}. All of them had already taken the PSAT (Preliminary SAT) which results were used as covariates. +%Even if the test is constructed to be resistant to short-term +%efforts directed specifically toward improving test performance, each of the schools is successful at increasing +%SAT scores. +For each school, the estimated treatment effect and the standard error of the effect estimate are given. +These are calculated by an analysis of covariance adjustment appropriate for a completely randomized experiment +\citep{Rubin:1981}. This example was analyzed using a hierarchical normal model in \cite{Rubin:1981} and +\citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). + +\subsection{Leukaemia registration data}\label{Leukaemia} +Spatial data usually arises on different, non-nesting spatial scales. One example is childhood leukaemia +registration data analyzed by \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001} +using ecologic regression. Data are given for Greater London bounded by the M25 orbital motorway. +%% Revision 2005-01-10 start +The data are not available as an example in \RO{} but we use the example here +to illustrate +alternative calls to the \verb+bugs()+ function and output analysis using the \pkg{coda} package. +%% Revision 2005-01-10 end + +The observed number of leukaemia cases among children under 15 years old is given at ward level. Census wards are +administrative areas containing approximately 5000 to 10\,000 people. Central London is divided into 873 wards. The +number of incident cases of leukaemia in children is available from 1985 until 1996 from the Office of National +Statistics and the Thames Cancer Registry. A plot of these numbers is given in Figure~\ref{observed}. + +\begin{figure} +\begin{center} +\includegraphics[width=0.85\textwidth]{countssw} +\caption{\label{observed}Observed number of cases of childhood leukaemia in 1985--1996} +\end{center} +\end{figure} + +Additionally, the number of expected cases (cf.~Fig.~\ref{expected}) is calculated on the same +resolution using population numbers for different age-sex-strata and the national leukaemia +rate for the corresponding strata, for details see \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001}. + +\begin{figure} +\begin{center} +\includegraphics[width=0.85\textwidth]{expectedsw} +\caption{\label{expected}Expected number of cases of childhood leukaemia in 1985--1996}%, as obtained from a simple demographic model} +\end{center} +\end{figure} + +It is assumed that benzene emissions have an effect on the incidence rate of leukaemia. Benzene emission rates are +available in tonnes per year from an atmospheric emissions inventory for London +\citep{Buckingham;Clewley;Hutchinson;Sadler;Shah:1997} produced by the London Research Centre. They are provided +at 1km $\times$ 1km grid cells, giving 2132 grid cells in total. +Their spatial distribution is shown in Figure~\ref{benzene}. + +\begin{figure} +\begin{center} +\includegraphics[width=0.9\textwidth]{benzolsw} +\caption{\label{benzene}Benzene emissions in tonnes per year} +\end{center} +\end{figure} + +For further details on the data see \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001}. + +We model these data by Poisson-Gamma models introduced by \cite{Best;Ickstadt;Wolpert:2000} using \OpenBUGS{}. +A linking matrix containing information which grid cell belongs to which ward +and to which amount is required. This matrix is calculated using \R{}. +Unfortunately, \OpenBUGS{} does not support a list format such as directly produced by \R{}. +Therefore, the data must be provided as a matrix with 2132 rows and 873 columns (or vice versa). +Most of the entries of this matrix are zeroes, but using \verb+dump()+ to export it from \R{} +yields in a file size of 14.2~MB. +Unfortunately, opening a file of such size really slows \OpenBUGS{} down, +and it was not even possible on some of our PCs. +Importing data written by our \RO{} package does not make any problems using the batch mode, +probably due to memory management issues in \OpenBUGS{}. + + +\section{Implementation}\label{Programming} +The implementation of the \RO{} package is straightforward. +The ``main'' function \verb+bugs()+ is intended to be called by the user. +In principle, it is a wrapper for several other functions called therein step by step as follows: +\begin{enumerate} + \item \verb+bugs.data.inits()+ writes the data files \file{data.txt}, and \file{inits1.txt}, \file{inits2.txt}, ... + into the working directory. These files will be used by \OpenBUGS{} during batch processing. + + In particular, input for \OpenBUGS{} must not exceed a certain number of digits. + Moreover, it needs an \verb+E+ instead of an \verb+e+ in scientific notation. + Scientific notation is particularly desirable because of the ``number of digits'' limitation. + The default (\verb+digits = 5+) is to, e.g., reformat the number \verb+123456.789+ to \verb@1.23457E+05@. + \item \verb+bugs.script()+ writes the file \file{script.txt} that is used by \OpenBUGS{} for batch processing. + \item \verb+bugs.run()+ updates the lengths of the adaptive phases in the \WinBUGS{} registry + (using a function \verb+bugs.update.settings()+), + calls \WinBUGS{}, and runs it in batch mode with \file{script.txt}. + \item \verb+bugs.sims()+ is only called if the argument \verb+codaPkg+ has been set to \verb+FALSE+ (the default). + Otherwise \verb+bugs()+ returns the filenames of stored data. These can, for example, + be imported by package \pkg{coda} (see the example in Section~\ref{Leukaemia2}, page~\pageref{codaexample}), + which provides functions for convergence diagnostics, + calculation of Monte Carlo estimates, trace plots, and so forth. + + The function \verb+bugs.sims()+ reads simulations from \OpenBUGS{} into \R{} (not necessarily called by \verb+bugs()+ + itself), formats them, + monitors convergence, performs convergence checks, and computes medians and quantiles. + It also prepares the output for \verb+bugs()+ itself. +\end{enumerate} +These functions are not intended to be called by the user directly. +Arguments are passed from \verb+bugs()+ to the other functions, if appropriate. +A shortened help file of \verb+bugs()+ listing all arguments is given in Appendix~\ref{Doc}; +for the full version type \verb+?bugs+ in \R{} after having installed and loaded the package \RO{} +(see Section~\ref{Introduction}). + +%\newpage +As known from \OpenBUGS{}, one must specify the \verb+data+ in form of a list, with list names equal to the names +of data in the corresponding \OpenBUGS{} model. Alternatively, it is possible to specify a vector or list of names +(of mode \verb+character+). In that case objects of that names are looked for in the environment in which +\verb+bugs()+ has been called (usually that is the user's Workspace, \verb+.GlobalEnv+). +%% Revision 2005-01-10 start +If data have already been written in a file called \file{data.txt} to the working directory, +it is possible to specify \verb+data = "data.txt"+. +%% Revision 2005-01-10 end +One will usually want to supply initial values. +This can be done either in the form of a function \verb+inits()+ that creates these values, so that +different chains can be automatically initialized at different points (see Section \ref{School2}), or by specifying them +directly (see Section \ref{Leukaemia2}). +If \verb+inits()+ is not specified, +\verb+bugs()+ just uses the starting values created by \OpenBUGS{}; but in practice \OpenBUGS{} can crash when +reasonable initial values are not specified, and so we recommend constructing a simple \verb+inits()+ function to +simulate reasonable starting points \cite[Section C.2]{Gelman:2003}. It is also necessary to specify which +parameters should be saved for monitoring by specifying \verb+parameters.to.save+. + +The user might also want to change the defaults for the length of the burn-in (\verb+n.burnin+, which defaults to half the length of the chain) +period for every MCMC run and the number of iterations (\verb+n.iter+, default value 3) +that are used to calculate Monte Carlo estimates. +%SS: Achtung: n.iter=n.burn.in + length of stored chain! +The specification of a thinning parameter (\verb+n.thin+) is possible as well; this is useful when the number of parameters is large, to keep the saved output to a reasonably-sized R object. + +By setting the argument \verb+debug = TRUE+, +\OpenBUGS{} remains open after the run. +This way it is possible to find errors in the code or the data structure, +or even to work with that software as in a usual run. This feature is not +available with Linux execution. + +It is possible to run one or more Markov chains. +The number of chains (\verb+n.chains+) must be specified together with the chains' initial values (\verb+inits+). +If more than one Markov chain is requested and \verb+codaPkg+ is set to \verb+FALSE+, the convergence diagnostic +$\hat{R}$ \citep{Brooks;Gelman:1998} is calculated by \verb+bugs.sims()+ for each of the saved parameters. + +%% Revision 2005-01-10 start +Since the communication between \OpenBUGS{} and \R{} is based on files, +rather huge files will be saved in the working directory by the \verb+bugs()+ call, +either files to be read in by \verb+bugs()+ itself, or by the \pkg{coda} package. +The user might want to delete those files after the desired contents has been imported into \R{}, +and save those objects, e.g., as compressed \R{} data files. +%% Revision 2005-01-10 end + +The function \verb+bugs()+ returns a rather complex object of class \verb+bugs+, +if called with argument \verb+codaPkg = FALSE+. +In order to look at the structure of such an object, type \verb+str(objectname)+. +For convenience, \RO{} provides methods corresponding to class \verb+bugs+ for +the generic functions \verb+print()+ and \verb+plot()+. + +So that user will not be overwhelmed with information; summaries of the output are provided by the +\verb+print()+ method. That is, some parameters of the \verb+bugs()+ call are summarized, and mean, +standard deviation, several quantiles of the parameters and convergence diagnostics based on \cite{Gelman;Rubin:1992} +are printed. See the example in +Section~\ref{School2}, page~\pageref{schoolssim}, for a typical output. As with \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}, +%\pagebreak + the DIC computed by \verb+bugs.sims()+ is defined as the posterior mean +of the deviance plus $p_D$, the estimated effective number of parameters in the posterior distribution. We define +$p_D$ as half the posterior variance of the deviance and estimate it as half the average of the within-chain +variances of the deviance.\footnote{In contrast, \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}, + and OpenBUGS, define $p_D$ as the +posterior mean of the deviance evaluated at the posterior mean of the parameter values. We cannot use that +definition because the deviance function is not available to our program, which calls \OpenBUGS{} from the +``outside''. Both definitions of $p_D$---ours and that introduced by \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}---can be +derived from the asymptotic $\chi^2$ distribution of the deviance relative to its minimum \citep[Section 6.7]{Gelman:2003}. +We make no claim that our measure of $p_D$ is superior to that of \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}; +we choose this measure purely because it is computationally possible given what is available to us from the \OpenBUGS{} output.} + + +The \verb+plot()+ for objects of class \verb+bugs+ +provides information condensed in some plots conveniently arranged within the same graphics device. +For an example, see Figure~\ref{plot} in Section~\ref{School2}. It is intended to adapt this function to work with MCMC output in general, even if obtained from software other than OpenBUGS. + + + +\section{Examples continued}\label{Example2} +The Examples introduced in Section~\ref{Example2} are continued in this Section. +We apply the functions provided by \RO{} +to the examples' data and analyze the output. + +\subsection{Schools data}\label{School2} +Schools example data (see Section~\ref{School}) are available with the \RO{} package: +\begin{Code} + > data(schools) + > schools + school estimate sd + 1 A 28.39 14.9 + 2 B 7.94 10.2 + 3 C -2.75 16.3 + 4 D 6.82 11.0 + 5 E -0.64 9.4 + 6 F 0.63 11.4 + 7 G 18.01 10.4 + 8 H 12.16 17.6 +\end{Code} +For modeling these data, we use a hierarchical model as proposed by \citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). +We assume a normal distribution for the observed estimate for each school with +mean \verb+theta+ and inverse-variance \verb+tau.y+. +The inverse-variance is given as $1/\verb+sigma.y+^{2}$ and its prior distribution is uniform on (0,1000). For the mean +\verb+theta+, we employ another normal distribution with mean \verb+mu.theta+ and inverse-variance \verb+tau.theta+. For +their prior distributions, see the following \OpenBUGS{} code: + + +\begin{Code} + model { + for (j in 1:J) + { + y[j] ~ dnorm (theta[j], tau.y[j]) + theta[j] ~ dnorm (mu.theta, tau.theta) + tau.y[j] <- pow(sigma.y[j], -2) + } + mu.theta ~ dnorm (0.0, 1.0E-6) + tau.theta <- pow(sigma.theta, -2) + sigma.theta ~ dunif (0, 1000) + } +\end{Code} +This model must be stored in a separate file, e.g.~\file{schools.bug}\footnote{Emacs Speaks Statistics (ESS) +by \cite{rossini04}, a package available with Gnu Emacs \citep{stallmann99}, +recognizes and properly formats Bugs model files that have the .bug extension.}, +in an appropriate directory, say \path{c:/schools/}. +In \R{} the user must prepare the data inputs the \verb+bugs()+ function needs. +This can be a list containing the name of each data vector, e.g. +\begin{Code} + > J <- nrow(schools) + > y <- schools$estimate + > sigma.y <- schools$sd + > data <- list ("J", "y", "sigma.y") +\end{Code} +Using these data and the model file, we can run an MCMC simulation to get estimates for \verb+theta+, +\verb+mu.theta+ and \verb+sigma.theta+. Before running, the user must decide how many chains to be run +(\verb+n.chain = 3+) for how many iterations (\verb+n.iter = 1000+). +If the length of burn-in is not specified, \verb+n.burnin = floor(n.iter/2)+ is used, that is, 500 in this example. +Additionally, the user must specify initial values for the chains, for example by writing a function. This can be done by +\begin{Code} + > inits <- function(){ + + list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100), + + sigma.theta = runif(1, 0, 100)) + + } +\end{Code} +Now, the user can start the MCMC simulation by typing +\begin{Code} + > schools.sim <- bugs(data, inits, model.file = "c:/schools/schools.bug", + + parameters = c("theta", "mu.theta", "sigma.theta"), + + n.chains = 3, n.iter = 1000) +\end{Code} +in \R{}.\label{schoolssim} +For other available arguments, see Appendix \ref{Doc}. + +The results in objects \verb+schools.sim+ can conveniently be printed by \verb+print(schools.sim)+. +The generic function \verb+print()+ calls the print method for an object of class \verb+bugs+ +provided by \RO{}. +For this example, you will get something like + +\small +\begin{Code} + > print(schools.sim) + Inference for Bugs model at "c:/schools/schools.bug" + 3 chains, each with 1000 iterations (first 500 discarded) + n.sims = 1500 iterations saved + mean sd 2.5% 25% 50% 75% 97.5% Rhat n.eff + theta[1] 11.1 9.1 -3.0 5.0 10.0 16.0 31.8 1.1 39 + theta[2] 7.6 6.6 -4.7 3.3 7.8 11.6 21.1 1.1 42 + theta[3] 5.7 8.4 -12.5 0.6 6.1 10.8 21.8 1.0 150 + theta[4] 7.1 7.0 -6.6 2.7 7.2 11.5 21.0 1.1 42 + theta[5] 5.1 6.8 -9.5 0.7 5.2 9.7 18.1 1.0 83 + theta[6] 5.7 7.3 -9.7 1.0 6.2 10.2 20.0 1.0 56 + theta[7] 10.4 7.3 -2.1 5.3 9.8 15.3 25.5 1.1 27 + theta[8] 8.3 8.4 -6.6 2.8 8.1 12.7 26.2 1.0 64 + mu.theta 7.6 5.9 -3.0 3.7 8.0 11.0 19.5 1.1 35 + sigma.theta 6.7 5.6 0.3 2.8 5.1 9.2 21.2 1.1 46 + deviance 60.8 2.5 57.0 59.1 60.2 62.1 66.6 1.0 170 + pD = 3 and DIC = 63.8 (using the rule, pD = var(deviance)/2) + + For each parameter, n.eff is a crude measure of effective sample size, + and Rhat is the potential scale reduction factor (at convergence, Rhat=1). + DIC is an estimate of expected predictive error (lower deviance is better). +\end{Code} +\normalsize +Additionally, the user can generate a plot of the results by typing \verb+plot(schools.sim)+. +The resulting plot is given in Figure~\ref{plot}. +\begin{figure}[t] +\begin{center} +\fbox{ +\includegraphics[width=0.9\textwidth]{plot} +} \caption{\label{plot}Plot produced by \RO{} package for the schools example. } +\end{center} +\end{figure} +In this plot, the left column shows a quick +summary of inference and convergence ($\widehat{R}$ is close to 1.0 for all parameters, indicating good mixing of +the three chains and thus approximate convergence); and the right column shows inferences for each set of +parameters. As can be seen in the right column, \RO{} uses the parameter names in \OpenBUGS{} to structure the +output into scalar, vector, and arrays of parameters, in addition to storing the parameters as a long vector. + +For the interpretation of these results see \citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). + +\subsection{Leukaemia registration data}\label{Leukaemia2} +The leukaemia registration data (see Section \ref{Leukaemia}) are used to show data modeling and output reading +into \R{} using the \pkg{coda} package. A simple model for these data looks as follows: +\begin{Code} +model{ + beta.0 ~ dgamma(a.0, tau.0) + beta.benz ~ dgamma(a.benz, tau.benz) + a.0 <- 0.575 + tau.0 <- a.0*2 + a.benz <- 0.575 + tau.benz <- a.benz*2 +\end{Code} +\clearpage +\begin{Code} + for (i in 1:I) + { + count[i] ~ dpois(lambda[i]) + lambda[i] <- p[i]*expect[i] + for (j in 1:J) + { + prop[j,i] <- gamma[j,i]*(benz[j] - benzbar) + } + p[i]<- beta.0 + beta.benz*sum(prop[,i]) + } + } +\end{Code} +Here \verb+count+ denotes the number of observed incidences of childhood leukaemia in ward~\verb+i+. These are +assumed to be Poisson distributed with mean \verb+lambda+ depending on the number of expected cases \verb+expect+ +in ward \verb+i+ and an area-specific risk rate \verb+p+. For calculation of this area specific risk rate we use +an intercept \verb+beta.0+ and a term depending on the weighted sum of benzene emissions \verb+benz+ in each grid +cell \verb+j+. The weights are chosen proportional to the amount of area that ward \verb+i+ and grid cell \verb+j+ have +in common. + +In \R{} we can define all these data and then initialize the model. The data needed for this example are +\begin{description} +\item[\tt{benzbar}:] arithmetic mean of all benzene values, +\item[\tt{benz}:] a vector containing benzene emissions of all 2132 grid cells, +\item[\tt{expect}:] expected number of cases of childhood leukaemia in each of the 873 wards, +\item[\tt{count}:] observed number of childhood leukaemia in these wards, +\item[\tt{gamma}:] a $2132\times 873$ matrix containing the amount of area each grid cell and each ward have in common, +\item[\tt{J}:] total number of grid cells, i.e.~2132, and +\item[\tt{I}:] total number of ward cells, i.e.~873. +\end{description} +The parameters we want to store are regression coefficients \verb+beta.0+ and \verb+beta.benz+ as well as +\verb+p+, the area specific relative risk compared to the reference rate. This reference rate was used to +calculate the expected number of cases in each ward. + +Since we want to use the \pkg{coda} package for reading the data into \OpenBUGS{}, we specify \verb+codaPkg = TRUE+ +in the \verb+bugs()+ call: +\begin{Code} + > data <- list(benzbar = mean(benz), benz = benz, expect = expect, + + count = count, gamma = gamma, J = J, I = I) + > parameters <- c("beta.0", "beta.benz", "p") + > inits1 <- list(beta.0 = 1, beta.benz = 1) + > inits2 <- list(beta.0 = 0.5, beta.benz = 0.5) + > inits <- list(inits1, inits2) + > model <- bugs(data, inits, parameters, model.file = "c:/model.bug", + + n.chains = 2, n.iter = 8000, n.burnin = 5000, n.thin = 1, + + codaPkg = TRUE ) +\end{Code} + +\clearpage +Starting with, e.g.,\label{codaexample} +\begin{Code} + > library("coda") + > codaobject <- read.bugs(model) + > plot(codaobject) +\end{Code} +it is now possible to use the \pkg{coda} package for output analyses. + + +\section*{Acknowledgments} +The work of Uwe Ligges has been supported by the Deutsche Forschungsgemeinschaft, +Sonderforschungsbereich 475. +The work of Andrew Gelman has been supported by the U.S. National Science Foundation. + +\bibliography{literatur} + +\clearpage +\begin{appendix} +\section[Help page for the function bugs()]{Help page for the function \code{bugs()}\label{Doc}} +\small +This help page has been shortened. +\input{bugs} +\end{appendix} +\end{document} Deleted: trunk/R2OpenBUGS/inst/doc/R2WinBUGS.Rnw =================================================================== --- trunk/R2OpenBUGS/inst/doc/R2WinBUGS.Rnw 2010-08-07 19:37:04 UTC (rev 164) +++ trunk/R2OpenBUGS/inst/doc/R2WinBUGS.Rnw 2010-08-10 02:53:35 UTC (rev 165) @@ -1,506 +0,0 @@ -%\VignetteIndexEntry{R2WinBUGS} -\documentclass{Z} -\usepackage{RdRW,thumbpdf} -\newcommand{\WinBUGS}{{\proglang{WinBUGS}}{}} -\newcommand{\RW}{{\pkg{R2WinBUGS}}{}} -\renewcommand{\R}{{\proglang{R}}{}} -\setlength{\textheight}{23.5cm} - -\title{\RW{}:\protect\linebreak A Package for Running \WinBUGS{} from \R{}} -\author{Sibylle Sturtz\thanks{\email{st...@st...}}\\Fachbereich Statistik\\Universit\"at Dortmund\\Germany - \And - Uwe Ligges\thanks{\email{li...@st...}}\\Fachbereich Statistik\\Universit\"at Dortmund\\Germany - \And - Andrew Gelman\thanks{\email{ge...@st...}}\\Department of Statistics\\Columbia University\\USA -} -\Plainauthor{Sibylle Sturtz, Uwe Ligges, Andrew Gelman} -\Plaintitle{R2WinBUGS: A Package for Running WinBUGS from R} - -\Abstract{ -The \RW{} package provides convenient functions to call \WinBUGS{} from \R{}. It -automatically writes the data and scripts in a format readable by \WinBUGS{} for processing in batch mode, which -is possible since version 1.4. After the \WinBUGS{} process has finished, it is possible either to read the -resulting data into \R{} by the package itself---which gives a compact graphical summary of inference and -convergence diagnostics---or to use the facilities of the \pkg{coda} package for further analyses of the -output. Examples are given to demonstrate the usage of this package. -} - -\Keywords{\R{}, \WinBUGS{}, interface, MCMC} -\Plainkeywords{R, WinBUGS, interface, MCMC} - -\begin{document} -An earlier version of this vignette has been published by the Journal of Statistical Software:\\ -Sturtz S, Ligges U, Gelman A (2005): -``\RW{}: A Package for Running \WinBUGS{} from \R{}.'' -{\em Journal of Statistical Software}, 12(3), 1--16. - - -\section{Introduction}\label{Introduction} -The usage of Markov chain Monte Carlo (MCMC) methods became very popular within the last decade. \WinBUGS{} -\citep[\textbf{B}ayesian inference \textbf{U}sing \textbf{G}ibbs \textbf{S}ampling, ][] -{Spiegelhalter;Thomas;Best:2003} is a popular software for analyzing complex statistical models using MCMC -methods. This software uses Gibbs sampling \citep{Geman;Geman:1984,Gelfand;Smith:1990,Casella;George:1992} and the -Metropolis algorithm \citep{Metropolis;Rosenbluth;Rosenbluth;Teller;Teller:1953} -to generate a Markov chain by sampling from full conditional -distributions. -The \WinBUGS{} software is available for free -at \url{http://www.mrc-bsu.cam.ac.uk/bugs/}. -An introduction to MCMC methods is given in \cite{Gilks;Richardson;Spiegelhalter:1996}. - -Using \WinBUGS{}, the user must specify the model to run, and to load data and initial values for a specified -number of Markov chains. Then it is possible to run the Markov chain(s) and to save the results for the parameters -the user is interested in. Summary statistics of these data, convergence diagnostics, kernel estimates -etc.\ are available as well. -Nevertheless, some users of this software might be interested in saving the output and reading it into \R{} -\citep{RCore:2004} for further analyses. -\WinBUGS{} 1.4 comes with the ability to run the software in batch mode using scripts. - -The \RW{} package makes use of this feature and provides the tools to call \WinBUGS{} -directly after data manipulation in \R{}. Furthermore, it is possible to -work with the results after importing them back into \R{} again, for example to create posterior predictive simulations or, more generally, graphical displays of data and posterior simulations \citep{gelman:2004}. -Embedding in R can also be useful for frequently changed data or processing a bunch of data sets, -because it is much more convenient to use some \R{} functions (possibly within a loop) -rather than using ``copy \& paste'' to update data in \WinBUGS{} each time; however difficulties have been encountered in this area because both \R{} and \WinBUGS{} can lock up RAM in the Windows operating system. - -\R{} is a ``language for data analysis and graphics'' and an open source and -freely available statistical software package implementing that language, see \url{http://www.R-project.org/}. -Historically, \R{} is an implementation of the award-winning \proglang{S} -language and system \citep{becker:1984r,becker:1988r,chambers:1992,chambers:1998}. -\R{} and \RW{} are available from \emph{CRAN} (Comprehensive \R{} Archive Network), -i.e., \url{http://CRAN.R-Project.org} or one of its mirrors. -\RW{} could be ported to the commercial \proglang{S} implementation -\textsc{S-Plus}. Minor adaptions would be needed since \textsc{S-Plus} -lacks some of \R{}'s functions and capabilities. -If an internet connection is available, \RW{} can be installed by typing -\verb+install.packages("R2WinBUGS")+ at the \R{} command prompt. -Do not forget to load the package with \verb+library("R2WinBUGS")+. - -The package \pkg{coda} by \cite{Plummer;Best;Cowles;Vines:2004} is very useful for the analysis of \WinBUGS{}' -output, the reader might want to install this package as well. The CRAN package \pkg{boa} (Bayesian Output -Analysis Program) by \cite{Smith:2004} has similar aims. -\proglang{JAGS} (Just Another Gibbs Sampler) -by \cite{Plummer:2003} is a program for analysis of Bayesian hierarchical models using Gibbs sampling that aims for -the same functionality as classic \proglang{BUGS}. \proglang{JAGS} is developed to work closely together with \R{} and -the \pkg{coda} package. - -%% Revision 2005-01-10 start -A new and completely revised version of WinBUGS called \proglang{OpenBUGS} \citep{Spiegelhalter;Thomas;Best;Lunn:2004} -was lately published under the terms of the GPL. -\proglang{OpenBUGS} is also expected to run under Linux. -It provides a much more flexible API on which ``BRugs'' is based including -a dynamic link library, incorporating a component loader -that allows \R{} to make use of \proglang{OpenBUGS} components. -OpenBUGS is still in development and suffers frequent crashes. -As OpenBUGS becomes more reliable, -it is planned to merge ``BRugs'' and \RW{} into one \R{} package. -%% Revision 2005-01-10 end - -For other packages and projects on spatial statistics -related to \R{}, follow the link to ``\R{} spatial projects'' at CRAN. - -In this paper, we give two examples, involving educational testing experiments in schools (cf.~Section~\ref{School}), -and incidence of childhood leukaemia depending on benzene emissions (cf.~Section~\ref{Leukaemia}). Details on the -functions of \RW{} are given in Section~\ref{Programming}. These functions automatically write the data and a -script in a format readable by \WinBUGS{} for processing in batch mode, and call \WinBUGS{} from \R{}. After the -\WinBUGS{} process has finished, it is possible either to read the resulting data into \R{} by the package itself -or to use the facilities of the \pkg{coda} package for further analyses of the output. In Section~\ref{Example2}, -we demonstrate how to apply the functions provided by \RW{} on the examples' data, and how to analyze the output -both with package \pkg{coda} and with \RW{}'s methods to \verb+plot()+ and \verb+print()+ the output. - - -\section{Examples}\label{Examples} -In this Section, we introduce two examples which will be continued in Section~\ref{Example2}. - -\subsection{Schools data}\label{School} -The Scholastic Aptitude Test (SAT) measures the aptitude of high-schoolers in order to help colleges to make -admissions decisions. It is divided into two parts, verbal (SAT-V) and mathematical (SAT-M). -Our data comes from the SAT-V (Scholastic Aptitude Test-Verbal) on eight different high schools, from an experiment conducted in the late 1970s. -SAT-V is a standard multiple choice test administered by the Educational Testing Service. -This Service was interested in the effects of coaching programs for each of the selected schools. - -The study included coached and uncoached pupils, about sixty in each of the eight different schools; see -\cite{Rubin:1981}. All of them had already taken the PSAT (Preliminary SAT) which results were used as covariates. -%Even if the test is constructed to be resistant to short-term -%efforts directed specifically toward improving test performance, each of the schools is successful at increasing -%SAT scores. -For each school, the estimated treatment effect and the standard error of the effect estimate are given. -These are calculated by an analysis of covariance adjustment appropriate for a completely randomized experiment -\citep{Rubin:1981}. This example was analyzed using a hierarchical normal model in \cite{Rubin:1981} and -\citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). - -\subsection{Leukaemia registration data}\label{Leukaemia} -Spatial data usually arises on different, non-nesting spatial scales. One example is childhood leukaemia -registration data analyzed by \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001} -using ecologic regression. Data are given for Greater London bounded by the M25 orbital motorway. -%% Revision 2005-01-10 start -The data are not available as an example in \RW{} but we use the example here -to illustrate -alternative calls to the \verb+bugs()+ function and output analysis using the \pkg{coda} package. -%% Revision 2005-01-10 end - -The observed number of leukaemia cases among children under 15 years old is given at ward level. Census wards are -administrative areas containing approximately 5000 to 10\,000 people. Central London is divided into 873 wards. The -number of incident cases of leukaemia in children is available from 1985 until 1996 from the Office of National -Statistics and the Thames Cancer Registry. A plot of these numbers is given in Figure~\ref{observed}. - -\begin{figure} -\begin{center} -\includegraphics[width=0.85\textwidth]{countssw} -\caption{\label{observed}Observed number of cases of childhood leukaemia in 1985--1996} -\end{center} -\end{figure} - -Additionally, the number of expected cases (cf.~Fig.~\ref{expected}) is calculated on the same -resolution using population numbers for different age-sex-strata and the national leukaemia -rate for the corresponding strata, for details see \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001}. - -\begin{figure} -\begin{center} -\includegraphics[width=0.85\textwidth]{expectedsw} -\caption{\label{expected}Expected number of cases of childhood leukaemia in 1985--1996}%, as obtained from a simple demographic model} -\end{center} -\end{figure} - -It is assumed that benzene emissions have an effect on the incidence rate of leukaemia. Benzene emission rates are -available in tonnes per year from an atmospheric emissions inventory for London -\citep{Buckingham;Clewley;Hutchinson;Sadler;Shah:1997} produced by the London Research Centre. They are provided -at 1km $\times$ 1km grid cells, giving 2132 grid cells in total. -Their spatial distribution is shown in Figure~\ref{benzene}. - -\begin{figure} -\begin{center} -\includegraphics[width=0.9\textwidth]{benzolsw} -\caption{\label{benzene}Benzene emissions in tonnes per year} -\end{center} -\end{figure} - -For further details on the data see \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001}. - -We model these data by Poisson-Gamma models introduced by \cite{Best;Ickstadt;Wolpert:2000} using \WinBUGS{}. -A linking matrix containing information which grid cell belongs to which ward -and to which amount is required. This matrix is calculated using \R{}. -Unfortunately, \WinBUGS{} does not support a list format such as directly produced by \R{}. -Therefore, the data must be provided as a matrix with 2132 rows and 873 columns (or vice versa). -Most of the entries of this matrix are zeroes, but using \verb+dump()+ to export it from \R{} -yields in a file size of 14.2~MB. -Unfortunately, opening a file of such size really slows \WinBUGS{} down, -and it was not even possible on some of our PCs. -Importing data written by our \RW{} package does not make any problems using the batch mode, -probably due to memory management issues in \WinBUGS{}. - - -\section{Implementation}\label{Programming} -The implementation of the \RW{} package is straightforward. -The ``main'' function \verb+bugs()+ is intended to be called by the user. -In principle, it is a wrapper for several other functions called therein step by step as follows: -\begin{enumerate} - \item \verb+bugs.data.inits()+ writes the data files \file{data.txt}, and \file{inits1.txt}, \file{inits2.txt}, ... - into the working directory. These files will be used by \WinBUGS{} during batch processing. - - In particular, input for \WinBUGS{} must not exceed a certain number of digits. - Moreover, it needs an \verb+E+ instead of an \verb+e+ in scientific notation. - Scientific notation is particularly desirable because of the ``number of digits'' limitation. - The default (\verb+digits = 5+) is to, e.g., reformat the number \verb+123456.789+ to \verb@1.23457E+05@. - \item \verb+bugs.script()+ writes the file \file{script.txt} that is used by \WinBUGS{} for batch processing. - \item \verb+bugs.run()+ updates the lengths of the adaptive phases in the \WinBUGS{} registry - (using a function \verb+bugs.update.settings()+), - calls \WinBUGS{}, and runs it in batch mode with \file{script.txt}. - \item \verb+bugs.sims()+ is only called if the argument \verb+codaPkg+ has been set to \verb+FALSE+ (the default). - Otherwise \verb+bugs()+ returns the filenames of stored data. These can, for example, - be imported by package \pkg{coda} (see the example in Section~\ref{Leukaemia2}, page~\pageref{codaexample}), - which provides functions for convergence diagnostics, - calculation of Monte Carlo estimates, trace plots, and so forth. - - The function \verb+bugs.sims()+ reads simulations from \WinBUGS{} into \R{} (not necessarily called by \verb+bugs()+ - itself), formats them, - monitors convergence, performs convergence checks, and computes medians and quantiles. - It also prepares the output for \verb+bugs()+ itself. -\end{enumerate} -These functions are not intended to be called by the user directly. -Arguments are passed from \verb+bugs()+ to the other functions, if appropriate. -A shortened help file of \verb+bugs()+ listing all arguments is given in Appendix~\ref{Doc}; -for the full version type \verb+?bugs+ in \R{} after having installed and loaded the package \RW{} -(see Section~\ref{Introduction}). - -%\newpage -As known from \WinBUGS{}, one must specify the \verb+data+ in form of a list, with list names equal to the names -of data in the corresponding \WinBUGS{} model. Alternatively, it is possible to specify a vector or list of names -(of mode \verb+character+). In that case objects of that names are looked for in the environment in which -\verb+bugs()+ has been called (usually that is the user's Workspace, \verb+.GlobalEnv+). -%% Revision 2005-01-10 start -If data have already been written in a file called \file{data.txt} to the working directory, -it is possible to specify \verb+data = "data.txt"+. -%% Revision 2005-01-10 end -One will usually want to supply initial values. -This can be done either in the form of a function \verb+inits()+ that creates these values, so that -different chains can be automatically initialized at different points (see Section \ref{School2}), or by specifying them -directly (see Section \ref{Leukaemia2}). -If \verb+inits()+ is not specified, -\verb+bugs()+ just uses the starting values created by \WinBUGS{}; but in practice \WinBUGS{} can crash when -reasonable initial values are not specified, and so we recommend constructing a simple \verb+inits()+ function to -simulate reasonable starting points \cite[Section C.2]{Gelman:2003}. It is also necessary to specify which -parameters should be saved for monitoring by specifying \verb+parameters.to.save+. - -The user might also want to change the defaults for the length of the burn-in (\verb+n.burnin+, which defaults to half the length of the chain) -period for every MCMC run and the number of iterations (\verb+n.iter+, default value 3) -that are used to calculate Monte Carlo estimates. -%SS: Achtung: n.iter=n.burn.in + length of stored chain! -The specification of a thinning parameter (\verb+n.thin+) is possible as well; this is useful when the number of parameters is large, to keep the saved output to a reasonably-sized R object. In the default setting, the chains are thinned enough so that approximately 1000 simulation draws are saved. - -By setting the argument \verb+debug = TRUE+, -\WinBUGS{} remains open after the run. -This way it is possible to find errors in the code or the data structure, -or even to work with that software as in a usual run. - -It is possible to run one or more Markov chains. -The number of chains (\verb+n.chains+) must be specified together with the chains' initial values (\verb+inits+). -If more than one Markov chain is requested and \verb+codaPkg+ is set to \verb+FALSE+, the convergence diagnostic -$\hat{R}$ \citep{Brooks;Gelman:1998} is calculated by \verb+bugs.sims()+ for each of the saved parameters. - -%% Revision 2005-01-10 start -Since the communication between \WinBUGS{} and \R{} is based on files, -rather huge files will be saved in the working directory by the \verb+bugs()+ call, -either files to be read in by \verb+bugs()+ itself, or by the \pkg{coda} package. -The user might want to delete those files after the desired contents has been imported into \R{}, -and save those objects, e.g., as compressed \R{} data files. -%% Revision 2005-01-10 end - -The function \verb+bugs()+ returns a rather complex object of class \verb+bugs+, -if called with argument \verb+codaPkg = FALSE+. -In order to look at the structure of such an object, type \verb+str(objectname)+. -For convenience, \RW{} provides methods corresponding to class \verb+bugs+ for -the generic functions \verb+print()+ and \verb+plot()+. - -So that user will not be overwhelmed with information; summaries of the output are provided by the -\verb+print()+ method. That is, some parameters of the \verb+bugs()+ call are summarized, and mean, -standard deviation, several quantiles of the parameters and convergence diagnostics based on \cite{Gelman;Rubin:1992} -are printed. See the example in -Section~\ref{School2}, page~\pageref{schoolssim}, for a typical output. As with \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}, -%\pagebreak - the DIC computed by \verb+bugs.sims()+ is defined as the posterior mean -of the deviance plus $p_D$, the estimated effective number of parameters in the posterior distribution. We define -$p_D$ as half the posterior variance of the deviance and estimate it as half the average of the within-chain -variances of the deviance.\footnote{In contrast, \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}, - and WinBUGS, define $p_D$ as the -posterior mean of the deviance evaluated at the posterior mean of the parameter values. We cannot use that -definition because the deviance function is not available to our program, which calls \WinBUGS{} from the -``outside''. Both definitions of $p_D$---ours and that introduced by \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}---can be -derived from the asymptotic $\chi^2$ distribution of the deviance relative to its minimum \citep[Section 6.7]{Gelman:2003}. -We make no claim that our measure of $p_D$ is superior to that of \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}; -we choose this measure purely because it is computationally possible given what is available to us from the \WinBUGS{} output.} - - -The \verb+plot()+ for objects of class \verb+bugs+ -provides information condensed in some plots conveniently arranged within the same graphics device. -For an example, see Figure~\ref{plot} in Section~\ref{School2}. It is intended to adapt this function to work with MCMC output in general, even if obtained from software other than WinBUGS. - - - -\section{Examples continued}\label{Example2} -The Examples introduced in Section~\ref{Example2} are continued in this Section. -We apply the functions provided by \RW{} -to the examples' data and analyze the output. - -\subsection{Schools data}\label{School2} -Schools example data (see Section~\ref{School}) are available with the \RW{} package: -\begin{Code} - > data(schools) - > schools - school estimate sd - 1 A 28.39 14.9 - 2 B 7.94 10.2 - 3 C -2.75 16.3 - 4 D 6.82 11.0 - 5 E -0.64 9.4 - 6 F 0.63 11.4 - 7 G 18.01 10.4 - 8 H 12.16 17.6 -\end{Code} -For modeling these data, we use a hierarchical model as proposed by \citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). -We assume a normal distribution for the observed estimate for each school with -mean \verb+theta+ and inverse-variance \verb+tau.y+. -The inverse-variance is given as $1/\verb+sigma.y+^{2}$ and its prior distribution is uniform on (0,1000). For the mean -\verb+theta+, we employ another normal distribution with mean \verb+mu.theta+ and inverse-variance \verb+tau.theta+. For -their prior distributions, see the following \WinBUGS{} code: - - -\begin{Code} - model { - for (j in 1:J) - { - y[j] ~ dnorm (theta[j], tau.y[j]) - theta[j] ~ dnorm (mu.theta, tau.theta) - tau.y[j] <- pow(sigma.y[j], -2) - } - mu.theta ~ dnorm (0.0, 1.0E-6) - tau.theta <- pow(sigma.theta, -2) - sigma.theta ~ dunif (0, 1000) - } -\end{Code} -This model must be stored in a separate file, e.g.~\file{schools.bug}\footnote{Emacs Speaks Statistics (ESS) -by \cite{rossini04}, a package available with Gnu Emacs \citep{stallmann99}, -recognizes and properly formats Bugs model files that have the .bug extension.}, -in an appropriate directory, say \path{c:/schools/}. -In \R{} the user must prepare the data inputs the \verb+bugs()+ function needs. -This can be a list containing the name of each data vector, e.g. -\begin{Code} - > J <- nrow(schools) - > y <- schools$estimate - > sigma.y <- schools$sd - > data <- list ("J", "y", "sigma.y") -\end{Code} -Using these data and the model file, we can run an MCMC simulation to get estimates for \verb+theta+, -\verb+mu.theta+ and \verb+sigma.theta+. Before running, the user must decide how many chains to be run -(\verb+n.chain = 3+) for how many iterations (\verb+n.iter = 1000+). -If the length of burn-in is not specified, \verb+n.burnin = floor(n.iter/2)+ is used, that is, 500 in this example. -Additionally, the user must specify initial values for the chains, for example by writing a function. This can be done by -\begin{Code} - > inits <- function(){ - + list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100), - + sigma.theta = runif(1, 0, 100)) - + } -\end{Code} -Now, the user can start the MCMC simulation by typing -\begin{Code} - > schools.sim <- bugs(data, inits, model.file = "c:/schools/schools.bug", - + parameters = c("theta", "mu.theta", "sigma.theta"), - + n.chains = 3, n.iter = 1000, - + bugs.directory = "c:/Program Files/WinBUGS14/") -\end{Code} -in \R{}.\label{schoolssim} The argument \verb+bugs.directory+ must point to the directory -where \WinBUGS{} has been installed. -For other available arguments, see Appendix \ref{Doc}. - -The results in objects \verb+schools.sim+ can conveniently be printed by \verb+print(schools.sim)+. -The generic function \verb+print()+ calls the print method for an object of class \verb+bugs+ -provided by \RW{}. -For this example, you will get something like - -\small -\begin{Code} - > print(schools.sim) - Inference for Bugs model at "c:/schools/schools.bug" - 3 chains, each with 1000 iterations (first 500 discarded) - n.sims = 1500 iterations saved - mean sd 2.5% 25% 50% 75% 97.5% Rhat n.eff - theta[1] 11.1 9.1 -3.0 5.0 10.0 16.0 31.8 1.1 39 - theta[2] 7.6 6.6 -4.7 3.3 7.8 11.6 21.1 1.1 42 - theta[3] 5.7 8.4 -12.5 0.6 6.1 10.8 21.8 1.0 150 - theta[4] 7.1 7.0 -6.6 2.7 7.2 11.5 21.0 1.1 42 - theta[5] 5.1 6.8 -9.5 0.7 5.2 9.7 18.1 1.0 83 - theta[6] 5.7 7.3 -9.7 1.0 6.2 10.2 20.0 1.0 56 - theta[7] 10.4 7.3 -2.1 5.3 9.8 15.3 25.5 1.1 27 - theta[8] 8.3 8.4 -6.6 2.8 8.1 12.7 26.2 1.0 64 - mu.theta 7.6 5.9 -3.0 3.7 8.0 11.0 19.5 1.1 35 - sigma.theta 6.7 5.6 0.3 2.8 5.1 9.2 21.2 1.1 46 - deviance 60.8 2.5 57.0 59.1 60.2 62.1 66.6 1.0 170 - pD = 3 and DIC = 63.8 (using the rule, pD = var(deviance)/2) - - For each parameter, n.eff is a crude measure of effective sample size, - and Rhat is the potential scale reduction factor (at convergence, Rhat=1). - DIC is an estimate of expected predictive error (lower deviance is better). -\end{Code} -\normalsize -Additionally, the user can generate a plot of the results by typing \verb+plot(schools.sim)+. -The resulting plot is given in Figure~\ref{plot}. -\begin{figure}[t] -\begin{center} -\fbox{ -\includegraphics[width=0.9\textwidth]{plot} -} \caption{\label{plot}Plot produced by \RW{} package for the schools example. } -\end{center} -\end{figure} -In this plot, the left column shows a quick -summary of inference and convergence ($\widehat{R}$ is close to 1.0 for all parameters, indicating good mixing of -the three chains and thus approximate convergence); and the right column shows inferences for each set of -parameters. As can be seen in the right column, \RW{} uses the parameter names in \WinBUGS{} to structure the -output into scalar, vector, and arrays of parameters, in addition to storing the parameters as a long vector. - -For the interpretation of these results see \citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). - -\subsection{Leukaemia registration data}\label{Leukaemia2} -The leukaemia registration data (see Section \ref{Leukaemia}) are used to show data modeling and output reading -into \R{} using the \pkg{coda} package. A simple model for these data looks as follows: -\begin{Code} -model{ - beta.0 ~ dgamma(a.0, tau.0) - beta.benz ~ dgamma(a.benz, tau.benz) - a.0 <- 0.575 - tau.0 <- a.0*2 - a.benz <- 0.575 - tau.benz <- a.benz*2 -\end{Code} -\clearpage -\begin{Code} - for (i in 1:I) - { - count[i] ~ dpois(lambda[i]) - lambda[i] <- p[i]*expect[i] - for (j in 1:J) - { - prop[j,i] <- gamma[j,i]*(benz[j] - benzbar) - } - p[i]<- beta.0 + beta.benz*sum(prop[,i]) - } - } -\end{Code} -Here \verb+count+ denotes the number of observed incidences of childhood leukaemia in ward~\verb+i+. These are -assumed to be Poisson distributed with mean \verb+lambda+ depending on the number of expected cases \verb+expect+ -in ward \verb+i+ and an area-specific risk rate \verb+p+. For calculation of this area specific risk rate we use -an intercept \verb+beta.0+ and a term depending on the weighted sum of benzene emissions \verb+benz+ in each grid -cell \verb+j+. The weights are chosen proportional to the amount of area that ward \verb+i+ and grid cell \verb+j+ have -in common. - -In \R{} we can define all these data and then initialize the model. The data needed for this example are -\begin{description} -\item[\tt{benzbar}:] arithmetic mean of all benzene values, -\item[\tt{benz}:] a vector containing benzene emissions of all 2132 grid cells, -\item[\tt{expect}:] expected number of cases of childhood leukaemia in each of the 873 wards, -\item[\tt{count}:] observed number of childhood leukaemia in these wards, -\item[\tt{gamma}:] a $2132\times 873$ matrix containing the amount of area each grid cell and each ward have in common, -\item[\tt{J}:] total number of grid cells, i.e.~2132, and -\item[\tt{I}:] total number of ward cells, i.e.~873. -\end{description} -The parameters we want to store are regression coefficients \verb+beta.0+ and \verb+beta.benz+ as well as -\verb+p+, the area specific relative risk compared to the reference rate. This reference rate was used to -calculate the expected number of cases in each ward. - -Since we want to use the \pkg{coda} package for reading the data into \WinBUGS{}, we specify \verb+codaPkg = TRUE+ -in the \verb+bugs()+ call: -\begin{Code} - > data <- list(benzbar = mean(benz), benz = benz, expect = expect, - + count = count, gamma = gamma, J = J, I = I) - > parameters <- c("beta.0", "beta.benz", "p") - > inits1 <- list(beta.0 = 1, beta.benz = 1) - > inits2 <- list(beta.0 = 0.5, beta.benz = 0.5) - > inits <- list(inits1, inits2) - > model <- bugs(data, inits, parameters, model.file = "c:/model.bug", - + n.chains = 2, n.iter = 8000, n.burnin = 5000, n.thin = 1, - + codaPkg = TRUE, bugs.directory = "c:/Program File... [truncated message content] |
From: <snt...@us...> - 2010-08-16 22:30:25
|
Revision: 166 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=166&view=rev Author: snthomas99 Date: 2010-08-16 22:30:16 +0000 (Mon, 16 Aug 2010) Log Message: ----------- Fixed log file output in linux and added directory location to bugs fail message Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/R/bugs.run.R trunk/R2OpenBUGS/R/bugs.script.R trunk/R2OpenBUGS/inst/NEWS Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2010-08-10 02:53:35 UTC (rev 165) +++ trunk/R2OpenBUGS/DESCRIPTION 2010-08-16 22:30:16 UTC (rev 166) @@ -1,7 +1,7 @@ Package: R2OpenBUGS Title: Running OpenBUGS from R / S-PLUS Date: 2010-08-5 -Version: 1.0-0 +Version: 3.0-1 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. Modified: trunk/R2OpenBUGS/R/bugs.run.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.run.R 2010-08-10 02:53:35 UTC (rev 165) +++ trunk/R2OpenBUGS/R/bugs.run.R 2010-08-16 22:30:16 UTC (rev 166) @@ -43,5 +43,6 @@ tmp <- scan("CODAchain1.txt", character(), sep="\n") } tmp<-tmp[1:min(100,length(tmp))] - if(length(grep("OpenBUGS did not run correctly", tmp)) > 0) stop("Look at the log file and\ntry again with 'debug=TRUE' to figure out what went wrong within OpenBUGS.") + if(length(grep("OpenBUGS did not run correctly", tmp)) > 0) stop(paste("Look at the log file in ",getwd(), + " and\ntry again with 'debug=TRUE' to figure out what went wrong within OpenBUGS.")) } Modified: trunk/R2OpenBUGS/R/bugs.script.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.script.R 2010-08-10 02:53:35 UTC (rev 165) +++ trunk/R2OpenBUGS/R/bugs.script.R 2010-08-16 22:30:16 UTC (rev 166) @@ -49,7 +49,7 @@ thinUpdate <- paste("modelUpdate(", n.burnin, ",", n.thin, ")\n", sep="") cat( - "modelDisplay('log')\n", + if(.Platform$OS.type == "windows" | useWINE) "modelDisplay('log')\n", "modelCheck('", model, "')\n", "modelData('", data, "')\n", "modelCompile(", n.chains, ")\n", Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2010-08-10 02:53:35 UTC (rev 165) +++ trunk/R2OpenBUGS/inst/NEWS 2010-08-16 22:30:16 UTC (rev 166) @@ -1,12 +1,11 @@ Changes to R2OpenBUGS: -===================== -First version 1.0.0 -- Converted R2WinBUGS to use OpenBUGS scripts. Eliminated BRugs calls. +====================== -Changes to R2WinBUGS: -===================== +Update 3.0-1 +- Converted R2WinBUGS to use OpenBUGS scripts and eliminated BRugs calls. -Update 2.1-17 + +Update 2.1-17 - fix as.bugs.array as reported by S. McKay Curtis Update 2.1-16 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2010-09-02 16:44:25
|
Revision: 169 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=169&view=rev Author: snthomas99 Date: 2010-09-02 16:44:16 +0000 (Thu, 02 Sep 2010) Log Message: ----------- added invisible to system call in bugs.run to display openbugs gui Modified Paths: -------------- trunk/R2OpenBUGS/R/bugs.R trunk/R2OpenBUGS/R/bugs.run.R trunk/R2OpenBUGS/man/bugs.run.Rd Modified: trunk/R2OpenBUGS/R/bugs.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.R 2010-09-01 01:42:02 UTC (rev 168) +++ trunk/R2OpenBUGS/R/bugs.R 2010-09-02 16:44:16 UTC (rev 169) @@ -140,7 +140,7 @@ summary.only=summary.only, save.history=save.history, bugs.data.file = bugs.data.file, bugs.inits.files = bugs.inits.files, over.relax = over.relax) - bugs.run(n.burnin, OpenBUGS.pgm, WINE=WINE, useWINE=useWINE, + bugs.run(n.burnin, OpenBUGS.pgm, debug=debug, WINE=WINE, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) if(codaPkg) return(file.path(getwd(), paste("CODAchain", 1:n.chains, ".txt", sep=""))) Modified: trunk/R2OpenBUGS/R/bugs.run.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.run.R 2010-09-01 01:42:02 UTC (rev 168) +++ trunk/R2OpenBUGS/R/bugs.run.R 2010-09-02 16:44:16 UTC (rev 169) @@ -1,5 +1,5 @@ "bugs.run" <- - function(n.burnin, OpenBUGS.pgm, + function(n.burnin, OpenBUGS.pgm, debug=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL) { @@ -31,7 +31,10 @@ }else{ bugsCall<-paste(OpenBUGS.pgm,"<","script.txt",">",file.path(getwd(),"log.txt")) } - temp <- system(bugsCall) + if((.Platform$OS.type == "windows" | useWINE==TRUE) & debug){ + temp <- system(bugsCall,invisible=FALSE) + }else temp <- system(bugsCall) + if(temp == -1) stop("Error in bugs.run().") Modified: trunk/R2OpenBUGS/man/bugs.run.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.run.Rd 2010-09-01 01:42:02 UTC (rev 168) +++ trunk/R2OpenBUGS/man/bugs.run.Rd 2010-09-02 16:44:16 UTC (rev 169) @@ -7,13 +7,14 @@ internal use} \usage{ -bugs.run(n.burnin, OpenBUGS.pgm, +bugs.run(n.burnin, OpenBUGS.pgm, debug=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL) } \arguments{ \item{n.burnin}{length of burn in} \item{OpenBUGS.pgm}{Full path to the \pkg{OpenBUGS} executable or shell script} + \item{debug}{When debug=T, the OpenBUGS gui is displayed during execution. there is no effect with linux execution} \item{useWINE}{as in \code{\link{bugs}} meta function} \item{WINE}{as in \code{\link{bugs}} meta function} \item{newWINE}{as in \code{\link{bugs}} meta function} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2010-09-16 02:54:39
|
Revision: 172 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=172&view=rev Author: snthomas99 Date: 2010-09-16 02:54:33 +0000 (Thu, 16 Sep 2010) Log Message: ----------- Corrected bug in bugs.log and corrected some documentation Modified Paths: -------------- trunk/R2OpenBUGS/R/bugs.log.R trunk/R2OpenBUGS/man/bugs.data.Rd trunk/R2OpenBUGS/man/bugs.inits.Rd trunk/R2OpenBUGS/man/read.bugs.Rd Modified: trunk/R2OpenBUGS/R/bugs.log.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.log.R 2010-09-14 15:19:26 UTC (rev 171) +++ trunk/R2OpenBUGS/R/bugs.log.R 2010-09-16 02:54:33 UTC (rev 172) @@ -29,7 +29,7 @@ dimnames(m) <- list(row.names, col.names) return(m) } - stats <- extract(log.txt, "Node statistics") - DIC <- extract(log.txt, "DIC", skip=1, empty.left.col=FALSE) + stats <- extract(log.txt, "Summary statistics") + DIC <- extract(log.txt, "Deviance information", skip=0, empty.left.col=FALSE) list(stats=stats, DIC=DIC) } Modified: trunk/R2OpenBUGS/man/bugs.data.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.data.Rd 2010-09-14 15:19:26 UTC (rev 171) +++ trunk/R2OpenBUGS/man/bugs.data.Rd 2010-09-16 02:54:33 UTC (rev 172) @@ -2,8 +2,7 @@ \alias{bugs.data} \title{Writing input for OpenBUGS} -\description{Write file for \pkg{OpenBUGS} to read - for - internal use.} +\description{Write file for \pkg{OpenBUGS} to read.} \usage{ bugs.data(data, dir = getwd(), digits = 5, data.file = "data.txt") @@ -23,6 +22,5 @@ the data file is written} \seealso{The main function to be called by the user is \code{\link{bugs}}.} -\keyword{internal} \keyword{file} \keyword{IO} Modified: trunk/R2OpenBUGS/man/bugs.inits.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.inits.Rd 2010-09-14 15:19:26 UTC (rev 171) +++ trunk/R2OpenBUGS/man/bugs.inits.Rd 2010-09-16 02:54:33 UTC (rev 172) @@ -1,9 +1,9 @@ \name{bugs.inits} \alias{bugs.inits} -\title{Writing input for OpenBUGS - intended for internal use only} +\title{Writing input for OpenBUGS } \description{Write files \file{inits1.txt}, \file{inits2.txt}, etc., in - the working directory for \pkg{OpenBUGS} to read - for internal use.} + the working directory for \pkg{OpenBUGS} to read } \usage{ bugs.inits(inits, n.chains, digits, @@ -23,6 +23,5 @@ are written} \seealso{The main function to be called by the user is \code{\link{bugs}}.} -\keyword{internal} \keyword{IO} \keyword{file} Modified: trunk/R2OpenBUGS/man/read.bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/read.bugs.Rd 2010-09-14 15:19:26 UTC (rev 171) +++ trunk/R2OpenBUGS/man/read.bugs.Rd 2010-09-16 02:54:33 UTC (rev 172) @@ -16,7 +16,7 @@ \code{\link{bugs}} in call such as \code{bugs(....., codaPkg=TRUE, .....)}). Each of the files contains coda output for one chain produced by \pkg{OpenBUGS}, the \emph{directory} name of the corresponding - file \file{codaIndex.txt} is extracted from the first element of + file \file{CODAindex.txt} is extracted from the first element of \code{codafiles}.} \item{...}{further arguments to be passed to \code{\link[coda]{read.coda}}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2010-10-02 12:53:22
|
Revision: 174 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=174&view=rev Author: snthomas99 Date: 2010-10-02 12:53:15 +0000 (Sat, 02 Oct 2010) Log Message: ----------- trying to add validation code to R2OpenBUGS respository Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/NAMESPACE trunk/R2OpenBUGS/R/bugs.R trunk/R2OpenBUGS/R/bugs.run.R trunk/R2OpenBUGS/R/bugs.script.R trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/bugs.inits.Rd Added Paths: ----------- trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R Added: trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R (rev 0) +++ trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R 2010-10-02 12:53:15 UTC (rev 174) @@ -0,0 +1,49 @@ +library(R2OpenBUGS) + +## Selected examples which take a few seconds in total to run + +test.models <- c("Air", "Asia", "Beetles", "BiRats", "Camel", + "Dugongs", "Dyes", "Equiv", "Eyes", + "Line", "OtreesMVN", "Rats", "Stacks", + "Surgical", "Surgicalrand") + +test.params <- list(Air = c("X", "theta"), + Asia = c("bronchitis", "either", "lung.cancer"), + Beetles = c("alpha", "beta", "rhat"), + BiRats = c("mu.beta", "sigma"), + Camel = c("Sigma2", "rho", "tau"), + Dugongs = c("U3","alpha", "beta", "gamma", "sigma"), + Dyes = c("sigma2.btw", "sigma2.with", "theta"), + Equiv = c("equiv", "mu", "phi", "pi","sigma1", "sigma2", "theta"), + Eyes = c("P", "lambda", "sigma"), + Line = c("alpha", "beta", "sigma"), + OtreesMVN = c("mu","sigma", "sigmaC"), + Rats = c("alpha0", "beta.c", "sigma"), + Stacks = c("b", "b0", "outlier[21]","outlier[3]", "outlier[4]", "sigma"), + Surgical = "p", + Surgicalrand = c("p","pop.mean", "sigma") + ) + +test.modelfile = paste(test.models,"model.txt",sep="") +test.modelfile<-file.path('C:/Program Files/OpenBUGS/OpenBUGS312/Examples',test.modelfile) +test.datafile = paste(test.models,"data.txt",sep="") +test.datafile<-file.path('C:/Program Files/OpenBUGS/OpenBUGS312/Examples',test.datafile) +test.inits = paste(test.models,"inits.txt",sep="") +test.inits<-file.path('C:/Program Files/OpenBUGS/OpenBUGS312/Examples',test.inits) + +### Test for posterior means within 1 percent of previously saved values + +res.true <- vector(mode="list",length=length(test.modelfile)) +for (i in seq(along=test.models)) { + res.true[[i]]<-round(bugs(data=test.datafile[i], inits=test.inits[i], + para=test.params[[test.models[i]]],model.file=test.modelfile[i], + n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE)$summary,5) + +} + +dput(res.true,'validOpenBUGSResults.R') + + + + + Property changes on: trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R ___________________________________________________________________ Added: svn:executable + * Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2010-10-02 12:50:38 UTC (rev 173) +++ trunk/R2OpenBUGS/DESCRIPTION 2010-10-02 12:53:15 UTC (rev 174) @@ -1,7 +1,7 @@ Package: R2OpenBUGS Title: Running OpenBUGS from R / S-PLUS -Date: 2010-08-5 -Version: 3.0-1 +Date: 2010-09-30 +Version: 3.1-2 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. Modified: trunk/R2OpenBUGS/NAMESPACE =================================================================== --- trunk/R2OpenBUGS/NAMESPACE 2010-10-02 12:50:38 UTC (rev 173) +++ trunk/R2OpenBUGS/NAMESPACE 2010-10-02 12:53:15 UTC (rev 174) @@ -10,7 +10,8 @@ bugs.log, monitor, as.bugs.array, - write.model) + write.model, + validateInstallOpenBUGS) S3method(print, bugs) S3method(plot, bugs) Modified: trunk/R2OpenBUGS/R/bugs.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.R 2010-10-02 12:50:38 UTC (rev 173) +++ trunk/R2OpenBUGS/R/bugs.R 2010-10-02 12:53:15 UTC (rev 174) @@ -5,7 +5,7 @@ OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, paste("C:/Program Files/OpenBUGS/OpenBUGS", version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), - version='311', + version='312', working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, Modified: trunk/R2OpenBUGS/R/bugs.run.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.run.R 2010-10-02 12:50:38 UTC (rev 173) +++ trunk/R2OpenBUGS/R/bugs.run.R 2010-10-02 12:53:15 UTC (rev 174) @@ -27,6 +27,7 @@ native2win(file.path(getwd(), "script.txt"), useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH), "\" /", sep="") + if(!debug)bugsCall<-paste(bugsCall,"HEADLESS",sep="") if(useWINE) bugsCall <- paste(WINE, bugsCall) }else{ bugsCall <- paste(OpenBUGS.pgm, "<", "script.txt", ">", file.path(getwd(), "log.txt")) Modified: trunk/R2OpenBUGS/R/bugs.script.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.script.R 2010-10-02 12:50:38 UTC (rev 173) +++ trunk/R2OpenBUGS/R/bugs.script.R 2010-10-02 12:53:15 UTC (rev 174) @@ -46,7 +46,8 @@ bugs.seed.cmd <- paste("modelSetRN(", bugs.seed, ")\n", sep="") } - thinUpdate <- paste("modelUpdate(", n.burnin, ",", n.thin, ")\n", sep="") + thinUpdate <- paste("modelUpdate(", formatC(n.burnin, format='d'), ",", n.thin, + ",",formatC(n.burnin, format='d'), ")\n", sep="") cat( if(.Platform$OS.type == "windows" | useWINE) "modelDisplay('log')\n", @@ -61,7 +62,8 @@ savelist, summarylist, if(DIC) "dicSet()\n", - "modelUpdate(", n.iter-n.burnin, ",", n.thin, ")\n", + "modelUpdate(", formatC(n.iter-n.burnin, format='d'), ",", n.thin, + ",",formatC(n.iter-n.burnin, format='d'),")\n", "samplesCoda('*', '", coda, "')\n", "summaryStats('*')\n", if(DIC) "dicStats()\n", Modified: trunk/R2OpenBUGS/man/bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.Rd 2010-10-02 12:50:38 UTC (rev 173) +++ trunk/R2OpenBUGS/man/bugs.Rd 2010-10-02 12:53:15 UTC (rev 174) @@ -13,7 +13,7 @@ OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, paste("C:/Program Files/OpenBUGS/OpenBUGS", version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), - version='311', + version='312', working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, @@ -100,7 +100,9 @@ \item{WINEPATH}{Character, path to \file{winepath} binary file, it is tried hard (by a guess and the utilities \code{which} and \code{locate}) to get the information automatically if not given.} - \item{bugs.seed}{Random seed for \pkg{OpenBUGS}}. + \item{bugs.seed}{Random seed for \pkg{OpenBUGS}. Must be an integer between 1-14. Seed + specification changed between WinBUGS and OpenBUGS; see the OpenBUGS documentation for + details}. \item{summary.only}{If \code{TRUE}, only a parameter summary for very quick analyses is given, temporary created files are not removed in that case.} \item{save.history}{If \code{TRUE} (the default), trace plots are generated at the end.} Modified: trunk/R2OpenBUGS/man/bugs.inits.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.inits.Rd 2010-10-02 12:50:38 UTC (rev 173) +++ trunk/R2OpenBUGS/man/bugs.inits.Rd 2010-10-02 12:53:15 UTC (rev 174) @@ -16,7 +16,7 @@ \item{n.chains}{number of Markov chains} \item{digits}{number of significant digits used for \pkg{OpenBUGS} input, see \code{\link{formatC}}} - \item{inits.file}{name for the inits files R write the inits into.} + \item{inits.files}{name for the inits files R write the inits into.} } \value{Vector of names of \code{inits.files}; as a side effect, the inits files \file{inits*.txt} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2011-03-21 19:13:34
|
Revision: 181 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=181&view=rev Author: snthomas99 Date: 2011-03-21 19:13:27 +0000 (Mon, 21 Mar 2011) Log Message: ----------- added saveExec and restart features for use with OpenBUGS >3.2.1 Modified Paths: -------------- trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/R/bugs.R trunk/R2OpenBUGS/R/bugs.script.R trunk/R2OpenBUGS/R/print.bugs.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/validOpenBUGSResults.R trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/bugs.script.Rd Modified: trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/CreatevalidateOpenBUGS.R 2011-03-21 19:13:27 UTC (rev 181) @@ -25,11 +25,11 @@ ) test.modelfile = paste(test.models,"model.txt",sep="") -test.modelfile<-file.path('C:/Program Files/OpenBUGS/OpenBUGS312/Examples',test.modelfile) +test.modelfile<-file.path('C:/Program Files/OpenBUGS/OpenBUGS321/Examples',test.modelfile) test.datafile = paste(test.models,"data.txt",sep="") -test.datafile<-file.path('C:/Program Files/OpenBUGS/OpenBUGS312/Examples',test.datafile) +test.datafile<-file.path('C:/Program Files/OpenBUGS/OpenBUGS321/Examples',test.datafile) test.inits = paste(test.models,"inits.txt",sep="") -test.inits<-file.path('C:/Program Files/OpenBUGS/OpenBUGS312/Examples',test.inits) +test.inits<-file.path('C:/Program Files/OpenBUGS/OpenBUGS321/Examples',test.inits) ### Test for posterior means within 1 percent of previously saved values Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/DESCRIPTION 2011-03-21 19:13:27 UTC (rev 181) @@ -1,7 +1,7 @@ Package: R2OpenBUGS Title: Running OpenBUGS from R / S-PLUS -Date: 2010-09-30 -Version: 3.1-2 +Date: 2011-03-01 +Version: 3.2-1 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. @@ -12,9 +12,8 @@ it is possible to call a BUGS model, summarize inferences and convergence in a table and graph, and save the simulations in arrays for easy access in R / S-PLUS. -Depends: R (>= 2.9.2), coda (>= 0.11-0) -SystemRequirements: OpenBUGS >=3.1 -URL: http://www.stat.columbia.edu/~gelman/bugsR/ +Depends: R (>= 2.10.1), coda (>= 0.11-0) +SystemRequirements: OpenBUGS >=3.2.1 Maintainer: Uwe Ligges <li...@st...> License: GPL-2 Dialect: R, S-PLUS Modified: trunk/R2OpenBUGS/R/bugs.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.R 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/R/bugs.R 2011-03-21 19:13:27 UTC (rev 181) @@ -1,11 +1,12 @@ "bugs" <- -function(data, inits, parameters.to.save, n.iter, model.file="model.bug", +function(data, inits, parameters.to.save, n.iter, model.file="model.txt", n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, + saveExec=FALSE,restart=FALSE, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, paste("C:/Program Files/OpenBUGS/OpenBUGS", version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), - version='312', + version='321', working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, @@ -36,6 +37,11 @@ if(! bugs.seed %in% c(1:14))stop("OpenBUGS seed must be integer in 1-14") + if(!is.function(model.file) && + length(grep("\\.bug", tolower(model.file))))stop("model.file must be renamed with .txt rather than .bug") + + if(is.null(working.directory) && (saveExec || restart))stop("The working directory must be specified when saveExec or restart is TRUE") + if(!is.null(working.directory)) { working.directory <- path.expand(working.directory) savedWD <- getwd() @@ -120,7 +126,7 @@ } if(DIC) parameters.to.save <- c(parameters.to.save, "deviance") - ## Model files with extension ".bug" need to be renamed to ".txt" + ## Model files must have extension ".txt" if(!length(grep("\\.txt$", tolower(model.file)))) { new.model.file <- paste(basename(model.file), ".txt", sep="") if(!is.null(working.directory)) new.model.file <- file.path(working.directory, new.model.file) @@ -129,11 +135,18 @@ } else { new.model.file <- model.file } + + ## Create a filename model.file + .bug + model.file.bug<-gsub('\\.txt','.bug',basename(new.model.file)) + + if(restart && !file.exists(model.file.bug))stop("The .bug restart file was not found in the working directory") + if(useWINE){ ## Some tweaks for wine (particularly required for Mac OS) new.model.file <- gsub("//", "/", new.model.file) } bugs.script(parameters.to.save, n.chains, n.iter, n.burnin, n.thin, + saveExec,restart,model.file.bug, new.model.file, debug=debug, is.inits=!is.null(inits), DIC=DIC, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH, bugs.seed=bugs.seed, Modified: trunk/R2OpenBUGS/R/bugs.script.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.script.R 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/R/bugs.script.R 2011-03-21 19:13:27 UTC (rev 181) @@ -1,6 +1,7 @@ "bugs.script" <- function(parameters.to.save, n.chains, n.iter, n.burnin, - n.thin, model.file, debug=FALSE, is.inits, + n.thin, saveExec, restart, model.file.bug, + model.file, debug=FALSE, is.inits, DIC=FALSE, useWINE=FALSE, newWINE=TRUE, WINEPATH=NULL, bugs.seed=NULL, summary.only=FALSE, save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), @@ -26,6 +27,9 @@ coda <- file.path(working.directory, "/") coda <- native2win(coda, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) + model.file.bug<-file.path(working.directory,model.file.bug) + model.file.bug<-native2win(model.file.bug, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) + logFile <- file.path(working.directory, "log.odc") logFile <- native2win(logFile, useWINE=useWINE, newWINE=newWINE, WINEPATH=WINEPATH) logFileTxt <- file.path(working.directory, "log.txt") @@ -51,30 +55,40 @@ cat( if(.Platform$OS.type == "windows" | useWINE) "modelDisplay('log')\n", - "modelCheck('", model, "')\n", - "modelData('", data, "')\n", - "modelCompile(", n.chains, ")\n", - bugs.seed.cmd, - if(is.inits) initlist, - "modelGenInits()\n", - if(over.relax) 'over.relax("yes")\n', + if(restart)c("modelInternalize('", model.file.bug, "')\n"), + if(restart && n.burnin>0)c( + "samplesClear('*')\n", + "summaryClear('*')\n" + ), + if(!restart)c( + "modelCheck('", model, "')\n", + "modelData('", data, "')\n", + "modelCompile(", n.chains, ")\n" + ), + if(!restart)bugs.seed.cmd, + if(!restart && is.inits) initlist, + if(!restart)"modelGenInits()\n", + if(!restart && over.relax) 'over.relax("yes")\n', + if((!restart) || (n.burnin>0))c( thinUpdate, savelist, - summarylist, - if(DIC) "dicSet()\n", + summarylist + ), + if(((!restart) || (n.burnin>0)) && DIC) "dicSet()\n", "modelUpdate(", formatC(n.iter-n.burnin, format='d'), ",", n.thin, ",",formatC(n.iter-n.burnin, format='d'),")\n", "samplesCoda('*', '", coda, "')\n", "summaryStats('*')\n", if(DIC) "dicStats()\n", if (save.history) "samplesHistory('*')\n", + if(saveExec)c("modelExternalize('",model.file.bug,"')\n"), if(.Platform$OS.type == "windows" | useWINE) c("modelSaveLog('", logFile, "')\n", "modelSaveLog('", logFileTxt, "')\n"), file=script, sep="", append=FALSE) - if(!debug) cat("modelQuit('y')\n", file=script, append=TRUE) + if(!debug) cat("modelQuit('y')\n", file=script, append=TRUE) - sims.files <- paste(coda, "CODAchain", 1:n.chains, ".txt", sep="") + sims.files <- paste("CODAchain", 1:n.chains, ".txt", sep="") for(i in 1:n.chains) cat("OpenBUGS did not run correctly.\n", file=sims.files[i], append=FALSE) } Modified: trunk/R2OpenBUGS/R/print.bugs.R =================================================================== --- trunk/R2OpenBUGS/R/print.bugs.R 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/R/print.bugs.R 2011-03-21 19:13:27 UTC (rev 181) @@ -7,10 +7,10 @@ cat("Inference for Bugs model at \"", x$model.file, "\", ", sep="") if(!is.null(x$program)) cat("fit using ", x$program, ",", sep="") - cat("\n ", x$n.chains, " chains, each with ", x$n.iter, + cat("\nCurrent: ", x$n.chains, " chains, each with ", x$n.iter, " iterations (first ", x$n.burnin, " discarded)", sep = "") if(x$n.thin > 1) cat(", n.thin =", x$n.thin) - cat("\n n.sims =", x$n.sims, "iterations saved\n") + cat("\nCumulative: n.sims =", x$n.sims, "iterations saved\n") print(round(x$summary, digits.summary), ...) if(x$n.chains > 1) { Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/inst/NEWS 2011-03-21 19:13:27 UTC (rev 181) @@ -1,6 +1,15 @@ Changes to R2OpenBUGS: ====================== +Update 3.2-1 +- Added saveExec and restart options to the bugs function that uses + the OpenBUGS internalize/externalize feature to allow a user to + store the state of the OpenBUGS execution and continue + execution after checking results in R. + +Update 3.1-2.1 +- Corrected bug in WINE execution + Update 3.1-2 - Set default version of OpenBUGS to 3.1.2 - Fixed upper/lower case error in read.bugs Modified: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/validOpenBUGSResults.R =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/validOpenBUGSResults.R 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/validOpenBUGSResults.R 2011-03-21 19:13:27 UTC (rev 181) @@ -20,116 +20,111 @@ 53.13, 55.19025, 60.39, 59.36), .Dim = c(10L, 7L), .Dimnames = list( c("alpha", "beta", "rhat[1]", "rhat[2]", "rhat[3]", "rhat[4]", "rhat[5]", "rhat[6]", "rhat[7]", "rhat[8]"), c("mean", "sd", - "2.5%", "25%", "50%", "75%", "97.5%"))), structure(c(106.56037, -6.18615, 6.15259, 2.34291, 0.10596, 0.47872, 101.9, 5.977, 5.304, -105, 6.117, 5.817, 106.5, 6.187, 6.1185, 108.1, 6.255, 6.452, -111.1025, 6.397, 7.177), .Dim = c(3L, 7L), .Dimnames = list(c("mu.beta[1]", + "2.5%", "25%", "50%", "75%", "97.5%"))), structure(c(106.56034, +6.18619, 6.15206, 2.34366, 0.10595, 0.47828, 101.9, 5.976, 5.30397, +105, 6.117, 5.818, 106.5, 6.187, 6.118, 108.1, 6.254, 6.451, +111.2, 6.397, 7.18002), .Dim = c(3L, 7L), .Dimnames = list(c("mu.beta[1]", "mu.beta[2]", "sigma"), c("mean", "sd", "2.5%", "25%", "50%", -"75%", "97.5%"))), structure(c(3.2445, 0.02929, 0.02929, 3.20989, -0.0081, 0.85113, -0.00963, -0.00963, 0.86281, 2.1011, 2.50802, -2.50802, 2.13451, 0.65922, 0.50825, 0.71045, 0.71045, 0.50962, -1.14395, -4.77203, -4.77203, 1.101, -0.9073, 0.22139, -1.40502, --1.40502, 0.2234, 1.926, -1.638, -1.638, 1.917, -0.66862, 0.49587, --0.48102, -0.48102, 0.50065, 2.6875, 0.04017, 0.04017, 2.663, -0.01868, 0.7305, -0.00773, -0.00773, 0.74375, 3.89225, 1.715, -1.715, 3.82125, 0.68585, 1.07, 0.4545, 0.4545, 1.10125, 8.5671, -4.82202, 4.82202, 8.5781, 0.9098, 2.13205, 1.40205, 1.40205, -2.18202), .Dim = c(9L, 7L), .Dimnames = list(c("Sigma2[1,1]", -"Sigma2[1,2]", "Sigma2[2,1]", "Sigma2[2,2]", "rho", "tau[1,1]", -"tau[1,2]", "tau[2,1]", "tau[2,2]"), c("mean", "sd", "2.5%", -"25%", "50%", "75%", "97.5%"))), structure(c(1.85767, 2.64973, -0.96989, 0.86209, 0.09887, 0.26392, 0.07107, 0.07684, 0.03153, -0.0148, 1.323, 2.528, 0.8224, 0.7898, 0.07502, 1.701, 2.604, -0.9188, 0.8457, 0.08841, 1.854, 2.642, 0.9689, 0.8646, 0.09723, -2.026, 2.691, 1.018, 0.8836, 0.1074, 2.36802, 2.802, 1.122, 0.9144, -0.1326), .Dim = c(5L, 7L), .Dimnames = list(c("U3", "alpha", -"beta", "gamma", "sigma"), c("mean", "sd", "2.5%", "25%", "50%", -"75%", "97.5%"))), structure(c(2399.81116, 2970.23731, 1526.76347, -9152.71052, 1072.50035, 22.42927, 0.01173, 1559, 1483, 573.04999, -2217, 1515, 1388.49991, 2748, 1526, 2769.24997, 3466, 1539, 10140.49952, -5596.37451, 1570), .Dim = c(3L, 7L), .Dimnames = list(c("sigma2.btw", -"sigma2.with", "theta"), c("mean", "sd", "2.5%", "25%", "50%", -"75%", "97.5%"))), structure(c(0.99767, 1.43476, -0.00865, -0.1804, -0.11034, 0.1406, 0.99274, 0.04825, 0.0552, 0.05217, 0.05175, -0.03333, 0.05436, 0.05185, 1, 1.327, -0.113, -0.2831, 0.06521, -0.04439, 0.8931, 1, 1.4, -0.04039, -0.2121, 0.08657, 0.1057, -0.9604, 1, 1.435, -0.00813, -0.1808, 0.1033, 0.1356, 0.9919, -1, 1.469, 0.02322, -0.1495, 0.12722, 0.169, 1.023, 1, 1.544, -0.0942, -0.07637, 0.1929, 0.2663, 1.099), .Dim = c(7L, 7L), .Dimnames = list( - c("equiv", "mu", "phi", "pi", "sigma1", "sigma2", "theta" - ), c("mean", "sd", "2.5%", "25%", "50%", "75%", "97.5%"))), - structure(c(0.6029, 0.3971, 536.75923, 548.90934, 3.75937, - 0.08421, 0.08421, 0.92221, 1.21365, 0.6111, 0.4326, 0.2359, - 535.1, 546.5, 2.917, 0.54737, 0.34, 536.2, 548.2, 3.36175, - 0.6039, 0.3961, 536.7, 548.9, 3.654, 0.66, 0.45262, 537.3, - 549.7, 4.019, 0.7641, 0.5674, 538.6, 551.2, 5.27107), .Dim = c(5L, - 7L), .Dimnames = list(c("P[1]", "P[2]", "lambda[1]", "lambda[2]", - "sigma"), c("mean", "sd", "2.5%", "25%", "50%", "75%", "97.5%" - ))), structure(c(2.99564, 0.79689, 1.02513, 0.56926, 0.39621, - 0.72729, 1.914, 0.04475, 0.4099, 2.743, 0.6218, 0.625, 2.997, - 0.7995, 0.82675, 3.255, 0.9782, 1.16825, 4.08502, 1.541, - 2.82), .Dim = c(3L, 7L), .Dimnames = list(c("alpha", "beta", - "sigma"), c("mean", "sd", "2.5%", "25%", "50%", "75%", "97.5%" - ))), structure(c(5.26374, 2.19866, -5.88024, 0.25869, 0.27042, - 0.2265, 7.82296, 0.1335, 0.16648, 0.14127, 0.11614, 0.137, - 0.1076, 1.18539, 4.996, 1.87997, -6.165, 0.1277, 0.1201, - 0.1085, 5.90897, 5.187, 2.094, -5.964, 0.1849, 0.1843, 0.1586, - 6.984, 5.264, 2.197, -5.879, 0.2318, 0.24, 0.2008, 7.684, - 5.342, 2.3, -5.795, 0.2995, 0.3184, 0.26312, 8.521, 5.529, - 2.535, -5.603, 0.54651, 0.6038, 0.495, 10.5), .Dim = c(7L, - 7L), .Dimnames = list(c("mu[1]", "mu[2]", "mu[3]", "sigma[1]", - "sigma[2]", "sigma[3]", "sigmaC"), c("mean", "sd", "2.5%", - "25%", "50%", "75%", "97.5%"))), structure(c(106.61227, 6.18568, - 6.0953, 3.63673, 0.1075, 0.46858, 99.40975, 5.97597, 5.27197, - 104.2, 6.114, 5.776, 106.6, 6.187, 6.058, 109.1, 6.258, 6.386, - 113.6, 6.394, 7.106), .Dim = c(3L, 7L), .Dimnames = list( - c("alpha0", "beta.c", "sigma"), c("mean", "sd", "2.5%", - "25%", "50%", "75%", "97.5%"))), structure(c(0.71462, - 1.2978, -0.15277, -39.85965, 0.0106, 0.05567, 0.3192, 0.0106, - 0.05567, 0.3192, 0.0106, 0.05567, 0.3192, 3.38943, 0.14307, - 0.38863, 0.16594, 12.71407, 0.10241, 0.22928, 0.46618, 0.10241, - 0.22928, 0.46618, 0.10241, 0.22928, 0.46618, 0.62795, 0.43279, - 0.529, -0.4842, -65.22025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.417, - 0.62217, 1.049, -0.26012, -48.11, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2.945, 0.7155, 1.294, -0.15245, -39.96, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 3.299, 0.8063, 1.545, -0.04546, -31.5775, 0, - 0, 1, 0, 0, 1, 0, 0, 1, 3.742, 0.9984, 2.076, 0.1763, -14.38925, - 0, 1, 1, 0, 1, 1, 0, 1, 1, 4.84702), .Dim = c(14L, 7L), .Dimnames = list( - c("b[1]", "b[2]", "b[3]", "b0", "outlier[3]", "outlier[4]", - "outlier[21]", "outlier[3]", "outlier[4]", "outlier[21]", - "outlier[3]", "outlier[4]", "outlier[21]", "sigma"), - c("mean", "sd", "2.5%", "25%", "50%", "75%", "97.5%"))), - structure(c(0.02054, 0.12633, 0.07461, 0.05794, 0.04233, - 0.07062, 0.06659, 0.14758, 0.07197, 0.09058, 0.11631, 0.06903, - 0.01981, 0.0272, 0.02389, 0.00813, 0.01381, 0.01821, 0.02022, - 0.02414, 0.01787, 0.02864, 0.01984, 0.01339, 0.00053, 0.07787, - 0.03467, 0.04313, 0.01952, 0.03927, 0.03268, 0.1034, 0.04114, - 0.0432, 0.08016, 0.04533, 0.00614, 0.107, 0.0575, 0.05223, - 0.03235, 0.05768, 0.05224, 0.1307, 0.05927, 0.06978, 0.1024, - 0.05962, 0.01446, 0.1246, 0.07216, 0.0576, 0.04099, 0.06919, - 0.06439, 0.1463, 0.07056, 0.08795, 0.1156, 0.06826, 0.02884, - 0.1438, 0.08924, 0.06318, 0.05081, 0.08204, 0.07907, 0.1635, - 0.08303, 0.1081, 0.1293, 0.07747, 0.07305, 0.1833, 0.1272, - 0.07477, 0.073, 0.1104, 0.1108, 0.1976, 0.1112, 0.1544, 0.1578, - 0.09787), .Dim = c(12L, 7L), .Dimnames = list(c("p[1]", "p[2]", - "p[3]", "p[4]", "p[5]", "p[6]", "p[7]", "p[8]", "p[9]", "p[10]", - "p[11]", "p[12]"), c("mean", "sd", "2.5%", "25%", "50%", - "75%", "97.5%"))), structure(c(0.05312, 0.10302, 0.07048, - 0.05924, 0.05155, 0.06905, 0.06683, 0.12337, 0.07011, 0.07828, - 0.10214, 0.06848, 0.07268, 0.40333, 0.01954, 0.02166, 0.01741, - 0.00786, 0.01312, 0.01486, 0.01593, 0.02261, 0.01464, 0.01993, - 0.01758, 0.01165, 0.0101, 0.1541, 0.01824, 0.06663, 0.03985, - 0.04467, 0.02805, 0.04259, 0.03845, 0.08327, 0.04392, 0.04419, - 0.07166, 0.04744, 0.05319, 0.1655, 0.03923, 0.08746, 0.05844, - 0.05381, 0.04215, 0.0587, 0.05584, 0.1072, 0.06004, 0.06443, - 0.08969, 0.06035, 0.06617, 0.2989, 0.05219, 0.101, 0.06913, - 0.05897, 0.05093, 0.0683, 0.06577, 0.1217, 0.06922, 0.07633, - 0.1009, 0.06796, 0.07253, 0.3818, 0.0656, 0.1163, 0.08104, - 0.06431, 0.06019, 0.07812, 0.07685, 0.1379, 0.07919, 0.08994, - 0.1132, 0.07595, 0.07898, 0.48342, 0.09467, 0.1511, 0.1088, - 0.07536, 0.07873, 0.101, 0.1011, 0.1716, 0.1015, 0.1226, - 0.1401, 0.09301, 0.09334, 0.76511), .Dim = c(14L, 7L), .Dimnames = list( - c("p[1]", "p[2]", "p[3]", "p[4]", "p[5]", "p[6]", "p[7]", - "p[8]", "p[9]", "p[10]", "p[11]", "p[12]", "pop.mean", - "sigma"), c("mean", "sd", "2.5%", "25%", "50%", "75%", - "97.5%")))) +"75%", "97.5%"))), structure(c(3.199, 0.11791, 0.11791, 3.22327, +0.03519, 0.84975, -0.03162, -0.03162, 0.84991, 2.0602, 2.46612, +2.46612, 2.13682, 0.65527, 0.50303, 0.69675, 0.69675, 0.50508, +1.13, -4.57602, -4.57602, 1.11997, -0.9017, 0.22159, -1.38405, +-1.38405, 0.2153, 1.93675, -1.571, -1.571, 1.921, -0.65055, 0.4941, +-0.49565, -0.49565, 0.4931, 2.663, 0.23045, 0.23045, 2.662, 0.10835, +0.7321, -0.04676, -0.04676, 0.73415, 3.804, 1.777, 1.777, 3.848, +0.6978, 1.08225, 0.4324, 0.4324, 1.079, 8.43205, 4.69405, 4.69405, +8.66835, 0.9054, 2.13005, 1.346, 1.346, 2.16), .Dim = c(9L, 7L +), .Dimnames = list(c("Sigma2[1,1]", "Sigma2[1,2]", "Sigma2[2,1]", +"Sigma2[2,2]", "rho", "tau[1,1]", "tau[1,2]", "tau[2,1]", "tau[2,2]" +), c("mean", "sd", "2.5%", "25%", "50%", "75%", "97.5%"))), structure(c(1.85767, +2.64973, 0.96989, 0.86209, 0.09887, 0.26392, 0.07107, 0.07684, +0.03153, 0.0148, 1.323, 2.528, 0.8224, 0.7898, 0.07502, 1.701, +2.604, 0.9188, 0.8457, 0.08841, 1.854, 2.642, 0.9689, 0.8646, +0.09723, 2.026, 2.691, 1.018, 0.8836, 0.1074, 2.36802, 2.802, +1.122, 0.9144, 0.1326), .Dim = c(5L, 7L), .Dimnames = list(c("U3", +"alpha", "beta", "gamma", "sigma"), c("mean", "sd", "2.5%", "25%", +"50%", "75%", "97.5%"))), structure(c(2399.81116, 2970.23731, +1526.76347, 9152.71052, 1072.50035, 22.42927, 0.01173, 1559, +1483, 573.04999, 2217, 1515, 1388.49991, 2748, 1526, 2769.24997, +3466, 1539, 10140.49952, 5596.37451, 1570), .Dim = c(3L, 7L), .Dimnames = list( + c("sigma2.btw", "sigma2.with", "theta"), c("mean", "sd", + "2.5%", "25%", "50%", "75%", "97.5%"))), structure(c(0.99767, +1.43476, -0.00865, -0.1804, 0.11034, 0.1406, 0.99274, 0.04825, +0.0552, 0.05217, 0.05175, 0.03333, 0.05436, 0.05185, 1, 1.327, +-0.113, -0.2831, 0.06521, 0.04439, 0.8931, 1, 1.4, -0.04039, +-0.2121, 0.08657, 0.1057, 0.9604, 1, 1.435, -0.00813, -0.1808, +0.1033, 0.1356, 0.9919, 1, 1.469, 0.02322, -0.1495, 0.12722, +0.169, 1.023, 1, 1.544, 0.0942, -0.07637, 0.1929, 0.2663, 1.099 +), .Dim = c(7L, 7L), .Dimnames = list(c("equiv", "mu", "phi", +"pi", "sigma1", "sigma2", "theta"), c("mean", "sd", "2.5%", "25%", +"50%", "75%", "97.5%"))), structure(c(0.6029, 0.3971, 536.75923, +548.90934, 3.75937, 0.08421, 0.08421, 0.92221, 1.21365, 0.6111, +0.4326, 0.2359, 535.1, 546.5, 2.917, 0.54737, 0.34, 536.2, 548.2, +3.36175, 0.6039, 0.3961, 536.7, 548.9, 3.654, 0.66, 0.45262, +537.3, 549.7, 4.019, 0.7641, 0.5674, 538.6, 551.2, 5.27107), .Dim = c(5L, +7L), .Dimnames = list(c("P[1]", "P[2]", "lambda[1]", "lambda[2]", +"sigma"), c("mean", "sd", "2.5%", "25%", "50%", "75%", "97.5%" +))), structure(c(2.99564, 0.79689, 1.02513, 0.56926, 0.39621, +0.72729, 1.914, 0.04475, 0.4099, 2.743, 0.6218, 0.625, 2.997, +0.7995, 0.82675, 3.255, 0.9782, 1.16825, 4.08502, 1.541, 2.82 +), .Dim = c(3L, 7L), .Dimnames = list(c("alpha", "beta", "sigma" +), c("mean", "sd", "2.5%", "25%", "50%", "75%", "97.5%"))), structure(c(5.26188, +2.19814, -5.8793, 0.25999, 0.26441, 0.22576, 7.8008, 0.13613, +0.16157, 0.14278, 0.11727, 0.12765, 0.10712, 1.17804, 4.991, +1.883, -6.17302, 0.1279, 0.11789, 0.1088, 5.88897, 5.185, 2.09675, +-5.964, 0.1859, 0.18, 0.1573, 6.964, 5.263, 2.195, -5.877, 0.2326, +0.2333, 0.1999, 7.6745, 5.34, 2.296, -5.79, 0.30132, 0.3123, +0.263, 8.483, 5.527, 2.525, -5.61, 0.55141, 0.59261, 0.492, 10.46 +), .Dim = c(7L, 7L), .Dimnames = list(c("mu[1]", "mu[2]", "mu[3]", +"sigma[1]", "sigma[2]", "sigma[3]", "sigmaC"), c("mean", "sd", +"2.5%", "25%", "50%", "75%", "97.5%"))), structure(c(106.61227, +6.18568, 6.0953, 3.63673, 0.1075, 0.46858, 99.40975, 5.97597, +5.27197, 104.2, 6.114, 5.776, 106.6, 6.187, 6.058, 109.1, 6.258, +6.386, 113.6, 6.394, 7.106), .Dim = c(3L, 7L), .Dimnames = list( + c("alpha0", "beta.c", "sigma"), c("mean", "sd", "2.5%", "25%", + "50%", "75%", "97.5%"))), structure(c(0.71462, 1.2978, -0.15277, +-39.85965, 0.0106, 0.05567, 0.3192, 0.0106, 0.05567, 0.3192, +0.0106, 0.05567, 0.3192, 3.38943, 0.14307, 0.38863, 0.16594, +12.71407, 0.10241, 0.22928, 0.46618, 0.10241, 0.22928, 0.46618, +0.10241, 0.22928, 0.46618, 0.62795, 0.43279, 0.529, -0.4842, +-65.22025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.417, 0.62217, 1.049, +-0.26012, -48.11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.945, 0.7155, 1.294, +-0.15245, -39.96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.299, 0.8063, 1.545, +-0.04546, -31.5775, 0, 0, 1, 0, 0, 1, 0, 0, 1, 3.742, 0.9984, +2.076, 0.1763, -14.38925, 0, 1, 1, 0, 1, 1, 0, 1, 1, 4.84702), .Dim = c(14L, +7L), .Dimnames = list(c("b[1]", "b[2]", "b[3]", "b0", "outlier[3]", +"outlier[4]", "outlier[21]", "outlier[3]", "outlier[4]", "outlier[21]", +"outlier[3]", "outlier[4]", "outlier[21]", "sigma"), c("mean", +"sd", "2.5%", "25%", "50%", "75%", "97.5%"))), structure(c(0.02054, +0.12633, 0.07461, 0.05794, 0.04233, 0.07062, 0.06659, 0.14758, +0.07197, 0.09058, 0.11631, 0.06903, 0.01981, 0.0272, 0.02389, +0.00813, 0.01381, 0.01821, 0.02022, 0.02414, 0.01787, 0.02864, +0.01984, 0.01339, 0.00053, 0.07787, 0.03467, 0.04313, 0.01952, +0.03927, 0.03268, 0.1034, 0.04114, 0.0432, 0.08016, 0.04533, +0.00614, 0.107, 0.0575, 0.05223, 0.03235, 0.05768, 0.05224, 0.1307, +0.05927, 0.06978, 0.1024, 0.05962, 0.01446, 0.1246, 0.07216, +0.0576, 0.04099, 0.06919, 0.06439, 0.1463, 0.07056, 0.08795, +0.1156, 0.06826, 0.02884, 0.1438, 0.08924, 0.06318, 0.05081, +0.08204, 0.07907, 0.1635, 0.08303, 0.1081, 0.1293, 0.07747, 0.07305, +0.1833, 0.1272, 0.07477, 0.073, 0.1104, 0.1108, 0.1976, 0.1112, +0.1544, 0.1578, 0.09787), .Dim = c(12L, 7L), .Dimnames = list( + c("p[1]", "p[2]", "p[3]", "p[4]", "p[5]", "p[6]", "p[7]", + "p[8]", "p[9]", "p[10]", "p[11]", "p[12]"), c("mean", "sd", + "2.5%", "25%", "50%", "75%", "97.5%"))), structure(c(0.05312, +0.10302, 0.07048, 0.05924, 0.05155, 0.06905, 0.06683, 0.12337, +0.07011, 0.07828, 0.10214, 0.06848, 0.07268, 0.40333, 0.01954, +0.02166, 0.01741, 0.00786, 0.01312, 0.01486, 0.01593, 0.02261, +0.01464, 0.01993, 0.01758, 0.01165, 0.0101, 0.1541, 0.01824, +0.06663, 0.03985, 0.04467, 0.02805, 0.04259, 0.03845, 0.08327, +0.04392, 0.04419, 0.07166, 0.04744, 0.05319, 0.1655, 0.03923, +0.08746, 0.05844, 0.05381, 0.04215, 0.0587, 0.05584, 0.1072, +0.06004, 0.06443, 0.08969, 0.06035, 0.06617, 0.2989, 0.05219, +0.101, 0.06913, 0.05897, 0.05093, 0.0683, 0.06577, 0.1217, 0.06922, +0.07633, 0.1009, 0.06796, 0.07253, 0.3818, 0.0656, 0.1163, 0.08104, +0.06431, 0.06019, 0.07812, 0.07685, 0.1379, 0.07919, 0.08994, +0.1132, 0.07595, 0.07898, 0.48342, 0.09467, 0.1511, 0.1088, 0.07536, +0.07873, 0.101, 0.1011, 0.1716, 0.1015, 0.1226, 0.1401, 0.09301, +0.09334, 0.76511), .Dim = c(14L, 7L), .Dimnames = list(c("p[1]", +"p[2]", "p[3]", "p[4]", "p[5]", "p[6]", "p[7]", "p[8]", "p[9]", +"p[10]", "p[11]", "p[12]", "pop.mean", "sigma"), c("mean", "sd", +"2.5%", "25%", "50%", "75%", "97.5%")))) Modified: trunk/R2OpenBUGS/man/bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.Rd 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/man/bugs.Rd 2011-03-21 19:13:27 UTC (rev 181) @@ -7,13 +7,14 @@ saves the simulations for easy access in \R or S-PLUS.} \usage{ -bugs(data, inits, parameters.to.save, n.iter, model.file="model.bug", +bugs(data, inits, parameters.to.save, n.iter, model.file="model.txt", n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, + saveExec=FALSE,restart=FALSE, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, paste("C:/Program Files/OpenBUGS/OpenBUGS", version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), - version='312', + version='321', working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, @@ -37,12 +38,12 @@ e.g. by the function \code{\link{bugs.inits}}.} \item{parameters.to.save}{character vector of the names of the parameters to save which should be monitored} - \item{model.file}{file containing the model written in \pkg{OpenBUGS} code. - The extension can be either \file{.bug} or \file{.txt}. - If the extension is \file{.bug} and \code{program=="OpenBUGS"}, - a copy of the file with extension \file{.txt} will be created - in the \code{bugs()} call and removed afterwards. Note that - similarly named \file{.txt} files will be overwritten. + \item{model.file}{File containing the model written in \pkg{OpenBUGS} code. + The extension must be \file{.txt}. + The old convention allowing model.file to be named \file{.bug} has been eliminated + because the new \pkg{OpenBUGS} feature that allows the program image + to be saved and later restarted uses the .bug extension for the saved + images. Alternatively, \code{model.file} can be an R function that contains a BUGS model that is written to a temporary model file (see \code{\link{tempfile}}) using \code{\link{write.model}}.} \item{n.chains}{number of Markov chains (default: 3)} @@ -57,6 +58,22 @@ \code{n.iter}. Setting \code{n.thin}=2, doubles the number of iterations OpenBUGS performs, but does not change \code{n.iter} or \code{n.burnin}. Thinning implemented in this manner is not captured in summaries created by packages such as \pkg{coda}.} + \item{saveExec}{If TRUE, a re-startable image of the OpenBUGS execution is + saved with \code{basename(model.file)} and extension .bug in the working + directory, which must be specified. The .bug files can be large, so + users should monitor them carefully and remove them when not needed. +} + \item{restart}{If TRUE, execution resumes with the final status from + the previous execution stored in the .bug file in the working directory. + If \code{n.burnin=0},additional iterations are performed and all iterations since + the previous burnin are used (including those from past executions). If + \code{n.burnin>0}, a new burnin is performed, and the previous iterations are + discarded, but execution continues from the status at the end of the previous + execution. When \code{restart=TRUE}, only \code{n.burnin}, \code{n.iter}, + and \code{saveExec} inputs + should be changed from the call creating the .bug file, otherwise + failed or erratic results may be produced. Note the default has \code{n.burnin>0}. +} \item{debug}{if \code{FALSE} (default), \pkg{OpenBUGS} is closed automatically when the script has finished running, otherwise \pkg{OpenBUGS} remains open for further investigation. The debug option is not available for linux execution.} Modified: trunk/R2OpenBUGS/man/bugs.script.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.script.Rd 2011-03-07 15:09:12 UTC (rev 180) +++ trunk/R2OpenBUGS/man/bugs.script.Rd 2011-03-21 19:13:27 UTC (rev 181) @@ -8,7 +8,8 @@ \usage{ bugs.script(parameters.to.save, n.chains, n.iter, n.burnin, - n.thin, model.file, debug=FALSE, is.inits, + n.thin, saveExec, restart, model.file.bug, + model.file, debug=FALSE, is.inits, DIC=FALSE, useWINE=FALSE, newWINE=TRUE, WINEPATH=NULL, bugs.seed=NULL, summary.only=FALSE, save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), @@ -21,6 +22,26 @@ \item{n.iter}{number of total iterations (including burn in)} \item{n.burnin}{length of burn in} \item{n.thin}{thinning parameter} + \item{saveExec}{If TRUE, a re-startable image of the OpenBUGS execution is + saved with \code{basename(model.file)} and extension .bug in the working + directory, which must be specified. The .bug files can be large, so + users should monitor them carefully and remove them when not needed. +} + \item{restart}{If TRUE, execution resumes with the final status from + the previous execution stored in the .bug file in the working directory. + If \code{n.burnin=0},additional iterations are performed and all iterations since + the previous burnin are used (including those from past executions). If + \code{n.burnin>0}, a new burnin is performed, and the previous iterations are + discarded, but execution continues from the status at the end of the previous + execution. When \code{restart=TRUE}, only \code{n.burnin}, \code{n.iter}, + and \code{saveExec} inputs + should be changed from the call creating the .bug file, otherwise + failed or erratic results may be produced. +} + \item{model.file.bug}{If saveExec or restart is TRUE, then \code{model.file.bug} + receives/contains the OpenBUGS program image for restarting the program. + \code{model.file.bug} is the name of the file with its full path + } \item{model.file}{file containing the model written in \pkg{OpenBUGS} code} \item{debug}{if \code{FALSE}, \pkg{OpenBUGS} is closed automatically, otherwise \pkg{OpenBUGS} remains open for further investigation. With This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2011-04-08 13:05:07
|
Revision: 185 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=185&view=rev Author: snthomas99 Date: 2011-04-08 13:05:01 +0000 (Fri, 08 Apr 2011) Log Message: ----------- adding validateInstallOpenBUGS that was inadvertantly missed in the last commit Added Paths: ----------- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd Added: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R (rev 0) +++ trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-04-08 13:05:01 UTC (rev 185) @@ -0,0 +1,63 @@ +validateInstallOpenBUGS<-function( + OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, + paste("C:/Program Files/OpenBUGS/OpenBUGS", + version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), + version='321', + OpenBUGS.examples=file.path(dirname(OpenBUGS.pgm),'Examples'), + useWINE=FALSE, WINE=NULL, + newWINE=TRUE, WINEPATH=NULL + ) +{ +## Selected examples which take a few seconds in total to run + +test.models <- c("Air", "Asia", "Beetles", "BiRats", "Camel", + "Dugongs", "Dyes", "Equiv", "Eyes", + "Line", "OtreesMVN", "Rats", "Stacks", + "Surgical", "Surgicalrand") + +test.params <- list(Air = c("X", "theta"), + Asia = c("bronchitis", "either", "lung.cancer"), + Beetles = c("alpha", "beta", "rhat"), + BiRats = c("mu.beta", "sigma"), + Camel = c("Sigma2", "rho", "tau"), + Dugongs = c("U3","alpha", "beta", "gamma", "sigma"), + Dyes = c("sigma2.btw", "sigma2.with", "theta"), + Equiv = c("equiv", "mu", "phi", "pi","sigma1", "sigma2", "theta"), + Eyes = c("P", "lambda", "sigma"), + Line = c("alpha", "beta", "sigma"), + OtreesMVN = c("mu","sigma", "sigmaC"), + Rats = c("alpha0", "beta.c", "sigma"), + Stacks = c("b", "b0", "outlier[21]","outlier[3]", "outlier[4]", "sigma"), + Surgical = "p", + Surgicalrand = c("p","pop.mean", "sigma") + ) + +test.modelfile = paste(test.models,"model.txt",sep="") +test.modelfile<-file.path(OpenBUGS.examples,test.modelfile) +test.datafile = paste(test.models,"data.txt",sep="") +test.datafile<-file.path(OpenBUGS.examples,test.datafile) +test.inits = paste(test.models,"inits.txt",sep="") +test.inits<-file.path(OpenBUGS.examples,test.inits) + +### Test for posterior means within 1 percent of previously saved values + +res.true<-dget(file=system.file("validateInstallOpenBUGS/validOpenBUGSResults.R",package="R2OpenBUGS") ) + +cat("The version of OpenBUGS on your computer is being compared to validation\n", + "results created using OpenBUGS version 3.2.1\n") + +for (i in seq(along=test.models)) { + fit<-round(bugs(data=test.datafile[i], inits=test.inits[i], + para=test.params[[test.models[i]]],model.file=test.modelfile[i], + n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE)$summary,5) + if(isTRUE(all.equal(fit,res.true[[i]],tol=1e-2))){ + cat(paste('Results matched for example',test.models[[i]],'\n',sep=' ')) + } else{ + cat(paste('Results did not match for example',test.models[[i]],'\n',sep=' ')) + } + flush.console() +} + return(invisible()) +} + + Property changes on: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R ___________________________________________________________________ Added: svn:executable + * Added: trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd =================================================================== --- trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd (rev 0) +++ trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-04-08 13:05:01 UTC (rev 185) @@ -0,0 +1,81 @@ +\name{validateInstallOpenBUGS} +\alias{validateInstallOpenBUGS} +\title{Compare OpenBUGS/R2OpenBUGS execution to results supplied with OpenBUGS} + +\description{A selected subset of the examples from the OpenBUGS manual is +executed and compared to results supplied with the package to validate +installation.} + +\usage{ +validateInstallOpenBUGS( + OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, + paste("C:/Program Files/OpenBUGS/OpenBUGS", + version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), + version='321', + OpenBUGS.examples=file.path(dirname(OpenBUGS.pgm),'Examples'), + useWINE=FALSE, WINE=NULL, + newWINE=TRUE, WINEPATH=NULL + ) +} + +\arguments{ + \item{OpenBUGS.pgm}{ For Windows or WINE execution, the full path to the OpenBUGS + executable. For linux execution, the full path to the OpenBUGS shell script (not + required if OpenBUGS is in the user's PATH variable). + If the global option \code{R2OpenBUGS.bugs.directory} is not \code{NULL}, + it will be used as the default.} + \item{version}{The version of OpenBUGS to validate. \code{version} is ignored + with linux execution or if \code{OpenBUGS.pgm} is specified. The current + comparison results were created with OpenBUGS 3.2.1} + \item{OpenBUGS.examples}{A directory with the OpenBUGS examples (text versions of + model, data, and inits). There is currently no default appropriate for linux.} + \item{useWINE}{logical; attempt to use the Wine emulator to run + \pkg{OpenBUGS}. Default is \code{FALSE}. If WINE is used, the arguments \code{OpenBUGS.pgm} and \code{working.directory} must be given in form of Linux paths +rather than Windows paths (if not \code{NULL}).} + \item{WINE}{Character, path to \file{wine} binary file, it is + tried hard (by a guess and the utilities \code{which} and \code{locate}) + to get the information automatically if not given.} + \item{newWINE}{Use new versions of Wine that have \file{winepath} + utility} + \item{WINEPATH}{Character, path to \file{winepath} binary file, it is + tried hard (by a guess and the utilities \code{which} and \code{locate}) + to get the information automatically if not given.} +} + +\details{ + Operation system support: + \itemize{ + \item \pkg{MS Windows} Yes + \item \pkg{Linux, intel processors} Yes, but GUI display and graphics not available. + \item \pkg{Mac OS X} and \pkg{Unix} Wine emulation via \code{useWINE=TRUE} + } + + If \code{useWINE=TRUE} is used, all paths (such as + \code{working.directory} and \code{model.file}, must be given in + native (Unix) style, but \code{OpenBUGS.pgm} can be given in + Windows path style (e.g. \dQuote{c:/Program Files/OpenBUGS/}) or + native (Unix) style + (e.g. \dQuote{/path/to/wine/folder/dosdevices/c:/Program + Files/OpenBUGS/OpenBUGS311/OpenBUGS.exe}). + +} + +\value{ +No data returned. Prints match/no match result to console for each example. +} + +\references{ + Gelman, A., Carlin, J.B., Stern, H.S., Rubin, D.B. (2003): + \emph{Bayesian Data Analysis}, 2nd edition, CRC Press. + + Sturtz, S., Ligges, U., Gelman, A. (2005): + R2WinBUGS: A Package for Running WinBUGS from R. + \emph{Journal of Statistical Software} 12(3), 1-16. +} + +\author{Neal Thomas based on BRugs examples created by Chris Jackaon.} + +\seealso{\code{\link{bugs}}} + +\keyword{interface} +\keyword{models} Property changes on: trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2011-08-26 15:24:58
|
Revision: 203 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=203&view=rev Author: ligges Date: 2011-08-26 15:24:52 +0000 (Fri, 26 Aug 2011) Log Message: ----------- improved auto-detect OpenBUGS routines (outsourced into non exported function findOpenBUGS.R()) Modified Paths: -------------- trunk/R2OpenBUGS/R/bugs.R trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd Added Paths: ----------- trunk/R2OpenBUGS/R/findOpenBUGS.R Modified: trunk/R2OpenBUGS/R/bugs.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.R 2011-08-26 15:23:52 UTC (rev 202) +++ trunk/R2OpenBUGS/R/bugs.R 2011-08-26 15:24:52 UTC (rev 203) @@ -3,40 +3,33 @@ n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, saveExec=FALSE,restart=FALSE, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, - OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, - paste("C:/Program Files/OpenBUGS/OpenBUGS", - version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), - version='321', - working.directory=NULL, + OpenBUGS.pgm=NULL, working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), over.relax = FALSE) { - ### check options for unix/linux if(.Platform$OS.type != "windows" & useWINE==FALSE){ if(debug)stop("The debug option is not available with linux/unix") if(save.history)("History plots (save.history) is not available with linux/unix") } - if (missing(OpenBUGS.pgm) && - !is.null(bugs.pgm <- getOption("R2OpenBUGS.pgm"))) { # requested by Jouni Kerman - OpenBUGS.pgm<- bugs.pgm - } + if(is.null(OpenBUGS.pgm)) + OpenBUGS.pgm <- file.path(findOpenBUGS(), "OpenBUGS.exe", fsep="\\") - if((.Platform$OS.type == "windows" | useWINE) & !file.exists(OpenBUGS.pgm)) - stop("OpenBUGS executable was not found" ) + if((.Platform$OS.type == "windows" | useWINE) & !file.exists(OpenBUGS.pgm)) + stop("OpenBUGS executable was not found" ) ## Is OpenBUGS.pgm defined in Windows (where second character is : ## i.e. C:\Program...) or Unix style path? if(useWINE && (substr(OpenBUGS.pgm, 2, 2) == ":")) { - OpenBUGS.pgm<- win2native(OpenBUGS.pgm, newWINE=newWINE, WINEPATH=WINEPATH) + OpenBUGS.pgm <- win2native(OpenBUGS.pgm, newWINE=newWINE, WINEPATH=WINEPATH) } + if(! bugs.seed %in% 1:14) + stop("OpenBUGS seed must be integer in 1:14") - if(! bugs.seed %in% c(1:14))stop("OpenBUGS seed must be integer in 1-14") - if(!is.function(model.file) && length(grep("\\.bug", tolower(model.file))))stop("model.file must be renamed with .txt rather than .bug") @@ -172,6 +165,3 @@ class(sims) <- "bugs" sims } - - - Added: trunk/R2OpenBUGS/R/findOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/findOpenBUGS.R (rev 0) +++ trunk/R2OpenBUGS/R/findOpenBUGS.R 2011-08-26 15:24:52 UTC (rev 203) @@ -0,0 +1,33 @@ +findOpenBUGS <- function(){ + dir <- Sys.getenv("OpenBUGS_PATH") + if(nchar(dir)) + return(dir) + + dir <- getOption("R2OpenBUGS.pgm") + if(!is.null(dir)) + return(dir) + + if(.Platform$OS.type != "windows") + return(NA) + + deps <- utils:::packageDescription("BRugs", fields="SystemRequirements") + version.req <- gsub(".*OpenBUGS ?\\(>= ?(.+)\\).*", "\\1", deps) + ob.reg <- try(utils:::readRegistry("Software\\OpenBUGS", "HLM", view = "32-bit"), silent = TRUE) + if (inherits(ob.reg, "try-error")) + return(NA) + + rnames <- names(ob.reg) + ver <- gsub("OpenBUGS ", "", rnames) + version.inst <- gsub("(.+)e$","\\1", ver) + + if(length(version.inst > 1)){ + id <- which(apply(outer(version.inst, version.inst, Vectorize(compareVersion, c("a", "b"))), 1, function(x) all(x >= 0))) + version.inst <- version.inst[id] + rnames <- rnames[id] + } + + if (compareVersion(max(version.inst), version.req) < 0) + warning("Found OpenBUGS version ", version.inst, ".\n Requires ", version.req, " or greater.") + + utils:::readRegistry(paste("Software", "OpenBUGS", rnames, sep="\\"), "HLM", view = "32-bit")[["InstallPath"]] +} Modified: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-08-26 15:23:52 UTC (rev 202) +++ trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-08-26 15:24:52 UTC (rev 203) @@ -1,8 +1,5 @@ validateInstallOpenBUGS<-function( - OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, - paste("C:/Program Files/OpenBUGS/OpenBUGS", - version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), - version='321', + OpenBUGS.pgm=NULL, OpenBUGS.examples=file.path(dirname(OpenBUGS.pgm),'Examples'), useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL @@ -10,6 +7,13 @@ { ## Selected examples which take a few seconds in total to run + +if(is.null(OpenBUGS.pgm)) + OpenBUGS.pgm <- file.path(findOpenBUGS(), "OpenBUGS.exe", fsep="\\") + +if(!file.exists(OpenBUGS.Examples)) + stop("Cannot find Examples in ", OpenBUGS.Examples) + test.models <- c("Air", "Asia", "Beetles", "BiRats", "Camel", "Dugongs", "Dyes", "Equiv", "Eyes", "Line", "OtreesMVN", "Rats", "Stacks", @@ -32,32 +36,31 @@ Surgicalrand = c("p","pop.mean", "sigma") ) -test.modelfile = paste(test.models,"model.txt",sep="") -test.modelfile<-file.path(OpenBUGS.examples,test.modelfile) -test.datafile = paste(test.models,"data.txt",sep="") -test.datafile<-file.path(OpenBUGS.examples,test.datafile) -test.inits = paste(test.models,"inits.txt",sep="") -test.inits<-file.path(OpenBUGS.examples,test.inits) +test.modelfile <- paste(test.models,"model.txt",sep="") +test.modelfile <- file.path(OpenBUGS.examples,test.modelfile) +test.datafile <- paste(test.models,"data.txt",sep="") +test.datafile <- file.path(OpenBUGS.examples,test.datafile) +test.inits <- paste(test.models,"inits.txt",sep="") +test.inits <- file.path(OpenBUGS.examples,test.inits) ### Test for posterior means within 1 percent of previously saved values -res.true<-dget(file=system.file("validateInstallOpenBUGS/validOpenBUGSResults.R",package="R2OpenBUGS") ) +res.true <- dget(file = system.file("validateInstallOpenBUGS/validOpenBUGSResults.R", package="R2OpenBUGS") ) -cat("The version of OpenBUGS on your computer is being compared to validation\n", +message("The version of OpenBUGS on your computer is being compared to validation\n", "results created using OpenBUGS version 3.2.1\n") for (i in seq(along=test.models)) { - fit<-round(bugs(data=test.datafile[i], inits=test.inits[i], + fit <- round(bugs(data=test.datafile[i], inits=test.inits[i], para=test.params[[test.models[i]]],model.file=test.modelfile[i], - n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE)$summary,5) - if(isTRUE(all.equal(fit,res.true[[i]],tol=1e-2))){ - cat(paste('Results matched for example',test.models[[i]],'\n',sep=' ')) + n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE)$summary, 5) + if(isTRUE(all.equal(fit, res.true[[i]], tol=1e-2))){ + message(paste('Results matched for example', test.models[[i]], '\n', sep=' ')) } else{ - cat(paste('Results did not match for example',test.models[[i]],'\n',sep=' ')) + message(paste('Results did not match for example',test.models[[i]], '\n', sep=' ')) } flush.console() } - return(invisible()) + invisible() } - Modified: trunk/R2OpenBUGS/man/bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.Rd 2011-08-26 15:23:52 UTC (rev 202) +++ trunk/R2OpenBUGS/man/bugs.Rd 2011-08-26 15:24:52 UTC (rev 203) @@ -11,11 +11,7 @@ n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, saveExec=FALSE,restart=FALSE, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, - OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, - paste("C:/Program Files/OpenBUGS/OpenBUGS", - version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), - version='321', - working.directory=NULL, + OpenBUGS.pgm=NULL, working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), @@ -93,10 +89,11 @@ \item{OpenBUGS.pgm}{ For Windows or WINE execution, the full path to the OpenBUGS executable. For linux execution, the full path to the OpenBUGS shell script (not required if OpenBUGS is in the user's PATH variable). - If the global option \code{R2OpenBUGS.bugs.directory} is not \code{NULL}, - it will be used as the default.} - \item{version}{The version of OpenBUGS to use. \code{version} is ignored - with linux execution or if \code{OpenBUGS.pgm} is specified.} + If \code{NULL} (unset) and the environment variable \code{OpenBUGS_PATH} is set the latter will be used as the default. + If \code{NULL} (unset), the environment variable \code{OpenBUGS_PATH} is unset and the global option \code{R2OpenBUGS.pgm} is not \code{NULL} the latter will be used as the default. + If nothing of the former is set and OS is Windows, the most recent OpenBUGS version + registered in the Windows registry will be used as the default. + } \item{working.directory}{sets working directory during execution of this function; \pkg{OpenBUGS}' in- and output will be stored in this directory; if \code{NULL}, a temporary working directory via @@ -108,7 +105,7 @@ \code{codaPkg=FALSE}.} \item{useWINE}{logical; attempt to use the Wine emulator to run \pkg{OpenBUGS}. Default is \code{FALSE}. If WINE is used, the arguments \code{OpenBUGS.pgm} and \code{working.directory} must be given in form of Linux paths -rather than Windows paths (if not \code{NULL}).} + rather than Windows paths (if not \code{NULL}).} \item{WINE}{Character, path to \file{wine} binary file, it is tried hard (by a guess and the utilities \code{which} and \code{locate}) to get the information automatically if not given.} @@ -259,7 +256,7 @@ parameters <- c("theta", "mu.theta", "sigma.theta") \dontrun{ -## You may need to edit "bugs.directory", +## You may need to specify "OpenBUGS.pgm" ## also you need write access in the working directory: schools.sim <- bugs(data, inits, parameters, model.file, n.chains=3, n.iter=5000) Modified: trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd =================================================================== --- trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-08-26 15:23:52 UTC (rev 202) +++ trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-08-26 15:24:52 UTC (rev 203) @@ -8,10 +8,7 @@ \usage{ validateInstallOpenBUGS( - OpenBUGS.pgm=ifelse(.Platform$OS.type == "windows" | useWINE==TRUE, - paste("C:/Program Files/OpenBUGS/OpenBUGS", - version,"/OpenBUGS.exe",sep=""),"OpenBUGS"), - version='321', + OpenBUGS.pgm=NULL, OpenBUGS.examples=file.path(dirname(OpenBUGS.pgm),'Examples'), useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL @@ -19,14 +16,7 @@ } \arguments{ - \item{OpenBUGS.pgm}{ For Windows or WINE execution, the full path to the OpenBUGS - executable. For linux execution, the full path to the OpenBUGS shell script (not - required if OpenBUGS is in the user's PATH variable). - If the global option \code{R2OpenBUGS.bugs.directory} is not \code{NULL}, - it will be used as the default.} - \item{version}{The version of OpenBUGS to validate. \code{version} is ignored - with linux execution or if \code{OpenBUGS.pgm} is specified. The current - comparison results were created with OpenBUGS 3.2.1} + \item{OpenBUGS.pgm}{See \code{\link{bugs}}.} \item{OpenBUGS.examples}{A directory with the OpenBUGS examples (text versions of model, data, and inits). There is currently no default appropriate for linux.} \item{useWINE}{logical; attempt to use the Wine emulator to run This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2011-08-26 16:23:02
|
Revision: 208 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=208&view=rev Author: ligges Date: 2011-08-26 16:22:56 +0000 (Fri, 26 Aug 2011) Log Message: ----------- use validateInstallOpenBUGS as test cases and adapt/workaround for running on 64-bit Windows with OpenBUGS installed in a path containing "()" (where OpenBUGS cannot read files from) Modified Paths: -------------- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd Added Paths: ----------- trunk/R2OpenBUGS/tests/ trunk/R2OpenBUGS/tests/R2OpenBUGS.R trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save Modified: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-08-26 16:21:28 UTC (rev 207) +++ trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-08-26 16:22:56 UTC (rev 208) @@ -1,6 +1,6 @@ -validateInstallOpenBUGS<-function( +validateInstallOpenBUGS <- function( OpenBUGS.pgm=NULL, - OpenBUGS.examples=file.path(dirname(OpenBUGS.pgm),'Examples'), + OpenBUGS.examples=NULL, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL ) @@ -9,11 +9,15 @@ if(is.null(OpenBUGS.pgm)) - OpenBUGS.pgm <- file.path(findOpenBUGS(), "OpenBUGS.exe", fsep="\\") + OpenBUGS.pgm <- file.path(findOpenBUGS(), "OpenBUGS.exe") -if(!file.exists(OpenBUGS.Examples)) - stop("Cannot find Examples in ", OpenBUGS.Examples) +if(is.null(OpenBUGS.examples)) + OpenBUGS.examples <- file.path(dirname(OpenBUGS.pgm), 'Examples') +if(!file.exists(OpenBUGS.examples)) + stop("Cannot find Examples in ", OpenBUGS.examples) + + test.models <- c("Air", "Asia", "Beetles", "BiRats", "Camel", "Dugongs", "Dyes", "Equiv", "Eyes", "Line", "OtreesMVN", "Rats", "Stacks", @@ -37,11 +41,9 @@ ) test.modelfile <- paste(test.models,"model.txt",sep="") -test.modelfile <- file.path(OpenBUGS.examples,test.modelfile) test.datafile <- paste(test.models,"data.txt",sep="") -test.datafile <- file.path(OpenBUGS.examples,test.datafile) test.inits <- paste(test.models,"inits.txt",sep="") -test.inits <- file.path(OpenBUGS.examples,test.inits) +test.pattern <- paste("^", test.models, ".*\\.txt$", sep="") ### Test for posterior means within 1 percent of previously saved values @@ -51,9 +53,11 @@ "results created using OpenBUGS version 3.2.1\n") for (i in seq(along=test.models)) { + exfiles <- dir(OpenBUGS.examples, pattern=test.pattern[i], full.names=TRUE) + ok <- file.copy(exfiles, tempdir()) fit <- round(bugs(data=test.datafile[i], inits=test.inits[i], para=test.params[[test.models[i]]],model.file=test.modelfile[i], - n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE)$summary, 5) + n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE, working.directory=tempdir())$summary, 5) if(isTRUE(all.equal(fit, res.true[[i]], tol=1e-2))){ message(paste('Results matched for example', test.models[[i]], '\n', sep=' ')) } else{ Modified: trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd =================================================================== --- trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-08-26 16:21:28 UTC (rev 207) +++ trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-08-26 16:22:56 UTC (rev 208) @@ -9,7 +9,7 @@ \usage{ validateInstallOpenBUGS( OpenBUGS.pgm=NULL, - OpenBUGS.examples=file.path(dirname(OpenBUGS.pgm),'Examples'), + OpenBUGS.examples=NULL, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL ) @@ -18,7 +18,7 @@ \arguments{ \item{OpenBUGS.pgm}{See \code{\link{bugs}}.} \item{OpenBUGS.examples}{A directory with the OpenBUGS examples (text versions of - model, data, and inits). There is currently no default appropriate for linux.} + model, data, and inits). If \code{NULL} we try to derive from \code{OpenBUGS.pgm}.} \item{useWINE}{logical; attempt to use the Wine emulator to run \pkg{OpenBUGS}. Default is \code{FALSE}. If WINE is used, the arguments \code{OpenBUGS.pgm} and \code{working.directory} must be given in form of Linux paths rather than Windows paths (if not \code{NULL}).} @@ -46,7 +46,7 @@ Windows path style (e.g. \dQuote{c:/Program Files/OpenBUGS/}) or native (Unix) style (e.g. \dQuote{/path/to/wine/folder/dosdevices/c:/Program - Files/OpenBUGS/OpenBUGS311/OpenBUGS.exe}). + Files/OpenBUGS/OpenBUGS321/OpenBUGS.exe}). } Property changes on: trunk/R2OpenBUGS/tests ___________________________________________________________________ Added: bugtraq:number + true Added: trunk/R2OpenBUGS/tests/R2OpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/tests/R2OpenBUGS.R (rev 0) +++ trunk/R2OpenBUGS/tests/R2OpenBUGS.R 2011-08-26 16:22:56 UTC (rev 208) @@ -0,0 +1,2 @@ +library("R2OpenBUGS") +validateInstallOpenBUGS() Added: trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save =================================================================== --- trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save (rev 0) +++ trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save 2011-08-26 16:22:56 UTC (rev 208) @@ -0,0 +1,56 @@ + +R Under development (unstable) (2011-08-25 r56795) +Copyright (C) 2011 The R Foundation for Statistical Computing +ISBN 3-900051-07-0 +Platform: i386-pc-mingw32/i386 (32-bit) + +R is free software and comes with ABSOLUTELY NO WARRANTY. +You are welcome to redistribute it under certain conditions. +Type 'license()' or 'licence()' for distribution details. + +R is a collaborative project with many contributors. +Type 'contributors()' for more information and +'citation()' on how to cite R or R packages in publications. + +Type 'demo()' for some demos, 'help()' for on-line help, or +'help.start()' for an HTML browser interface to help. +Type 'q()' to quit R. + +> library("R2OpenBUGS") +Loading required package: coda +Loading required package: lattice +> validateInstallOpenBUGS() +The version of OpenBUGS on your computer is being compared to validation +results created using OpenBUGS version 3.2.1 + +Results matched for example Air + +Results matched for example Asia + +Results matched for example Beetles + +Results matched for example BiRats + +Results matched for example Camel + +Results matched for example Dugongs + +Results matched for example Dyes + +Results matched for example Equiv + +Results matched for example Eyes + +Results matched for example Line + +Results matched for example OtreesMVN + +Results matched for example Rats + +Results matched for example Stacks + +Results matched for example Surgical + +Results matched for example Surgicalrand + +> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2011-09-21 01:08:44
|
Revision: 215 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=215&view=rev Author: snthomas99 Date: 2011-09-21 01:08:35 +0000 (Wed, 21 Sep 2011) Log Message: ----------- Fixed bug in validateInstallOpenBUGS and changed version number Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.pdf Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2011-09-01 09:43:58 UTC (rev 214) +++ trunk/R2OpenBUGS/DESCRIPTION 2011-09-21 01:08:35 UTC (rev 215) @@ -1,7 +1,7 @@ Package: R2OpenBUGS Title: Running OpenBUGS from R / S-PLUS Date: 2011-08-25 -Version: 3.2-2 +Version: 3.2-1.2 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. Modified: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-09-01 09:43:58 UTC (rev 214) +++ trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-09-21 01:08:35 UTC (rev 215) @@ -57,7 +57,9 @@ ok <- file.copy(exfiles, tempdir()) fit <- round(bugs(data=test.datafile[i], inits=test.inits[i], para=test.params[[test.models[i]]],model.file=test.modelfile[i], - n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE, working.directory=tempdir())$summary, 5) + n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE, + working.directory=tempdir(), + OpenBUGS.pgm=OpenBUGS.pgm)$summary, 5) if(isTRUE(all.equal(fit, res.true[[i]], tol=1e-2))){ message(paste('Results matched for example', test.models[[i]], '\n', sep=' ')) } else{ Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2011-09-01 09:43:58 UTC (rev 214) +++ trunk/R2OpenBUGS/inst/NEWS 2011-09-21 01:08:35 UTC (rev 215) @@ -1,6 +1,11 @@ Changes to R2OpenBUGS: ====================== +Update 3.2-1.2 +-Changed handling of default OpenBUGS program location and other changes + required for cran compliance +- Fixed bug in validInstallOpenBUGS with user-supplied program location + Update 3.2-1 - Added saveExec and restart options to the bugs function that uses the OpenBUGS internalize/externalize feature to allow a user to Modified: trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.pdf =================================================================== --- trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.pdf 2011-09-01 09:43:58 UTC (rev 214) +++ trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.pdf 2011-09-21 01:08:35 UTC (rev 215) @@ -235,7 +235,7 @@ /Type /XObject /Subtype /Form /FormType 1 -/PTEX.FileName (d:/temp/Rtmp0UCpFr/Rbuild5d10b9c/R2OpenBUGS/inst/doc/countssw.pdf) +/PTEX.FileName (C:/Documents\040and\040Settings/ThomasN/My\040Documents/BUGS/bugsdevel/bugs-r/R2OpenBUGS/inst/doc/countssw.pdf) /PTEX.PageNumber 1 /PTEX.InfoDict 58 0 R /BBox [0 0 432 216] @@ -1557,7 +1557,7 @@ /Type /XObject /Subtype /Form /FormType 1 -/PTEX.FileName (d:/temp/Rtmp0UCpFr/Rbuild5d10b9c/R2OpenBUGS/inst/doc/expectedsw.pdf) +/PTEX.FileName (C:/Documents\040and\040Settings/ThomasN/My\040Documents/BUGS/bugsdevel/bugs-r/R2OpenBUGS/inst/doc/expectedsw.pdf) /PTEX.PageNumber 1 /PTEX.InfoDict 66 0 R /BBox [0 0 432 216] @@ -2845,7 +2845,7 @@ /Type /XObject /Subtype /Form /FormType 1 -/PTEX.FileName (d:/temp/Rtmp0UCpFr/Rbuild5d10b9c/R2OpenBUGS/inst/doc/benzolsw.pdf) +/PTEX.FileName (C:/Documents\040and\040Settings/ThomasN/My\040Documents/BUGS/bugsdevel/bugs-r/R2OpenBUGS/inst/doc/benzolsw.pdf) /PTEX.PageNumber 1 /PTEX.InfoDict 85 0 R /BBox [0 0 432 216] @@ -3987,7 +3987,7 @@ /Type /XObject /Subtype /Form /FormType 1 -/PTEX.FileName (d:/temp/Rtmp0UCpFr/Rbuild5d10b9c/R2OpenBUGS/inst/doc/plot.pdf) +/PTEX.FileName (C:/Documents\040and\040Settings/ThomasN/My\040Documents/BUGS/bugsdevel/bugs-r/R2OpenBUGS/inst/doc/plot.pdf) /PTEX.PageNumber 1 /PTEX.InfoDict 132 0 R /BBox [0 0 470 469] @@ -5229,112 +5229,170 @@ 31 0 obj [2 0 R /Fit] endobj +184 0 obj << +/Length 99 +/Filter /FlateDecode +>> +stream +x\xDA3\xB6\xD432V0P04U02!s\x85C\xAEB.\xA0\xA0\x81P"\x93\x9C\xCB\xE5\xE4ɥ\xAE`\xC1\xA5\xEF\xE6\xD2\xF7\xF4U()*M\xE5\xD2w +pV0\xE4\xD2wQ\x886T0\x88\xE5\xF2tQ\x90\xA8\xAB\xFB\xFF\xBF +\xD8Hp\xB9zrr |
From: <snt...@us...> - 2011-12-19 13:12:12
|
Revision: 216 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=216&view=rev Author: snthomas99 Date: 2011-12-19 13:12:00 +0000 (Mon, 19 Dec 2011) Log Message: ----------- updated documentation and default pgm location code for cran release of 3.2.1-2 Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/R/bugs.R trunk/R2OpenBUGS/R/findOpenBUGS.R trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/man/R2WinBUGS-package.Rd trunk/R2OpenBUGS/man/as.bugs.array.Rd trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/bugs.sims.Rd trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd trunk/R2OpenBUGS/man/write.model.Rd Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/DESCRIPTION 2011-12-19 13:12:00 UTC (rev 216) @@ -1,19 +1,19 @@ Package: R2OpenBUGS -Title: Running OpenBUGS from R / S-PLUS -Date: 2011-08-25 +Title: Running OpenBUGS from R +Date: 2011-12-15 Version: 3.2-1.2 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. With considerable contributions by Gregor Gorjanc <gre...@bf...> and Jouni Kerman <ke...@st...>. - Ported to S-PLUS by Insightful Corp. Adapted to R2OpenBUGS from R2WinBUGS by Neal Thomas. + Adapted to R2OpenBUGS from R2WinBUGS by Neal Thomas. Description: Using this package, it is possible to call a BUGS model, summarize inferences and convergence in a table and graph, and save the simulations in arrays for easy access - in R / S-PLUS. + in R. Depends: R (>= 2.11.0), coda (>= 0.11-0) SystemRequirements: OpenBUGS (>= 3.2.1) -Maintainer: Neal Thomas <nea...@pf...> +Maintainer: Neal Thomas <nea...@ya...> License: GPL-2 -Dialect: R, S-PLUS +Dialect: R Modified: trunk/R2OpenBUGS/R/bugs.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.R 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/R/bugs.R 2011-12-19 13:12:00 UTC (rev 216) @@ -3,30 +3,36 @@ n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, saveExec=FALSE,restart=FALSE, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, - OpenBUGS.pgm=NULL, working.directory=NULL, + OpenBUGS.pgm=NULL, + working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), over.relax = FALSE) { - ### check options for unix/linux - if(.Platform$OS.type != "windows" & useWINE==FALSE){ - if(debug)stop("The debug option is not available with linux/unix") - if(save.history)("History plots (save.history) is not available with linux/unix") - } - if(is.null(OpenBUGS.pgm)) - OpenBUGS.pgm <- file.path(findOpenBUGS(), "OpenBUGS.exe") - if((.Platform$OS.type == "windows" | useWINE) & !file.exists(OpenBUGS.pgm)) - stop("OpenBUGS executable was not found" ) +if(is.null(OpenBUGS.pgm)){ + OpenBUGS.pgm <- findOpenBUGS() + if(.Platform$OS.type == "windows" | useWINE==TRUE) + OpenBUGS.pgm <- file.path(OpenBUGS.pgm, "OpenBUGS.exe") + } +if(!file.exists(OpenBUGS.pgm) && OpenBUGS.pgm!='OpenBUGS') + stop("Cannot find the OpenBUGS program") + ## Is OpenBUGS.pgm defined in Windows (where second character is : ## i.e. C:\Program...) or Unix style path? if(useWINE && (substr(OpenBUGS.pgm, 2, 2) == ":")) { OpenBUGS.pgm <- win2native(OpenBUGS.pgm, newWINE=newWINE, WINEPATH=WINEPATH) } + ### check options for unix/linux + if(.Platform$OS.type != "windows" && useWINE==FALSE){ + if(debug)stop("The debug option is not available with linux/unix") + if(save.history)("History plots (save.history) are not available with linux/unix") + } + if(! bugs.seed %in% 1:14) stop("OpenBUGS seed must be integer in 1:14") Modified: trunk/R2OpenBUGS/R/findOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/findOpenBUGS.R 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/R/findOpenBUGS.R 2011-12-19 13:12:00 UTC (rev 216) @@ -8,7 +8,7 @@ return(dir) if(.Platform$OS.type != "windows") - return(NA) + return('/usr/local/bin/OpenBUGS') deps <- utils:::packageDescription("R2OpenBUGS", fields="SystemRequirements") version.req <- gsub(".*OpenBUGS ?\\(>= ?(.+)\\).*", "\\1", deps) Modified: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-12-19 13:12:00 UTC (rev 216) @@ -7,13 +7,22 @@ { ## Selected examples which take a few seconds in total to run +if(is.null(OpenBUGS.pgm)){ + OpenBUGS.pgm <- findOpenBUGS() + if(.Platform$OS.type == "windows" | useWINE==TRUE) + OpenBUGS.pgm <- file.path(OpenBUGS.pgm, "OpenBUGS.exe") + } -if(is.null(OpenBUGS.pgm)) - OpenBUGS.pgm <- file.path(findOpenBUGS(), "OpenBUGS.exe") +if(!file.exists(OpenBUGS.pgm) && OpenBUGS.pgm!='OpenBUGS') + stop("Cannot find the OpenBUGS program") -if(is.null(OpenBUGS.examples)) - OpenBUGS.examples <- file.path(dirname(OpenBUGS.pgm), 'Examples') +if(is.null(OpenBUGS.examples)){ + if(.Platform$OS.type == "windows" | useWINE==TRUE){ + OpenBUGS.examples <- file.path(dirname(OpenBUGS.pgm), 'Examples') + }else OpenBUGS.examples <-'/usr/local/lib/OpenBUGS/doc/Examples' +} + if(!file.exists(OpenBUGS.examples)) stop("Cannot find Examples in ", OpenBUGS.examples) Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/inst/NEWS 2011-12-19 13:12:00 UTC (rev 216) @@ -2,7 +2,7 @@ ====================== Update 3.2-1.2 --Changed handling of default OpenBUGS program location and other changes +- Changed handling of default OpenBUGS program location and other changes required for cran compliance - Fixed bug in validInstallOpenBUGS with user-supplied program location Modified: trunk/R2OpenBUGS/man/R2WinBUGS-package.Rd =================================================================== --- trunk/R2OpenBUGS/man/R2WinBUGS-package.Rd 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/man/R2WinBUGS-package.Rd 2011-12-19 13:12:00 UTC (rev 216) @@ -4,13 +4,13 @@ \docType{package} -\title{Running OpenBUGS from R / S-PLUS} +\title{Running OpenBUGS from R} \description{ \pkg{R2OpenBUGS} Call a \pkg{BUGS} model, summarize inferences and convergence in a table and graph, and save the -simulations in arrays for easy access in \R / S-PLUS. The main command is \code{\link{bugs}}. +simulations in arrays for easy access in \R. The main command is \code{\link{bugs}}. } Modified: trunk/R2OpenBUGS/man/as.bugs.array.Rd =================================================================== --- trunk/R2OpenBUGS/man/as.bugs.array.Rd 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/man/as.bugs.array.Rd 2011-12-19 13:12:00 UTC (rev 216) @@ -50,7 +50,8 @@ \value{A \code{\link{bugs}} object is returned} \author{Jouni Kerman, \email{ke...@st...} with modification - by Andrew Gelman, \email{ge...@st...}, packaged by Uwe + by Andrew Gelman, \cr + \email{ge...@st...}, packaged by Uwe Ligges, \email{li...@st...}.} \seealso{\code{\link{bugs}}} Modified: trunk/R2OpenBUGS/man/bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.Rd 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/man/bugs.Rd 2011-12-19 13:12:00 UTC (rev 216) @@ -1,17 +1,18 @@ \name{bugs} \alias{bugs} -\title{Run OpenBUGS from R or S-PLUS} +\title{Run OpenBUGS from R} \description{The \code{bugs} function takes data and starting values as input. It automatically writes a \pkg{OpenBUGS} script, calls the model, and - saves the simulations for easy access in \R or S-PLUS.} + saves the simulations for easy access in \R.} \usage{ bugs(data, inits, parameters.to.save, n.iter, model.file="model.txt", n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, saveExec=FALSE,restart=FALSE, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, - OpenBUGS.pgm=NULL, working.directory=NULL, + OpenBUGS.pgm=NULL, + working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), @@ -55,7 +56,7 @@ performs, but does not change \code{n.iter} or \code{n.burnin}. Thinning implemented in this manner is not captured in summaries created by packages such as \pkg{coda}.} \item{saveExec}{If TRUE, a re-startable image of the OpenBUGS execution is - saved with \code{basename(model.file)} and extension .bug in the working + saved with \code{basename (model.file)} and extension .bug in the working directory, which must be specified. The .bug files can be large, so users should monitor them carefully and remove them when not needed. } @@ -86,13 +87,22 @@ 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 R2OpenBUGS).} - \item{OpenBUGS.pgm}{ For Windows or WINE execution, the full path to the OpenBUGS - executable. For linux execution, the full path to the OpenBUGS shell script (not - required if OpenBUGS is in the user's PATH variable). - If \code{NULL} (unset) and the environment variable \code{OpenBUGS_PATH} is set the latter will be used as the default. - If \code{NULL} (unset), the environment variable \code{OpenBUGS_PATH} is unset and the global option \code{R2OpenBUGS.pgm} is not \code{NULL} the latter will be used as the default. - If nothing of the former is set and OS is Windows, the most recent OpenBUGS version - registered in the Windows registry will be used as the default. + \item{OpenBUGS.pgm}{ For Windows or WINE execution, the full path + to the OpenBUGS + executable. For linux execution, the full path to the + OpenBUGS executable or shell script (the path to the shell + script is not + required if the OpenBUGS shell script is in the user's PATH variable). + If \code{NULL} (unset) and the environment variable + \code{OpenBUGS_PATH} is set the latter will be used as the default. + If \code{NULL} (unset), the environment variable + \code{OpenBUGS_PATH} is unset and the global option + \code{R2OpenBUGS.pgm} is not \code{NULL} the latter will be + used as the default. + If none of the former are set and OS is Windows, the + most recent OpenBUGS version + registered in the Windows registry will be used as the default. + For linux OS, the default location is /usr/local/bin/OpenBUGS. } \item{working.directory}{sets working directory during execution of this function; \pkg{OpenBUGS}' in- and output will be stored in this @@ -128,13 +138,13 @@ \enumerate{ \item Write a \pkg{BUGS} model in an ASCII file (hint: use \code{\link{write.model}}). - \item Go into \R / S-PLUS. + \item Go into \R. \item Prepare the inputs for the \code{bugs} function and run it (see Example section). - \item An \pkg{OpenBUGS} window will pop up and \R / S-PLUS will freeze + \item An \pkg{OpenBUGS} window will pop up and \R will freeze up. The model will now run in \pkg{OpenBUGS}. It might take awhile. You will see things happening in the Log window within \pkg{OpenBUGS}. When - \pkg{OpenBUGS} is done, its window will close and \R / S-PLUS will work + \pkg{OpenBUGS} is done, its window will close and \R will work again. \item If an error message appears, re-run with \code{debug=TRUE}. } @@ -156,7 +166,7 @@ \code{working.directory} and \code{model.file}, must be given in native (Unix) style, but \code{OpenBUGS.pgm} can be given in Windows path style (e.g. \dQuote{c:/Program Files/OpenBUGS/}) or - native (Unix) style + native (Unix) style \cr (e.g. \dQuote{/path/to/wine/folder/dosdevices/c:/Program Files/OpenBUGS/OpenBUGS321/OpenBUGS.exe}). Modified: trunk/R2OpenBUGS/man/bugs.sims.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.sims.Rd 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/man/bugs.sims.Rd 2011-12-19 13:12:00 UTC (rev 216) @@ -2,7 +2,7 @@ \alias{bugs.sims} \title{OpenBUGS output reader} -\description{Reads simulations from \pkg{OpenBUGS} into \R or S-PLUS, +\description{Reads simulations from \pkg{OpenBUGS} into \R, formats them, monitors convergence, performs convergence checks, and computes medians and quantiles - intended for internal use.} Modified: trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd =================================================================== --- trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-12-19 13:12:00 UTC (rev 216) @@ -17,8 +17,12 @@ \arguments{ \item{OpenBUGS.pgm}{See \code{\link{bugs}}.} - \item{OpenBUGS.examples}{A directory with the OpenBUGS examples (text versions of - model, data, and inits). If \code{NULL} we try to derive from \code{OpenBUGS.pgm}.} + \item{OpenBUGS.examples}{A directory with the OpenBUGS examples + (text versions of model, data, and inits). If \code{NULL}, for + Windows and WINE execution, 'Examples' directory is searched in the + \code{OpenBUGS.pgm} directory. For linux execution, the + directory is /usr/local/lib/OpenBUGS/doc/Examples, which is the default + location for the OpenBUGS linux installer.} \item{useWINE}{logical; attempt to use the Wine emulator to run \pkg{OpenBUGS}. Default is \code{FALSE}. If WINE is used, the arguments \code{OpenBUGS.pgm} and \code{working.directory} must be given in form of Linux paths rather than Windows paths (if not \code{NULL}).} @@ -44,7 +48,7 @@ \code{working.directory} and \code{model.file}, must be given in native (Unix) style, but \code{OpenBUGS.pgm} can be given in Windows path style (e.g. \dQuote{c:/Program Files/OpenBUGS/}) or - native (Unix) style + native (Unix) style \cr (e.g. \dQuote{/path/to/wine/folder/dosdevices/c:/Program Files/OpenBUGS/OpenBUGS321/OpenBUGS.exe}). Modified: trunk/R2OpenBUGS/man/write.model.Rd =================================================================== --- trunk/R2OpenBUGS/man/write.model.Rd 2011-09-21 01:08:35 UTC (rev 215) +++ trunk/R2OpenBUGS/man/write.model.Rd 2011-12-19 13:12:00 UTC (rev 216) @@ -1,13 +1,13 @@ \name{write.model} \alias{write.model} \title{Creating a OpenBUGS model file} -\description{Convert \R / S-PLUS function to a \pkg{OpenBUGS} model file} +\description{Convert \R function to a \pkg{OpenBUGS} model file} \usage{ write.model(model, con = "model.bug", digits = 5) } \arguments{ - \item{model}{\R / S-PLUS function containing the BUGS model in the BUGS + \item{model}{\R function containing the BUGS model in the BUGS model language, for minor differences see Section Details.} \item{con}{passed to \code{\link{writeLines}} which actually writes the model file} @@ -23,16 +23,11 @@ most BUGS models as \R functions. As a difference, BUGS syntax allows truncation specification like this: -\code{dnorm(...) I(...)} but this is illegal in \R and S-PLUS. To +\code{dnorm(...) I(...)} but this is illegal in \R. To overcome this incompatibility, use dummy operator \code{\%_\%} before \code{I(...)}: \code{dnorm(...) \%_\% I(...)}. The dummy operator \code{\%_\%} will be removed before the BUGS code is saved. -In S-PLUS, a warning is generated when the model function is defined if -the last statement in the model is an assignment. To avoid this -warning, add the line "invisible()" to the end of the model definition. -This line will be removed before the BUGS code is saved. - } \author{original idea by Jouni Kerman, modified by Uwe Ligges} @@ -52,9 +47,6 @@ if (is.R()){ # for R ## some temporary filename: filename <- file.path(tempdir(), "schoolsmodel.bug") -} else{ # for S-PLUS - ## put the file in the working directory: - filename <- "schoolsmodel.bug" } ## write model file: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2011-12-21 15:46:59
|
Revision: 221 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=221&view=rev Author: ligges Date: 2011-12-21 15:46:47 +0000 (Wed, 21 Dec 2011) Log Message: ----------- copied example into the package for test runs independent of openBUGS' Examples directory Modified Paths: -------------- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd Added Paths: ----------- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airinits1.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiadata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiainits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiamodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Cameldata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Camelinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Camelmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Linedata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Lineinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Linemodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsmissdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksdata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicaldata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalmodel.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalranddata.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalrandinits.txt trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalrandmodel.txt Modified: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-12-21 10:21:41 UTC (rev 220) +++ trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-12-21 15:46:47 UTC (rev 221) @@ -1,6 +1,5 @@ validateInstallOpenBUGS <- function( OpenBUGS.pgm=NULL, - OpenBUGS.examples=NULL, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL ) @@ -17,19 +16,6 @@ stop("Cannot find the OpenBUGS program") -if(is.null(OpenBUGS.examples)){ - if(.Platform$OS.type == "windows" | useWINE==TRUE){ - OpenBUGS.examples <- file.path(dirname(OpenBUGS.pgm), 'Examples') - }else { - ## best guess? - OpenBUGS.examples <- gsub("bin/OpenBUGS", "lib/OpenBUGS/Examples", OpenBUGS.pgm) - } -} - -if(!file.exists(OpenBUGS.examples)) - stop("Cannot find Examples in ", OpenBUGS.examples) - - test.models <- c("Air", "Asia", "Beetles", "BiRats", "Camel", "Dugongs", "Dyes", "Equiv", "Eyes", "Line", "OtreesMVN", "Rats", "Stacks", @@ -65,7 +51,7 @@ "results created using OpenBUGS version 3.2.1\n") for (i in seq(along=test.models)) { - exfiles <- dir(OpenBUGS.examples, pattern=test.pattern[i], full.names=TRUE) + exfiles <- dir(system.file("validateInstallOpenBUGS", package="R2OpenBUGS"), pattern=test.pattern[i], full.names=TRUE) ok <- file.copy(exfiles, tempdir()) fit <- round(bugs(data=test.datafile[i], inits=test.inits[i], para=test.params[[test.models[i]]],model.file=test.modelfile[i], Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2011-12-21 10:21:41 UTC (rev 220) +++ trunk/R2OpenBUGS/inst/NEWS 2011-12-21 15:46:47 UTC (rev 221) @@ -2,10 +2,13 @@ ====================== Update 3.2-1.3 -- cleanup: removed S-PLUS support completely since that was removed at several other places before +- cleanup: removed S-PLUS support completely since that was removed at several + other places before - fixed the bugs introduced with validInstallOpenBUGS - Changed handling of default OpenBUGS program location in a sensible way now - import logit from boot nowadays (seems nobody uses that anyway) +- examples from OpenBUGS copied into the package to allow for tests independent + of example data location Update 3.2-1.2 - Changed handling of default OpenBUGS program location and other changes Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(J = 3, y = c(21, 20, 15), n = c(48, 34, 21), Z = c(10, 30, 50), tau = 0.01234, alpha = 4.48, beta = 0.76) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ + list(theta = c(0.0, 0.0), X = c(0.0, 0.0, 0.0)) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airinits1.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airinits1.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airinits1.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(theta = c(NA, 0.0), theta0 = 0.0, X = c(0.0, 0.0, 0.0)) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Airmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,11 @@ + model + { + for(j in 1 : J) { + y[j] ~ dbin(p[j], n[j]) + logit(p[j]) <- theta[1] + theta[2] * X[j] + X[j] ~ dnorm(mu[j], tau) + mu[j] <- alpha + beta * Z[j] + } + theta[1] ~ dnorm(0.0, 0.001) + theta[2] ~ dnorm(0.0, 0.001) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiadata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiadata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiadata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,10 @@ +list(asia = 2, dyspnoea = 2, + p.tuberculosis = structure(.Data = c(0.99,0.01,0.95,0.05), .Dim = c(2,2)), + p.bronchitis = structure(.Data = c(0.70,0.30,0.40,0.60), .Dim = c(2,2)), + p.smoking = c(0.50,0.50), + p.lung.cancer = structure(.Data = c(0.99,0.01,0.90,0.10), .Dim = c(2,2)), + p.xray = structure(.Data = c(0.95,0.05,0.02,0.98), .Dim = c(2,2)), + p.dyspnoea = structure(.Data = c(0.9,0.1, + 0.2,0.8, + 0.3,0.7, + 0.1,0.9), .Dim = c(2,2,2))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiainits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiainits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiainits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(smoking = 1, tuberculosis = 1, lung.cancer = 1, bronchitis = 1, xray = 1) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiamodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiamodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Asiamodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,10 @@ + model + { + smoking ~ dcat(p.smoking[1:2]) + tuberculosis ~ dcat(p.tuberculosis[asia,1:2]) + lung.cancer ~ dcat(p.lung.cancer[smoking,1:2]) + bronchitis ~ dcat(p.bronchitis[smoking,1:2]) + either <- max(tuberculosis,lung.cancer) + xray ~ dcat(p.xray[either,1:2]) + dyspnoea ~ dcat(p.dyspnoea[either,bronchitis,1:2]) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,3 @@ +list( x = c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839), + n = c(59, 60, 62, 56, 63, 59, 62, 60), + r = c(6, 13, 18, 28, 52, 53, 61, 60), N = 8) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(alpha.star=0, beta=0) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Beetlesmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,11 @@ + model + { + for( i in 1 : N ) { + r[i] ~ dbin(p[i],n[i]) + logit(p[i]) <- alpha.star + beta * (x[i] - mean(x[])) + rhat[i] <- n[i] * p[i] + } + alpha <- alpha.star - beta * mean(x[]) + beta ~ dnorm(0.0,0.001) + alpha.star ~ dnorm(0.0,0.001) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,36 @@ + list(x = c(8.0, 15.0, 22.0, 29.0, 36.0), N = 30, T = 5, + Omega = structure(.Data = c(200, 0, 0, 0.2), .Dim = c(2, 2)), + mean = c(0,0), + prec = structure(.Data = c(1.0E-6, 0, 0, 1.0E-6), .Dim = c(2, 2)), + Y = structure( + .Data = c(151, 199, 246, 283, 320, + 145, 199, 249, 293, 354, + 147, 214, 263, 312, 328, + 155, 200, 237, 272, 297, + 135, 188, 230, 280, 323, + 159, 210, 252, 298, 331, + 141, 189, 231, 275, 305, + 159, 201, 248, 297, 338, + 177, 236, 285, 350, 376, + 134, 182, 220, 260, 296, + 160, 208, 261, 313, 352, + 143, 188, 220, 273, 314, + 154, 200, 244, 289, 325, + 171, 221, 270, 326, 358, + 163, 216, 242, 281, 312, + 160, 207, 248, 288, 324, + 142, 187, 234, 280, 316, + 156, 203, 243, 283, 317, + 157, 212, 259, 307, 336, + 152, 203, 246, 286, 321, + 154, 205, 253, 298, 334, + 139, 190, 225, 267, 302, + 146, 191, 229, 272, 302, + 157, 211, 250, 285, 323, + 132, 185, 237, 286, 331, + 160, 207, 257, 303, 345, + 169, 216, 261, 295, 333, + 157, 205, 248, 289, 316, + 137, 180, 219, 258, 291, + 153, 200, 244, 286, 324), + .Dim = c(30,5))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,10 @@ + list(mu.beta = c(0,0), tauC = 1, + beta = structure( + .Data = c(100,6,100,6,100,6,100,6,100,6, + 100,6,100,6,100,6,100,6,100,6, + 100,6,100,6,100,6,100,6,100,6, + 100,6,100,6,100,6,100,6,100,6, + 100,6,100,6,100,6,100,6,100,6, + 100,6,100,6,100,6,100,6,100,6), + .Dim = c(30, 2)), + R = structure(.Data = c(1,0,0,1), .Dim = c(2, 2))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/BiRatsmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,15 @@ + model + { + for( i in 1 : N ) { + beta[i , 1 : 2] ~ dmnorm(mu.beta[], R[ , ]) + for( j in 1 : T ) { + Y[i, j] ~ dnorm(mu[i , j], tauC) + mu[i, j] <- beta[i, 1] + beta[i, 2] * x[j] + } + } + + mu.beta[1 : 2] ~ dmnorm(mean[], prec[ , ]) + R[1 : 2 , 1 : 2] ~ dwish(Omega[ , ], 2) + tauC ~ dgamma(0.001, 0.001) + sigma <- 1 / sqrt(tauC) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Cameldata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Cameldata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Cameldata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,15 @@ +list(N= 12, + Y = structure( + .Data = c(1,1, + 1,-1, + -1,1, + -1, -1, + 2, NA, + 2, NA, + -2, NA, + -2, NA, + NA, 2, + NA, 2, + NA, -2, + NA, -2), + .Dim = c(12, 2))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Camelinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Camelinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Camelinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,15 @@ +list(tau = structure(.Data = c(0.1,0,0,0.1), .Dim = c(2,2)), + Y = structure( + .Data = c(NA,NA, + NA,NA, + NA,NA, + NA, NA, + NA, 1, + NA, 1, + NA, 1, + NA, 1, + 1, NA, + 1, NA, + 1, NA, + 1, NA), + .Dim = c(12, 2))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Camelmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Camelmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Camelmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,15 @@ + model + { + for (i in 1 : N){ + Y[i, 1 : 2] ~ dmnorm(mu[], tau[ , ]) + } + mu[1] <- 0 + mu[2] <- 0 + tau[1 : 2,1 : 2] ~ dwish(R[ , ], 2) + R[1, 1] <- 0.001 + R[1, 2] <- 0 + R[2, 1] <- 0; + R[2, 2] <- 0.001 + Sigma2[1 : 2,1 : 2] <- inverse(tau[ , ]) + rho <- Sigma2[1, 2] / sqrt(Sigma2[1, 1] * Sigma2[2, 2]) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,6 @@ + list(x = c( 1.0, 1.5, 1.5, 1.5, 2.5, 4.0, 5.0, 5.0, 7.0, + 8.0, 8.5, 9.0, 9.5, 9.5, 10.0, 12.0, 12.0, 13.0, + 13.0, 14.5, 15.5, 15.5, 16.5, 17.0, 22.5, 29.0, 31.5), + Y = c(1.80, 1.85, 1.87, 1.77, 2.02, 2.27, 2.15, 2.26, 2.47, + 2.19, 2.26, 2.40, 2.39, 2.41, 2.50, 2.32, 2.32, 2.43, + 2.47, 2.56, 2.65, 2.47, 2.64, 2.56, 2.70, 2.72, 2.57), N = 27) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(alpha = 1, beta = 1, tau = 1, gamma = 0.9) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dugongsmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,13 @@ + model + { + for( i in 1 : N ) { + Y[i] ~ dnorm(mu[i], tau) + mu[i] <- alpha - beta * pow(gamma,x[i]) + } + alpha ~ dnorm(0.0, 1.0E-6) + beta ~ dnorm(0.0, 1.0E-6) + gamma ~ dunif(0.5, 1.0) + tau ~ dgamma(0.001, 0.001) + sigma <- 1 / sqrt(tau) + U3 <- logit(gamma) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,8 @@ +list(batches = 6, samples = 5, + y = structure( + .Data = c(1545, 1440, 1440, 1520, 1580, + 1540, 1555, 1490, 1560, 1495, + 1595, 1550, 1605, 1510, 1560, + 1445, 1440, 1595, 1465, 1545, + 1595, 1630, 1515, 1635, 1625, + 1520, 1455, 1450, 1480, 1445), .Dim = c(6, 5))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(theta=1500, tau.with=1, tau.btw=1) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Dyesmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,14 @@ + model + { + for(i in 1 : batches) { + mu[i] ~ dnorm(theta, tau.btw) + for(j in 1 : samples) { + y[i , j] ~ dnorm(mu[i], tau.with) + } + } + sigma2.with <- 1 / tau.with + sigma2.btw <- 1 / tau.btw + tau.with ~ dgamma(0.001, 0.001) + tau.btw ~ dgamma(0.001, 0.001) + theta ~ dnorm(0.0, 1.0E-10) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,13 @@ +list(N = 10, P = 2, + group = c(1, 1, -1, -1, -1, 1, 1, 1, -1, -1), + Y = structure(.Data = c(1.40, 1.65, + 1.64, 1.57, + 1.44, 1.58, + 1.36, 1.68, + 1.65, 1.69, + 1.08, 1.31, + 1.09, 1.43, + 1.25, 1.44, + 1.25, 1.39, + 1.30, 1.52), .Dim = c(10, 2)), + sign = c(1, -1)) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(mu=0, phi=0, pi=0, tau1= 1, tau2 = 1) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Equivmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,20 @@ + model + { + for( k in 1 : P ) { + for( i in 1 : N ) { + Y[i , k] ~ dnorm(m[i , k], tau1) + m[i , k] <- mu + sign[T[i , k]] * phi / 2 + sign[k] * pi / 2 + delta[i] + T[i , k] <- group[i] * (k - 1.5) + 1.5 + } + } + for( i in 1 : N ) { + delta[i] ~ dnorm(0.0, tau2) + } + tau1 ~ dgamma(0.001, 0.001) sigma1 <- 1 / sqrt(tau1) + tau2 ~ dgamma(0.001, 0.001) sigma2 <- 1 / sqrt(tau2) + mu ~ dnorm(0.0, 1.0E-6) + phi ~ dnorm(0.0, 1.0E-6) + pi ~ dnorm(0.0, 1.0E-6) + theta <- exp(phi) + equiv <- step(theta - 0.8) - step(theta - 1.2) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,10 @@ +list(y = c(529.0, 530.0, 532.0, 533.1, 533.4, 533.6, 533.7, 534.1, 534.8, 535.3, + 535.4, 535.9, 536.1, 536.3, 536.4, 536.6, 537.0, 537.4, 537.5, 538.3, + 538.5, 538.6, 539.4, 539.6, 540.4, 540.8, 542.0, 542.8, 543.0, 543.5, + 543.8, 543.9, 545.3, 546.2, 548.8, 548.7, 548.9, 549.0, 549.4, 549.9, + 550.6, 551.2, 551.4, 551.5, 551.6, 552.8, 552.9,553.2), N = 48, alpha = c(1, 1), + T = c(1, NA, NA, NA, NA, NA, NA, NA, NA, NA, + NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, + NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, + NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, + NA, NA, NA, NA, NA, NA, NA, 2)) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(lambda = c(535, NA), theta = 5, tau = 0.1) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Eyesmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,13 @@ + model + { + for( i in 1 : N ) { + y[i] ~ dnorm(mu[i], tau) + mu[i] <- lambda[T[i]] + T[i] ~ dcat(P[]) + } + P[1:2] ~ ddirch(alpha[]) + theta ~ dnorm(0.0, 1.0E-6)I(0.0, ) + lambda[2] <- lambda[1] + theta + lambda[1] ~ dnorm(0.0, 1.0E-6) + tau ~ dgamma(0.001, 0.001) sigma <- 1 / sqrt(tau) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Linedata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Linedata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Linedata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(x = c(1, 2, 3, 4, 5), Y= c(1, 3, 3, 3, 5), xbar = 3, N = 5) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Lineinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Lineinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Lineinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(alpha = 0, beta = 0, tau = 1) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Linemodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Linemodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Linemodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,10 @@ + model + { + for( i in 1 : N ) { + Y[i] ~ dnorm(mu[i],tau) + mu[i] <- alpha + beta * (x[i] - xbar) + } + tau ~ dgamma(0.001,0.001) sigma <- 1 / sqrt(tau) + alpha ~ dnorm(0.0,1.0E-6) + beta ~ dnorm(0.0,1.0E-6) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,15 @@ + list(n = 7, K = 5, x = c(118.00, 484.00, 664.00, 1004.00, 1231.00, 1372.00, 1582.00), + Y = structure( + .Data = c(30.00, 58.00, 87.00, 115.00, 120.00, 142.00, 145.00, + 33.00, 69.00, 111.00, 156.00, 172.00, 203.00, 203.00, + 30.00, 51.00, 75.00, 108.00, 115.00, 139.00, 140.00, + 32.00, 62.00, 112.00, 167.00, 179.00, 209.00, 214.00, + 30.00, 49.00, 81.00, 125.00, 142.00, 174.00, 177.00), + .Dim = c(5, 7)), + mean = c(0, 0, 0), + R = structure(.Data = c(0.1, 0, 0, + 0, 0.1, 0, + 0, 0, 0.1), .Dim = c(3, 3)), + prec = structure(.Data = c(1.0E-6, 0, 0, + 0, 1.0E-6, 0, + 0, 0, 1.0E-6), .Dim = c(3, 3))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,12 @@ + list(theta = structure( + .Data = c(5, 2, -6, + 5, 2, -6, + 5, 2, -6, + 5, 2, -6, + 5, 2, -6), + .Dim = c(5, 3)), + mu = c(5, 2, -6), + tau = structure(.Data = c(0.1, 0, 0, + 0, 0.1, 0, + 0, 0, 0.1), .Dim = c(3, 3)), + tauC = 20) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/OtreesMVNmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,18 @@ + model { + for (i in 1:K) { + for (j in 1:n) { + Y[i, j] ~ dnorm(eta[i, j], tauC) + eta[i, j] <- phi[i, 1] / (1 + phi[i, 2] * exp(phi[i, 3] * x[j])) + } + phi[i, 1] <- exp(theta[i, 1]) + phi[i, 2] <- exp(theta[i, 2]) - 1 + phi[i, 3] <- -exp(theta[i, 3]) + theta[i, 1:3] ~ dmnorm(mu[1:3], tau[1:3, 1:3]) + } + mu[1:3] ~ dmnorm(mean[1:3], prec[1:3, 1:3]) + tau[1:3, 1:3] ~ dwish(R[1:3, 1:3], 3) + sigma2[1:3, 1:3] <- inverse(tau[1:3, 1:3]) + for (i in 1 : 3) {sigma[i] <- sqrt(sigma2[i, i]) } + tauC ~ dgamma(1.0E-3, 1.0E-3) + sigmaC <- 1 / sqrt(tauC) + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,33 @@ +list(x = c(8.0, 15.0, 22.0, 29.0, 36.0), xbar = 22, N = 30, T = 5, + Y = structure( + .Data = c(151, 199, 246, 283, 320, + 145, 199, 249, 293, 354, + 147, 214, 263, 312, 328, + 155, 200, 237, 272, 297, + 135, 188, 230, 280, 323, + 159, 210, 252, 298, 331, + 141, 189, 231, 275, 305, + 159, 201, 248, 297, 338, + 177, 236, 285, 350, 376, + 134, 182, 220, 260, 296, + 160, 208, 261, 313, 352, + 143, 188, 220, 273, 314, + 154, 200, 244, 289, 325, + 171, 221, 270, 326, 358, + 163, 216, 242, 281, 312, + 160, 207, 248, 288, 324, + 142, 187, 234, 280, 316, + 156, 203, 243, 283, 317, + 157, 212, 259, 307, 336, + 152, 203, 246, 286, 321, + 154, 205, 253, 298, 334, + 139, 190, 225, 267, 302, + 146, 191, 229, 272, 302, + 157, 211, 250, 285, 323, + 132, 185, 237, 286, 331, + 160, 207, 257, 303, 345, + 169, 216, 261, 295, 333, + 157, 205, 248, 289, 316, + 137, 180, 219, 258, 291, + 153, 200, 244, 286, 324), + .Dim = c(30,5))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,6 @@ +list(alpha = c(250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, + 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250), + beta = c(6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), + alpha.c = 150, beta.c = 10, + tau.c = 1, alpha.tau = 1, beta.tau = 1) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsmissdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsmissdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsmissdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,33 @@ + list(x = c(8.0, 15.0, 22.0, 29.0, 36.0), xbar = 22, N = 30, T = 5, + Y = structure( + .Data = c(151, 199, 246, 283, 320, + 145, 199, 249, 293, 354, + 147, 214, 263, 312, 328, + 155, 200, 237, 272, 297, + 135, 188, 230, 280, 323, + 159, 210, 252, 298, NA, + 141, 189, 231, 275, NA, + 159, 201, 248, 297, NA, + 177, 236, 285, 350, NA, + 134, 182, 220, 260, NA, + 160, 208, 261, 313, NA, + 143, 188, 220, NA, NA, + 154, 200, 244, NA, NA, + 171, 221, 270, NA, NA, + 163, 216, 242, NA, NA, + 160, 207, 248, NA, NA, + 142, 187, 234, NA, NA, + 156, 203, 243, NA, NA, + 157, 212, 259, NA, NA, + 152, 203, 246, NA, NA, + 154, 205, 253, NA, NA, + 139, 190, NA, NA, NA, + 146, 191, NA, NA, NA, + 157, 211, NA, NA, NA, + 132, 185, NA, NA, NA, + 160, NA, NA, NA, NA, + 169, NA, NA, NA, NA, + 157, NA, NA, NA, NA, + 137, NA, NA, NA, NA, + 153, NA, NA, NA, NA), + .Dim = c(30,5))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Ratsmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,18 @@ + model + { + for( i in 1 : N ) { + for( j in 1 : T ) { + Y[i , j] ~ dnorm(mu[i , j],tau.c) + mu[i , j] <- alpha[i] + beta[i] * (x[j] - xbar) + } + alpha[i] ~ dnorm(alpha.c,alpha.tau) + beta[i] ~ dnorm(beta.c,beta.tau) + } + tau.c ~ dgamma(0.001,0.001) + sigma <- 1 / sqrt(tau.c) + alpha.c ~ dnorm(0.0,1.0E-6) + alpha.tau ~ dgamma(0.001,0.001) + beta.c ~ dnorm(0.0,1.0E-6) + beta.tau ~ dgamma(0.001,0.001) + alpha0 <- alpha.c - xbar * beta.c + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksdata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksdata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksdata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,23 @@ +list(p = 3, N = 21, + Y = c(42, 37, 37, 28, 18, 18, 19, 20, 15, 14, 14, 13, 11, 12, 8, 7, 8, 8, 9, 15, 15), + x = structure(.Data = c( 80, 27, 89, + 80, 27, 88, + 75, 25, 90, + 62, 24, 87, + 62, 22, 87, + 62, 23, 87, + 62, 24, 93, + 62, 24, 93, + 58, 23, 87, + 58, 18, 80, + 58, 18, 89, + 58, 17, 88, + 58, 18, 82, + 58, 19, 93, + 50, 18, 89, + 50, 18, 86, + 50, 19, 72, + 50, 19, 79, + 50, 20, 80, + 56, 20, 82, + 70, 20, 91), .Dim = c(21, 3))) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ +list(beta0 = 10, beta=c(0,0, 0), tau = 0.1, phi = 0.1) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Stacksmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,35 @@ + model + { + # Standardise x's and coefficients + for (j in 1 : p) { + b[j] <- beta[j] / sd(x[ , j ]) + for (i in 1 : N) { + z[i, j] <- (x[i, j] - mean(x[, j])) / sd(x[ , j]) + } + } + b0 <- beta0 - b[1] * mean(x[, 1]) - b[2] * mean(x[, 2]) - b[3] * mean(x[, 3]) + + # Model + d <- 4; # degrees of freedom for t + for (i in 1 : N) { + Y[i] ~ dnorm(mu[i], tau) + # Y[i] ~ ddexp(mu[i], tau) + # Y[i] ~ dt(mu[i], tau, d) + + mu[i] <- beta0 + beta[1] * z[i, 1] + beta[2] * z[i, 2] + beta[3] * z[i, 3] + stres[i] <- (Y[i] - mu[i]) / sigma + outlier[i] <- step(stres[i] - 2.5) + step(-(stres[i] + 2.5) ) + } + # Priors + beta0 ~ dnorm(0, 0.00001) + for (j in 1 : p) { + beta[j] ~ dnorm(0, 0.00001) # coeffs independent + # beta[j] ~ dnorm(0, phi) # coeffs exchangeable (ridge regression) + } + tau ~ dgamma(1.0E-3, 1.0E-3) + phi ~ dgamma(1.0E-2,1.0E-2) + # standard deviation of error distribution + sigma <- sqrt(1 / tau) # normal errors + # sigma <- sqrt(2) / tau # double exponential errors + # sigma <- sqrt(d / (tau * (d - 2))); # t errors on d degrees of freedom + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicaldata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicaldata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicaldata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,3 @@ +list(n = c(47, 148, 119, 810, 211, 196, 148, 215, 207, 97, 256, 360), + r = c(0, 18, 8, 46, 8, 13, 9, 31, 14, 8, 29, 24), + N = 12) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1 @@ + list(p = c(0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1)) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,7 @@ + model + { + for( i in 1 : N ) { + p[i] ~ dbeta(1.0, 1.0) + r[i] ~ dbin(p[i], n[i]) + } + } Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalranddata.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalranddata.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalranddata.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,3 @@ +list(n = c(47, 148, 119, 810, 211, 196, 148, 215, 207, 97, 256, 360), + r = c(0, 18, 8, 46, 8, 13, 9, 31, 14, 8, 29, 24), + N = 12) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalrandinits.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalrandinits.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalrandinits.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,2 @@ +list(b = c( 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1), + tau = 1, mu = 0) \ No newline at end of file Added: trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalrandmodel.txt =================================================================== --- trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalrandmodel.txt (rev 0) +++ trunk/R2OpenBUGS/inst/validateInstallOpenBUGS/Surgicalrandmodel.txt 2011-12-21 15:46:47 UTC (rev 221) @@ -0,0 +1,12 @@ + model + { + for( i in 1 : N ) { + b[i] ~ dnorm(mu,tau) + r[i] ~ dbin(p[i],n[i]) + logit(p[i]) <- b[i] + } + pop.mean <- exp(mu) / (1 + exp(mu)) + mu ~ dnorm(0.0,1.0E-6) + sigma <- 1 / sqrt(tau) + tau ~ dgamma(0.001,0.001) + } Modified: trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd =================================================================== --- trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-12-21 10:21:41 UTC (rev 220) +++ trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-12-21 15:46:47 UTC (rev 221) @@ -9,7 +9,6 @@ \usage{ validateInstallOpenBUGS( OpenBUGS.pgm=NULL, - OpenBUGS.examples=NULL, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL ) @@ -17,9 +16,6 @@ \arguments{ \item{OpenBUGS.pgm}{See \code{\link{bugs}}.} - \item{OpenBUGS.examples}{A directory with the OpenBUGS examples - (text versions of model, data, and inits). If \code{NULL}, we try to derive the location - of the 'Examples' directory from the \code{OpenBUGS.pgm} directory.} \item{useWINE}{logical; attempt to use the Wine emulator to run \pkg{OpenBUGS}. Default is \code{FALSE}. If WINE is used, the arguments \code{OpenBUGS.pgm} and \code{working.directory} must be given in form of Linux paths rather than Windows paths (if not \code{NULL}).} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2011-12-21 10:13:31
|
Revision: 217 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=217&view=rev Author: ligges Date: 2011-12-21 10:13:19 +0000 (Wed, 21 Dec 2011) Log Message: ----------- - cleanup: removed S-PLUS support completely since that was removed at several other places before - fixed the bugs introduced with validInstallOpenBUGS - Changed handling of default OpenBUGS program location in a sensible way now - still needed: valid maintainer address, testing on Linux Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/NAMESPACE trunk/R2OpenBUGS/R/attach.all.R trunk/R2OpenBUGS/R/bugs.R trunk/R2OpenBUGS/R/bugs.data.R trunk/R2OpenBUGS/R/bugs.inits.R trunk/R2OpenBUGS/R/bugs.plot.inferences.R trunk/R2OpenBUGS/R/bugs.plot.summary.R trunk/R2OpenBUGS/R/bugs.run.R trunk/R2OpenBUGS/R/bugs.sims.R trunk/R2OpenBUGS/R/bugs.update.settings.R trunk/R2OpenBUGS/R/findOpenBUGS.R trunk/R2OpenBUGS/R/monitor.R trunk/R2OpenBUGS/R/plot.bugs.R trunk/R2OpenBUGS/R/read.bugs.R trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R trunk/R2OpenBUGS/R/wineutils.R trunk/R2OpenBUGS/R/write.model.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/inst/doc/bugs.tex trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd trunk/R2OpenBUGS/man/write.model.Rd trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/DESCRIPTION 2011-12-21 10:13:19 UTC (rev 217) @@ -1,7 +1,7 @@ Package: R2OpenBUGS Title: Running OpenBUGS from R -Date: 2011-12-15 -Version: 3.2-1.2 +Date: 2011-12-20 +Version: 3.2-1.3 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. @@ -12,7 +12,7 @@ it is possible to call a BUGS model, summarize inferences and convergence in a table and graph, and save the simulations in arrays for easy access in R. -Depends: R (>= 2.11.0), coda (>= 0.11-0) +Depends: R (>= 2.11.0), coda (>= 0.11-0), boot SystemRequirements: OpenBUGS (>= 3.2.1) Maintainer: Neal Thomas <nea...@ya...> License: GPL-2 Modified: trunk/R2OpenBUGS/NAMESPACE =================================================================== --- trunk/R2OpenBUGS/NAMESPACE 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/NAMESPACE 2011-12-21 10:13:19 UTC (rev 217) @@ -1,4 +1,5 @@ importFrom(coda, mcmc.list, as.mcmc.list, read.coda) +importFrom(boot, logit) export(bugs, attach.all, Modified: trunk/R2OpenBUGS/R/attach.all.R =================================================================== --- trunk/R2OpenBUGS/R/attach.all.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/attach.all.R 2011-12-21 10:13:19 UTC (rev 217) @@ -1,5 +1,4 @@ attach.all <- function(x, overwrite = NA, name = "attach.all"){ - if(is.R()){ rem <- names(x) %in% ls(.GlobalEnv) if(!any(rem)) overwrite <- FALSE rem <- names(x)[rem] @@ -17,12 +16,6 @@ } if(overwrite) remove(list=rem, envir=.GlobalEnv) attach(x, name=name) - } else { - ## next line is a dirty trick for R'd codetools check in R-2.5.0 - ## (should be removed after codetoold have been improved): - attach.default <- get("attach.default") - attach.default(x, name = name) - } } attach.bugs <- function (x, overwrite = NA){ @@ -36,17 +29,9 @@ } detach.all <- function(name = "attach.all"){ - if (is.R()){ do.call("detach", list(name=name)) - } else { - do.call("detach", list(what=name)) - } } detach.bugs <- function(){ - if (is.R()){ detach.all("bugs.sims") - } else { - invisible(detach.all("bugs.sims")) - } } Modified: trunk/R2OpenBUGS/R/bugs.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/bugs.R 2011-12-21 10:13:19 UTC (rev 217) @@ -14,11 +14,11 @@ if(is.null(OpenBUGS.pgm)){ OpenBUGS.pgm <- findOpenBUGS() - if(.Platform$OS.type == "windows" | useWINE==TRUE) + if(.Platform$OS.type == "windows" || useWINE) OpenBUGS.pgm <- file.path(OpenBUGS.pgm, "OpenBUGS.exe") - } +} -if(!file.exists(OpenBUGS.pgm) && OpenBUGS.pgm!='OpenBUGS') +if(!file.exists(OpenBUGS.pgm)) stop("Cannot find the OpenBUGS program") ## Is OpenBUGS.pgm defined in Windows (where second character is : @@ -28,7 +28,7 @@ } ### check options for unix/linux - if(.Platform$OS.type != "windows" && useWINE==FALSE){ + if(.Platform$OS.type != "windows" && !useWINE){ if(debug)stop("The debug option is not available with linux/unix") if(save.history)("History plots (save.history) are not available with linux/unix") } @@ -54,8 +54,6 @@ ## Wine if(useWINE) { - if(!is.R()) - stop("Non-Windows platforms not yet supported in R2OpenBUGS for S-PLUS") ## Attempt to find wine and winepath if(is.null(WINE)) WINE <- findUnixBinary(x="wine") if(is.null(WINEPATH)) WINEPATH <- findUnixBinary(x="winepath") @@ -80,15 +78,9 @@ ## model.file is not a file name but a model function if(is.function(model.file)){ temp <- tempfile("model") - temp <- - if(is.R() || .Platform$OS.type != "windows"){ - paste(temp, "txt", sep=".") - } else { - gsub("\\.tmp$", ".txt", temp) - } + temp <- paste(temp, "txt", sep=".") write.model(model.file, con=temp, digits=digits) model.file <- gsub("\\\\", "/", temp) - if(!is.R()) on.exit(file.remove(model.file), add=TRUE) } if(inTempDir && basename(model.file) == model.file) try(file.copy(file.path(savedWD, model.file), model.file, overwrite = TRUE)) Modified: trunk/R2OpenBUGS/R/bugs.data.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.data.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/bugs.data.R 2011-12-21 10:13:19 UTC (rev 217) @@ -1,239 +1,13 @@ "bugs.data" <- function(data, dir = getwd(), digits = 5, data.file = "data.txt"){ if(is.numeric(unlist(data))) - if(is.R()) { write.datafile(lapply(data, formatC, digits = digits, format = "E"), file.path(dir, data.file)) - } - else { - writeDatafileS4(data, towhere = data.file) - } else { - if(is.R()) { data.list <- lapply(as.list(data), get, pos = parent.frame(2)) names(data.list) <- as.list(data) write.datafile(lapply(data.list, formatC, digits = digits, format = "E"), file.path(dir, data.file)) - } - else { - data.list <- lapply(as.list(data), get, where = parent.frame(2)) - names(data.list) <- unlist(data) - writeDatafileS4(data.list, towhere = data.file) - } } return(data.file) } - - -if(is.R()){ - ## need some fake functions for codetools - toSingleS4 <- function(...) - stop("This function is not intended to be called in R!") - "writeDatafileS4" <- toSingleS4 -} else { - -### The rest of this file is for S-PLUS only... - - -"writeDatafileS4" <- -# -# Writes to file "towhere" text defining a list containing "DATA" in a form compatable with OpenBUGS. -# Required arguments: -# DATA - either a data frame or else a list consisting of any combination of scalars, vectors, arrays or data frames (but not lists). -# If a list, all list elements that are not data.frames must be named. Names of data.frames in DATA are ignored. -# Optional arguments: -# towhere - file to receive output. Is clipboard by default, which is convenient for pasting into a OpenBUGS ODC file. -# fill - If numeric, number of columns for output. If FALSE, output will be on one line. If TRUE (default), number of -# columns is given by .Options$width. -# Value: -# Text defining a list is output to file "towhere". -# Details: -# The function performs considerable checking of DATA argument. Since OpenBUGS requires numeric input, no factors or character vectors -# are allowed. All data must be named, either as named elements of DATA (if it is a list) or else using the names given in data frames. -# Data frames may contain matrices. -# Arrays of any dimension are rearranged to be in row-major order, as required by OpenBUGS. Scientific notation is also handled properly. -# In particular, the number will consist of a mantissa _containing a decimal point_ followed by "E", then either "+" or "-", and finally -# a _two-digit_ number. S-Plus does not always provide a decimal point in the mantissa, uses "e" instead of "E", followed by -# either a "+" or "-" and then _three_ digits. -# Written by Terry Elrod. Disclaimer: This function is used at the user's own risk. -# Please send comments to Ter...@UA.... -# Revision history: 2002-11-19. Fixed to handle missing values properly. -function(DATA, towhere = "clipboard", fill = TRUE) -{ - formatDataS4 = - # - # Prepared DATA for input to OpenBUGS. - function(DATA) - { - if(!is.list(DATA)) - stop("DATA must be a named list or data frame.") - dlnames <- names(DATA) - if(is.data.frame(DATA)) - DATA <- as.list(DATA) - # - # Checking for lists in DATA.... - lind <- sapply(DATA, is.list) - # Checking for data frames in DATA.... - dfind <- sapply(DATA, is.data.frame) - # Any lists that are not data frames?... - if(any(lind & !dfind)) stop("DATA may not contain lists.") - # Checking for unnamed elements of list that are not data frames.... - if(any(dlnames[!dfind] == "")) stop( - "When DATA is a list, all its elements that are not data frames must be named." - ) - # Checking for duplicate names.... - dupnames <- unique(dlnames[duplicated(dlnames)]) - if(length(dupnames) > 0) - stop(paste( - "The following names are used more than once in DATA:", - paste(dupnames, collapse = ", "))) - if(any(dfind)) { - dataold <- DATA - DATA <- vector("list", 0) - for(i in seq(along = dataold)) { - if(dfind[i]) - DATA <- c(DATA, as.list(dataold[[i]])) - else DATA <- c(DATA, dataold[i]) - } - dataold <- NULL - } - dlnames <- names(DATA) - dupnames <- unique(dlnames[duplicated(dlnames)]) - # Checking for duplicated names again (now that columns of data frames are included).... - if(length(dupnames) > 0) stop(paste( - "The following names are used more than once in DATA (at least once within a data frame):", - paste(dupnames, collapse = ", "))) - # Checking for factors.... - factorind <- sapply(DATA, is.factor) - if(any(factorind)) - stop(paste( - "DATA may not include factors. One or more factor variables were detected:", - paste(dlnames[factorind], collapse = ", "))) - # Checking for character vectors.... - charind <- sapply(DATA, is.character) - if(any(charind)) - stop(paste( - "OpenBUGS does not handle character data. One or more character variables were detected:", - paste(dlnames[charind], collapse = ", "))) - # Checking for complex vectors.... - complexind <- sapply(DATA, is.complex) - if(any(complexind)) - stop(paste( - "OpenBUGS does not handle complex data. One or more complex variables were detected:", - paste(dlnames[complexind], collapse = ", "))) - # Checking for values farther from zero than 1E+38 (which is limit of single precision).... - toobigind <- sapply(DATA, function(x) - { - y <- abs(x[!is.na(x)]) - any(y[y > 0] > 9.9999999999999998e+37) - } - ) - if(any(toobigind)) - stop(paste( - "OpenBUGS works in single precision. The following variables contain data outside the range +/-1.0E+38: ", - paste(dlnames[toobigind], collapse = ", "), - ".\n", sep = "")) - # Checking for values in range +/-1.0E-38 (which is limit of single precision).... - toosmallind <- sapply(DATA, function(x) - { - y <- abs(x[!is.na(x)]) - any(y[y > 0] < 9.9999999999999996e-39) - } - ) - n <- length(dlnames) - data.string <- as.list(rep(NA, n)) - for(i in 1:n) { - if(length(DATA[[i]]) == 1) { - ac <- toSingleS4(DATA[[i]]) - data.string[[i]] <- paste(names(DATA)[i], "=", - ac, sep = "") - next - } - if(is.vector(DATA[[i]]) & length(DATA[[i]]) > 1) { - ac <- toSingleS4(DATA[[i]]) - data.string[[i]] <- paste(names(DATA)[i], "=c(", - paste(ac, collapse = ", "), ")", sep = - "") - next - } - if(is.array(DATA[[i]])) { - ac <- toSingleS4(aperm(DATA[[i]])) - data.string[[i]] <- paste(names(DATA)[i], - "= structure(.Data= c(", paste(ac, - collapse = ", "), "), \n .Dim=c(", - paste(as.character(dim(DATA[[i]])), - collapse = ", "), "))", sep = "") - } - } - data.tofile <- paste("list(", paste(unlist(data.string), - collapse = ", "), ")", sep = "") - if(any(toosmallind)) - warning(paste( - "OpenBUGS works in single precision. The following variables contained nonzero data", - "\ninside the range +/-1.0E-38 that were set to zero: ", - paste(dlnames[toosmallind], collapse = ", "), - ".\n", sep = "")) - return(data.tofile) - } - rslt <- formatDataS4(DATA) - cat(rslt, file = towhere, fill = fill) - invisible(0) -} - - -toSingleS4 <- -# -# Takes numeric vector and removes digit of exponent in scientific notation (if any) -# -# Written by Terry Elrod. Disclaimer: This function is used at the user's own risk. -# Please send comments to Ter...@UA.... -# Revision history: 2002-11-19. Fixed to handle missing values properly. -function(x) -{ - xdim <- dim(x) - x <- as.character(as.single(x)) - - # First to look for positives: - pplus <- regMatchPos(x, "e\\+0") - pplusind <- apply(pplus, 1, function(y) - (!any(is.na(y)))) - if(any(pplusind)) { - # Making sure that periods are in mantissa... - init <- substring(x[pplusind], 1, pplus[ - pplusind, 1] - 1) - #...preceeding exponent - pper <- regMatchPos(init, "\\.") - pperind <- apply(pper, 1, function(y) - (all(is.na(y)))) - if(any(pperind)) - init[pperind] <- paste(init[pperind], - ".0", sep = "") - # Changing the format of the exponent... - x[pplusind] <- paste(init, "E+", substring( - x[pplusind], pplus[pplusind, 2] + 1), - sep = "") - } - # Then to look for negatives: - pminus <- regMatchPos(x, "e\\-0") - pminusind <- apply(pminus, 1, function(y) - (!any(is.na(y)))) - if(any(pminusind)) { - # Making sure that periods are in mantissa... - init <- substring(x[pminusind], 1, pminus[ - pminusind, 1] - 1) - #...preceeding exponent - pper <- regMatchPos(init, "\\.") - pperind <- apply(pper, 1, function(y) - (all(is.na(y)))) - if(any(pperind)) - init[pperind] <- paste(init[pperind], - ".0", sep = "") - # Changing the format of the exponent... - x[pminusind] <- paste(init, "E-", substring( - x[pminusind], pminus[pminusind, 2] + - 1), sep = "") - } - x -} - -} Modified: trunk/R2OpenBUGS/R/bugs.inits.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.inits.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/bugs.inits.R 2011-12-21 10:13:19 UTC (rev 217) @@ -4,18 +4,11 @@ if(!is.null(inits)) { for(i in 1:n.chains) { if(is.function(inits)) - if(is.R()) { write.datafile(lapply(inits(), formatC, digits = digits, format = "E"), inits.files[i]) - } else { - writeDatafileS4(inits(), towhere = inits.files[i]) - } - else if(is.R()) { + else write.datafile(lapply(inits[[i]], formatC, digits = digits, format = "E"), inits.files[i]) - } else { - writeDatafileS4(inits[[i]], towhere = inits.files[i]) - } } } return(inits.files) Modified: trunk/R2OpenBUGS/R/bugs.plot.inferences.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.plot.inferences.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/bugs.plot.inferences.R 2011-12-21 10:13:19 UTC (rev 217) @@ -29,16 +29,8 @@ height <- .6 par (mar=c(0,0,1,0)) - ## if in Splus, suppress printing of warnings during the plotting. - ## otherwise a warning is generated - if (!is.R()){ - warn.settings <- options("warn")[[1]] - options (warn = -1) - } plot (c(0,1), c(-n.roots-.5,-.4), ann=FALSE, bty="n", xaxt="n", yaxt="n", type="n") - if (!is.R()) - options(warn = warn.settings) W <- max(strwidth(rootnames, cex=cex.names)) B <- (1-W)/3.8 Modified: trunk/R2OpenBUGS/R/bugs.plot.summary.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.plot.summary.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/bugs.plot.summary.R 2011-12-21 10:13:19 UTC (rev 217) @@ -30,11 +30,7 @@ J[J==max(J)] <- max(J)-1 total <- ceiling(sum(J+.5)) } - if (is.R()){ pos <- -1 - } else { - pos <- -1.5 - } ypos <- NULL id <- NULL ystart <- NULL @@ -44,25 +40,12 @@ ystart <- numeric(n.roots) for (k in 1:n.roots){ ystart[k] <- pos - if (is.R()) { ypos <- c(ypos, pos - seq(0, J[k]-1)) - } else { - # In S-PLUS, increase the vertical spacing - ypos <- c(ypos, pos - 1.5*seq(0, J[k]-1)) - } id <- c(id, 1:J[k]) - if (is.R()) { pos <- pos - J[k] -.5 - } else { - pos <- pos - 1.5*J[k] -0.75 - } if (k>1) jj <- c(jj, sum(J0[1:(k-1)]) + (1:J[k])) } - if (is.R()){ bottom <- min(ypos)-1 - } else { - bottom <- min(ypos)-1.5 - } med <- numeric(sum(J)) i80 <- matrix( , sum(J), 2) i80.chains <- array (NA, c(sum(J), n.chains, 2)) @@ -78,16 +61,8 @@ a <- -b * p.rng[1] par (mar=c(0,0,1,3)) - # if in Splus, suppress printing of warnings during the plotting. - # otherwise a warning is generated - if (!is.R()){ - warn.settings <- options("warn")[[1]] - options (warn = -1) - } plot (c(0,1), c(min(bottom, -max.length)-3,2.5), ann=FALSE, bty="n", xaxt="n", yaxt="n", type="n") - if (!is.R()) - options(warn = warn.settings) W <- max(strwidth(unlist(dimnames(summ)[[1]]), cex=cex.names)) B <- (1-W)/3.6 @@ -126,16 +101,7 @@ for (j in 1:sum(J)){ name <- dimnames(summ)[[1]][jj[j]] if (id[j]==1) - if (is.R()) { text (0, ypos[j], name, adj=0, cex=cex.names) - } else { - # in S-PLUS, strwidth is an upper bound on the length of the string, - # so we must align the brackets differently than in R - pos <- as.vector(regexpr("[[]", name)) - text (0, ypos[j], substring(name, 1, pos-1), adj=0, cex=cex.names) - text (strwidth(substring(name,1,pos-1),cex=cex.names), - ypos[j], substring(name, pos, nchar(name)), adj=0, cex=cex.names) - } else { pos <- as.vector(regexpr("[[]", name)) text (strwidth(substring(name,1,pos-1),cex=cex.names), Modified: trunk/R2OpenBUGS/R/bugs.run.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.run.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/bugs.run.R 2011-12-21 10:13:19 UTC (rev 217) @@ -4,18 +4,11 @@ newWINE=TRUE, WINEPATH=NULL) { - if(useWINE && !is.R()) - stop("Non-Windows platforms not yet supported in R2OpenBUGS for S-PLUS") - - ## Update the lengths of the adaptive phases in the Bugs updaters +## Update the lengths of the adaptive phases in the Bugs updaters # try(bugs.update.settings(n.burnin, bugs.directory)) # # ## Return the lengths of the adaptive phases to their original settings -# if(is.R()) { # .fileCopy <- file.copy -# } else { -# .fileCopy <- splus.file.copy -# } # on.exit(try(.fileCopy(file.path(bugs.directory, "System/Rsrc/Registry_Rsave.odc"), # file.path(bugs.directory, "System/Rsrc/Registry.odc"), # overwrite=TRUE))) @@ -41,12 +34,8 @@ ## !!!! need to check these conditions ## Stop and print an error message if Bugs did not run correctly - if(is.R()) { tmp <- scan("CODAchain1.txt", character(), quiet=TRUE, sep="\n") - } else { - tmp <- scan("CODAchain1.txt", character(), sep="\n") - } - tmp<-tmp[1:min(100,length(tmp))] + tmp <- tmp[1:min(100,length(tmp))] if(length(grep("OpenBUGS did not run correctly", tmp)) > 0) stop(paste("Look at the log file in ",getwd(), " and\ntry again with 'debug=TRUE' to figure out what went wrong within OpenBUGS.")) } Modified: trunk/R2OpenBUGS/R/bugs.sims.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.sims.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/bugs.sims.R 2011-12-21 10:13:19 UTC (rev 217) @@ -5,16 +5,8 @@ sims.files <- paste ("CODAchain", 1:n.chains, ".txt", sep="") ## read in the names of the parameters and the indices of their samples index <- read.table("CODAindex.txt", header = FALSE, sep = " ") - ## in Splus, read.table interprets the first row of the file as row names, - ## while in R it does not - if(is.R()) { - parameter.names <- as.vector(index[, 1]) - n.keep <- index[1, 3] - index[1, 2] + 1 - } - else { - parameter.names <- row.names(index) - n.keep <- index[1, 2] - index[1, 1] + 1 - } + parameter.names <- as.vector(index[, 1]) + n.keep <- index[1, 3] - index[1, 2] + 1 n.parameters <- length(parameter.names) n.sims <- n.keep*n.chains sims <- matrix( , n.sims, n.parameters) @@ -58,11 +50,7 @@ rank.long <- unlist(long.short) for (i in 1:n.chains){ - if(is.R()) { sims.i <- scan(sims.files[i], quiet = TRUE)[2 * (1:(n.keep * n.parameters))] - } else { - sims.i <- scan(sims.files[i])[2 * (1:(n.keep * n.parameters))] - } sims[(n.keep*(i-1)+1):(n.keep*i), ] <- sims.i sims.array[,i,] <- sims.i } @@ -125,7 +113,6 @@ LOG <- bugs.log("log.txt")$DIC 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] pD <- numeric(n.chains) DIC <- numeric(n.chains) @@ -144,5 +131,3 @@ } all } - -if(!is.R()) .subset <- function(x, index) x[index] Modified: trunk/R2OpenBUGS/R/bugs.update.settings.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.update.settings.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/bugs.update.settings.R 2011-12-21 10:13:19 UTC (rev 217) @@ -1,7 +1,6 @@ "bugs.update.settings" <- function (n.burnin, bugs.directory) { - if(is.R()) { .fileCopy <- file.copy .regexpr <- function(...) regexpr(..., useBytes = TRUE) .sub <- function(...) sub(..., useBytes = TRUE) @@ -10,12 +9,6 @@ function(...) writeBin(..., useBytes = TRUE) else writeBin - } else { - .fileCopy <- splus.file.copy - .regexpr <- regexpr - .sub <- sub - .writeBin <- writeBin - } char.burnin <- as.character(n.burnin - 1) @@ -46,15 +39,3 @@ .writeBin(registry, file.path(bugs.directory, "System/Rsrc/Registry.odc"), endian="little") } - - -splus.file.copy <- function(from, to, overwrite=FALSE) -{ - if(!file.exists(from)) - stop("File: ", from, " does not exist") - if(!overwrite && file.exists(to)) - stop("File: ", to, " already exists and overwrite is FALSE") - n <- file.info(from)$size - z <- writeBin(readBin(from, what="integer", size=1, n=n), to, size=1) - invisible(z) -} Modified: trunk/R2OpenBUGS/R/findOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/findOpenBUGS.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/findOpenBUGS.R 2011-12-21 10:13:19 UTC (rev 217) @@ -8,7 +8,7 @@ return(dir) if(.Platform$OS.type != "windows") - return('/usr/local/bin/OpenBUGS') + return(Sys.which('OpenBUGS')) deps <- utils:::packageDescription("R2OpenBUGS", fields="SystemRequirements") version.req <- gsub(".*OpenBUGS ?\\(>= ?(.+)\\).*", "\\1", deps) Modified: trunk/R2OpenBUGS/R/monitor.R =================================================================== --- trunk/R2OpenBUGS/R/monitor.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/monitor.R 2011-12-21 10:13:19 UTC (rev 217) @@ -30,9 +30,6 @@ confshrink = conv.p$confshrink, n.eff = conv.p$n.eff) } else if (trans[i]=="logit"){ - if (!is.R()){ - logit <- function (x) { log(x /(1- x)) } - } conv.p <- conv.par(logit(ai), n.chains, Rupper.keep=Rupper.keep) conv.p <- list(quantiles = invlogit(conv.p$quantiles), confshrink = conv.p$confshrink, n.eff = conv.p$n.eff) Modified: trunk/R2OpenBUGS/R/plot.bugs.R =================================================================== --- trunk/R2OpenBUGS/R/plot.bugs.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/plot.bugs.R 2011-12-21 10:13:19 UTC (rev 217) @@ -2,10 +2,7 @@ mar.old <- par("mar") pty.old <- par(pty = "m") mfrow.old <- par("mfrow") - if (is.R()) layout(matrix(c(1,2),1,2)) - else - par(mfrow = c(1,2)) bugs.plot.summary (x, ...) bugs.plot.inferences (x, display.parallel, ...) @@ -17,42 +14,5 @@ header <- paste(header, x$n.chains, " chains, each with ", x$n.iter, " iterations (first ", x$n.burnin, " discarded)", sep = "") mtext(header, outer = TRUE, line = -1, cex = 0.7) - if (is.R()) par(pty = pty.old[[1]], mar = mar.old, mfrow = mfrow.old) - else invisible(par(pty = pty.old[[1]], mar = mar.old, mfrow = mfrow.old)) + par(pty = pty.old[[1]], mar = mar.old, mfrow = mfrow.old) } - -if (!is.R()) { - -strwidth <-function(s, units = c("user", "inches", "figure"), cex = NULL) { - s<-as.character(s) - if (!missing(cex)) { - oldcex <- par(cex=cex) - on.exit(par(oldcex)) - } - units <- match.arg(units) - if (units == "user") { - nchar(s) * par("cxy")[1] - } else if (units == "inches") { - nchar(s) * par("cin")[1] - } else if (units == "figure") { - nchar(s) * par("cin")[1] / par("fin")[1] - } -} - -strheight <- function(s, units = "user", cex = NULL) { - s<-as.character(s) - if (!missing(cex)) { - oldcex <- par(cex=cex) - on.exit(par(oldcex)) - } - units <- match.arg(units) - if (units == "user") { - par("cxy")[2] - } else if (units == "inches") { - par("cin")[2] - } else if (units == "figure") { - par("cin")[2] / par("fin")[2] - } -} - -} #ends if (!is.R()) Modified: trunk/R2OpenBUGS/R/read.bugs.R =================================================================== --- trunk/R2OpenBUGS/R/read.bugs.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/read.bugs.R 2011-12-21 10:13:19 UTC (rev 217) @@ -1,6 +1,4 @@ read.bugs <- function(codafiles, ...){ - if(!is.R() && !require("coda")) - stop("package 'coda' is required to use this function") mcmc.list(lapply(codafiles, read.coda, index.file = file.path(dirname(codafiles[1]), "CODAindex.txt"), ...)) Modified: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2011-12-21 10:13:19 UTC (rev 217) @@ -13,14 +13,17 @@ OpenBUGS.pgm <- file.path(OpenBUGS.pgm, "OpenBUGS.exe") } -if(!file.exists(OpenBUGS.pgm) && OpenBUGS.pgm!='OpenBUGS') +if(!file.exists(OpenBUGS.pgm)) stop("Cannot find the OpenBUGS program") if(is.null(OpenBUGS.examples)){ if(.Platform$OS.type == "windows" | useWINE==TRUE){ OpenBUGS.examples <- file.path(dirname(OpenBUGS.pgm), 'Examples') - }else OpenBUGS.examples <-'/usr/local/lib/OpenBUGS/doc/Examples' + }else { + ## best guess? + OpenBUGS.examples <- gsub("bin/OpenBUGS", "lib/OpenBUGS/Examples", OpenBUGS.pgm) + } } if(!file.exists(OpenBUGS.examples)) Modified: trunk/R2OpenBUGS/R/wineutils.R =================================================================== --- trunk/R2OpenBUGS/R/wineutils.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/wineutils.R 2011-12-21 10:13:19 UTC (rev 217) @@ -26,7 +26,6 @@ native2win <- function(x, useWINE=.Platform$OS.type != "windows", newWINE=TRUE, WINEPATH=NULL) { - if (is.R()){ ## Translate Unix path to Windows (wine) path if(useWINE) { if(newWINE) { @@ -39,9 +38,6 @@ } else { x } - } else { #S-PLUS - gsub("\\\\", "/", x) - } } win2native <- function(x, useWINE=.Platform$OS.type != "windows", Modified: trunk/R2OpenBUGS/R/write.model.R =================================================================== --- trunk/R2OpenBUGS/R/write.model.R 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/R/write.model.R 2011-12-21 10:13:19 UTC (rev 217) @@ -1,26 +1,11 @@ write.model <- function(model, con = "model.bug", digits = 5) { - if (is.R()){ - model.text <- c("model", replaceScientificNotationR(body(model), digits = digits)) - # "[\+\-]?\d*\.?[Ee]?[\+\-]?\d*" - } else { - ## In S-PLUS the source code of a function can be obtained with - ## as.character(function_name). This omits the "function_name <- function()" piece - model.text <- paste("model", as.character(model)) - } + model.text <- c("model", replaceScientificNotationR(body(model), digits = digits)) + # "[\+\-]?\d*\.?[Ee]?[\+\-]?\d*" model.text <- gsub("%_%", "", model.text) - if (!is.R()){ - ## In S-PLUS, scientific notation is different than it is in OpenBUGS. - ## Change the format of any numbers in scientific notation. - model.text <- replaceScientificNotationS(model.text) - - ## remove the "invisible()" line. - model.text <- gsub("invisible[ ]*\\([ ]*\\)", "", model.text) - } writeLines(model.text, con = con) } - replaceScientificNotationR <- function(bmodel, digits = 5){ env <- new.env() assign("rSNRidCounter", 0, envir=env) @@ -47,37 +32,3 @@ } bmodel } - - - -replaceScientificNotationS <- function(text){ -## Change the format of any numbers in "text" that are in S-PLUS -## scientific notation to OpenBUGS scientific notation - - ## First, handle the positive exponents - ## Find the first instance - ## Note that the number may or may not have a decimal point. - sciNoteLoc <- regexpr("[0-9]*\\.{0,1}[0-9]*e\\+0[0-9]{2}", text) - - ## For every instance, replace the number - while(sciNoteLoc > -1){ - sciNoteEnd <- sciNoteLoc + attr(sciNoteLoc, "match.length")-1 - sciNote <- substring(text, sciNoteLoc, sciNoteEnd) - text <- gsub(sciNote, toSingleS4(sciNote), text) - sciNoteLoc <- regexpr("[0-9]*\\.{0,1}[0-9]*e\\+0[0-9]{2}", text) - } - - ## Then, handle the negative exponents - ## Find the first instance - sciNoteLoc <- regexpr("[0-9]*\\.{0,1}[0-9]*e\\-0[0-9]{2}", text) - - ## For every instance, replace the number - while(sciNoteLoc > -1){ - sciNoteEnd <- sciNoteLoc + attr(sciNoteLoc, "match.length")-1 - sciNote <- substring(text, sciNoteLoc, sciNoteEnd) - text <- gsub(sciNote, toSingleS4(sciNote), text) - sciNoteLoc <- regexpr("[0-9]*\\.{0,1}[0-9]*e\\-0[0-9]{2}", text) - } - - text -} Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/inst/NEWS 2011-12-21 10:13:19 UTC (rev 217) @@ -1,6 +1,11 @@ Changes to R2OpenBUGS: ====================== +Update 3.2-1.3 +- cleanup: removed S-PLUS support completely since that was removed at several other places before +- fixed the bugs introduced with validInstallOpenBUGS +- Changed handling of default OpenBUGS program location in a sensible way now + Update 3.2-1.2 - Changed handling of default OpenBUGS program location and other changes required for cran compliance Modified: trunk/R2OpenBUGS/inst/doc/bugs.tex =================================================================== --- trunk/R2OpenBUGS/inst/doc/bugs.tex 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/inst/doc/bugs.tex 2011-12-21 10:13:19 UTC (rev 217) @@ -1,25 +1,25 @@ \inputencoding{utf8} -\HeaderA{bugs}{Run OpenBUGS from R or S-PLUS}{bugs} +\HeaderA{bugs}{Run OpenBUGS from R}{bugs} \keyword{interface}{bugs} \keyword{models}{bugs} % \begin{Description}\relax The \code{bugs} function takes data and starting values as input. It automatically writes a \pkg{OpenBUGS} script, calls the model, and -saves the simulations for easy access in \R{} or S-PLUS. +saves the simulations for easy access in \R{}. \end{Description} % \begin{Usage} \begin{verbatim} bugs(data, inits, parameters.to.save, n.iter, model.file="model.txt", - n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, + n.chains=3, n.burnin=floor(n.iter / 2), n.thin=1, saveExec=FALSE,restart=FALSE, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, OpenBUGS.pgm=NULL, working.directory=NULL, clearWD=FALSE, useWINE=FALSE, WINE=NULL, newWINE=TRUE, WINEPATH=NULL, bugs.seed=1, summary.only=FALSE, - save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), - over.relax = FALSE) + save.history=(.Platform$OS.type == "windows" | useWINE==TRUE), + over.relax = FALSE) \end{verbatim} \end{Usage} % @@ -28,15 +28,15 @@ \item[\code{data}] either a named list (names corresponding to variable names in the \code{model.file}) of the data for the \pkg{OpenBUGS} model, \emph{or} a vector or list of the names of the data objects used by -the model. If \code{data} is a one element character vector (such as \code{"data.txt"}), -it is assumed that data have already been written to the working directory into that file, +the model. If \code{data} is a one element character vector (such as \code{"data.txt"}), +it is assumed that data have already been written to the working directory into that file, e.g. by the function \code{\LinkA{bugs.data}{bugs.data}}. \item[\code{inits}] a list with \code{n.chains} elements; each element of the list is itself a list of starting values for the \pkg{OpenBUGS} model, \emph{or} a function creating (possibly random) initial values. Alternatively, if \code{inits=NULL}, initial values are generated -by \pkg{OpenBUGS}. If \code{inits} is a character vector with \code{n.chains} elements, -it is assumed that inits have already been written to the working directory into those files, +by \pkg{OpenBUGS}. If \code{inits} is a character vector with \code{n.chains} elements, +it is assumed that inits have already been written to the working directory into those files, e.g. by the function \code{\LinkA{bugs.inits}{bugs.inits}}. \item[\code{parameters.to.save}] character vector of the names of the parameters to save which should be monitored @@ -45,8 +45,8 @@ The old convention allowing model.file to be named \file{.bug} has been eliminated because the new \pkg{OpenBUGS} feature that allows the program image to be saved and later restarted uses the .bug extension for the saved -images. -Alternatively, \code{model.file} can be an R function that contains a BUGS model that is written to a +images. +Alternatively, \code{model.file} can be an R function that contains a BUGS model that is written to a temporary model file (see \code{\LinkA{tempfile}{tempfile}}) using \code{\LinkA{write.model}{write.model}}. \item[\code{n.chains}] number of Markov chains (default: 3) \item[\code{n.iter}] number of total iterations per chain (including burn in; @@ -54,26 +54,26 @@ \item[\code{n.burnin}] length of burn in, i.e. number of iterations to discard at the beginning. Default is \code{n.iter/2}, that is, discarding the first half of the simulations. -\item[\code{n.thin}] Thinning rate. Must be a positive integer. The default is +\item[\code{n.thin}] Thinning rate. Must be a positive integer. The default is \code{n.thin} = 1. The thinning is implemented in the OpenBUGS update phase, so thinned samples are never stored, and they are not counted in \code{n.burnin} or -\code{n.iter}. Setting \code{n.thin}=2, doubles the number of iterations OpenBUGS +\code{n.iter}. Setting \code{n.thin}=2, doubles the number of iterations OpenBUGS performs, but does not change \code{n.iter} or \code{n.burnin}. Thinning implemented in this manner is not captured in summaries created by packages such as \pkg{coda}. \item[\code{saveExec}] If TRUE, a re-startable image of the OpenBUGS execution is saved with \code{basename(model.file)} and extension .bug in the working -directory, which must be specified. The .bug files can be large, so +directory, which must be specified. The .bug files can be large, so users should monitor them carefully and remove them when not needed. \item[\code{restart}] If TRUE, execution resumes with the final status from the previous execution stored in the .bug file in the working directory. If \code{n.burnin=0},additional iterations are performed and all iterations since the previous burnin are used (including those from past executions). If -\code{n.burnin>0}, a new burnin is performed, and the previous iterations are +\code{n.burnin>0}, a new burnin is performed, and the previous iterations are discarded, but execution continues from the status at the end of the previous -execution. When \code{restart=TRUE}, only \code{n.burnin}, \code{n.iter}, -and \code{saveExec} inputs -should be changed from the call creating the .bug file, otherwise +execution. When \code{restart=TRUE}, only \code{n.burnin}, \code{n.iter}, +and \code{saveExec} inputs +should be changed from the call creating the .bug file, otherwise failed or erratic results may be produced. Note the default has \code{n.burnin>0}. \item[\code{debug}] if \code{FALSE} (default), \pkg{OpenBUGS} is closed automatically @@ -89,15 +89,15 @@ is returned, if \code{TRUE} file names of \pkg{OpenBUGS} output are returned for easy access by the \pkg{coda} package through function \code{\LinkA{read.bugs}{read.bugs}}. -A \code{bugs} object can be converted to an \code{mcmc.list} object as -used by the \pkg{coda} package with the method \code{\LinkA{as.mcmc.list}{as.mcmc.list}} +A \code{bugs} object can be converted to an \code{mcmc.list} object as +used by the \pkg{coda} package with the method \code{\LinkA{as.mcmc.list}{as.mcmc.list}} (for which a method is provided by R2OpenBUGS). \item[\code{OpenBUGS.pgm}] For Windows or WINE execution, the full path to the OpenBUGS executable. For linux execution, the full path to the OpenBUGS shell script (not -required if OpenBUGS is in the user's PATH variable). -If \code{NULL} (unset) and the environment variable \code{OpenBUGS\_PATH} is set the latter will be used as the default. +required if OpenBUGS is in the user's PATH variable). +If \code{NULL} (unset) and the environment variable \code{OpenBUGS\_PATH} is set the latter will be used as the default. If \code{NULL} (unset), the environment variable \code{OpenBUGS\_PATH} is unset and the global option \code{R2OpenBUGS.pgm} is not \code{NULL} the latter will be used as the default. -If nothing of the former is set and OS is Windows, the most recent OpenBUGS version +If nothing of the former is set and OS is Windows, the most recent OpenBUGS version registered in the Windows registry will be used as the default. \item[\code{working.directory}] sets working directory during execution of @@ -113,17 +113,17 @@ \pkg{OpenBUGS}. Default is \code{FALSE}. If WINE is used, the arguments \code{OpenBUGS.pgm} and \code{working.directory} must be given in form of Linux paths rather than Windows paths (if not \code{NULL}). \item[\code{WINE}] Character, path to \file{wine} binary file, it is -tried hard (by a guess and the utilities \code{which} and \code{locate}) +tried hard (by a guess and the utilities \code{which} and \code{locate}) to get the information automatically if not given. \item[\code{newWINE}] Use new versions of Wine that have \file{winepath} utility \item[\code{WINEPATH}] Character, path to \file{winepath} binary file, it is -tried hard (by a guess and the utilities \code{which} and \code{locate}) +tried hard (by a guess and the utilities \code{which} and \code{locate}) to get the information automatically if not given. -\item[\code{bugs.seed}] Random seed for \pkg{OpenBUGS}. Must be an integer between 1-14. Seed -specification changed between WinBUGS and OpenBUGS; see the OpenBUGS documentation for +\item[\code{bugs.seed}] Random seed for \pkg{OpenBUGS}. Must be an integer between 1-14. Seed +specification changed between WinBUGS and OpenBUGS; see the OpenBUGS documentation for details. -\item[\code{summary.only}] If \code{TRUE}, only a parameter summary for very quick analyses is given, +\item[\code{summary.only}] If \code{TRUE}, only a parameter summary for very quick analyses is given, temporary created files are not removed in that case. \item[\code{save.history}] If \code{TRUE} (the default), trace plots are generated at the end. \item[\code{over.relax}] If \code{TRUE}, over-relaxed form of MCMC is used if available from OpenBUGS. @@ -136,13 +136,13 @@ \item Write a \pkg{BUGS} model in an ASCII file (hint: use \code{\LinkA{write.model}{write.model}}). -\item Go into \R{} / S-PLUS. +\item Go into \R{}. \item Prepare the inputs for the \code{bugs} function and run it (see Example section). -\item An \pkg{OpenBUGS} window will pop up and \R{} / S-PLUS will freeze +\item An \pkg{OpenBUGS} window will pop up and \R{} will freeze up. The model will now run in \pkg{OpenBUGS}. It might take awhile. You will see things happening in the Log window within \pkg{OpenBUGS}. When -\pkg{OpenBUGS} is done, its window will close and \R{} / S-PLUS will work +\pkg{OpenBUGS} is done, its window will close and \R{} will work again. \item If an error message appears, re-run with \code{debug=TRUE}. @@ -174,7 +174,7 @@ Windows path style (e.g. ``c:/Program Files/OpenBUGS/'') or native (Unix) style (e.g. ``/path/to/wine/folder/dosdevices/c:/Program -Files/OpenBUGS/OpenBUGS321/OpenBUGS.exe''). +Files/OpenBUGS/OpenBUGS321/OpenBUGS.exe''). \end{Details} % @@ -278,7 +278,7 @@ parameters <- c("theta", "mu.theta", "sigma.theta") -## Not run: +## Not run: ## You may need to specify "OpenBUGS.pgm" ## also you need write access in the working directory: schools.sim <- bugs(data, inits, parameters, model.file, Modified: trunk/R2OpenBUGS/man/bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.Rd 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/man/bugs.Rd 2011-12-21 10:13:19 UTC (rev 217) @@ -102,7 +102,7 @@ If none of the former are set and OS is Windows, the most recent OpenBUGS version registered in the Windows registry will be used as the default. - For linux OS, the default location is /usr/local/bin/OpenBUGS. + For other operating systems, the location is guessed by \code{Sys.which("OpenBUGS")}. } \item{working.directory}{sets working directory during execution of this function; \pkg{OpenBUGS}' in- and output will be stored in this Modified: trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd =================================================================== --- trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/man/validateInstallOpenBUGS.Rd 2011-12-21 10:13:19 UTC (rev 217) @@ -18,11 +18,8 @@ \arguments{ \item{OpenBUGS.pgm}{See \code{\link{bugs}}.} \item{OpenBUGS.examples}{A directory with the OpenBUGS examples - (text versions of model, data, and inits). If \code{NULL}, for - Windows and WINE execution, 'Examples' directory is searched in the - \code{OpenBUGS.pgm} directory. For linux execution, the - directory is /usr/local/lib/OpenBUGS/doc/Examples, which is the default - location for the OpenBUGS linux installer.} + (text versions of model, data, and inits). If \code{NULL}, we try to derive the location + of the 'Examples' directory from the \code{OpenBUGS.pgm} directory.} \item{useWINE}{logical; attempt to use the Wine emulator to run \pkg{OpenBUGS}. Default is \code{FALSE}. If WINE is used, the arguments \code{OpenBUGS.pgm} and \code{working.directory} must be given in form of Linux paths rather than Windows paths (if not \code{NULL}).} Modified: trunk/R2OpenBUGS/man/write.model.Rd =================================================================== --- trunk/R2OpenBUGS/man/write.model.Rd 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/man/write.model.Rd 2011-12-21 10:13:19 UTC (rev 217) @@ -44,10 +44,8 @@ sigma.theta ~ dunif (0, 1000) } -if (is.R()){ # for R ## some temporary filename: filename <- file.path(tempdir(), "schoolsmodel.bug") -} ## write model file: write.model(schoolsmodel, filename) Modified: trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save =================================================================== --- trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save 2011-12-19 13:12:00 UTC (rev 216) +++ trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save 2011-12-21 10:13:19 UTC (rev 217) @@ -1,5 +1,5 @@ -R Under development (unstable) (2011-08-25 r56795) +R version 2.14.0 (2011-10-31) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-bit) @@ -19,6 +19,14 @@ > library("R2OpenBUGS") Loading required package: coda Loading required package: lattice +Loading required package: boot + +Attaching package: 'boot' + +The following object(s) are masked from 'package:lattice': + + melanoma + > validateInstallOpenBUGS() The version of OpenBUGS on your computer is being compared to validation results created using OpenBUGS version 3.2.1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2011-12-22 10:27:05
|
Revision: 226 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=226&view=rev Author: ligges Date: 2011-12-22 10:26:55 +0000 (Thu, 22 Dec 2011) Log Message: ----------- moved dependencies to imports Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/NAMESPACE trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2011-12-22 10:25:55 UTC (rev 225) +++ trunk/R2OpenBUGS/DESCRIPTION 2011-12-22 10:26:55 UTC (rev 226) @@ -12,8 +12,8 @@ it is possible to call a BUGS model, summarize inferences and convergence in a table and graph, and save the simulations in arrays for easy access in R. -Depends: R (>= 2.11.0), coda (>= 0.11-0), boot +Depends: R (>= 2.11.0) +Imports: coda (>= 0.11-0), boot SystemRequirements: OpenBUGS (>= 3.2.1) Maintainer: Neal Thomas <snt...@ya...> License: GPL-2 -Dialect: R Modified: trunk/R2OpenBUGS/NAMESPACE =================================================================== --- trunk/R2OpenBUGS/NAMESPACE 2011-12-22 10:25:55 UTC (rev 225) +++ trunk/R2OpenBUGS/NAMESPACE 2011-12-22 10:26:55 UTC (rev 226) @@ -1,4 +1,4 @@ -importFrom(coda, mcmc.list, as.mcmc.list, read.coda) +importFrom(coda, mcmc, mcmc.list, as.mcmc.list, read.coda) importFrom(boot, logit) export(bugs, Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2011-12-22 10:25:55 UTC (rev 225) +++ trunk/R2OpenBUGS/inst/NEWS 2011-12-22 10:26:55 UTC (rev 226) @@ -9,6 +9,7 @@ - import logit from boot nowadays (seems nobody uses that anyway) - examples from OpenBUGS copied into the package to allow for tests independent of example data location +- moved dependencies to imports Update 3.2-1.2 - Changed handling of default OpenBUGS program location and other changes Modified: trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save =================================================================== --- trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save 2011-12-22 10:25:55 UTC (rev 225) +++ trunk/R2OpenBUGS/tests/R2OpenBUGS.Rout.save 2011-12-22 10:26:55 UTC (rev 226) @@ -17,16 +17,6 @@ Type 'q()' to quit R. > library("R2OpenBUGS") -Loading required package: coda -Loading required package: lattice -Loading required package: boot - -Attaching package: 'boot' - -The following object(s) are masked from 'package:lattice': - - melanoma - > validateInstallOpenBUGS() The version of OpenBUGS on your computer is being compared to validation results created using OpenBUGS version 3.2.1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2012-02-08 12:57:42
|
Revision: 249 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=249&view=rev Author: snthomas99 Date: 2012-02-08 12:57:28 +0000 (Wed, 08 Feb 2012) Log Message: ----------- Fixing DIC problem and updating documentation Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/R/bugs.sims.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.pdf trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/bugs.log.Rd Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2012-01-06 09:50:47 UTC (rev 248) +++ trunk/R2OpenBUGS/DESCRIPTION 2012-02-08 12:57:28 UTC (rev 249) @@ -1,7 +1,7 @@ Package: R2OpenBUGS Title: Running OpenBUGS from R -Date: 2011-12-20 -Version: 3.2-1.3 +Date: 2012-2-04 +Version: 3.2-1.4 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. Modified: trunk/R2OpenBUGS/R/bugs.sims.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.sims.R 2012-01-06 09:50:47 UTC (rev 248) +++ trunk/R2OpenBUGS/R/bugs.sims.R 2012-02-08 12:57:28 UTC (rev 249) @@ -124,7 +124,8 @@ pD=mean(pD), DIC=mean(DIC))) } else { ## Use BUGS calculation of DIC all <- c(all, list(isDIC=TRUE, DICbyR=FALSE, - pD=LOG[nrow(LOG),3], DIC=LOG[nrow(LOG),4])) + pD=LOG[nrow(LOG),4], DIC=LOG[nrow(LOG),3])) + ## order reversed in OpenBUGS from WinBUGS } } else { all <- c(all, isDIC=FALSE) Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2012-01-06 09:50:47 UTC (rev 248) +++ trunk/R2OpenBUGS/inst/NEWS 2012-02-08 12:57:28 UTC (rev 249) @@ -1,6 +1,11 @@ Changes to R2OpenBUGS: ====================== +Update 3.2-1.4 +- Corrected printing of pD and DIC, which were reversed +- Updated documentation to note difference in DIC reporting between Windows and Linux, and the lack of support for the bugs.log function under Linux +- Fixed problem with references in vignette + Update 3.2-1.3 - cleanup: removed S-PLUS support completely since that was removed at several other places before Modified: trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.pdf =================================================================== --- trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.pdf 2012-01-06 09:50:47 UTC (rev 248) +++ trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.pdf 2012-02-08 12:57:28 UTC (rev 249) @@ -1,246 +1,635 @@ %PDF-1.5 %\xD0\xD4\xC5\xD8 1 0 obj -<< /S /GoTo /D [2 0 R /Fit] >> +<< /S /GoTo /D (Section.0.Introduction.1) >> endobj -10 0 obj << -/Length 4405 +4 0 obj +(Introduction) +endobj +5 0 obj +<< /S /GoTo /D (Section.1.Examples.1) >> +endobj +8 0 obj +(Examples) +endobj +9 0 obj +<< /S /GoTo /D (Subsection.2.0.Schools\040data.2) >> +endobj +12 0 obj +(Schools data) +endobj +13 0 obj +<< /S /GoTo /D (Subsection.2.1.Leukaemia\040registration\040data.2) >> +endobj +16 0 obj +(Leukaemia registration data) +endobj +17 0 obj +<< /S /GoTo /D (Section.2.Implementation.1) >> +endobj +20 0 obj +(Implementation) +endobj +21 0 obj +<< /S /GoTo /D (Section.3.Examples\040continued.1) >> +endobj +24 0 obj +(Examples continued) +endobj +25 0 obj +<< /S /GoTo /D (Subsection.4.0.Schools\040data.2) >> +endobj +28 0 obj +(Schools data) +endobj +29 0 obj +<< /S /GoTo /D (Subsection.4.1.Leukaemia\040registration\040data.2) >> +endobj +32 0 obj +(Leukaemia registration data) +endobj +33 0 obj +<< /S /GoTo /D (Section..Help\040page\040for\040the\040function\040bugs\(\).1) >> +endobj +36 0 obj +(Help page for the function bugs\(\)) +endobj +37 0 obj +<< /S /GoTo /D (appendix.A) >> +endobj +40 0 obj +(bugs) +endobj +41 0 obj +<< /S /GoTo /D [42 0 R /Fit] >> +endobj +64 0 obj << +/Length 4292 /Filter /FlateDecode >> stream -x\xDA\xD5;\xD9rG\x92\xEF\xFA -\xC4<l\x80B\xB9\xEB\xE8\xCB\xFB\xE0\x91\xBD\xB6bgG\xE3YQ -?\x8C\xE7\xA1 4\xC8\xE1\xE0\xA0\xD3\xD4N\xC4\xFE\xFA\xE6Y] -4i\xCAX]GVVޙU\xCCf\xB7\xB3l\xF6\xF6U&\xBF\xBF\xFD\xF0\xEA\xAB -;\xB3\xA5q6\xB3\xEB\x99ބ`g\xA5\xB3Ɔz\xF6a5\xFB\xDB\xFC\xFD\x95\x9D\xBB\xEF\xAF\xAE\x9C\xB7\xD0\xDE\xC1Ϸ\xDF^_\xFD\xFDß |
From: <snt...@us...> - 2012-02-08 16:29:13
|
Revision: 250 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=250&view=rev Author: snthomas99 Date: 2012-02-08 16:28:59 +0000 (Wed, 08 Feb 2012) Log Message: ----------- minor updates to vignette location and validateInstallOpenBUGS Modified Paths: -------------- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R Added Paths: ----------- trunk/R2OpenBUGS/vignettes/ trunk/R2OpenBUGS/vignettes/R2OpenBUGS.Rnw trunk/R2OpenBUGS/vignettes/RdRW.sty trunk/R2OpenBUGS/vignettes/Z.cls trunk/R2OpenBUGS/vignettes/benzolsw.pdf trunk/R2OpenBUGS/vignettes/bugs.tex trunk/R2OpenBUGS/vignettes/countssw.pdf trunk/R2OpenBUGS/vignettes/expectedsw.pdf trunk/R2OpenBUGS/vignettes/literatur.bib trunk/R2OpenBUGS/vignettes/literatur.bst trunk/R2OpenBUGS/vignettes/plot.pdf Removed Paths: ------------- trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.Rnw trunk/R2OpenBUGS/inst/doc/RdRW.sty trunk/R2OpenBUGS/inst/doc/Z.cls trunk/R2OpenBUGS/inst/doc/benzolsw.pdf trunk/R2OpenBUGS/inst/doc/bugs.tex trunk/R2OpenBUGS/inst/doc/countssw.pdf trunk/R2OpenBUGS/inst/doc/expectedsw.pdf trunk/R2OpenBUGS/inst/doc/literatur.bib trunk/R2OpenBUGS/inst/doc/literatur.bst trunk/R2OpenBUGS/inst/doc/plot.pdf Modified: trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2012-02-08 12:57:28 UTC (rev 249) +++ trunk/R2OpenBUGS/R/validateInstallOpenBUGS.R 2012-02-08 16:28:59 UTC (rev 250) @@ -54,7 +54,7 @@ exfiles <- dir(system.file("validateInstallOpenBUGS", package="R2OpenBUGS"), pattern=test.pattern[i], full.names=TRUE) ok <- file.copy(exfiles, tempdir()) fit <- round(bugs(data=test.datafile[i], inits=test.inits[i], - para=test.params[[test.models[i]]],model.file=test.modelfile[i], + parameters.to.save=test.params[[test.models[i]]],model.file=test.modelfile[i], n.burnin=5000, n.iter=20000, n.thin=1, n.chains=1, DIC=FALSE, working.directory=tempdir(), OpenBUGS.pgm=OpenBUGS.pgm)$summary, 5) Deleted: trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.Rnw =================================================================== --- trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.Rnw 2012-02-08 12:57:28 UTC (rev 249) +++ trunk/R2OpenBUGS/inst/doc/R2OpenBUGS.Rnw 2012-02-08 16:28:59 UTC (rev 250) @@ -1,495 +0,0 @@ -%\VignetteIndexEntry{R2OpenBUGS} -\documentclass{Z} -\usepackage{RdRW,thumbpdf} -\newcommand{\WinBUGS}{{\proglang{WinBUGS}}{}} -\newcommand{\OpenBUGS}{{\proglang{OpenBUGS}}{}} -\newcommand{\RW}{{\pkg{R2WinBUGS}}{}} -\newcommand{\RO}{{\pkg{R2OpenBUGS}}{}} -\renewcommand{\R}{{\proglang{R}}{}} -\setlength{\textheight}{23.5cm} - -\title{\RO{}:\protect\linebreak A Package for Running \OpenBUGS{} from \R{}} -\author{Sibylle Sturtz\thanks{\email{st...@st...}}\\Fachbereich Statistik\\Universit\"at Dortmund\\Germany - \And - Uwe Ligges\thanks{\email{li...@st...}}\\Fachbereich Statistik\\Universit\"at Dortmund\\Germany - \And - Andrew Gelman\thanks{\email{ge...@st...}}\\Department of Statistics\\Columbia University\\USA -} -\Plainauthor{Sibylle Sturtz, Uwe Ligges, Andrew Gelman} -\Plaintitle{R2OpenBUGS: A Package for Running OpenBUGS from R} - -\Abstract{ -The \RO{} package provides convenient functions to call \OpenBUGS{} from \R{}. It -automatically writes the data and scripts in a format readable by \OpenBUGS{} for processing in batch mode, which -is possible since version 1.4. After the \OpenBUGS{} process has finished, it is possible either to read the -resulting data into \R{} by the package itself---which gives a compact graphical summary of inference and -convergence diagnostics---or to use the facilities of the \pkg{coda} package for further analyses of the -output. Examples are given to demonstrate the usage of this package. -} - -\Keywords{\R{}, \OpenBUGS{}, interface, MCMC} -\Plainkeywords{R, OpenBUGS, interface, MCMC} - -\begin{document} -An earlier version of this vignette has been published by the Journal of Statistical Software:\\ -Sturtz S, Ligges U, Gelman A (2005): -``\RW{}: A Package for Running \WinBUGS{} from \R{}.'' -{\em Journal of Statistical Software}, 12(3), 1--16. -\RO{} was adapted from \RW{} by Neal Thomas. - - -\section{Introduction}\label{Introduction} -The usage of Markov chain Monte Carlo (MCMC) methods became very popular within the last decade. \OpenBUGS{} -\citep[\textbf{B}ayesian inference \textbf{U}sing \textbf{G}ibbs \textbf{S}ampling, ][] -{Spiegelhalter;Thomas;Best:2003} is a popular software for analyzing complex statistical models using MCMC -methods. This software uses Gibbs sampling \citep{Geman;Geman:1984,Gelfand;Smith:1990,Casella;George:1992} and the -Metropolis algorithm \citep{Metropolis;Rosenbluth;Rosenbluth;Teller;Teller:1953} -to generate a Markov chain by sampling from full conditional -distributions. -The \OpenBUGS{} software is available for free -at \url{http://www.OpenBUGS.info}. -An introduction to MCMC methods is given in \cite{Gilks;Richardson;Spiegelhalter:1996}. - -Using \OpenBUGS{}, the user must specify the model to run, and to load data and initial values for a specified -number of Markov chains. Then it is possible to run the Markov chain(s) and to save the results for the parameters -the user is interested in. Summary statistics of these data, convergence diagnostics, kernel estimates -etc.\ are available as well. -Nevertheless, some users of this software might be interested in saving the output and reading it into \R{} -\citep{RCore:2004} for further analyses. -\OpenBUGS{} comes with the ability to run the software in batch mode using scripts. - -The \RO{} package makes use of this feature and provides the tools to call \OpenBUGS{} -directly after data manipulation in \R{}. Furthermore, it is possible to -work with the results after importing them back into \R{} again, for example to create posterior predictive simulations or, more generally, graphical displays of data and posterior simulations \citep{gelman:2004}. -Embedding in R can also be useful for frequently changed data or processing a bunch of data sets, -because it is much more convenient to use some \R{} functions (possibly within a loop) -rather than using ``copy \& paste'' to update data in \OpenBUGS{} each time; however difficulties have been encountered in this area because both \R{} and \OpenBUGS{} can lock up RAM in the Windows operating system. - -\R{} is a ``language for data analysis and graphics'' and an open source and -freely available statistical software package implementing that language, see \url{http://www.R-project.org/}. -Historically, \R{} is an implementation of the award-winning \proglang{S} -language and system \citep{becker:1984r,becker:1988r,chambers:1992,chambers:1998}. -\R{} and \RO{} are available from \emph{CRAN} (Comprehensive \R{} Archive Network), -i.e., \url{http://CRAN.R-Project.org} or one of its mirrors. -\RO{} could be ported to the commercial \proglang{S} implementation -\textsc{S-Plus}. Minor adaptions would be needed since \textsc{S-Plus} -lacks some of \R{}'s functions and capabilities. -If an internet connection is available, \RO{} can be installed by typing -\verb+install.packages("R2OpenBUGS")+ at the \R{} command prompt. -Do not forget to load the package with \verb+library("R2OpenBUGS")+. - -The package \pkg{coda} by \cite{Plummer;Best;Cowles;Vines:2004} is very useful for the analysis of \OpenBUGS{}' -output, the reader might want to install this package as well. The CRAN package \pkg{boa} (Bayesian Output -Analysis Program) by \cite{Smith:2004} has similar aims. -\proglang{JAGS} (Just Another Gibbs Sampler) -by \cite{Plummer:2003} is a program for analysis of Bayesian hierarchical models using Gibbs sampling that aims for -the same functionality as classic \proglang{BUGS}. \proglang{JAGS} is developed to work closely together with \R{} and -the \pkg{coda} package. - -%% Revision 2005-01-10 end - -In this paper, we give two examples, involving educational testing experiments in schools (cf.~Section~\ref{School}), -and incidence of childhood leukaemia depending on benzene emissions (cf.~Section~\ref{Leukaemia}). Details on the -functions of \RO{} are given in Section~\ref{Programming}. These functions automatically write the data and a -script in a format readable by \OpenBUGS{} for processing in batch mode, and call \OpenBUGS{} from \R{}. After the -\OpenBUGS{} process has finished, it is possible either to read the resulting data into \R{} by the package itself -or to use the facilities of the \pkg{coda} package for further analyses of the output. In Section~\ref{Example2}, -we demonstrate how to apply the functions provided by \RO{} on the examples' data, and how to analyze the output -both with package \pkg{coda} and with \RO{}'s methods to \verb+plot()+ and \verb+print()+ the output. - - -\section{Examples}\label{Examples} -In this Section, we introduce two examples which will be continued in Section~\ref{Example2}. - -\subsection{Schools data}\label{School} -The Scholastic Aptitude Test (SAT) measures the aptitude of high-schoolers in order to help colleges to make -admissions decisions. It is divided into two parts, verbal (SAT-V) and mathematical (SAT-M). -Our data comes from the SAT-V (Scholastic Aptitude Test-Verbal) on eight different high schools, from an experiment conducted in the late 1970s. -SAT-V is a standard multiple choice test administered by the Educational Testing Service. -This Service was interested in the effects of coaching programs for each of the selected schools. - -The study included coached and uncoached pupils, about sixty in each of the eight different schools; see -\cite{Rubin:1981}. All of them had already taken the PSAT (Preliminary SAT) which results were used as covariates. -%Even if the test is constructed to be resistant to short-term -%efforts directed specifically toward improving test performance, each of the schools is successful at increasing -%SAT scores. -For each school, the estimated treatment effect and the standard error of the effect estimate are given. -These are calculated by an analysis of covariance adjustment appropriate for a completely randomized experiment -\citep{Rubin:1981}. This example was analyzed using a hierarchical normal model in \cite{Rubin:1981} and -\citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). - -\subsection{Leukaemia registration data}\label{Leukaemia} -Spatial data usually arises on different, non-nesting spatial scales. One example is childhood leukaemia -registration data analyzed by \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001} -using ecologic regression. Data are given for Greater London bounded by the M25 orbital motorway. -%% Revision 2005-01-10 start -The data are not available as an example in \RO{} but we use the example here -to illustrate -alternative calls to the \verb+bugs()+ function and output analysis using the \pkg{coda} package. -%% Revision 2005-01-10 end - -The observed number of leukaemia cases among children under 15 years old is given at ward level. Census wards are -administrative areas containing approximately 5000 to 10\,000 people. Central London is divided into 873 wards. The -number of incident cases of leukaemia in children is available from 1985 until 1996 from the Office of National -Statistics and the Thames Cancer Registry. A plot of these numbers is given in Figure~\ref{observed}. - -\begin{figure} -\begin{center} -\includegraphics[width=0.85\textwidth]{countssw} -\caption{\label{observed}Observed number of cases of childhood leukaemia in 1985--1996} -\end{center} -\end{figure} - -Additionally, the number of expected cases (cf.~Fig.~\ref{expected}) is calculated on the same -resolution using population numbers for different age-sex-strata and the national leukaemia -rate for the corresponding strata, for details see \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001}. - -\begin{figure} -\begin{center} -\includegraphics[width=0.85\textwidth]{expectedsw} -\caption{\label{expected}Expected number of cases of childhood leukaemia in 1985--1996}%, as obtained from a simple demographic model} -\end{center} -\end{figure} - -It is assumed that benzene emissions have an effect on the incidence rate of leukaemia. Benzene emission rates are -available in tonnes per year from an atmospheric emissions inventory for London -\citep{Buckingham;Clewley;Hutchinson;Sadler;Shah:1997} produced by the London Research Centre. They are provided -at 1km $\times$ 1km grid cells, giving 2132 grid cells in total. -Their spatial distribution is shown in Figure~\ref{benzene}. - -\begin{figure} -\begin{center} -\includegraphics[width=0.9\textwidth]{benzolsw} -\caption{\label{benzene}Benzene emissions in tonnes per year} -\end{center} -\end{figure} - -For further details on the data see \cite{Best;Cockings;Bennett;Wakefield;Elliot:2001}. - -We model these data by Poisson-Gamma models introduced by \cite{Best;Ickstadt;Wolpert:2000} using \OpenBUGS{}. -A linking matrix containing information which grid cell belongs to which ward -and to which amount is required. This matrix is calculated using \R{}. -Unfortunately, \OpenBUGS{} does not support a list format such as directly produced by \R{}. -Therefore, the data must be provided as a matrix with 2132 rows and 873 columns (or vice versa). -Most of the entries of this matrix are zeroes, but using \verb+dump()+ to export it from \R{} -yields in a file size of 14.2~MB. -Unfortunately, opening a file of such size really slows \OpenBUGS{} down, -and it was not even possible on some of our PCs. -Importing data written by our \RO{} package does not make any problems using the batch mode, -probably due to memory management issues in \OpenBUGS{}. - - -\section{Implementation}\label{Programming} -The implementation of the \RO{} package is straightforward. -The ``main'' function \verb+bugs()+ is intended to be called by the user. -In principle, it is a wrapper for several other functions called therein step by step as follows: -\begin{enumerate} - \item \verb+bugs.data.inits()+ writes the data files \file{data.txt}, and \file{inits1.txt}, \file{inits2.txt}, ... - into the working directory. These files will be used by \OpenBUGS{} during batch processing. - - In particular, input for \OpenBUGS{} must not exceed a certain number of digits. - Moreover, it needs an \verb+E+ instead of an \verb+e+ in scientific notation. - Scientific notation is particularly desirable because of the ``number of digits'' limitation. - The default (\verb+digits = 5+) is to, e.g., reformat the number \verb+123456.789+ to \verb@1.23457E+05@. - \item \verb+bugs.script()+ writes the file \file{script.txt} that is used by \OpenBUGS{} for batch processing. - \item \verb+bugs.run()+ updates the lengths of the adaptive phases in the \WinBUGS{} registry - (using a function \verb+bugs.update.settings()+), - calls \WinBUGS{}, and runs it in batch mode with \file{script.txt}. - \item \verb+bugs.sims()+ is only called if the argument \verb+codaPkg+ has been set to \verb+FALSE+ (the default). - Otherwise \verb+bugs()+ returns the filenames of stored data. These can, for example, - be imported by package \pkg{coda} (see the example in Section~\ref{Leukaemia2}, page~\pageref{codaexample}), - which provides functions for convergence diagnostics, - calculation of Monte Carlo estimates, trace plots, and so forth. - - The function \verb+bugs.sims()+ reads simulations from \OpenBUGS{} into \R{} (not necessarily called by \verb+bugs()+ - itself), formats them, - monitors convergence, performs convergence checks, and computes medians and quantiles. - It also prepares the output for \verb+bugs()+ itself. -\end{enumerate} -These functions are not intended to be called by the user directly. -Arguments are passed from \verb+bugs()+ to the other functions, if appropriate. -A shortened help file of \verb+bugs()+ listing all arguments is given in Appendix~\ref{Doc}; -for the full version type \verb+?bugs+ in \R{} after having installed and loaded the package \RO{} -(see Section~\ref{Introduction}). - -%\newpage -As known from \OpenBUGS{}, one must specify the \verb+data+ in form of a list, with list names equal to the names -of data in the corresponding \OpenBUGS{} model. Alternatively, it is possible to specify a vector or list of names -(of mode \verb+character+). In that case objects of that names are looked for in the environment in which -\verb+bugs()+ has been called (usually that is the user's Workspace, \verb+.GlobalEnv+). -%% Revision 2005-01-10 start -If data have already been written in a file called \file{data.txt} to the working directory, -it is possible to specify \verb+data = "data.txt"+. -%% Revision 2005-01-10 end -One will usually want to supply initial values. -This can be done either in the form of a function \verb+inits()+ that creates these values, so that -different chains can be automatically initialized at different points (see Section \ref{School2}), or by specifying them -directly (see Section \ref{Leukaemia2}). -If \verb+inits()+ is not specified, -\verb+bugs()+ just uses the starting values created by \OpenBUGS{}; but in practice \OpenBUGS{} can crash when -reasonable initial values are not specified, and so we recommend constructing a simple \verb+inits()+ function to -simulate reasonable starting points \cite[Section C.2]{Gelman:2003}. It is also necessary to specify which -parameters should be saved for monitoring by specifying \verb+parameters.to.save+. - -The user might also want to change the defaults for the length of the burn-in (\verb+n.burnin+, which defaults to half the length of the chain) -period for every MCMC run and the number of iterations (\verb+n.iter+, default value 3) -that are used to calculate Monte Carlo estimates. -%SS: Achtung: n.iter=n.burn.in + length of stored chain! -The specification of a thinning parameter (\verb+n.thin+) is possible as well; this is useful when the number of parameters is large, to keep the saved output to a reasonably-sized R object. - -By setting the argument \verb+debug = TRUE+, -\OpenBUGS{} remains open after the run. -This way it is possible to find errors in the code or the data structure, -or even to work with that software as in a usual run. This feature is not -available with Linux execution. - -It is possible to run one or more Markov chains. -The number of chains (\verb+n.chains+) must be specified together with the chains' initial values (\verb+inits+). -If more than one Markov chain is requested and \verb+codaPkg+ is set to \verb+FALSE+, the convergence diagnostic -$\hat{R}$ \citep{Brooks;Gelman:1998} is calculated by \verb+bugs.sims()+ for each of the saved parameters. - -%% Revision 2005-01-10 start -Since the communication between \OpenBUGS{} and \R{} is based on files, -rather huge files will be saved in the working directory by the \verb+bugs()+ call, -either files to be read in by \verb+bugs()+ itself, or by the \pkg{coda} package. -The user might want to delete those files after the desired contents has been imported into \R{}, -and save those objects, e.g., as compressed \R{} data files. -%% Revision 2005-01-10 end - -The function \verb+bugs()+ returns a rather complex object of class \verb+bugs+, -if called with argument \verb+codaPkg = FALSE+. -In order to look at the structure of such an object, type \verb+str(objectname)+. -For convenience, \RO{} provides methods corresponding to class \verb+bugs+ for -the generic functions \verb+print()+ and \verb+plot()+. - -So that user will not be overwhelmed with information; summaries of the output are provided by the -\verb+print()+ method. That is, some parameters of the \verb+bugs()+ call are summarized, and mean, -standard deviation, several quantiles of the parameters and convergence diagnostics based on \cite{Gelman;Rubin:1992} -are printed. See the example in -Section~\ref{School2}, page~\pageref{schoolssim}, for a typical output. As with \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}, -%\pagebreak - the DIC computed by \verb+bugs.sims()+ is defined as the posterior mean -of the deviance plus $p_D$, the estimated effective number of parameters in the posterior distribution. We define -$p_D$ as half the posterior variance of the deviance and estimate it as half the average of the within-chain -variances of the deviance.\footnote{In contrast, \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}, - and OpenBUGS, define $p_D$ as the -posterior mean of the deviance evaluated at the posterior mean of the parameter values. We cannot use that -definition because the deviance function is not available to our program, which calls \OpenBUGS{} from the -``outside''. Both definitions of $p_D$---ours and that introduced by \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}---can be -derived from the asymptotic $\chi^2$ distribution of the deviance relative to its minimum \citep[Section 6.7]{Gelman:2003}. -We make no claim that our measure of $p_D$ is superior to that of \cite{Spiegelhalter;Best;Carlin;vdLinde:2002}; -we choose this measure purely because it is computationally possible given what is available to us from the \OpenBUGS{} output.} - - -The \verb+plot()+ for objects of class \verb+bugs+ -provides information condensed in some plots conveniently arranged within the same graphics device. -For an example, see Figure~\ref{plot} in Section~\ref{School2}. It is intended to adapt this function to work with MCMC output in general, even if obtained from software other than OpenBUGS. - - - -\section{Examples continued}\label{Example2} -The Examples introduced in Section~\ref{Example2} are continued in this Section. -We apply the functions provided by \RO{} -to the examples' data and analyze the output. - -\subsection{Schools data}\label{School2} -Schools example data (see Section~\ref{School}) are available with the \RO{} package: -\begin{Code} - > data(schools) - > schools - school estimate sd - 1 A 28.39 14.9 - 2 B 7.94 10.2 - 3 C -2.75 16.3 - 4 D 6.82 11.0 - 5 E -0.64 9.4 - 6 F 0.63 11.4 - 7 G 18.01 10.4 - 8 H 12.16 17.6 -\end{Code} -For modeling these data, we use a hierarchical model as proposed by \citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). -We assume a normal distribution for the observed estimate for each school with -mean \verb+theta+ and inverse-variance \verb+tau.y+. -The inverse-variance is given as $1/\verb+sigma.y+^{2}$ and its prior distribution is uniform on (0,1000). For the mean -\verb+theta+, we employ another normal distribution with mean \verb+mu.theta+ and inverse-variance \verb+tau.theta+. For -their prior distributions, see the following \OpenBUGS{} code: - - -\begin{Code} - model { - for (j in 1:J) - { - y[j] ~ dnorm (theta[j], tau.y[j]) - theta[j] ~ dnorm (mu.theta, tau.theta) - tau.y[j] <- pow(sigma.y[j], -2) - } - mu.theta ~ dnorm (0.0, 1.0E-6) - tau.theta <- pow(sigma.theta, -2) - sigma.theta ~ dunif (0, 1000) - } -\end{Code} -This model must be stored in a separate file, e.g.~\file{schools.bug}\footnote{Emacs Speaks Statistics (ESS) -by \cite{rossini04}, a package available with Gnu Emacs \citep{stallmann99}, -recognizes and properly formats Bugs model files that have the .bug extension.}, -in an appropriate directory, say \path{c:/schools/}. -In \R{} the user must prepare the data inputs the \verb+bugs()+ function needs. -This can be a list containing the name of each data vector, e.g. -\begin{Code} - > J <- nrow(schools) - > y <- schools$estimate - > sigma.y <- schools$sd - > data <- list ("J", "y", "sigma.y") -\end{Code} -Using these data and the model file, we can run an MCMC simulation to get estimates for \verb+theta+, -\verb+mu.theta+ and \verb+sigma.theta+. Before running, the user must decide how many chains to be run -(\verb+n.chain = 3+) for how many iterations (\verb+n.iter = 1000+). -If the length of burn-in is not specified, \verb+n.burnin = floor(n.iter/2)+ is used, that is, 500 in this example. -Additionally, the user must specify initial values for the chains, for example by writing a function. This can be done by -\begin{Code} - > inits <- function(){ - + list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100), - + sigma.theta = runif(1, 0, 100)) - + } -\end{Code} -Now, the user can start the MCMC simulation by typing -\begin{Code} - > schools.sim <- bugs(data, inits, model.file = "c:/schools/schools.bug", - + parameters = c("theta", "mu.theta", "sigma.theta"), - + n.chains = 3, n.iter = 1000) -\end{Code} -in \R{}.\label{schoolssim} -For other available arguments, see Appendix \ref{Doc}. - -The results in objects \verb+schools.sim+ can conveniently be printed by \verb+print(schools.sim)+. -The generic function \verb+print()+ calls the print method for an object of class \verb+bugs+ -provided by \RO{}. -For this example, you will get something like - -\small -\begin{Code} - > print(schools.sim) - Inference for Bugs model at "c:/schools/schools.bug" - 3 chains, each with 1000 iterations (first 500 discarded) - n.sims = 1500 iterations saved - mean sd 2.5% 25% 50% 75% 97.5% Rhat n.eff - theta[1] 11.1 9.1 -3.0 5.0 10.0 16.0 31.8 1.1 39 - theta[2] 7.6 6.6 -4.7 3.3 7.8 11.6 21.1 1.1 42 - theta[3] 5.7 8.4 -12.5 0.6 6.1 10.8 21.8 1.0 150 - theta[4] 7.1 7.0 -6.6 2.7 7.2 11.5 21.0 1.1 42 - theta[5] 5.1 6.8 -9.5 0.7 5.2 9.7 18.1 1.0 83 - theta[6] 5.7 7.3 -9.7 1.0 6.2 10.2 20.0 1.0 56 - theta[7] 10.4 7.3 -2.1 5.3 9.8 15.3 25.5 1.1 27 - theta[8] 8.3 8.4 -6.6 2.8 8.1 12.7 26.2 1.0 64 - mu.theta 7.6 5.9 -3.0 3.7 8.0 11.0 19.5 1.1 35 - sigma.theta 6.7 5.6 0.3 2.8 5.1 9.2 21.2 1.1 46 - deviance 60.8 2.5 57.0 59.1 60.2 62.1 66.6 1.0 170 - pD = 3 and DIC = 63.8 (using the rule, pD = var(deviance)/2) - - For each parameter, n.eff is a crude measure of effective sample size, - and Rhat is the potential scale reduction factor (at convergence, Rhat=1). - DIC is an estimate of expected predictive error (lower deviance is better). -\end{Code} -\normalsize -Additionally, the user can generate a plot of the results by typing \verb+plot(schools.sim)+. -The resulting plot is given in Figure~\ref{plot}. -\begin{figure}[t] -\begin{center} -\fbox{ -\includegraphics[width=0.9\textwidth]{plot} -} \caption{\label{plot}Plot produced by \RO{} package for the schools example. } -\end{center} -\end{figure} -In this plot, the left column shows a quick -summary of inference and convergence ($\widehat{R}$ is close to 1.0 for all parameters, indicating good mixing of -the three chains and thus approximate convergence); and the right column shows inferences for each set of -parameters. As can be seen in the right column, \RO{} uses the parameter names in \OpenBUGS{} to structure the -output into scalar, vector, and arrays of parameters, in addition to storing the parameters as a long vector. - -For the interpretation of these results see \citeauthor{Gelman:2003} (\citeyear{Gelman:2003}, Section 5.5). - -\subsection{Leukaemia registration data}\label{Leukaemia2} -The leukaemia registration data (see Section \ref{Leukaemia}) are used to show data modeling and output reading -into \R{} using the \pkg{coda} package. A simple model for these data looks as follows: -\begin{Code} -model{ - beta.0 ~ dgamma(a.0, tau.0) - beta.benz ~ dgamma(a.benz, tau.benz) - a.0 <- 0.575 - tau.0 <- a.0*2 - a.benz <- 0.575 - tau.benz <- a.benz*2 -\end{Code} -\clearpage -\begin{Code} - for (i in 1:I) - { - count[i] ~ dpois(lambda[i]) - lambda[i] <- p[i]*expect[i] - for (j in 1:J) - { - prop[j,i] <- gamma[j,i]*(benz[j] - benzbar) - } - p[i]<- beta.0 + beta.benz*sum(prop[,i]) - } - } -\end{Code} -Here \verb+count+ denotes the number of observed incidences of childhood leukaemia in ward~\verb+i+. These are -assumed to be Poisson distributed with mean \verb+lambda+ depending on the number of expected cases \verb+expect+ -in ward \verb+i+ and an area-specific risk rate \verb+p+. For calculation of this area specific risk rate we use -an intercept \verb+beta.0+ and a term depending on the weighted sum of benzene emissions \verb+benz+ in each grid -cell \verb+j+. The weights are chosen proportional to the amount of area that ward \verb+i+ and grid cell \verb+j+ have -in common. - -In \R{} we can define all these data and then initialize the model. The data needed for this example are -\begin{description} -\item[\tt{benzbar}:] arithmetic mean of all benzene values, -\item[\tt{benz}:] a vector containing benzene emissions of all 2132 grid cells, -\item[\tt{expect}:] expected number of cases of childhood leukaemia in each of the 873 wards, -\item[\tt{count}:] observed number of childhood leukaemia in these wards, -\item[\tt{gamma}:] a $2132\times 873$ matrix containing the amount of area each grid cell and each ward have in common, -\item[\tt{J}:] total number of grid cells, i.e.~2132, and -\item[\tt{I}:] total number of ward cells, i.e.~873. -\end{description} -The parameters we want to store are regression coefficients \verb+beta.0+ and \verb+beta.benz+ as well as -\verb+p+, the area specific relative risk compared to the reference rate. This reference rate was used to -calculate the expected number of cases in each ward. - -Since we want to use the \pkg{coda} package for reading the data into \OpenBUGS{}, we specify \verb+codaPkg = TRUE+ -in the \verb+bugs()+ call: -\begin{Code} - > data <- list(benzbar = mean(benz), benz = benz, expect = expect, - + count = count, gamma = gamma, J = J, I = I) - > parameters <- c("beta.0", "beta.benz", "p") - > inits1 <- list(beta.0 = 1, beta.benz = 1) - > inits2 <- list(beta.0 = 0.5, beta.benz = 0.5) - > inits <- list(inits1, inits2) - > model <- bugs(data, inits, parameters, model.file = "c:/model.bug", - + n.chains = 2, n.iter = 8000, n.burnin = 5000, n.thin = 1, - + codaPkg = TRUE ) -\end{Code} - -\clearpage -Starting with, e.g.,\label{codaexample} -\begin{Code} - > library("coda") - > codaobject <- read.bugs(model) - > plot(codaobject) -\end{Code} -it is now possible to use the \pkg{coda} package for output analyses. - - -\section*{Acknowledgments} -The work of Uwe Ligges has been supported by the Deutsche Forschungsgemeinschaft, -Sonderforschungsbereich 475. -The work of Andrew Gelman has been supported by the U.S. National Science Foundation. - -\bibliography{literatur} - -\clearpage -\begin{appendix} -\section[Help page for the function bugs()]{Help page for the function \code{bugs()}\label{Doc}} -\small -This help page has been shortened. -\input{bugs} -\end{appendix} -\end{document} Deleted: trunk/R2OpenBUGS/inst/doc/RdRW.sty =================================================================== --- trunk/R2OpenBUGS/inst/doc/RdRW.sty 2012-02-08 12:57:28 UTC (rev 249) +++ trunk/R2OpenBUGS/inst/doc/RdRW.sty 2012-02-08 16:28:59 UTC (rev 250) @@ -1,363 +0,0 @@ -%%% Rd.sty ... Style for printing the R manual -%%% -%%% Modified 1998/01/05 by Fri...@ci... -%%% Modified 1998/07/07 by Martin Maechler -%%% Modified 1999/11/20 by Brian Ripley -%%% Modified 1999/12/26 by Kurt Hornik -%%% and so on. - -\NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{Rd}{} - -\RequirePackage{ifthen} -\newboolean{Rd@has@ae} -\newboolean{Rd@use@ae} -\newboolean{Rd@use@hyper} -\newboolean{Rd@has@times} -\newboolean{Rd@use@times} -\newboolean{Rd@use@cm-super} -\newboolean{Rd@has@lm} -\newboolean{Rd@use@lm} -\DeclareOption{ae}{\setboolean{Rd@use@ae}{true}} -\DeclareOption{hyper}{\setboolean{Rd@use@hyper}{true}} -\DeclareOption{times}{\setboolean{Rd@use@times}{true}} -\DeclareOption{lm}{\setboolean{Rd@use@lm}{true}} -\DeclareOption{cm-super}{\setboolean{Rd@use@cm-super}{true}} -\ProcessOptions -\RequirePackage{longtable} -\setcounter{LTchunksize}{250} -\ifthenelse{\boolean{Rd@use@hyper}} -{\IfFileExists{hyperref.sty}{}{\setboolean{Rd@use@hyper}{false} - \message{package hyperref not found}}} -{} - -\RequirePackage{bm} % standard boldsymbol -\RequirePackage{alltt} % {verbatim} allowing \.. -\RequirePackage{verbatim} % small example code -\RequirePackage{url} % set urls - -%% See 'upquote.sty' for details. -%% We use \pkg{verbatim} for our ExampleCode environment, which in its -%% \verbatim@font has an explicit \let\do\do@noligs\verbatim@nolig@list -%% rather than (the identical) \@noligs from the LaTeX2e kernel. -%% Hence, we add to \verbatim@font ... suggestion by Bernd Raichle -%% <ra...@In...>. -\RequirePackage{upquote} -\g@addto@macro\verbatim@font\@noligs - -%% \addtolength{\textheight}{12mm} -%% \addtolength{\topmargin}{-9mm} % still fits on US paper -%% \addtolength{\textwidth}{24mm} % still fits on US paper -%% \setlength{\oddsidemargin}{10mm} -%% \setlength{\evensidemargin}{\oddsidemargin} - -\newenvironment{display}[0]% - {\begin{list}{}{\setlength{\leftmargin}{30pt}}\item}% - {\end{list}} -\newcommand{\HTML}{{\normalfont\textsc{html}}} -\newcommand{\R}{{\normalfont\textsf{R}}{}} -\newcommand{\Rdash}{-} - -\def\href#1#2{\special{html:<a href="#1">}{#2}\special{html:</a>}} - -\newcommand{\vneed}[1]{% - \penalty-1000\vskip#1 plus 10pt minus #1\penalty-1000\vspace{-#1}} - -\newcommand{\Rdcontents}[1]{% modified \tableofcontents -- not \chapter -\section*{{#1}\@mkboth{\MakeUppercase#1}{\MakeUppercase#1}} - \@starttoc{toc}} - -\newcommand{\Header}[2]{% - \vneed{1ex} - \markboth{#1}{#1} - \noindent - \nopagebreak - \begin{center} - \ifthenelse{\boolean{Rd@use@hyper}}% - {\def\@currentHref{page.\thepage} - \hypertarget{Rfn.#1}{\index{#1@\texttt{#1}}}% - \myaddcontentsline{toc}{subsection}{#1}% - \pdfbookmark[1]{#1}{Rfn.#1}} - {\addcontentsline{toc}{subsection}{#1} - \index{#1@\texttt{#1}|textbf}} - \hrule - \parbox{0.95\textwidth}{% - \begin{ldescription}[1.5in] - \item[\texttt{#1}] \emph{#2} - \end{ldescription}} - \hrule - \end{center} - \nopagebreak} -% -% -% -% \alias{<alias>}{<header>} -\ifthenelse{\boolean{Rd@use@hyper}} -{\newcommand{\alias}[2]{\hypertarget{Rfn.#1}{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}}} -{\newcommand{\alias}[2]{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}} -\ifthenelse{\boolean{Rd@use@hyper}} -{\newcommand{\methalias}[2]{\hypertarget{Rfn.#1}{\relax}}} -{\newcommand{\methalias}[2]{}} -% \keyword{<topic>}{<header>} -\newcommand{\keyword}[2]{\index{$*$Topic{\large\ \textbf{#1}}!#2@\texttt{#2}}} -% -\newcommand{\Itemize}[1]{\begin{itemize}{#1}\end{itemize}} -\newcommand{\Enumerate}[1]{\begin{enumerate}{#1}\end{enumerate}} -\newcommand{\describe}[1]{\begin{description}{#1}\end{description}} - -\newcommand{\Tabular}[2]{% - \par\begin{longtable}{#1} - #2 - \end{longtable}} - -\newlength{\ldescriptionwidth} -\newcommand{\ldescriptionlabel}[1]{% - \settowidth{\ldescriptionwidth}{{#1}}% - \ifdim\ldescriptionwidth>\labelwidth - {\parbox[b]{\labelwidth}% - {\makebox[0pt][l]{#1}\\[1pt]\makebox{}}}% - \else - \makebox[\labelwidth][l]{{#1}}% - \fi - \hfil\relax} -\newenvironment{ldescription}[1][1in]% - {\begin{list}{}% - {\setlength{\labelwidth}{#1}% - \setlength{\leftmargin}{\labelwidth}% - \addtolength{\leftmargin}{\labelsep}% - \renewcommand{\makelabel}{\ldescriptionlabel}}}% - {\end{list}} - -\newenvironment{Rdsection}[1]{% - \ifx\@empty#1\else\subsubsection*{#1}\fi - \begin{list}{}{\setlength{\leftmargin}{0.25in}}\item} - {\end{list}} - -\newenvironment{Arguments}{% - \begin{Rdsection}{Arguments}}{\end{Rdsection}} -\newenvironment{Author}{% - \begin{Rdsection}{Author(s)}}{\end{Rdsection}} -\newenvironment{Description}{% - \begin{Rdsection}{Description}}{\end{Rdsection}} -\newenvironment{Details}{% - \begin{Rdsection}{Details}}{\end{Rdsection}} -\newenvironment{Examples}{% - \begin{Rdsection}{Examples}}{\end{Rdsection}} -\newenvironment{Note}{% - \begin{Rdsection}{Note}}{\end{Rdsection}} -\newenvironment{References}{% - \begin{Rdsection}{References}}{\end{Rdsection}} -\newenvironment{SeeAlso}{% - \begin{Rdsection}{See Also}}{\end{Rdsection}} -\newenvironment{Format}{% - \begin{Rdsection}{Format}}{\end{Rdsection}} -\newenvironment{Source}{% - \begin{Rdsection}{Source}}{\end{Rdsection}} -\newenvironment{Section}[1]{% - \begin{Rdsection}{#1}}{\end{Rdsection}} -\newenvironment{Usage}{% - \begin{Rdsection}{Usage}}{\end{Rdsection}} -\newenvironment{Value}{% - \begin{Rdsection}{Value}}{\end{Rdsection}} - -\newenvironment{ExampleCode}{\small\verbatim}{\endverbatim} - -\ifx\textbackslash\undefined%-- e.g. for MM - \newcommand{\bsl}{\ifmmode\backslash\else$\backslash$\fi} -\else - \newcommand{\bsl}{\ifmmode\backslash\else\textbackslash\fi} -\fi -%fails for index (but is not used there...) -\newcommand{\SIs}{\relax\ifmmode\leftarrow\else$\leftarrow$\fi} -\newcommand{\SIIs}{\relax\ifmmode<\leftarrow\else$<\leftarrow$\fi} -\newcommand{\Sbecomes}{\relax\ifmmode\rightarrow\else$\rightarrow$\fi} -% -\newcommand{\deqn}[2]{\[#1\]} -\newcommand{\eqn}[2]{$#1$} -\newcommand{\bold}[1]{\ifmmode\bm{#1}\else\textbf{#1}\fi} -\newcommand{\file}[1]{`\textsf{#1}'} - -\ifthenelse{\boolean{Rd@use@hyper}} -{\newcommand{\link}[1]{\hyperlink{Rfn.#1}{#1}\index{#1@\texttt{#1}}}} -{\newcommand{\link}[1]{#1\index{#1@\texttt{#1}}}} - -\newcommand{\email}[1]{$\langle${#1}$\rangle$} - -%% \code without `-' ligatures -{\catcode`\-=\active% - \global\def\code{\bgroup% - \catcode`\-=\active \let-\codedash% - \Rd@code}} -\def\codedash{-\discretionary{}{}{}} -\def\Rd@code#1{\texttt{#1}\egroup} - -\def\AsIs{\bgroup\let\do\@makeother\Rd@AsIs@dospecials\Rd@AsIsX} -\def\Rd@AsIs@dospecials{\do\$\do\&\do\#\do\^\do\_\do\%\do\~} -\def\Rd@AsIsX#1{\normalfont #1\egroup} -\let\command=\code -\let\env=\code - -\newcommand\samp{`\bgroup\@noligs\@sampx} -\def\@sampx#1{{\normalfont\texttt{#1}}\egroup'} -\let\option=\samp - -\newcommand{\var}[1]{{\normalfont\textsl{#1}}} - -\newcommand{\dfn}[1]{\textsl{#1}} -\let\Cite=\dfn - -\newcommand{\acronym}[1]{\textsc{\lowercase{#1}}} -\newcommand{\kbd}[1]{\texttt{\textsl{#1}}} - -\newcommand{\strong}[1]{{\normalfont\fontseries{b}\selectfont #1}} -\let\pkg=\strong - -\newcommand{\sQuote}[1]{`#1'} -\newcommand{\dQuote}[1]{``#1''} - -\IfFileExists{ae.sty}{\setboolean{Rd@has@ae}{true}}{} -\ifthenelse{\boolean{Rd@use@ae}\and\boolean{Rd@has@ae}}{% - \usepackage[T1]{fontenc} - \usepackage{ae} - \input{t1aett.fd} - \DeclareFontShape{T1}{aett}{bx}{n}{<->ssub*aett/m/n}{}} - {\message{NOT loading ae}} -\IfFileExists{times.sty}{\setboolean{Rd@has@times}{true}}{} -\ifthenelse{\boolean{Rd@use@times}\and\boolean{Rd@has@times}}{% - \usepackage[T1]{fontenc} - \usepackage{times}} - {\message{NOT loading times}} -\IfFileExists{lmodern.sty}{\setboolean{Rd@has@lm}{true}}{} -\ifthenelse{\boolean{Rd@use@lm}\and\boolean{Rd@has@lm}}{% - \usepackage[T1]{fontenc} - \usepackage{lmodern}} - {\message{NOT loading lmodern}} -\ifthenelse{\boolean{Rd@use@cm-super}}{% - \usepackage[T1]{fontenc}}{} - -\ifthenelse{\boolean{Rd@use@hyper}}{% - \RequirePackage{color} - \def\myaddcontentsline#1#2#3{% - \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}{page.\thepage}}} - \RequirePackage{hyperref} - \DeclareTextCommand{\Rpercent}{PD1}{\045} % percent - %% <NOTE> - %% Formerly in R's hyperref.cfg, possibly to be shared with Sweave.sty - %% as well (but without setting pagebackref as this can give trouble - %% for .bib entries containing URLs with '#' characters). - \definecolor{Blue}{rgb}{0,0,0.8} - \definecolor{Red}{rgb}{0.7,0,0} - \hypersetup{% - hyperindex,% - colorlinks,% - pagebackref,% - linktocpage,% - plainpages=false,% - linkcolor=Blue,% - citecolor=Blue,% - urlcolor=Red,% - pdfstartview=Fit,% - pdfview={XYZ null null null}% - } - %% </NOTE> - \renewcommand\tableofcontents{% - \if@twocolumn - \@restonecoltrue\onecolumn - \else - \@restonecolfalse - \fi - \chapter*{\contentsname - \@mkboth{% - \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}% - \pdfbookmark{Contents}{contents} - \@starttoc{toc}% - \if@restonecol\twocolumn\fi - } - \renewenvironment{theindex} - {\if@twocolumn - \@restonecolfalse - \else - \@restonecoltrue - \fi - \columnseprule \z@ - \columnsep 35\p@ - \twocolumn[\@makeschapterhead{\indexname}]% - \@mkboth{\MakeUppercase\indexname}% - {\MakeUppercase\indexname}% - \pdfbookmark{Index}{index} - \myaddcontentsline{toc}{chapter}{Index} - \thispagestyle{plain}\parindent\z@ - \parskip\z@ \@plus .3\p@\relax - \raggedright - \let\item\@idxitem} - {\if@restonecol\onecolumn\else\clearpage\fi} - }{ - \renewenvironment{theindex} - {\if@twocolumn - \@restonecolfalse - \else - \@restonecoltrue - \fi - \columnseprule \z@ - \columnsep 35\p@ - \twocolumn[\@makeschapterhead{\indexname}]% - \@mkboth{\MakeUppercase\indexname}% - {\MakeUppercase\indexname}% - \addcontentsline{toc}{chapter}{Index} - \thispagestyle{plain}\parindent\z@ - \parskip\z@ \@plus .3\p@\relax - \raggedright - \let\item\@idxitem} - {\if@restonecol\onecolumn\else\clearpage\fi} - } - -% new definitions for R >= 2.0.0 -\ifthenelse{\boolean{Rd@use@hyper}} -{\newcommand{\LinkA}[2]{\hyperlink{Rfn.#2}{#1}\index{#1@\texttt{#1}|textit}}} -{\newcommand{\LinkA}[2]{#1\index{#1@\texttt{#1}|textit}}} -% -% \alias{<alias>}{<header>} -\ifthenelse{\boolean{Rd@use@hyper}} -{\newcommand{\aliasA}[3]{\hypertarget{Rfn.#3}{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}}} -{\newcommand{\aliasA}[3]{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}} -\ifthenelse{\boolean{Rd@use@hyper}} -{\newcommand{\methaliasA}[3]{\hypertarget{Rfn.#3}{\relax}}} -{\newcommand{\methaliasA}[3]{}} -\newcommand{\HeaderA}[3]{% - \vneed{1ex} - \markboth{#1}{#1} - \noindent - \nopagebreak - \begin{center} - \ifthenelse{\boolean{Rd@use@hyper}}% - {\def\@currentHref{page.\thepage} - \hypertarget{Rfn.#3}{\index{#1@\texttt{#1}}}% - \myaddcontentsline{toc}{subsection}{#1}% - \pdfbookmark[1]{#1}{Rfn.#3}} - {\addcontentsline{toc}{subsection}{#1} - \index{#1@\texttt{#1}|textbf}} - \hrule - \parbox{0.95\textwidth}{% - \begin{ldescription}[1.5in] - \item[\texttt{#1}] \emph{#2} - \end{ldescription}} - \hrule - \end{center} - \nopagebreak} -\DeclareTextCommandDefault{\Rpercent}{\%{}} -%% for use with the output of encoded_text_to_latex -\ProvideTextCommandDefault{\textdegree}{\ensuremath{{^\circ}}} -\ProvideTextCommandDefault{\textonehalf}{\ensuremath{\frac12}} -\ProvideTextCommandDefault{\textonequarter}{\ensuremath{\frac14}} -\ProvideTextCommandDefault{\textthreequarters}{\ensuremath{\frac34}} -\ProvideTextCommandDefault{\textcent}{\TextSymbolUnavailable\textcent} -\ProvideTextCommandDefault{\textyen}{\TextSymbolUnavailable\textyen} -\ProvideTextCommandDefault{\textcurrency}{\TextSymbolUnavailable\textcurrency} -\ProvideTextCommandDefault{\textbrokenbar}{\TextSymbolUnavailable\textbrokenbar} -\ProvideTextCommandDefault{\texteuro}{\TextSymbolUnavailable\texteuro} -\providecommand{\mathonesuperior}{\ensuremath{^1}} -\providecommand{\mathtwosuperior}{\ensuremath{^2}} -\providecommand{\maththreesuperior}{\ensuremath{^3}} - -\InputIfFileExists{Rd.cfg}{% - \typeout{Reading personal defaults ...}}{} Deleted: trunk/R2OpenBUGS/inst/doc/Z.cls =================================================================== --- trunk/R2OpenBUGS/inst/doc/Z.cls 2012-02-08 12:57:28 UTC (rev 249) +++ trunk/R2OpenBUGS/inst/doc/Z.cls 2012-02-08 16:28:59 UTC (rev 250) @@ -1,183 +0,0 @@ -\def\fileversion{1.0} -\def\filename{Z} -\def\filedate{2004/10/08} -%% -%% Package `Z' to use with LaTeX2e for Z reports -%% Copyright (C) 2004 Achim Zeileis -%% -\NeedsTeXFormat{LaTeX2e} -\ProvidesClass{Z}[\filedate\space\fileversion\space Z class by Achim Zeileis] - -%% options -\LoadClass[10pt,a4paper,twoside]{article} -\newif\if@notitle -\@notitlefalse -\DeclareOption{notitle}{\@notitletrue} -\ProcessOptions - -%% required packages -\RequirePackage{graphicx,a4wide,color,hyperref,ae,fancyvrb,thumbpdf} -\RequirePackage[T1]{fontenc} -\usepackage[authoryear,round,longnamesfirst]{natbib} -\bibpunct{(}{)}{;}{a}{}{,} -\bibliographystyle{literatur} - -%% paragraphs -\setlength{\parskip}{0.7ex plus0.1ex minus0.1ex} -\setlength{\parindent}{0em} - -%% commands -\let\code=\texttt -\let\proglang=\textsf -\newcommand{\E}{\mathsf{E}} -\newcommand{\VAR}{\mathsf{VAR}} -\newcommand{\COV}{\mathsf{COV}} -\newcommand{\Prob}{\mathsf{P}} - -%% for all publications -\newcommand{\Plaintitle}[1]{\def\@Plaintitle{#1}} -\newcommand{\Shorttitle}[1]{\def\@Shorttitle{#1}} -\newcommand{\Plainauthor}[1]{\def\@Plainauthor{#1}} -\newcommand{\Keywords}[1]{\def\@Keywords{#1}} -\newcommand{\Plainkeywords}[1]{\def\@Plainkeywords{#1}} -\newcommand{\Abstract}[1]{\def\@Abstract{#1}} - -%% defaults -\author{Firstname Lastname\\Affiliation} -\title{Title} -\Abstract{---!!!---an abstract is required---!!!---} -\Plainauthor{\@author} -\Plaintitle{\@title} -\Shorttitle{\@title} -\Keywords{---!!!---at least one keyword is required---!!!---} -\Plainkeywords{\@Keywords} - -%% Sweave(-like) -\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl} -\DefineVerbatimEnvironment{Soutput}{Verbatim}{} -\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl} -%\newenvironment{Schunk}{}{} -\DefineVerbatimEnvironment{Code}{Verbatim}{} -\DefineVerbatimEnvironment{CodeInput}{Verbatim}{fontshape=sl} -\DefineVerbatimEnvironment{CodeOutput}{Verbatim}{} -\newenvironment{CodeChunk}{}{} -\setkeys{Gin}{width=0.8\textwidth} - -%% new \maketitle -\def\maketitle{ - \begingroup - \def\thefootnote{\fnsymbol{footnote}} - \def\@makefnmark{\hbox to 0pt{$^{\@thefnmark}$\hss}} - \long\def\@makefntext##1{\parindent 1em\noindent - \hbox to1.8em{\hss $\m@th ^{\@thefnmark}$}##1} - \@maketitle \@thanks - \endgroup - \setcounter{footnote}{0} - \thispagestyle{empty} - \markboth{\centerline{\@Shorttitle}}{\centerline{\@Plainauthor}} - \pagestyle{myheadings} - - \let\maketitle\relax \let\@maketitle\relax - \gdef\@thanks{}\gdef\@author{}\gdef\@title{}\let\thanks\relax -} - -\def\@maketitle{\vbox{\hsize\textwidth \linewidth\hsize - {\centering - {\LARGE\bf \@title\par} - \def\And{\end{tabular}\hfil\linebreak[0]\hfil - \begin{tabular}[t]{c}\large\bf\rule{\z@}{24pt}\ignorespaces}% - \begin{tabular}[t]{c}\large\bf\rule{\z@}{24pt}\@author\end{tabular}% - \vskip 0.3in minus 0.1in - \hrule - \begin{abstract} - \@Abstract - \end{abstract}} - \textit{Keywords}:~\@Keywords. - \vskip 0.1in minus 0.05in - \hrule - \vskip 0.2in minus 0.1in -}} - - -%% sections, subsections, and subsubsections -\newlength{\preXLskip} -\newlength{\preLskip} -\newlength{\preMskip} -\newlength{\preSskip} -\newlength{\postMskip} -\newlength{\postSskip} -\setlength{\preXLskip}{1.8\baselineskip plus 0.5ex minus 0ex} -\setlength{\preLskip}{1.5\baselineskip plus 0.3ex minus 0ex} -\setlength{\preMskip}{1\baselineskip plus 0.2ex minus 0ex} -\setlength{\preSskip}{.8\baselineskip plus 0.2ex minus 0ex} -\setlength{\postMskip}{.5\baselineskip plus 0ex minus 0.1ex} -\setlength{\postSskip}{.3\baselineskip plus 0ex minus 0.1ex} - -\newcommand{\jsssec}[2][default]{\vskip \preXLskip% - \pdfbookmark[1]{#1}{Section.\thesection.#1}% - \refstepcounter{section}% - \centerline{\textbf{\Large \thesection. #2}} \nopagebreak - \vskip \postMskip \nopagebreak} -\newcommand{\jsssecnn}[1]{\vskip \preXLskip% - \centerline{\textbf{\Large #1}} \nopagebreak - \vskip \postMskip \nopagebreak} - -\newcommand{\jsssubsec}[2][default]{\vskip \preMskip% - \pdfbookmark[2]{#1}{Subsection.\thesubsection.#1}% - \refstepcounter{subsection}% - \textbf{\large \thesubsection. #2} \nopagebreak - \vskip \postSskip \nopagebreak} -\newcommand{\jsssubsecnn}[1]{\vskip \preMskip% - \textbf{\large #1} \nopagebreak - \vskip \postSskip \nopagebreak} - -\newcommand{\jsssubsubsec}[2][default]{\vskip \preSskip% - \pdfbookmark[3]{#1}{Subsubsection.\thesubsubsection.#1}% - \refstepcounter{subsubsection}% - {\large \textit{#2}} \nopagebreak - \vskip \postSskip \nopagebreak} -\newcommand{\jsssubsubsecnn}[1]{\vskip \preSskip% - {\textit{\large #1}} \nopagebreak - \vskip \postSskip \nopagebreak} - -\newcommand{\jsssimplesec}[2][default]{\vskip \preLskip% -%% \pdfbookmark[1]{#1}{Section.\thesection.#1}% - \refstepcounter{section}% - \textbf{\large #1} \nopagebreak - \vskip \postSskip \nopagebreak} -\newcommand{\jsssimplesecnn}[1]{\vskip \preLskip% - \textbf{\large #1} \nopagebreak - \vskip \postSskip \nopagebreak} - -\renewcommand{\section}{\secdef \jsssec \jsssecnn} -\renewcommand{\subsection}{\secdef \jsssubsec \jsssubsecnn} -\renewcommand{\subsubsection}{\secdef \jsssubsubsec \jsssubsubsecnn} - -%% colors -\definecolor{Red}{rgb}{0.7,0,0} -\definecolor{Blue}{rgb}{0,0,0.8} -\hypersetup{% - hyperindex = {true}, - colorlinks = {true}, - linktocpage = {true}, - plainpages = {false}, - linkcolor = {Blue}, - citecolor = {Blue}, - urlcolor = {Red}, - pdfstartview = {Fit}, - pdfpagemode = {UseOutlines}, - pdfview = {XYZ null null null} -} - -\AtBeginDocument{ - \hypersetup{% - pdfauthor = {\@Plainauthor}, - pdftitle = {\@Plaintitle}, - pdfkeywords = {\@Plainkeywords} - } -} -\if@notitle - %% \AtBeginDocument{\maketitle} -\else - \AtBeginDocument{\maketitle} -\fi Deleted: trunk/R2OpenBUGS/inst/doc/benzolsw.pdf =================================================================== --- trunk/R2OpenBUGS/inst/doc/benzolsw.pdf 2012-02-08 12:57:28 UTC (rev 249) +++ trunk/R2OpenBUGS/inst/doc/benzolsw.pdf 2012-02-08 16:28:59 UTC (rev 250) @@ -1,871 +0,0 @@ -%PDF-1.1 -%\xBF\xF7\xA2\xFE -1 0 obj -<< /Pages 3 0 R /Type /Catalog >> -endobj -2 0 obj -<< /CreationDate (D:20040419142809) /Creator (R) /ModDate (D:20040419142809) /Producer (R 1.8.1) /Title (R Graphics Output) >> -endobj -3 0 obj -<< /Count 1 /Kids [ 4 0 R ] /MediaBox [ 0 0 432 216 ] /Type /Pages >> -endobj -4 0 obj -<< /Contents 5 0 R /Parent 3 0 R /Resources 6 0 R /Type /Page >> -endobj -5 0 obj -<< /Length 100248 /Filter /FlateDecode >> -stream -x\x9C\x8C\xFDK\xAE.9\xAF\xF6\xEF(\xCE\xA1\xB74ܨ\xEAT\xA3\xE0΅ -ƿ -\xD8O\xDF[⛔N\xBAs\x90\xB9vI\xE9\x93(\xD7 -E\xFA\xF3?\xFEI\xFE\xF7?\xE9\xFB\xF3?\xFD\xF9?\xFF\xEB\xFF\xF3\xE7\xFF\xFC\xF3\xFD\xF3}\xF0O^ퟕ\xFF\xE4\xD4\xF7\xFF\xFD_\xFF\xEB\x9F\xFFߟ\xFF\xE3\xBF\xD2\xEF\x9A\xCEU\xBF\xF8\xDF\xFE\xEBCP\xFE\xFD\xFF\xFE\xBF\xE0h\xFE\xEF\xFF\xFA\xFF\xFF\xCF\xBE?\xFF\xCB\xFD\xF9\xD3\xFA?}\xFC\xC9_\xF9g\xB6?? -\xA8\xFF\xCC\xF4\xE7? -\xE8\xFF\x8C\xC0\xF8\xE7k\xA0+\xC6?\xE5\x83+&m0 n\xF9 |
From: <snt...@us...> - 2012-07-12 02:22:18
|
Revision: 253 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=253&view=rev Author: snthomas99 Date: 2012-07-12 02:22:12 +0000 (Thu, 12 Jul 2012) Log Message: ----------- V3.2.2.1 Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/R/bugs.log.R trunk/R2OpenBUGS/R/bugs.sims.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/man/bugs.Rd trunk/R2OpenBUGS/man/bugs.log.Rd Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2012-05-01 12:57:10 UTC (rev 252) +++ trunk/R2OpenBUGS/DESCRIPTION 2012-07-12 02:22:12 UTC (rev 253) @@ -1,7 +1,7 @@ Package: R2OpenBUGS Title: Running OpenBUGS from R -Date: 2012-2-04 -Version: 3.2-1.4 +Date: 2012-4-20 +Version: 3.2-2.1 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. @@ -14,6 +14,6 @@ in R. Depends: R (>= 2.11.0) Imports: coda (>= 0.11-0), boot -SystemRequirements: OpenBUGS (>= 3.2.1) +SystemRequirements: OpenBUGS (>= 3.2.2) Maintainer: Neal Thomas <snt...@ya...> License: GPL-2 Modified: trunk/R2OpenBUGS/R/bugs.log.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.log.R 2012-05-01 12:57:10 UTC (rev 252) +++ trunk/R2OpenBUGS/R/bugs.log.R 2012-07-12 02:22:12 UTC (rev 253) @@ -18,7 +18,9 @@ if(n.cols < 1) return(NA) mxlen <- sapply(mx, length) end <- which(mxlen!=n.cols)[1] - 1 - mx <- mx[1:end] + if(!is.na(end)){ ### if output block does not end mx + mx <- mx[1:end] + } cm <- matrix(unlist(mx), ncol=n.cols, byrow=TRUE) # character format if(empty.left.col) cm <- cm[,-1] # empty column col.names <- cm[1, -1] # first column is just "node" Modified: trunk/R2OpenBUGS/R/bugs.sims.R =================================================================== --- trunk/R2OpenBUGS/R/bugs.sims.R 2012-05-01 12:57:10 UTC (rev 252) +++ trunk/R2OpenBUGS/R/bugs.sims.R 2012-07-12 02:22:12 UTC (rev 253) @@ -4,7 +4,7 @@ ## Read the simulations from Bugs into R, format them, and monitor convergence sims.files <- paste ("CODAchain", 1:n.chains, ".txt", sep="") ## read in the names of the parameters and the indices of their samples - index <- read.table("CODAindex.txt", header = FALSE, sep = " ") + index <- read.table("CODAindex.txt", header = FALSE, sep = "") parameter.names <- as.vector(index[, 1]) n.keep <- index[1, 3] - index[1, 2] + 1 n.parameters <- length(parameter.names) Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2012-05-01 12:57:10 UTC (rev 252) +++ trunk/R2OpenBUGS/inst/NEWS 2012-07-12 02:22:12 UTC (rev 253) @@ -1,6 +1,11 @@ Changes to R2OpenBUGS: ====================== +Update 3.2-2.1 +- Updated reading of CODA file formats for version 3.2.2 of OpenBUGS, which + now consistently uses tab delimiters. Problems with reading the log + file were corrected as part of the new version of OpenBUGS. + Update 3.2-1.4 - Corrected printing of pD and DIC, which were reversed - Updated documentation to note difference in DIC reporting between Windows and Linux, and the lack of support for the bugs.log function under Linux Modified: trunk/R2OpenBUGS/man/bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.Rd 2012-05-01 12:57:10 UTC (rev 252) +++ trunk/R2OpenBUGS/man/bugs.Rd 2012-07-12 02:22:12 UTC (rev 253) @@ -75,11 +75,11 @@ when the script has finished running, otherwise \pkg{OpenBUGS} remains open for further investigation. The debug option is not available for linux execution.} \item{DIC}{logical; if \code{TRUE} (default), compute deviance, pD, - and DIC. For Windows execution, the results are extracted directly + and DIC. The results are extracted directly from the \pkg{OpenBUGS} log, which uses the rule \code{pD = - Dbar - Dhat}. For linux execution, or + Dbar - Dhat}. If extraction fails or if there are less iterations than required for the - adaptive phase, the rule \code{pD=var(deviance) / 2} is + adaptive phase, the rule \code{pD=var(deviance) / 2} is computed in R. See \code{\link{bugs.log}} for more information on extracting results from the log file.} \item{digits}{number of significant digits used for \pkg{OpenBUGS} input, see Modified: trunk/R2OpenBUGS/man/bugs.log.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.log.Rd 2012-05-01 12:57:10 UTC (rev 252) +++ trunk/R2OpenBUGS/man/bugs.log.Rd 2012-07-12 02:22:12 UTC (rev 253) @@ -17,8 +17,8 @@ \item{DIC}{A matrix containing the DIC statistics as returned from \pkg{OpenBUGS}.} } -\details{ The function is only supported under Windows execution because the \code{OpenBUGS} log file under Linux execution has a different format. The function -returns \code{NA} for both elements of the list under Linux. +\details{Returns the OpenBUGS summary statistics and DIC extracted directly +from the log file. } \seealso{The main function that generates the log file is \code{\link{bugs}}.} \author{Jouni Kerman} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2013-04-07 17:34:33
|
Revision: 263 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=263&view=rev Author: ligges Date: 2013-04-07 17:34:22 +0000 (Sun, 07 Apr 2013) Log Message: ----------- change .path.package() -> system.file() and update version dependency Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/man/attach.all.Rd Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2013-04-07 17:33:18 UTC (rev 262) +++ trunk/R2OpenBUGS/DESCRIPTION 2013-04-07 17:34:22 UTC (rev 263) @@ -12,7 +12,7 @@ it is possible to call a BUGS model, summarize inferences and convergence in a table and graph, and save the simulations in arrays for easy access in R. -Depends: R (>= 2.11.0) +Depends: R (>= 2.13.0) Imports: coda (>= 0.11-0), boot SystemRequirements: OpenBUGS (>= 3.2.2) Maintainer: Neal Thomas <snt...@ya...> Modified: trunk/R2OpenBUGS/man/attach.all.Rd =================================================================== --- trunk/R2OpenBUGS/man/attach.all.Rd 2013-04-07 17:33:18 UTC (rev 262) +++ trunk/R2OpenBUGS/man/attach.all.Rd 2013-04-07 17:34:22 UTC (rev 263) @@ -64,7 +64,7 @@ \examples{ # An example model file is given in: -model.file <- file.path(.path.package("R2OpenBUGS"), "model", "schools.txt") +model.file <- system.file("model", "schools.txt", package="R2OpenBUGS") # Some example data (see ?schools for details): data(schools) J <- nrow(schools) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <snt...@us...> - 2015-04-07 19:05:14
|
Revision: 268 http://sourceforge.net/p/bugs-r/code/268 Author: snthomas99 Date: 2015-04-07 19:05:12 +0000 (Tue, 07 Apr 2015) Log Message: ----------- Version3.2-3.1 with bugs.inits external Modified Paths: -------------- trunk/R2OpenBUGS/DESCRIPTION trunk/R2OpenBUGS/NAMESPACE trunk/R2OpenBUGS/R/findOpenBUGS.R trunk/R2OpenBUGS/inst/NEWS trunk/R2OpenBUGS/man/bugs.Rd Modified: trunk/R2OpenBUGS/DESCRIPTION =================================================================== --- trunk/R2OpenBUGS/DESCRIPTION 2013-08-18 22:31:14 UTC (rev 267) +++ trunk/R2OpenBUGS/DESCRIPTION 2015-04-07 19:05:12 UTC (rev 268) @@ -1,7 +1,7 @@ Package: R2OpenBUGS Title: Running OpenBUGS from R -Date: 2013-4-10 -Version: 3.2-2.2 +Date: 2015-4-06 +Version: 3.2-3.1 Author: originally written as R2WinBUGS by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. Modified: trunk/R2OpenBUGS/NAMESPACE =================================================================== --- trunk/R2OpenBUGS/NAMESPACE 2013-08-18 22:31:14 UTC (rev 267) +++ trunk/R2OpenBUGS/NAMESPACE 2015-04-07 19:05:12 UTC (rev 268) @@ -9,6 +9,7 @@ bugs.data, read.bugs, bugs.log, + bugs.inits, monitor, as.bugs.array, write.model, Modified: trunk/R2OpenBUGS/R/findOpenBUGS.R =================================================================== --- trunk/R2OpenBUGS/R/findOpenBUGS.R 2013-08-18 22:31:14 UTC (rev 267) +++ trunk/R2OpenBUGS/R/findOpenBUGS.R 2015-04-07 19:05:12 UTC (rev 268) @@ -10,9 +10,9 @@ if(.Platform$OS.type != "windows") return(Sys.which('OpenBUGS')) - deps <- utils:::packageDescription("R2OpenBUGS", fields="SystemRequirements") + deps <- utils::packageDescription("R2OpenBUGS", fields="SystemRequirements") version.req <- gsub(".*OpenBUGS ?\\(>= ?(.+)\\).*", "\\1", deps) - ob.reg <- try(utils:::readRegistry("Software\\OpenBUGS", "HLM", view = "32-bit"), silent = TRUE) + ob.reg <- try(utils::readRegistry("Software\\OpenBUGS", "HLM", view = "32-bit"), silent = TRUE) if (inherits(ob.reg, "try-error")) return(NA) @@ -29,5 +29,5 @@ if (compareVersion(max(version.inst), version.req) < 0) warning("Found OpenBUGS version ", version.inst, ".\n Requires ", version.req, " or greater.") - utils:::readRegistry(paste("Software", "OpenBUGS", rnames, sep="\\"), "HLM", view = "32-bit")[["InstallPath"]] + utils::readRegistry(paste("Software", "OpenBUGS", rnames, sep="\\"), "HLM", view = "32-bit")[["InstallPath"]] } Modified: trunk/R2OpenBUGS/inst/NEWS =================================================================== --- trunk/R2OpenBUGS/inst/NEWS 2013-08-18 22:31:14 UTC (rev 267) +++ trunk/R2OpenBUGS/inst/NEWS 2015-04-07 19:05:12 UTC (rev 268) @@ -1,6 +1,9 @@ Changes to R2OpenBUGS: ====================== +Update 3.2-3 +- bugs.inits function is now exported. + Update 3.2-2.1 - Updated reading of CODA file formats for version 3.2.2 of OpenBUGS, which now consistently uses tab delimiters. Problems with reading the log Modified: trunk/R2OpenBUGS/man/bugs.Rd =================================================================== --- trunk/R2OpenBUGS/man/bugs.Rd 2013-08-18 22:31:14 UTC (rev 267) +++ trunk/R2OpenBUGS/man/bugs.Rd 2015-04-07 19:05:12 UTC (rev 268) @@ -232,8 +232,9 @@ \emph{Journal of Statistical Software} 12(3), 1-16. } -\author{Andrew Gelman, \email{ge...@st...}, - \url{http:/www.stat.columbia.edu/~gelman/bugsR/}; modifications and +\author{Andrew Gelman, + \email{ge...@st...}; + modifications and packaged by Sibylle Sturtz, \email{st...@st...}, Uwe Ligges, and Neal Thomas} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |