You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(11) |
Dec
(20) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
|
Mar
|
Apr
(7) |
May
(24) |
Jun
(15) |
Jul
(5) |
Aug
(21) |
Sep
(85) |
Oct
(9) |
Nov
|
Dec
|
2008 |
Jan
(15) |
Feb
(11) |
Mar
|
Apr
(2) |
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
(29) |
Oct
(47) |
Nov
(1) |
Dec
(1) |
2009 |
Jan
(8) |
Feb
(12) |
Mar
(14) |
Apr
(4) |
May
(1) |
Jun
|
Jul
(5) |
Aug
|
Sep
|
Oct
(11) |
Nov
(18) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
(1) |
Apr
(3) |
May
(24) |
Jun
|
Jul
(1) |
Aug
(7) |
Sep
(5) |
Oct
(3) |
Nov
(4) |
Dec
|
2011 |
Jan
|
Feb
|
Mar
(13) |
Apr
(3) |
May
(2) |
Jun
|
Jul
(1) |
Aug
(24) |
Sep
(3) |
Oct
|
Nov
|
Dec
(29) |
2012 |
Jan
(5) |
Feb
(5) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
(1) |
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(5) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Gregor G. <gre...@bf...> - 2007-08-09 05:33:29
|
Thanks Ben! I will look at this in the evening (CET). Ben Bolker wrote: > I have taken a *fairly* recent svn copy of R2WinBUGS (missed the > last couple of updates reported this morning, but I hope you can > still use the patch) and made the changes required for me to > run the example in ?bugs out of the box, without specifying > a different command line than I would under Windows. > > Specifically, the changes are: > > bugs.R: change WINEPATH=NULL to WINEPATH=Sys.getenv("WINEPATH") > bugs.run.R: take out a newWINE flag and pass WINEPATH through in > call to win2native() > wineutils.R: update win2native() > > These changes will require at least one tweak to the .Rd files, which I'm > happy to make, but I'd like some other Linux users to check these mods > out and make sure they don't break anything ... > > These changes have slipped through the cracks a couple of times, I'd > love it they could get in this time so I can get up to date with > R2WinBUGS -- > > for what it's worth, I can't run R CMD check on R2WinBUGS on my system > because BRugs is now a required dependency, and it won't install under > Linux ... > > cheers > Ben Bolker > > > diff -c -r R2WinBUGS.new/R/bugs.R bugs-r/trunk/R2WinBUGS/R/bugs.R > *** R2WinBUGS.new/R/bugs.R 2007-08-07 16:53:47.000000000 -0400 > --- bugs-r/trunk/R2WinBUGS/R/bugs.R 2007-06-14 09:37:13.000000000 -0400 > *************** > *** 8,14 **** > program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), > working.directory=NULL, > clearWD=FALSE, useWINE=.Platform$OS.type != "windows", > WINE=Sys.getenv("WINE"), > ! newWINE=FALSE, WINEPATH=Sys.getenv("WINEPATH")) > { > program <- match.arg(program) > if(program %in% c("openbugs", "OpenBUGS", "OpenBugs")) { > --- 8,14 ---- > program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), > working.directory=NULL, > clearWD=FALSE, useWINE=.Platform$OS.type != "windows", > WINE=Sys.getenv("WINE"), > ! newWINE=FALSE, WINEPATH=NULL) > { > program <- match.arg(program) > if(program %in% c("openbugs", "OpenBUGS", "OpenBugs")) { > diff -c -r R2WinBUGS.new/R/bugs.run.R bugs-r/trunk/R2WinBUGS/R/bugs.run.R > *** R2WinBUGS.new/R/bugs.run.R 2007-08-07 17:17:41.000000000 -0400 > --- bugs-r/trunk/R2WinBUGS/R/bugs.run.R 2007-06-14 09:37:13.000000000 -0400 > *************** > *** 4,13 **** > newWINE = TRUE, WINEPATH = NULL){ > > if(useWINE && !is.R()) > ! stop ("Non-Windows platforms not yet supported in R2WinBUGS for > S-PLUS") > ! > ! ## BB: took out !newWINE (?), added WINEPATH > ! if(useWINE) bugs.directory <- win2native(bugs.directory,WINEPATH=WINEPATH) > > ## Update the lengths of the adaptive phases in the Bugs updaters > try(bugs.update.settings(n.burnin, bugs.directory)) > --- 4,11 ---- > newWINE = TRUE, WINEPATH = NULL){ > > if(useWINE && !is.R()) > ! stop ("Non-Windows platforms not yet supported in R2WinBUGS for > S-PLUS") > ! if(useWINE && !newWINE) bugs.directory <- win2native(bugs.directory) > > ## Update the lengths of the adaptive phases in the Bugs updaters > try(bugs.update.settings(n.burnin, bugs.directory)) > diff -c -r R2WinBUGS.new/R/wineutils.R bugs-r/trunk/R2WinBUGS/R/wineutils.R > *** R2WinBUGS.new/R/wineutils.R 2007-08-08 09:34:32.000000000 -0400 > --- bugs-r/trunk/R2WinBUGS/R/wineutils.R 2007-06-14 > 09:37:13.000000000 -0400 > *************** > *** 45,61 **** > } > > > ! win2native <- function(x, useWINE=.Platform$OS.type != "windows", > ! newWINE=TRUE, > ! WINEPATH=Sys.getenv("WINEPATH")) { > ! ## win -> native > ! if (useWINE) { > ! if (!newWINE) { > ! winedriveTr(x) > ! } else { > ! system(paste(WINEPATH, " \"", x, "\"", sep = ""), intern = TRUE) > ! } > ! } > else x > } > > --- 45,52 ---- > } > > > ! win2native <- function(x, useWINE=.Platform$OS.type != "windows") { # > win -> native > ! if (useWINE) winedriveTr(x) > else x > } > > > -- Lep pozdrav / With regards, Gregor Gorjanc ---------------------------------------------------------------------- University of Ljubljana PhD student Biotechnical Faculty www: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department blog: http://ggorjan.blogspot.com Groblje 3 mail: gregor.gorjanc <at> bfro.uni-lj.si SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe tel: +386 (0)1 72 17 861 ---------------------------------------------------------------------- |
From: Ben B. <bo...@zo...> - 2007-08-08 13:58:50
|
I have taken a *fairly* recent svn copy of R2WinBUGS (missed the last couple of updates reported this morning, but I hope you can still use the patch) and made the changes required for me to run the example in ?bugs out of the box, without specifying a different command line than I would under Windows. Specifically, the changes are: bugs.R: change WINEPATH=NULL to WINEPATH=Sys.getenv("WINEPATH") bugs.run.R: take out a newWINE flag and pass WINEPATH through in call to win2native() wineutils.R: update win2native() These changes will require at least one tweak to the .Rd files, which I'm happy to make, but I'd like some other Linux users to check these mods out and make sure they don't break anything ... These changes have slipped through the cracks a couple of times, I'd love it they could get in this time so I can get up to date with R2WinBUGS -- for what it's worth, I can't run R CMD check on R2WinBUGS on my system because BRugs is now a required dependency, and it won't install under Linux ... cheers Ben Bolker diff -c -r R2WinBUGS.new/R/bugs.R bugs-r/trunk/R2WinBUGS/R/bugs.R *** R2WinBUGS.new/R/bugs.R 2007-08-07 16:53:47.000000000 -0400 --- bugs-r/trunk/R2WinBUGS/R/bugs.R 2007-06-14 09:37:13.000000000 -0400 *************** *** 8,14 **** program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), working.directory=NULL, clearWD=FALSE, useWINE=.Platform$OS.type != "windows", WINE=Sys.getenv("WINE"), ! newWINE=FALSE, WINEPATH=Sys.getenv("WINEPATH")) { program <- match.arg(program) if(program %in% c("openbugs", "OpenBUGS", "OpenBugs")) { --- 8,14 ---- program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), working.directory=NULL, clearWD=FALSE, useWINE=.Platform$OS.type != "windows", WINE=Sys.getenv("WINE"), ! newWINE=FALSE, WINEPATH=NULL) { program <- match.arg(program) if(program %in% c("openbugs", "OpenBUGS", "OpenBugs")) { diff -c -r R2WinBUGS.new/R/bugs.run.R bugs-r/trunk/R2WinBUGS/R/bugs.run.R *** R2WinBUGS.new/R/bugs.run.R 2007-08-07 17:17:41.000000000 -0400 --- bugs-r/trunk/R2WinBUGS/R/bugs.run.R 2007-06-14 09:37:13.000000000 -0400 *************** *** 4,13 **** newWINE = TRUE, WINEPATH = NULL){ if(useWINE && !is.R()) ! stop ("Non-Windows platforms not yet supported in R2WinBUGS for S-PLUS") ! ! ## BB: took out !newWINE (?), added WINEPATH ! if(useWINE) bugs.directory <- win2native(bugs.directory,WINEPATH=WINEPATH) ## Update the lengths of the adaptive phases in the Bugs updaters try(bugs.update.settings(n.burnin, bugs.directory)) --- 4,11 ---- newWINE = TRUE, WINEPATH = NULL){ if(useWINE && !is.R()) ! stop ("Non-Windows platforms not yet supported in R2WinBUGS for S-PLUS") ! if(useWINE && !newWINE) bugs.directory <- win2native(bugs.directory) ## Update the lengths of the adaptive phases in the Bugs updaters try(bugs.update.settings(n.burnin, bugs.directory)) diff -c -r R2WinBUGS.new/R/wineutils.R bugs-r/trunk/R2WinBUGS/R/wineutils.R *** R2WinBUGS.new/R/wineutils.R 2007-08-08 09:34:32.000000000 -0400 --- bugs-r/trunk/R2WinBUGS/R/wineutils.R 2007-06-14 09:37:13.000000000 -0400 *************** *** 45,61 **** } ! win2native <- function(x, useWINE=.Platform$OS.type != "windows", ! newWINE=TRUE, ! WINEPATH=Sys.getenv("WINEPATH")) { ! ## win -> native ! if (useWINE) { ! if (!newWINE) { ! winedriveTr(x) ! } else { ! system(paste(WINEPATH, " \"", x, "\"", sep = ""), intern = TRUE) ! } ! } else x } --- 45,52 ---- } ! win2native <- function(x, useWINE=.Platform$OS.type != "windows") { # win -> native ! if (useWINE) winedriveTr(x) else x } |
From: <li...@us...> - 2007-08-08 11:31:44
|
Revision: 36 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=36&view=rev Author: ligges Date: 2007-08-08 04:31:43 -0700 (Wed, 08 Aug 2007) Log Message: ----------- minor tweaks: ignoree the ReadMe when building, comment that we might need to ship sources (GPL!), documentiung that bugsData might drop significant digits for integers Modified Paths: -------------- trunk/BRugs/inst/README-inst_OpenBUGS trunk/BRugs/man/bugs.data.Rd Added Paths: ----------- trunk/BRugs/.Rbuildignore Added: trunk/BRugs/.Rbuildignore =================================================================== --- trunk/BRugs/.Rbuildignore (rev 0) +++ trunk/BRugs/.Rbuildignore 2007-08-08 11:31:43 UTC (rev 36) @@ -0,0 +1 @@ +inst/README-inst_OpenBUGS Modified: trunk/BRugs/inst/README-inst_OpenBUGS =================================================================== --- trunk/BRugs/inst/README-inst_OpenBUGS 2007-08-08 09:48:36 UTC (rev 35) +++ trunk/BRugs/inst/README-inst_OpenBUGS 2007-08-08 11:31:43 UTC (rev 36) @@ -9,3 +9,7 @@ OpenBUGS/Examples/*.txt OpenBUGS/Manuals/*.bmp OpenBUGS/Manuals/*.html + + +Hmmm, but we maybe should ship all OpenBUGS, +because we may need to ship sources according to GPL. Modified: trunk/BRugs/man/bugs.data.Rd =================================================================== --- trunk/BRugs/man/bugs.data.Rd 2007-08-08 09:48:36 UTC (rev 35) +++ trunk/BRugs/man/bugs.data.Rd 2007-08-08 11:31:43 UTC (rev 36) @@ -15,6 +15,8 @@ \value{ Invisibly returns the \code{fileName}. } +\note{\code{bugsData} uses \code{format="E"} internally, i.e. you need to + pay attention when writing integers containg many significant digits to the data file.} \seealso{\code{\link{BRugs}}} \keyword{file} \concept{data} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-08 09:48:33
|
Revision: 35 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=35&view=rev Author: ggorjan Date: 2007-08-08 02:48:36 -0700 (Wed, 08 Aug 2007) Log Message: ----------- Reverting back to use of samplesSetThin() before burnin phase. But note that this is inefficient as has been pointed by Dawn for WinBUGS. Move to modelUpdate(niter, thin) is needed, but I am not yet sure what else needs to be modified. Modified Paths: -------------- trunk/R2WinBUGS/R/openbugs.R Modified: trunk/R2WinBUGS/R/openbugs.R =================================================================== --- trunk/R2WinBUGS/R/openbugs.R 2007-08-08 08:56:34 UTC (rev 34) +++ trunk/R2WinBUGS/R/openbugs.R 2007-08-08 09:48:36 UTC (rev 35) @@ -51,7 +51,7 @@ BRugs::modelInits(inits) BRugs::modelGenInits() } - ## BRugs::samplesSetThin(nThin) + BRugs::samplesSetThin(nThin) ## set the adaptive phases adaptivelines <- scan(system.file("OpenBUGS", "Bugs", "Rsrc", "Registry.txt", package="BRugs"), @@ -61,7 +61,7 @@ sapply(factories, BRugs::modelSetAP, max(0, nBurnin-1)) BRugs::modelUpdate(nBurnin) - BRugs::samplesSetThin(nThin) + ## BRugs::samplesSetThin(nThin) if(DIC) { BRugs::dicSet() on.exit(BRugs::dicClear(), add = TRUE) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-08-08 08:56:33
|
Revision: 34 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=34&view=rev Author: ggorjan Date: 2007-08-08 01:56:34 -0700 (Wed, 08 Aug 2007) Log Message: ----------- Using only history(*) in batch script since history(*, history.doc) does not create separate (history.odc) log file. Modified Paths: -------------- trunk/R2WinBUGS/R/bugs.log.R trunk/R2WinBUGS/R/bugs.script.R Modified: trunk/R2WinBUGS/R/bugs.log.R =================================================================== --- trunk/R2WinBUGS/R/bugs.log.R 2007-08-03 14:47:08 UTC (rev 33) +++ trunk/R2WinBUGS/R/bugs.log.R 2007-08-08 08:56:34 UTC (rev 34) @@ -34,7 +34,7 @@ DICEnd <- grep("history(", logfile, fixed=TRUE) - 1 ## - 1 to remove - ## "history(+, ..." + ## "history(..." if(!length(DICEnd) || !length(DICStart) || (DICEnd < DICStart)){ DICTable <- NA Modified: trunk/R2WinBUGS/R/bugs.script.R =================================================================== --- trunk/R2WinBUGS/R/bugs.script.R 2007-08-03 14:47:08 UTC (rev 33) +++ trunk/R2WinBUGS/R/bugs.script.R 2007-08-08 08:56:34 UTC (rev 34) @@ -12,7 +12,6 @@ model.file } else file.path(working.directory, model.file) data <- file.path(working.directory, "data.txt") - history <- file.path(working.directory, "history.odc") coda <- file.path(working.directory, "coda") logfile <- file.path(working.directory, "log.odc") logfileTxt <- file.path(working.directory, "log.txt") @@ -40,7 +39,7 @@ "coda (*, '", native2win(coda, WINEPATH=WINEPATH), "')\n"),redo), "stats (*)\n", if(DIC) "dic.stats()\n", - "history (*, '", native2win(history, WINEPATH=WINEPATH), "')\n", + "history (*)\n", "save ('", native2win(logfile, WINEPATH=WINEPATH), "')\n", "save ('", native2win(logfileTxt, WINEPATH=WINEPATH), "')\n", file=script, sep="", append=FALSE) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Gregor G. <gre...@bf...> - 2007-08-07 12:59:53
|
Dawn Woodard wrote: > It looks like the recent change that we made in how thinning is > handled in R2WinBUGS can cause a slow-down. If you run the schools > example with n.iter = 400000, n.thin = 40, n.chains = 1, the old > version runs quickly and the new version takes much longer. Perhaps > we should go back to the previous code? I apologize for introducing > this bug. The reason why we made the change was so that when the > mcmc.list object is read into R/S-PLUS using read.bugs, the thinning > attribute is correct. I don't know whether there is another way to > accomplish this. Hi, sorry for late reply. I have looked at the issue you brought up. Old and current code has in essence (left the code and right your example) thin.updater(n.thin) thin.updater(40) update(n.burnin/n.thin) update(400 000 / 2 / 40) which means saving 10 000 samples, while proposed change was update(n.burnin) update(400 000 / 2) thin.samples(n.thin) thin.samples(40) which ends in saving 200 000 samples of which only every 40th was kept. Notice that two different script commands are used i.e. thin.updater() and thin.samples(). I tried thin.samples() before and after update() and the resulting CODA files are OK, however it takes some while to finnish with burnin phase. If I understand correctly, thin.samples() is only relevant for ouput, while thin.updater() is relevant for the samplers i.e. sampling, but saving only i-th sample. I will ask Andrew Thomas about this. -- Lep pozdrav / With regards, Gregor Gorjanc ---------------------------------------------------------------------- University of Ljubljana PhD student Biotechnical Faculty www: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department blog: http://ggorjan.blogspot.com Groblje 3 mail: gregor.gorjanc <at> bfro.uni-lj.si SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe tel: +386 (0)1 72 17 861 ---------------------------------------------------------------------- |
From: <woo...@us...> - 2007-08-03 14:47:07
|
Revision: 33 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=33&view=rev Author: woodard_ Date: 2007-08-03 07:47:08 -0700 (Fri, 03 Aug 2007) Log Message: ----------- Allow samplesMonitors to handle vectors of parameter names rather than a single parameter name. Fix typos in error messages. More edits for improved compatibility with S-PLUS. Modified Paths: -------------- trunk/BRugs/R/buildMCMC.R trunk/BRugs/R/plot.bgr.R trunk/BRugs/R/plot.density.R trunk/BRugs/R/plot.history.R trunk/BRugs/R/samples.monitors.R trunk/BRugs/man/help.WinBUGS.Rd Modified: trunk/BRugs/R/buildMCMC.R =================================================================== --- trunk/BRugs/R/buildMCMC.R 2007-07-31 18:19:44 UTC (rev 32) +++ trunk/BRugs/R/buildMCMC.R 2007-08-03 14:47:08 UTC (rev 33) @@ -83,6 +83,9 @@ } mcmcobj <- lapply(samplesChain, mcmc, start = beg, end = end, thin = thin) - class(mcmcobj) <- "mcmc.list" + if(is.R()) + class(mcmcobj) <- "mcmc.list" + else + oldClass(mcmcobj) <- "mcmc.list" mcmcobj } Modified: trunk/BRugs/R/plot.bgr.R =================================================================== --- trunk/BRugs/R/plot.bgr.R 2007-07-31 18:19:44 UTC (rev 32) +++ trunk/BRugs/R/plot.bgr.R 2007-08-03 14:47:08 UTC (rev 33) @@ -5,7 +5,7 @@ { sM <- samplesMonitors(node) if(length(sM) > 1 || sM != node) - stop("node must be a scalar variable from the model, for arrays use samplesAutoC") + stop("node must be a scalar variable from the model, for arrays use samplesBgr") grid <- bgrGrid(node, bins = bins) bgr <- sapply(grid, bgrPoint, node = node) yRange <- range(bgr[4,]) Modified: trunk/BRugs/R/plot.density.R =================================================================== --- trunk/BRugs/R/plot.density.R 2007-07-31 18:19:44 UTC (rev 32) +++ trunk/BRugs/R/plot.density.R 2007-08-03 14:47:08 UTC (rev 33) @@ -4,7 +4,7 @@ { sM <- samplesMonitors(node) if(length(sM) > 1 || sM != node) - stop("node must be a scalar variable from the model, for arrays use samplesAutoC") + stop("node must be a scalar variable from the model, for arrays use samplesDensity") nodeName <- sQuote(node) command <- paste("SamplesEmbed.SetVariable(", nodeName, ")") .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") Modified: trunk/BRugs/R/plot.history.R =================================================================== --- trunk/BRugs/R/plot.history.R 2007-07-31 18:19:44 UTC (rev 32) +++ trunk/BRugs/R/plot.history.R 2007-08-03 14:47:08 UTC (rev 33) @@ -5,7 +5,7 @@ { sM <- samplesMonitors(node) if(length(sM) > 1 || sM != node) - stop("node must be a scalar variable from the model, for arrays use samplesAutoC") + stop("node must be a scalar variable from the model, for arrays use samplesHistory") nodeName <- sQuote(node) command <- paste("SamplesEmbed.SetVariable(", nodeName, ")") .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") Modified: trunk/BRugs/R/samples.monitors.R =================================================================== --- trunk/BRugs/R/samples.monitors.R 2007-07-31 18:19:44 UTC (rev 32) +++ trunk/BRugs/R/samples.monitors.R 2007-08-03 14:47:08 UTC (rev 33) @@ -2,6 +2,7 @@ function(node) # List all sample monitors corresponding to node { + if (is.R()){ command <- paste("SamplesEmbed.SetVariable(", sQuote(node), ");SamplesEmbed.StatsGuard;SamplesEmbed.Labels") .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") @@ -16,10 +17,34 @@ invisible("model has probably not yet been updated") } else { - if (is.R()) scan(buffer, what = "character", quiet = TRUE, sep="\n") - else - scan(buffer, what = "character", sep="\n") } } + } else { + sampsMonsSingle <- function(node){ + command <- paste("SamplesEmbed.SetVariable(", sQuote(node), + ");SamplesEmbed.StatsGuard;SamplesEmbed.Labels") + .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") + buffer <- file.path(tempdir(), "buffer.txt") + rlb <- readLines(buffer) + len <- length(rlb) + if (len == 1 && rlb == "command is not allowed (greyed out)") + message(rlb) + else{ + if(len == 0){ + message("model has probably not yet been updated") + invisible("model has probably not yet been updated") + } + else { + scan(buffer, what = "character", sep="\n") + } + } + } + for(i in seq(along=node)){ + mons <- lapply(node, sampsMonsSingle) + } + mons <- unlist(mons) + return(mons) + + } } Modified: trunk/BRugs/man/help.WinBUGS.Rd =================================================================== --- trunk/BRugs/man/help.WinBUGS.Rd 2007-07-31 18:19:44 UTC (rev 32) +++ trunk/BRugs/man/help.WinBUGS.Rd 2007-08-03 14:47:08 UTC (rev 33) @@ -8,6 +8,9 @@ \arguments{ \item{browser}{the name of the program to be used as hypertext browser. It should be in the PATH, or a full path specified.} } +\details{ + Not yet available in S-PLUS. +} \seealso{\code{\link{help.BRugs}}} \examples{ \dontrun{ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <woo...@us...> - 2007-07-31 18:19:42
|
Revision: 32 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=32&view=rev Author: woodard_ Date: 2007-07-31 11:19:44 -0700 (Tue, 31 Jul 2007) Log Message: ----------- Revert handling of thinning to earlier code. The change that was made caused WinBUGS to run more slowly due to saving many more samples. Modified Paths: -------------- trunk/R2WinBUGS/R/bugs.script.R Modified: trunk/R2WinBUGS/R/bugs.script.R =================================================================== --- trunk/R2WinBUGS/R/bugs.script.R 2007-07-25 09:25:49 UTC (rev 31) +++ trunk/R2WinBUGS/R/bugs.script.R 2007-07-31 18:19:44 UTC (rev 32) @@ -22,9 +22,8 @@ savelist <- paste("set (", parameters.to.save, ")\n", sep="") redo <- ceiling((n.iter-n.burnin)/(n.thin*bin)) - thinUpdateCommand <- paste("update (", n.burnin, ")\n", - "thin.samples (", n.thin, ")\n", sep = "") - bin = bin * n.thin + thinUpdateCommand <- paste("thin.updater (", n.thin, ")\n", + "update (", ceiling(n.burnin/n.thin), ")\n", sep = "") cat( "display ('log')\n", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Uwe L. <li...@st...> - 2007-07-25 09:32:19
|
Hi Dawn, thank you very much for your BRugs port to S-PLUS and the integration of OpenBUGS 3.0.1! I applied some minor tweaks to a couple of files and I am happy for now. The new version is in the sourceforge repository (where you already have got access permissions). Can you check it under S-PLUS again, please? Then I'd like to make a release on CRAN. Thanks again! Uwe Dawn Woodard wrote: > Dr. Ligges, > > The altered BRugs package source is attached. It does not include > OpenBUGS; I just copied the OpenBUGS from > > http://mathstat.helsinki.fi/openbugs/OpenBUGS.zip > > to the inst subdirectory. > > I also attached a listing of the main suggested changes to the code. > The remainder are small changes to the S-PLUS code for compatibility. > There are a few functions that I have not yet tested in S-PLUS, such as > modelDynamic, modelFactory, and getGraphObj. > > Thank you very much! > Dawn > > ------------------------------------------------------------------------ > > Changes to the S-PLUS Code in the BRugs Package > > Dawn Woodard > > > > *Changes to R & S code* > > > > 1. The initialization functions were changed to work with v.3.0.1 of > OpenBUGS > 2. The HTML help files have moved from the docu/ subdirectory of > OpenBUGS to the Manuals subdirectory, and so “help.WinBUGS” and > “help.BRugs” have been changed accordingly. > 3. When the DIC stats are obtained from OpenBUGS in the dicStats > function, the new version of OpenBUGS has extra lines to give > minimum deviance information; the old version of OpenBUGS did not > have those lines. These lines are removed from the buffer. > > > > *Changes to S code only* > > > > 1. The “tempdir” function does not exist in S-PLUS. We are working > on creating it. In the meantime, I defined tempdir to return the > working directory. This is not a permanent solution since then > BRugs does not run if the working directory is write-protected; > for instance I had to alter the BRugs and BRugsFit examples to get > them to run. > 2. “browseURL” does not exist in S-PLUS. I am looking into this; in > the meantime, the functions “help.BRugs” and “help.WinBUGS” do not > work in S-PLUS. > 3. “scan” does not have a “quiet” option in S-PLUS; this option has > been removed > 4. The function “dev.interactive” does not exist in S-PLUS; calls to > this option have been replaced by calls to “interactive” > 5. writeModel, bugsData, and bugsInits from R2WinBUGS have been > updated to work in S-PLUS. The changes mimic the changes to the > corresponding functions in R2WinBUGS > 6. The “real” function does not exist in S-PLUS, so calls to this > function have been replaced by calls to “double” > 7. Slashes in file path strings are different in S-PLUS than in R > 8. The “ann” graphical argument is not available in S-PLUS > 9. S-PLUS gives a warning when the package is built if the last line > in a function is an assignment. A call to “invisible” has been > added to the ends of these functions. > |
From: <li...@us...> - 2007-07-25 09:26:32
|
Revision: 31 http://bugs-r.svn.sourceforge.net/bugs-r/?rev=31&view=rev Author: ligges Date: 2007-07-25 02:25:49 -0700 (Wed, 25 Jul 2007) Log Message: ----------- - OpenBUGS 3.0.1 has been integrated (most of the work done by Dawn Woodard, Insighful, thank you Dawn!) - BRugs has been ported to S-PLUS (all of the work done by Dawn Woodard, Insighful, thank you Dawn!) Modified Paths: -------------- trunk/BRugs/DESCRIPTION trunk/BRugs/NAMESPACE trunk/BRugs/R/bgr.point.R trunk/BRugs/R/bugs.data.R trunk/BRugs/R/bugs.inits.R trunk/BRugs/R/buildMCMC.R trunk/BRugs/R/dic.stats.R trunk/BRugs/R/model.check.R trunk/BRugs/R/model.data.R trunk/BRugs/R/model.factory.R trunk/BRugs/R/model.inits.R trunk/BRugs/R/plot.autoC.R trunk/BRugs/R/plot.density.R trunk/BRugs/R/plot.history.R trunk/BRugs/R/samples.autoC.R trunk/BRugs/R/samples.bgr.R trunk/BRugs/R/samples.density.R trunk/BRugs/R/samples.history.R trunk/BRugs/R/samples.monitors.R trunk/BRugs/R/samples.sample.R trunk/BRugs/R/samples.stats.R trunk/BRugs/R/summary.stats.R trunk/BRugs/R/unix/help.R trunk/BRugs/R/windows/help.R trunk/BRugs/R/write.model.R trunk/BRugs/R/zzz.R trunk/BRugs/configure trunk/BRugs/man/BRugs.Rd trunk/BRugs/man/samples.autoC.Rd trunk/BRugs/man/samples.bgr.Rd trunk/BRugs/man/samples.density.Rd trunk/BRugs/man/samples.history.Rd trunk/BRugs/tests/BRugs.Rout.save Added Paths: ----------- trunk/BRugs/inst/README-inst_OpenBUGS Modified: trunk/BRugs/DESCRIPTION =================================================================== --- trunk/BRugs/DESCRIPTION 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/DESCRIPTION 2007-07-25 09:25:49 UTC (rev 31) @@ -1,12 +1,11 @@ Package: BRugs -Title: OpenBUGS and its R interface BRugs -Version: 0.3-3 -Date: 2006-09-12 +Title: OpenBUGS and its R / S-PLUS interface BRugs +Version: 0.4-0 +Date: 2007-07-24 Author: The Chief Software Bug is Andrew Thomas, with web assistance from Real Bug Bob O'Hara. Other members of the BUGS team are statisticians David Spiegelhalter, Nicky Best, Dave Lunn and Ken Rice. Dave Lunn has also made major contributions to the software development. R Code modified, extended and packaged for R by Uwe Ligges and Sibylle Sturtz. Some ideas taken from the R2WinBUGS package based on code by Andrew Gelman. -Description: An R package containing OpenBUGS and its R interface BRugs. +Description: An R / S-PLUS package containing OpenBUGS and its R / S-PLUS interface BRugs. Maintainer: Uwe Ligges <li...@st...> -Depends: R (>= 2.0.0) -Suggests: coda +Depends: R (>= 2.5.0), coda SystemRequirements: currently the only supported OS is Windows, we expect to support Linux in future releases License: GPL version 2 URL: http://mathstat.helsinki.fi/openbugs/ Modified: trunk/BRugs/NAMESPACE =================================================================== --- trunk/BRugs/NAMESPACE 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/NAMESPACE 2007-07-25 09:25:49 UTC (rev 31) @@ -1,4 +1,5 @@ useDynLib(BRugs) +importFrom(coda, mcmc) export(BRugsFit, bugsData, bugsInits, buildMCMC, currentValues, dicClear, dicSet, dicStats, getGraphObj, getNumChains, Modified: trunk/BRugs/R/bgr.point.R =================================================================== --- trunk/BRugs/R/bgr.point.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/bgr.point.R 2007-07-25 09:25:49 UTC (rev 31) @@ -12,14 +12,24 @@ sampleSize <- as.integer(.C("Integer", command, nchar(command), integer(1), integer(1), PACKAGE="BRugs")[[3]]) command <- "SamplesEmbed.Sample" - sample <- .C("RealArray", command, nchar(command), real(sampleSize), - as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] + if (is.R()) + sample <- .C("RealArray", command, nchar(command), real(sampleSize), + as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] + else + sample <- .C("RealArray", command, nchar(command), double(sampleSize), + as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] lenChain <- sampleSize %/% numChains - dq <- quantile(sample, c(0.1, 0.9), names = FALSE) + if (is.R()) + dq <- quantile(sample, c(0.1, 0.9), names = FALSE) + else + dq <- quantile(sample, c(0.1, 0.9)) d.delta <- dq[2] - dq[1] n.delta <- 0 for (i in 1:numChains) { - nq <- quantile(sample[((i - 1) * lenChain + 1) : (i * lenChain)], c(0.1, 0.9), names = FALSE) + if (is.R()) + nq <- quantile(sample[((i - 1) * lenChain + 1) : (i * lenChain)], c(0.1, 0.9), names = FALSE) + else + nq <- quantile(sample[((i - 1) * lenChain + 1) : (i * lenChain)], c(0.1, 0.9)) n.delta <- n.delta + nq[2] - nq[1] } n.delta <- n.delta / numChains Modified: trunk/BRugs/R/bugs.data.R =================================================================== --- trunk/BRugs/R/bugs.data.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/bugs.data.R 2007-07-25 09:25:49 UTC (rev 31) @@ -1,11 +1,237 @@ -"bugsData" <- +"bugsData" <- function(data, fileName = file.path(getwd(), "data.txt"), digits = 5){ if(is.numeric(unlist(data))) - write.datafile(lapply(data, formatC, digits = digits, format = "E"), fileName) + if(is.R()) { + write.datafile(lapply(data, formatC, digits = digits, format = "E"), fileName) + } + else { + writeDatafileS4(data, towhere = "data.txt") + } else { - 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"), fileName) - } + 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"), fileName) + } + else { + data.list <- lapply(as.list(data), get, where = parent.frame(2)) + names(data.list) <- unlist(data) + writeDatafileS4(data.list, towhere = "data.txt") + } + } invisible(fileName) } + + +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 WinBUGS. +# 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 WinBUTS 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 WinBUGS 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 WinBUGS. 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 WinBUGS. + 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( + "WinBUGS 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( + "WinBUGS 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( + "WinBUGS 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( + "WinBUGS 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/BRugs/R/bugs.inits.R =================================================================== --- trunk/BRugs/R/bugs.inits.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/bugs.inits.R 2007-07-25 09:25:49 UTC (rev 31) @@ -7,9 +7,15 @@ if(!is.null(inits)){ for (i in 1:numChains){ if (is.function(inits)) - write.datafile(lapply(inits(), formatC, digits = digits, format = "E"), fileName[i]) + if (is.R()) + write.datafile(lapply(inits(), formatC, digits = digits, format = "E"), fileName[i]) + else + writeDatafileS4(inits(), towhere = fileName[i]) else - write.datafile(lapply(inits[[i]], formatC, digits = digits, format = "E"), fileName[i]) + if (is.R()) + write.datafile(lapply(inits[[i]], formatC, digits = digits, format = "E"), fileName[i]) + else + writeDatafileS4(inits[[i]], towhere = fileName[i]) } } invisible(fileName) Modified: trunk/BRugs/R/buildMCMC.R =================================================================== --- trunk/BRugs/R/buildMCMC.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/buildMCMC.R 2007-07-25 09:25:49 UTC (rev 31) @@ -1,7 +1,11 @@ buildMCMC <- function(node, beg = samplesGetBeg(), end = samplesGetEnd(), firstChain = samplesGetFirstChain(), lastChain = samplesGetLastChain(), thin = samplesGetThin()){ + + if(!is.R() && !require("coda")) + stop("package 'coda' is required to use this function") + oldBeg <- samplesGetBeg() oldEnd <- samplesGetEnd() oldFirstChain <- samplesGetFirstChain() @@ -34,8 +38,12 @@ sampleSize <- as.integer(.C("Integer", command, nchar(command), integer(1), integer(1), PACKAGE = "BRugs")[[3]]) command <- "SamplesEmbed.Sample" - sample <- .C("RealArray", command, nchar(command), real(sampleSize), + if (is.R()) + sample <- .C("RealArray", command, nchar(command), real(sampleSize), sampleSize, integer(1), PACKAGE = "BRugs")[[3]] + else + sample <- .C("RealArray", command, nchar(command), double(sampleSize), + sampleSize, integer(1), PACKAGE = "BRugs")[[3]] numChains <- samplesGetLastChain() - samplesGetFirstChain() + 1 matrix(sample, ncol = numChains) } @@ -59,7 +67,10 @@ samplesChain <- vector(mode="list", length=numChains) for(i in 1:numChains){ - temp <- sapply(samples, function(x) x[,i]) + if (is.R()) + temp <- sapply(samples, function(x) x[,i]) + else + temp <- sapply(samples, function(x,j) { x[,j]}, j=i) ##### If we want to special-case 1D-mcmc objects: # if(ncol(temp) == 1){ # dim(temp) <- NULL @@ -71,13 +82,7 @@ # } } - require(coda) mcmcobj <- lapply(samplesChain, mcmc, start = beg, end = end, thin = thin) class(mcmcobj) <- "mcmc.list" mcmcobj } - - - - - Modified: trunk/BRugs/R/dic.stats.R =================================================================== --- trunk/BRugs/R/dic.stats.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/dic.stats.R 2007-07-25 09:25:49 UTC (rev 31) @@ -7,8 +7,14 @@ buffer <- file.path(tempdir(), "buffer.txt") rlb <- readLines(buffer) len <- length(rlb) - if (len > 1) + if (len > 1) { + # Remove the extra lines in the buffer that contain the minimum deviance information + minDeviancePos <- regexpr(pattern = "Minimum deviance", text = rlb) + lineToRemove <- which(minDeviancePos != -1) + rlb <- rlb [1:(lineToRemove-1)] + writeLines(rlb, buffer) read.table(buffer) - else + } else { message(rlb) + } } Modified: trunk/BRugs/R/model.check.R =================================================================== --- trunk/BRugs/R/model.check.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/model.check.R 2007-07-25 09:25:49 UTC (rev 31) @@ -11,7 +11,11 @@ stop(fileName, " is a directory, but a file is required") command <- paste("BugsEmbed.SetFilePath(", sQuote(fileName), ");BugsEmbed.ParseGuard;BugsEmbed.Parse", sep = "") - .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") + if (!is.R()) { + command <- gsub ("\\\\", "/", command) + command <- gsub ("//", "/", command) + } + .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE = "BRugs") if(getOption("BRugsVerbose")) buffer() } Modified: trunk/BRugs/R/model.data.R =================================================================== --- trunk/BRugs/R/model.data.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/model.data.R 2007-07-25 09:25:49 UTC (rev 31) @@ -12,6 +12,10 @@ stop(fileNm, " is a directory, but a file is required") command <- paste("BugsEmbed.SetFilePath(", sQuote(fileNm), ");BugsEmbed.LoadDataGuard;BugsEmbed.LoadData", sep = "") + if (!is.R()){ + command <- gsub ("\\\\", "/", command) + command <- gsub ("//", "/", command) + } .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") if(getOption("BRugsVerbose")) buffer() Modified: trunk/BRugs/R/model.factory.R =================================================================== --- trunk/BRugs/R/model.factory.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/model.factory.R 2007-07-25 09:25:49 UTC (rev 31) @@ -1,6 +1,6 @@ modelDisable <- function(factory){ command <- paste("UpdaterMethods.SetFactory('", factory,"');UpdaterMethods.Disable", sep = "") - invisible(.C("CmdInterpreter", comand, nchar(command), integer(1))) + invisible(.C("CmdInterpreter", command, nchar(command), integer(1))) } Modified: trunk/BRugs/R/model.inits.R =================================================================== --- trunk/BRugs/R/model.inits.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/model.inits.R 2007-07-25 09:25:49 UTC (rev 31) @@ -22,6 +22,10 @@ command <- paste("BugsEmbed.SetFilePath(", filename, "); BugsEmbed.LoadInitsGuard; BugsEmbed.chain := ", as.character(chainNum[i]), "; BugsEmbed.LoadInits") + if (!is.R()){ + command <- gsub ("\\\\", "/", command) + command <- gsub ("//", "/", command) + } .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") if(getOption("BRugsVerbose")){ cat("Initializing chain ", chainNum[i], ": ", sep="") Modified: trunk/BRugs/R/plot.autoC.R =================================================================== --- trunk/BRugs/R/plot.autoC.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/plot.autoC.R 2007-07-25 09:25:49 UTC (rev 31) @@ -10,11 +10,19 @@ command <- paste("SamplesEmbed.SetVariable(", nodeName, ")") .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") command <- "SamplesEmbed.SampleSize" - sampleSize <- as.integer(.C("Integer", command, nchar(command), - integer(1), integer(1), PACKAGE="BRugs")[3]) + if (is.R()) + sampleSize <- as.integer(.C("Integer", command, nchar(command), + integer(1), integer(1), PACKAGE="BRugs")[3]) + else + sampleSize <- as.integer(.C("Integer", command, nchar(command), + integer(1), integer(1), PACKAGE="BRugs")[[3]]) command <- "SamplesEmbed.Sample" - sample <- .C("RealArray", command, nchar(command), real(sampleSize), - as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] + if (is.R()) + sample <- .C("RealArray", command, nchar(command), real(sampleSize), + as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] + else + sample <- .C("RealArray", command, nchar(command), double(sampleSize), + as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] chain <- samplesGetFirstChain() if (sd(sample) > 1.0E-10) acfresult <- acf(sample, col = colour[chain], main = if(is.null(main)) nodeName else main, Modified: trunk/BRugs/R/plot.density.R =================================================================== --- trunk/BRugs/R/plot.density.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/plot.density.R 2007-07-25 09:25:49 UTC (rev 31) @@ -12,14 +12,22 @@ sampleSize <- as.integer(.C("Integer", command, nchar(command), integer(1), integer(1), PACKAGE="BRugs")[[3]]) command <- "SamplesEmbed.Sample" - sample <- .C("RealArray", command, nchar(command), real(sampleSize), - as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] + if (is.R()) + sample <- .C("RealArray", command, nchar(command), real(sampleSize), + as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] + else + sample <- .C("RealArray", command, nchar(command), double(sampleSize), + as.integer(sampleSize), integer(1), PACKAGE="BRugs")[[3]] + absSample <- abs(sample) intSample <- as.integer(absSample + 1.0E-10) zero <- absSample - intSample intSample <- as.integer(sample) if (sum(zero) > 0){ - d <- density(sample, adjust = 1.25) + if (is.R()) + d <- density(sample, adjust = 1.25) + else + d <- density(sample) plot(d$x, d$y, type = "l", main = if(is.null(main)) nodeName else main, xlab = xlab , ylab = ylab, col = col, ...) } Modified: trunk/BRugs/R/plot.history.R =================================================================== --- trunk/BRugs/R/plot.history.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/plot.history.R 2007-07-25 09:25:49 UTC (rev 31) @@ -10,11 +10,20 @@ command <- paste("SamplesEmbed.SetVariable(", nodeName, ")") .C("CmdInterpreter", command, nchar(command), integer(1), PACKAGE="BRugs") command <- "SamplesEmbed.SampleSize" - sampleSize <- as.integer(.C("Integer", command, nchar(command), + if (is.R()){ + sampleSize <- as.integer(.C("Integer", command, nchar(command), integer(1), integer(1), PACKAGE="BRugs")[3]) + } else { + sampleSize <- as.integer(.C("Integer", command, nchar(command), + integer(1), integer(1), PACKAGE="BRugs")[3][[1]]) + } command <- "SamplesEmbed.Sample" - sample <- .C("RealArray", command, nchar(command), real(sampleSize), - sampleSize, integer(1), PACKAGE="BRugs")[[3]] + if (is.R()) + sample <- .C("RealArray", command, nchar(command), real(sampleSize), + sampleSize, integer(1), PACKAGE="BRugs")[[3]] + else + sample <- .C("RealArray", command, nchar(command), double(sampleSize), + sampleSize, integer(1), PACKAGE="BRugs")[[3]] end <- min(c(modelIteration(), samplesGetEnd())) thin <- samplesGetThin() numChains <- samplesGetLastChain() - samplesGetFirstChain() + 1 Modified: trunk/BRugs/R/samples.autoC.R =================================================================== --- trunk/BRugs/R/samples.autoC.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/samples.autoC.R 2007-07-25 09:25:49 UTC (rev 31) @@ -3,8 +3,12 @@ thin = samplesGetThin(), plot = TRUE, mfrow = c(3, 2), ask = NULL, ann = TRUE, ...) # Plot auto correlation function { - if(is.null(ask)) + if(is.null(ask)) { + if (is.R()) ask <- !((dev.cur() > 1) && !dev.interactive()) + else + ask <- !((dev.cur() > 1) && !interactive()) + } oldBeg <- samplesGetBeg() oldEnd <- samplesGetEnd() oldFirstChain <- samplesGetFirstChain() @@ -27,7 +31,10 @@ thin <- max(c(thin, 1)) samplesSetThin(thin) mons <- samplesMonitors(node) - par(mfrow = mfrow, ask = ask, ann = ann) + if (is.R()) + par(mfrow = mfrow, ask = ask, ann = ann) + else + par(mfrow = mfrow, ask = ask) result <- lapply(mons, plotAutoC, plot = plot, ...) names(result) <- mons if(plot) invisible(result) Modified: trunk/BRugs/R/samples.bgr.R =================================================================== --- trunk/BRugs/R/samples.bgr.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/samples.bgr.R 2007-07-25 09:25:49 UTC (rev 31) @@ -5,8 +5,12 @@ ask = NULL, ann = TRUE, ...) # Plot bgr statistic { - if(is.null(ask)) + if(is.null(ask)) { + if (is.R()) ask <- !((dev.cur() > 1) && !dev.interactive()) + else + ask <- !((dev.cur() > 1) && !interactive()) + } oldBeg <- samplesGetBeg() oldEnd <- samplesGetEnd() oldFirstChain <- samplesGetFirstChain() @@ -27,7 +31,10 @@ thin <- max(c(thin, 1)) samplesSetThin(thin) mons <- samplesMonitors(node) - par(mfrow = mfrow, ask = ask, ann = ann) + if (is.R()) + par(mfrow = mfrow, ask = ask, ann = ann) + else + par(mfrow = mfrow, ask = ask) result <- lapply(mons, plotBgr, bins = bins, plot = plot, ...) names(result) <- mons if(plot) invisible(result) Modified: trunk/BRugs/R/samples.density.R =================================================================== --- trunk/BRugs/R/samples.density.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/samples.density.R 2007-07-25 09:25:49 UTC (rev 31) @@ -4,8 +4,12 @@ thin = samplesGetThin(), mfrow = c(3, 2), ask = NULL, ann = TRUE, ...) # Plot posterior density { - if(is.null(ask)) + if(is.null(ask)) { + if (is.R()) ask <- !((dev.cur() > 1) && !dev.interactive()) + else + ask <- !((dev.cur() > 1) && !interactive()) + } oldBeg <- samplesGetBeg() oldEnd <- samplesGetEnd() oldFirstChain <- samplesGetFirstChain() @@ -26,6 +30,11 @@ thin <- max(c(thin, 1)) samplesSetThin(thin) mons <- samplesMonitors(node) - par(mfrow = mfrow, ask = ask, ann = ann) + if (is.R()) + par(mfrow = mfrow, ask = ask, ann = ann) + else + par(mfrow = mfrow, ask = ask) junk <- sapply(mons, plotDensity, ...) + if (!is.R()) + invisible() } Modified: trunk/BRugs/R/samples.history.R =================================================================== --- trunk/BRugs/R/samples.history.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/samples.history.R 2007-07-25 09:25:49 UTC (rev 31) @@ -4,8 +4,12 @@ thin = samplesGetThin(), plot = TRUE, mfrow = c(3, 1), ask = NULL, ann = TRUE, ...) # Plot history { - if(is.null(ask)) + if(is.null(ask)) { + if (is.R()) ask <- !((dev.cur() > 1) && !dev.interactive()) + else + ask <- !((dev.cur() > 1) && !interactive()) + } oldBeg <- samplesGetBeg() oldEnd <- samplesGetEnd() oldFirstChain <- samplesGetFirstChain() @@ -25,7 +29,10 @@ thin <- max(c(thin, 1)) samplesSetThin(thin) mons <- samplesMonitors(node) - par(mfrow = mfrow, ask = ask, ann = ann) + if (is.R()) + par(mfrow = mfrow, ask = ask, ann = ann) + else + par(mfrow = mfrow, ask = ask) result <- lapply(mons, plotHistory, plot = plot, ...) names(result) <- mons if(plot) invisible(result) Modified: trunk/BRugs/R/samples.monitors.R =================================================================== --- trunk/BRugs/R/samples.monitors.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/samples.monitors.R 2007-07-25 09:25:49 UTC (rev 31) @@ -15,7 +15,11 @@ message("model has probably not yet been updated") invisible("model has probably not yet been updated") } - else + else { + if (is.R()) scan(buffer, what = "character", quiet = TRUE, sep="\n") + else + scan(buffer, what = "character", sep="\n") + } } } Modified: trunk/BRugs/R/samples.sample.R =================================================================== --- trunk/BRugs/R/samples.sample.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/samples.sample.R 2007-07-25 09:25:49 UTC (rev 31) @@ -10,6 +10,10 @@ sampleSize <- as.integer(.C("Integer", command, nchar(command), integer(1), integer(1), PACKAGE="BRugs")[[3]]) command <- "SamplesEmbed.Sample" - .C("RealArray", command, nchar(command), - real(sampleSize), sampleSize, integer(1), PACKAGE="BRugs")[[3]] + if (is.R()) + .C("RealArray", command, nchar(command), + real(sampleSize), sampleSize, integer(1), PACKAGE="BRugs")[[3]] + else + .C("RealArray", command, nchar(command), + double(sampleSize), sampleSize, integer(1), PACKAGE="BRugs")[[3]] } Modified: trunk/BRugs/R/samples.stats.R =================================================================== --- trunk/BRugs/R/samples.stats.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/samples.stats.R 2007-07-25 09:25:49 UTC (rev 31) @@ -23,10 +23,16 @@ thin <- max(c(thin, 1)) samplesSetThin(thin) nodeName <- sQuote(node) + + if (is.R()){ + result <- data.frame(mean=NULL, sd=NULL, MC_error = NULL, val2.5pc=NULL, + median=NULL, val97.5pc=NULL, start = NULL, sample=NULL) + } else { + result <- data.frame(mean=numeric(), sd=numeric(), MC.error = numeric(), + val2.5pc=numeric(), median=numeric(), val97.5pc=numeric(), + start = numeric(), sample=numeric()) + } - - result <- data.frame(mean=NULL, sd=NULL, MC_error = NULL, val2.5pc=NULL, - median=NULL, val97.5pc=NULL, start = NULL, sample=NULL) for(i in seq(along=nodeName)){ command <- paste("SamplesEmbed.SetVariable(", nodeName[i], ");SamplesEmbed.StatsGuard;SamplesEmbed.Stats") Modified: trunk/BRugs/R/summary.stats.R =================================================================== --- trunk/BRugs/R/summary.stats.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/summary.stats.R 2007-07-25 09:25:49 UTC (rev 31) @@ -3,8 +3,12 @@ # Calculates statistics for summary monitor associated with node in OpenBUGS model { nodeName <- sQuote(node) - result <- data.frame(mean=NULL, sd=NULL, val2.5pc=NULL, - median=NULL, val97.5pc=NULL, sample=NULL) + if (is.R()) + result <- data.frame(mean=NULL, sd=NULL, val2.5pc=NULL, + median=NULL, val97.5pc=NULL, sample=NULL) + else + result <- data.frame(mean=numeric(), sd=numeric(), val2.5pc=numeric(), + median=numeric(), val97.5pc=numeric(), sample=numeric()) for(i in seq(along=nodeName)){ command <- paste("SummaryEmbed.SetVariable(", nodeName[i], "); SummaryEmbed.StatsGuard;", "SummaryEmbed.Stats") Modified: trunk/BRugs/R/unix/help.R =================================================================== --- trunk/BRugs/R/unix/help.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/unix/help.R 2007-07-25 09:25:49 UTC (rev 31) @@ -1,15 +1,17 @@ help.BRugs <- function(browser = getOption("browser")) { - # stolen from help.start() - if(is.null(browser)) - stop("Invalid browser name, check options(\"browser\").") - writeLines(strwrap(paste("If", browser, "is already running,", - "it is *not* restarted, and you must", - "switch to its window."), - exdent = 4)) - writeLines("Otherwise, be patient ...") - browseURL(system.file("OpenBUGS", "docu", "BRugs Manual.html", package="BRugs")) - invisible("") + ## stolen from help.start() + # if(is.null(browser)) + # stop("Invalid browser name, check options(\"browser\").") + # writeLines(strwrap(paste("If", browser, "is already running,", + # "it is *not* restarted, and you must", + # "switch to its window."), + # exdent = 4)) + # writeLines("Otherwise, be patient ...") + # browseURL(system.file("OpenBUGS", "docu", "BRugs Manual.html", package="BRugs")) + # invisible("") + ## Andrew now omits the BRugs introduction, hence just pointing to help.WinBUGS these days: + help.WinBUGS(browser = browser) } help.WinBUGS <- function(browser = getOption("browser")) Modified: trunk/BRugs/R/windows/help.R =================================================================== --- trunk/BRugs/R/windows/help.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/windows/help.R 2007-07-25 09:25:49 UTC (rev 31) @@ -1,22 +1,27 @@ help.BRugs <- function(browser = getOption("browser")) { - # stolen from help.start() - a <- system.file("OpenBUGS", "docu", "BRugs Manual.html", package="BRugs") - if (!file.exists(a)) - stop("I can't find the html help") - a <- chartr("/", "\\", a) - message("If nothing happens, you should open `", a, "' yourself") - browseURL(a, browser = browser) - invisible("") + ## stolen from help.start() + # a <- system.file("OpenBUGS", "Manuals", "WinBUGS Manual.html", package="BRugs") + # if (!file.exists(a)) + # stop("I can't find the html help") + # a <- chartr("/", "\\", a) + # message("If nothing happens, you should open `", a, "' yourself") + # browseURL(a, browser = browser) + # invisible("") + ## Andrew now omits the BRugs introduction, hence just pointing to help.WinBUGS these days: + help.WinBUGS(browser = browser) } help.WinBUGS <- function(browser = getOption("browser")) { # stolen from help.start() - a <- system.file("OpenBUGS", "docu", "WinBUGS Manual.html", package="BRugs") + a <- system.file("OpenBUGS", "Manuals", "WinBUGS Manual.html", package="BRugs") if (!file.exists(a)) stop("I can't find the html help") - a <- chartr("/", "\\", a) + if (is.R()) + a <- chartr("/", "\\", a) + else + a <- gsub ("/", "\\\\", a) message("If nothing happens, you should open `", a, "' yourself") browseURL(a, browser = browser) invisible("") Modified: trunk/BRugs/R/write.model.R =================================================================== --- trunk/BRugs/R/write.model.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/write.model.R 2007-07-25 09:25:49 UTC (rev 31) @@ -1,7 +1,54 @@ writeModel <- function(model, con = "model.txt") { - model.text <- attr(model, "source") - model.text <- sub("^\\s*function\\s*\\(\\s*\\)", "model", model.text) + if (is.R()){ + model.text <- attr(model, "source") + model.text <- sub("^\\s*function\\s*\\(\\s*\\)", "model", model.text) + } 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 <- as.character(model) + model.text <- paste("model", model.text) + } model.text <- sub("%_%", "", model.text) + if (!is.R()){ + ## In S-PLUS, scientific notation is different than it is in WinBUGS. + ## Change the format of any numbers in scientific notation. + model.text <- replaceScientificNotation(model.text) + + ## remove the "invisible()" line. + model.text <- gsub("invisible[ ]*\\([ ]*\\)", "", model.text) + } writeLines(model.text, con = con) } + +replaceScientificNotation <- function(text){ +## Change the format of any numbers in "text" that are in S-PLUS +## scientific notation to WinBUGS 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/BRugs/R/zzz.R =================================================================== --- trunk/BRugs/R/zzz.R 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/R/zzz.R 2007-07-25 09:25:49 UTC (rev 31) @@ -1,3 +1,5 @@ +if (is.R()){ + ".onLoad" <- function(lib, pkg){ ## Don't know whether we have to do this before useDynLib()??? #Sys.putenv("LD_ASSUME_KERNEL"="2.4.1") @@ -6,16 +8,44 @@ ## we do have a NAMESPACE now: library.dynam("BRugs", pkg, lib) len <- nchar(root) tempDir <- gsub("\\\\", "/", tempdir()) - .C("Initialize", as.character(root), as.character(tempDir), - as.integer(len), nchar(tempDir), PACKAGE="BRugs") + .C("SetRoot", as.character(root), len, PACKAGE="BRugs") + .C("SetTempDir", as.character(tempDir), nchar(tempDir), PACKAGE="BRugs") + command <- "BugsMappers.SetDest(2)" + .C("CmdInterpreter", as.character(command), nchar(command), integer(1), PACKAGE="BRugs") + #.C("Initialize", as.character(root), as.character(tempDir), + # as.integer(len), nchar(tempDir), PACKAGE="BRugs") if(is.null(getOption("BRugsVerbose"))) options("BRugsVerbose" = TRUE) } ".onAttach" <- function(lib, pkg){ - message("Welcome to BRugs running on OpenBUGS version 2.2.0 beta") + message("Welcome to BRugs running on OpenBUGS version 3.0.1") } ".onUnload" <- function(libpath){ library.dynam.unload("BRugs", libpath) } + +} else { # ends if (is.R()) + +".First.lib" <- function(lib.loc, section) +{ + dyn.open(system.file("OpenBUGS", "brugs.dll", package="BRugs")) + ## sets path / file variables and initializes subsystems + root <- file.path(system.file("OpenBUGS", package="BRugs")) + len <- nchar(root) + tempDir <- gsub("\\\\", "/", tempdir()) + .C("SetRoot", as.character(root), len) + .C("SetTempDir", as.character(tempDir), nchar(tempDir)) + command <- "BugsMappers.SetDest(2)" + .C("CmdInterpreter", as.character(command), nchar(command), integer(1)) + if(is.null(getOption("BRugsVerbose"))) + options("BRugsVerbose" = TRUE) + invisible() +} + +.tempDir <- getwd() + +tempdir <- function(){ .tempDir } + +} # ends else Modified: trunk/BRugs/configure =================================================================== --- trunk/BRugs/configure 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/configure 2007-07-25 09:25:49 UTC (rev 31) @@ -1,2 +1,3 @@ -echo "Package 'BRugs' currently only works under Windows.\nIt is supposed to work under Linux in future releases." -exit 1 +echo "Package 'BRugs' currently only works under Windows.\nIt is supposed to work under Linux in future releases." +exit 1 + Added: trunk/BRugs/inst/README-inst_OpenBUGS =================================================================== --- trunk/BRugs/inst/README-inst_OpenBUGS (rev 0) +++ trunk/BRugs/inst/README-inst_OpenBUGS 2007-07-25 09:25:49 UTC (rev 31) @@ -0,0 +1,11 @@ +Here goes from the current OpenBUGS distribution: + +OpenBUGS +OpenBUGS/brugs.dll +OpenBUGS/brugs.so +OpenBUGS/libtaucs.dll +OpenBUGS/Examples/*.bmp +OpenBUGS/Examples/*.html +OpenBUGS/Examples/*.txt +OpenBUGS/Manuals/*.bmp +OpenBUGS/Manuals/*.html Modified: trunk/BRugs/man/BRugs.Rd =================================================================== --- trunk/BRugs/man/BRugs.Rd 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/man/BRugs.Rd 2007-07-25 09:25:49 UTC (rev 31) @@ -37,7 +37,7 @@ of any successes or failures. } %\references{} -\seealso{\code{\link{help.WinBUGS}} and the meta function \code{\link{BRugsFit}}} +\seealso{\code{\link{help.WinBUGS}} (which currently is called from \code{help.BRugs}) and the meta function \code{\link{BRugsFit}}} \examples{ ### Step by step example: ### library(BRugs) # loading BRugs @@ -67,7 +67,8 @@ setwd(oldwd) \dontrun{ # Getting more (online-)help: -help.BRugs() +if (is.R()) + help.BRugs() } } \keyword{interface} Modified: trunk/BRugs/man/samples.autoC.Rd =================================================================== --- trunk/BRugs/man/samples.autoC.Rd 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/man/samples.autoC.Rd 2007-07-25 09:25:49 UTC (rev 31) @@ -14,7 +14,8 @@ \item{thin}{To only use every \code{thin}-th value of the stored sample for statistics.} \item{plot}{Logical, whether to plot the ACF or only return the values. If \code{TRUE}, values are returned invisibly.} \item{mfrow, ask, ann}{Graphical parameters, see \code{\link{par}} for details. - \code{ask} defaults to \code{TRUE} unless it is plotting into an already opened non-interactive device.} + \code{ask} defaults to \code{TRUE} unless it is plotting into an already opened non-interactive device. + The \code{ann} parameter is not available in S-PLUS, and will be ignored if it is set.} \item{...}{Further graphical parameters as in \code{\link{par}} may also be passed as arguments to \code{\link{plotAutoC}}.} } Modified: trunk/BRugs/man/samples.bgr.Rd =================================================================== --- trunk/BRugs/man/samples.bgr.Rd 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/man/samples.bgr.Rd 2007-07-25 09:25:49 UTC (rev 31) @@ -20,7 +20,8 @@ \item{plot}{Logical, whether to plot the BGR statistics or only return the values. If \code{TRUE}, values are returned invisibly.} \item{mfrow, ask, ann}{Graphical parameters, see \code{\link{par}} for details. - \code{ask} defaults to \code{TRUE} unless it is plotting into an already opened non-interactive device.} + \code{ask} defaults to \code{TRUE} unless it is plotting into an already opened non-interactive device. + The \code{ann} parameter is not available in S-PLUS, and will be ignored if it is set.} \item{...}{Further graphical parameters as in \code{\link{par}} may also be passed as arguments to \code{\link{plotBgr}}.} } Modified: trunk/BRugs/man/samples.density.Rd =================================================================== --- trunk/BRugs/man/samples.density.Rd 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/man/samples.density.Rd 2007-07-25 09:25:49 UTC (rev 31) @@ -15,7 +15,8 @@ \item{firstChain, lastChain}{Arguments to select a sub group of chains to plot density estimate or histogram for.} \item{thin}{to only use every \code{thin}-th value of the stored sample for statistics.} \item{mfrow, ask, ann}{Graphical parameters, see \code{\link{par}} for details. - \code{ask} defaults to \code{TRUE} unless it is plotting into an already opened non-interactive device.} + \code{ask} defaults to \code{TRUE} unless it is plotting into an already opened non-interactive device. + The \code{ann} parameter is not available in S-PLUS, and will be ignored if it is set.} \item{...}{Further graphical parameters as in \code{\link{par}} may also be passed as arguments to \code{\link{plotDensity}}.} } Modified: trunk/BRugs/man/samples.history.Rd =================================================================== --- trunk/BRugs/man/samples.history.Rd 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/man/samples.history.Rd 2007-07-25 09:25:49 UTC (rev 31) @@ -16,7 +16,8 @@ \item{plot}{Logical, whether to plot the trace or only return the values. If \code{TRUE}, values are returned invisibly.} \item{mfrow, ask, ann}{Graphical parameters, see \code{\link{par}} for details. - \code{ask} defaults to \code{TRUE} unless it is plotting into an already opened non-interactive device.} + \code{ask} defaults to \code{TRUE} unless it is plotting into an already opened non-interactive device. + The \code{ann} parameter is not available in S-PLUS, and will be ignored if it is set.} \item{...}{Further graphical parameters as in \code{\link{par}} may also be passed as arguments to \code{\link{plotHistory}}.} } Modified: trunk/BRugs/tests/BRugs.Rout.save =================================================================== --- trunk/BRugs/tests/BRugs.Rout.save 2007-06-13 00:59:08 UTC (rev 30) +++ trunk/BRugs/tests/BRugs.Rout.save 2007-07-25 09:25:49 UTC (rev 31) @@ -1,6 +1,7 @@ -R : Copyright 2005, The R Foundation for Statistical Computing -Version 2.1.0 Patched (2005-05-11), ISBN 3-900051-07-0 +R version 2.5.1 (2007-06-27) +Copyright (C) 2007 The R Foundation for Statistical Computing +ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -11,144 +12,146 @@ '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 a HTML browser interface to help. +'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(BRugs) -Welcome to BRugs running on OpenBUGS version 2.2.0 beta +Loading required package: coda +Loading required package: lattice +Welcome to BRugs running on OpenBUGS version 3.0.1 > > BRugsFit(data = "ratsdata.txt", inits = "ratsinits.txt", + para = c("alpha", "beta"), modelFile = "ratsmodel.txt", + numChains = 1, + working.directory = system.file("OpenBUGS", "Examples", + package = "BRugs")) -model is syntactically correct -data loaded -model compiled +model is syntactically correct +data loaded +model compiled [1] "ratsinits.txt" -Initializing chain 1: model is initialized -1000 updates took 0 s -deviance set -monitor set for variable 'alpha' -monitor set for variable 'beta' -1000 updates took 0 s +Initializing chain 1: model is initialized +1000 updates took 0 s +deviance set +monitor set for variable 'alpha' +monitor set for variable 'beta' +1000 updates took 0 s $Stats mean sd MC_error val2.5pc median val97.5pc start sample -alpha[1] 239.800 2.4710 0.081260 234.500 239.800 244.300 1001 1000 -alpha[2] 247.900 2.6820 0.065740 242.300 248.000 253.300 1001 1000 -alpha[3] 252.400 2.8660 0.083620 246.800 252.600 257.900 1001 1000 -alpha[4] 232.700 2.7010 0.074410 227.000 232.800 238.100 1001 1000 -alpha[5] 231.600 2.7430 0.090660 226.200 231.600 236.800 1001 1000 -alpha[6] 249.600 2.6090 0.074790 244.400 249.700 254.600 1001 1000 -alpha[7] 228.800 2.5900 0.086230 224.100 228.600 234.000 1001 1000 -alpha[8] 248.400 2.6310 0.079340 243.000 248.500 253.300 1001 1000 -alpha[9] 283.100 2.7810 0.093740 277.700 283.200 288.400 1001 1000 -alpha[10] 219.200 2.6770 0.072100 214.000 219.200 224.500 1001 1000 -alpha[11] 258.200 2.7820 0.082720 252.900 258.300 263.400 1001 1000 -alpha[12] 228.100 2.5830 0.089030 222.900 228.100 233.100 1001 1000 -alpha[13] 242.300 2.6500 0.081100 237.100 242.300 247.500 1001 1000 -alpha[14] 268.200 2.7510 0.082220 262.800 268.200 273.500 1001 1000 -alpha[15] 242.800 2.6530 0.093230 237.800 242.800 247.900 1001 1000 -alpha[16] 245.300 2.7780 0.080010 239.800 245.400 250.800 1001 1000 -alpha[17] 232.000 2.6820 0.067020 226.800 232.000 237.300 1001 1000 -alpha[18] 240.300 2.7140 0.105800 234.900 240.400 245.600 1001 1000 -alpha[19] 253.700 2.7090 0.073890 248.200 253.600 258.700 1001 1000 -alpha[20] 241.700 2.6860 0.097940 236.600 241.700 246.900 1001 1000 -alpha[21] 248.500 2.7710 0.081320 243.100 248.500 253.900 1001 1000 -alpha[22] 225.300 2.6960 0.087560 220.200 225.300 230.800 1001 1000 -alpha[23] 228.600 2.5970 0.087210 223.400 228.600 233.800 1001 1000 -alpha[24] 245.200 2.7210 0.089540 239.600 245.200 250.600 1001 1000 -alpha[25] 234.500 2.7300 0.073650 229.100 234.500 239.900 1001 1000 -alpha[26] 254.000 2.6520 0.087640 249.000 254.100 259.200 1001 1000 -alpha[27] 254.400 2.7170 0.080260 249.200 254.400 259.600 1001 1000 -alpha[28] 243.000 2.6980 0.065220 237.700 243.100 248.200 1001 1000 -alpha[29] 217.800 2.7660 0.094850 212.200 217.800 223.000 1001 1000 -alpha[30] 241.300 2.7330 0.080940 236.000 241.300 246.500 1001 1000 -beta[1] 6.074 0.2424 0.009256 5.616 6.073 6.565 1001 1000 -beta[2] 7.042 0.2472 0.008130 6.571 7.038 7.530 1001 1000 -beta[3] 6.482 0.2505 0.007121 6.007 6.480 6.969 1001 1000 -beta[4] 5.348 0.2429 0.009942 4.874 5.345 5.812 1001 1000 -beta[5] 6.589 0.2475 0.009652 6.116 6.574 7.089 1001 1000 -beta[6] 6.174 0.2372 0.007914 5.698 6.176 6.635 1001 1000 -beta[7] 5.982 0.2511 0.009924 5.512 5.977 6.482 1001 1000 -beta[8] 6.407 0.2379 0.006988 5.959 6.406 6.871 1001 1000 -beta[9] 7.066 0.2543 0.007695 6.567 7.073 7.590 1001 1000 -beta[10] 5.846 0.2474 0.006672 5.366 5.847 6.328 1001 1000 -beta[11] 6.802 0.2418 0.007856 6.308 6.806 7.274 1001 1000 -beta[12] 6.129 0.2398 0.009423 5.669 6.123 6.623 1001 1000 -beta[13] 6.159 0.2400 0.008713 5.709 6.162 6.650 1001 1000 -beta[14] 6.696 0.2393 0.007849 6.217 6.696 7.158 1001 1000 -beta[15] 5.429 0.2562 0.009106 4.919 5.444 5.896 1001 1000 -beta[16] 5.916 0.2353 0.007259 5.448 5.915 6.382 1001 1000 -beta[17] 6.280 0.2475 0.007826 5.764 6.266 6.765 1001 1000 -beta[18] 5.849 0.2437 0.007895 5.379 5.854 6.331 1001 1000 -beta[19] 6.413 0.2448 0.008416 5.954 6.400 6.903 1001 1000 -beta[20] 6.062 0.2366 0.008115 5.626 6.053 6.538 1001 1000 -beta[21] 6.406 0.2419 0.006763 5.923 6.405 6.875 1001 1000 -beta[22] 5.868 0.2450 0.006494 5.404 5.877 6.346 1001 1000 -beta[23] 5.748 0.2438 0.008933 5.258 5.749 6.224 1001 1000 -beta[24] 5.911 0.2402 0.006082 5.426 5.914 6.381 1001 1000 -beta[25] 6.904 0.2489 0.007867 6.416 6.904 7.410 1001 1000 -beta[26] 6.543 0.2413 0.008710 6.082 6.545 7.011 1001 1000 -beta[27] 5.903 0.2480 0.008511 5.452 5.899 6.409 1001 1000 -beta[28] 5.840 0.2470 0.007768 5.358 5.847 6.341 1001 1000 -beta[29] 5.674 0.2452 0.007864 5.202 5.673 6.173 1001 1000 -beta[30] 6.121 0.2308 0.006812 5.668 6.127 6.582 1001 1000 +alpha[1] 239.900 2.7070 0.076220 234.400 239.900 245.000 1001 1000 +alpha[2] 247.700 2.6960 0.089790 242.200 247.800 253.000 1001 1000 +alpha[3] 252.600 2.6770 0.081210 247.200 252.700 257.800 1001 1000 +alpha[4] 232.600 2.6430 0.089860 227.700 232.700 238.100 1001 1000 +alpha[5] 231.600 2.6680 0.081590 226.500 231.600 236.700 1001 1000 +alpha[6] 249.700 2.7320 0.084880 244.600 249.600 255.300 1001 1000 +alpha[7] 228.700 2.7620 0.099880 223.200 228.700 234.200 1001 1000 +alpha[8] 248.400 2.7140 0.080630 243.300 248.400 254.000 1001 1000 +alpha[9] 283.400 2.7480 0.061700 277.700 283.400 288.800 1001 1000 +alpha[10] 219.400 2.6790 0.074340 214.100 219.200 225.000 1001 1000 +alpha[11] 258.200 2.7220 0.094600 253.100 258.100 264.100 1001 1000 +alpha[12] 228.100 2.7470 0.092450 222.800 228.100 233.200 1001 1000 +alpha[13] 242.600 2.4970 0.069930 237.700 242.500 247.400 1001 1000 +alpha[14] 268.200 2.6500 0.076140 263.000 268.200 273.400 1001 1000 +alpha[15] 242.700 2.6800 0.074650 237.500 242.800 248.200 1001 1000 +alpha[16] 245.400 2.7440 0.090230 239.800 245.400 250.900 1001 1000 +alpha[17] 232.100 2.6820 0.076820 226.900 232.100 237.700 1001 1000 +alpha[18] 240.600 2.5760 0.083010 235.600 240.600 245.700 1001 1000 +alpha[19] 253.800 2.6350 0.084970 248.700 253.900 258.900 1001 1000 +alpha[20] 241.600 2.7230 0.073110 236.500 241.500 247.100 1001 1000 +alpha[21] 248.700 2.5980 0.085770 243.500 248.800 253.700 1001 1000 +alpha[22] 225.200 2.7820 0.077450 219.800 225.200 230.500 1001 1000 +alpha[23] 228.300 2.7290 0.069540 222.300 228.400 233.400 1001 1000 +alpha[24] 245.000 2.7410 0.071480 239.700 245.100 250.400 1001 1000 +alpha[25] 234.500 2.6630 0.092080 229.000 234.500 239.500 1001 1000 +alpha[26] 254.000 2.6180 0.089310 249.000 254.000 259.200 1001 1000 +alpha[27] 254.300 2.7780 0.102600 248.900 254.500 259.900 1001 1000 +alpha[28] 242.900 2.6100 0.078810 237.900 242.900 247.900 1001 1000 +alpha[29] 217.800 2.5840 0.084150 212.600 217.800 222.900 1001 1000 +alpha[30] 241.500 2.6040 0.085820 236.500 241.600 246.800 1001 1000 +beta[1] 6.068 0.2464 0.008693 5.584 6.064 6.544 1001 1000 +beta[2] 7.054 0.2581 0.009510 6.529 7.063 7.565 1001 1000 +beta[3] 6.473 0.2417 0.008479 5.994 6.475 6.947 1001 1000 +beta[4] 5.327 0.2531 0.010990 4.835 5.328 5.820 1001 1000 +beta[5] 6.564 0.2498 0.007435 6.084 6.563 7.088 1001 1000 +beta[6] 6.179 0.2462 0.009767 5.682 6.182 6.663 1001 1000 +beta[7] 5.976 0.2508 0.005942 5.491 5.979 6.477 1001 1000 +beta[8] 6.406 0.2414 0.007365 5.928 6.408 6.892 1001 1000 +beta[9] 7.073 0.2465 0.008848 6.604 7.073 7.539 1001 1000 +beta[10] 5.830 0.2545 0.007829 5.324 5.828 6.321 1001 1000 +beta[11] 6.790 0.2445 0.008118 6.304 6.787 7.259 1001 1000 +beta[12] 6.115 0.2383 0.007260 5.643 6.118 6.558 1001 1000 +beta[13] 6.143 0.2388 0.006842 5.698 6.134 6.607 1001 1000 +beta[14] 6.684 0.2476 0.007014 6.229 6.689 7.169 1001 1000 +beta[15] 5.420 0.2668 0.011640 4.867 5.421 5.941 1001 1000 +beta[16] 5.926 0.2417 0.006787 5.453 5.932 6.407 1001 1000 +beta[17] 6.257 0.2359 0.006193 5.776 6.263 6.725 1001 1000 +beta[18] 5.833 0.2397 0.007924 5.375 5.838 6.304 1001 1000 +beta[19] 6.401 0.2556 0.008447 5.916 6.386 6.898 1001 1000 +beta[20] 6.066 0.2341 0.006553 5.589 6.061 6.530 1001 1000 +beta[21] 6.394 0.2447 0.007466 5.871 6.400 6.889 1001 1000 +beta[22] 5.865 0.2453 0.006486 5.395 5.865 6.352 1001 1000 +beta[23] 5.739 0.2450 0.008503 5.262 5.733 6.217 1001 1000 +beta[24] 5.883 0.2491 0.006714 5.400 5.875 6.395 1001 1000 +beta[25] 6.903 0.2516 0.006540 6.407 6.894 7.403 1001 1000 +beta[26] 6.553 0.2360 0.006531 6.096 6.548 7.030 1001 1000 +beta[27] 5.898 0.2525 0.008045 5.420 5.896 6.399 1001 1000 +beta[28] 5.850 0.2506 0.008446 5.363 5.855 6.343 1001 1000 +beta[29] 5.666 0.2380 0.007562 5.189 5.679 6.139 1001 1000 +beta[30] 6.125 0.2443 0.007231 5.661 6.129 6.613 1001 1000 $DIC - Dbar Dhat DIC pD -Y 967 913 1021 54 -total 967 913 1021 54 + Dbar Dhat DIC pD +Y 966.7 912.5 1021 54.27 +total 966.7 912.5 1021 54.27 > > setwd(system.file("OpenBUGS", "Examples", package="BRugs")) > modelCheck("ratsmodel.txt") -model is syntactically correct +model is syntactically correct > modelData("ratsdata.txt") -data loaded +data loaded > modelCompile(numChains=2) -model compiled +model compiled > modelInits(rep("ratsinits.txt", 2)) -Initializing chain 1: initial values loaded but this or another chain contain uninitialized variables -Initializing chain 2: model is initialized +Initializing chain 1: initial values loaded but this or another chain contain uninitialized variables +Initializing chain 2: model is initialized > modelUpdate(1000) -1000 updates took 0 s +1000 updates took 0 s > samplesSet(c("alpha0", "alpha")) -monitor set for variable 'alpha0' -monitor set for variable 'alpha' +monitor set for variable 'alpha0' +monitor set for variable 'alpha' > modelUpdate(1000) -1000 updates took 0 s +1000 updates took 0 s > samplesStats("*") mean sd MC_error val2.5pc median val97.5pc start sample -alpha[1] 239.9 2.684 0.06498 234.80 240.0 245.1 1001 2000 -alpha[2] 247.8 2.733 0.05468 242.50 247.9 253.1 1001 2000 -alpha[3] 252.4 2.653 0.05837 247.10 252.4 257.4 1001 2000 -alpha[4] 232.6 2.641 0.06602 227.40 232.6 237.7 1001 2000 -alpha[5] 231.5 2.696 0.05603 226.30 231.5 236.9 1001 2000 -alpha[6] 249.7 2.689 0.05530 244.40 249.7 254.8 1001 2000 -alpha[7] 228.6 2.703 0.05136 223.50 228.6 234.0 1001 2000 -alpha[8] 248.4 2.653 0.06213 243.20 248.4 253.6 1001 2000 -alpha[9] 283.3 2.740 0.05856 278.10 283.3 288.7 1... [truncated message content] |
From: Uwe L. <li...@st...> - 2007-07-24 17:19:26
|
Dawn Woodard wrote: > > > It looks like the recent change that we made in how thinning is handled > in R2WinBUGS can cause a slow-down. If you run the schools example with > n.iter = 400000, n.thin = 40, n.chains = 1, the old version runs quickly > and the new version takes much longer. Perhaps we should go back to the > previous code? I apologize for introducing this bug. The reason why we > made the change was so that when the mcmc.list object is read into > R/S-PLUS using read.bugs, the thinning attribute is correct. I don’t > know whether there is another way to accomplish this. I'm fine with going back. Are there any ideas by others how to fix it really properly? Dawn, I am just working on the BRugs stuff you sent me and I think we I'll move it to the repository tomorrow, just a few improvements for R from my side. Additionally, I think we can put OpenBUGS to Sourceforge as well. Andrew told me that just "a few" files are required to be included. Best, Uwe > > > Thank you! > > Dawn > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > Bugs-r-devel mailing list > Bug...@li... > https://lists.sourceforge.net/lists/listinfo/bugs-r-devel |
From: Dawn W. <dwo...@in...> - 2007-07-24 14:18:52
|
=20 It looks like the recent change that we made in how thinning is handled = in R2WinBUGS can cause a slow-down. If you run the schools example with = n.iter =3D 400000, n.thin =3D 40, n.chains =3D 1, the old version runs quickly = and the new version takes much longer. Perhaps we should go back to the previous = code? I apologize for introducing this bug. The reason why we made the change = was so that when the mcmc.list object is read into R/S-PLUS using read.bugs, = the thinning attribute is correct. I don't know whether there is another = way to accomplish this. =20 Thank you! Dawn=20 |
From: <gg...@us...> - 2007-06-13 00:59:07
|
Revision: 30 http://svn.sourceforge.net/bugs-r/?rev=30&view=rev Author: ggorjan Date: 2007-06-12 17:59:08 -0700 (Tue, 12 Jun 2007) Log Message: ----------- There was a bug related to use of OpenBUGS and as.bugs.array due to using DIC as a placholder for DIC stats and not a TRUE/FALSE - now using isDIC more consistently as well as DICbyR to distinguish between BUGS and R calculation of pD. I have also made some cosmetic changes in help as well as code files. Modified Paths: -------------- trunk/R2WinBUGS/Changes trunk/R2WinBUGS/R/as.bugs.array.R trunk/R2WinBUGS/R/bugs.R trunk/R2WinBUGS/R/bugs.plot.summary.R trunk/R2WinBUGS/R/bugs.sims.R trunk/R2WinBUGS/R/openbugs.R trunk/R2WinBUGS/R/print.bugs.R trunk/R2WinBUGS/man/as.bugs.array.Rd trunk/R2WinBUGS/man/attach.all.Rd trunk/R2WinBUGS/man/bugs.Rd trunk/R2WinBUGS/man/bugs.data.Rd trunk/R2WinBUGS/man/bugs.inits.Rd trunk/R2WinBUGS/man/bugs.log.Rd trunk/R2WinBUGS/man/bugs.plot.Rd trunk/R2WinBUGS/man/bugs.run.Rd trunk/R2WinBUGS/man/bugs.script.Rd trunk/R2WinBUGS/man/bugs.sims.Rd trunk/R2WinBUGS/man/bugs.update.settings.Rd trunk/R2WinBUGS/man/decode.parameter.name.Rd trunk/R2WinBUGS/man/monitor.Rd trunk/R2WinBUGS/man/openbugs.Rd trunk/R2WinBUGS/man/plot.bugs.Rd trunk/R2WinBUGS/man/print.bugs.Rd trunk/R2WinBUGS/man/read.bugs.Rd trunk/R2WinBUGS/man/write.datafile.Rd trunk/R2WinBUGS/man/write.model.Rd Modified: trunk/R2WinBUGS/Changes =================================================================== --- trunk/R2WinBUGS/Changes 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/Changes 2007-06-13 00:59:08 UTC (rev 30) @@ -1,229 +1,230 @@ -Changes to R2WinBUGS: -===================== - -Update 2.1-5 (12 June 2007): -- proper indexing of CODA files also in R version -- fixed useWINE documentation in bugs help page -- note on supported BUGS versions -- as.bugs.array now returns info on used rule for pD i.e. var(deviance)/2 -- some internal fixes related to is.null(DIC) -- merging and reversing ChangeLog files - -Update 2.1-4 (20 May 2007): -- Depending on coda now (Namespace issues) -- some more fixes for codetools checks -- Vignette has been updated - -Update 2.1-3 (13 May 2007): -- Ported to S-PLUS by Insightful Corp. -- some fixes for codetools checks - -Update 2.0-4 (01 November 2006): -- print.bugs / plot.bugs documentation fixes -- write.model() fix - -Update 2.0-3 (06 October 2006): -- \\. -> [.] in regular expressions - -Update 2.0-2 (26 July 2006): -- changes for DIC, making use of BUGS internal calculations -- some doc fixes - -Update 2.0-1 (26 May 2006): -- some wine patches for 2.2-0 by Gregor Gorjanc - -Update 2.0-0 (08 May 2006): -- bugs() doc fix/updates on scrambling -- bugs.run() has new arg useWINE (by Gregor Gorjanc) -- bugs() and bugs.script() patched for WINEPATH issue -- bugs.script() changed to save log file in ASCII -- new function bugs.log() by Gregor Gorjanc -- new functions as.bugs.array, openbugs and sort.name by - Jouni Kerman and Andrew Gelman -- new function write.model() based on ideas from Jouni Kerman - -Update 1.1-1 (17 Feb 2006): -- WINE tweaks (mainly by Gregor Gorjanc) - -Update 1.1-0 (14 Dec 2005): -- Contribution by Ben Bolker and Yun Yan's rbugs package: - make R2WinBUGS work under WINE - -Update 1.0-1 (14 Nov 2005): -- make inits=NULL work (again ?) - -Update 1.0-0 (05 Aug 2005): -- attach.all(), detach.all(), attach.bugs() and detach.bugs() added/changed - more or less according to Andrew Gelman's current bugs.R - -Update 0.2-9 (26 July 2005): -- bugs has new argument clearWD - -Update 0.2-8 (30 May 2005): -- bugs passed DIC to bugs.script in order to be able to disable it - -Update 0.2-6 (18 May 2005): -- bugs() changes in order to return a file names of coda output files -- new read.bugs() returns a coda mcmc.list object, if codaPkg=TRUE. - -Update 0.2-5 (20 Oct 2004): -- bugs() and bugs.script() have a new argument bin that allows to specify - a number of iterations. After each "bin" iterations the coda files are saved. - -Update 0.2-4 (05 Oct 2004): -- bugs.script() did not work for large n.iter values in update step - (no scientific notation allowed) - -Update 0.2-3 (10 Sept 2004): -- bugs.data.inits split to bugs.inits and bugs.data, the latter exported - from the Namespace. - Now we can use already written data files in bugs(). - -Update 0.2-2 (28 Apr 2004): -- schools data: original (see references) instead of the rounded data - -During the process of packaging R2WinBUGS_0.1 - R2WinBUGS_0.2-1, -quite a lot of changes had been made. Those changes are not -documented anywhere ... - -During the process of packaging R2WinBUGS_0.1, quite a lot of changes had -been made. Those changes are not documented anywhere ... - -Changes prior to R2WinBUGS_0.1: -=============================== - -Update 30 Oct 2003: - 1. Minor change to a return() statement to be compatible with R 1.8 - 2. Just a warning (from Ben Goodrich): if you are running Bugs.R inside - a loop, you have to be careful with the data() and the inits() - functions since they will not necessarily recognize locally-defined - variables. One workaround is to define the variables used in data() - and inits() using global assignments (<<-), but this can sometimes - make the program run slower. -Update 29 Aug 2003: - 1. Fixed "bugs.data.inits" function so you can use data that have the - same names as R functions. - 2. Changed T and F to TRUE and FALSE everywhere in case the variables - T and F are used as data in the main program - 3. Caution: if you are entering the data as a list of variable names - (see 10 Apr 2003 update, item 1), the data to be input into must - be global variables. This can be relevant if you are running bugs() - inside an R function. - 4. Caution: bugs() has difficulty processing ragged arrays. It is - better to save a whole matrix (e.g., "theta") rather than parts - (e.g., "theta[1:10,1]", "theta[1:5,2]"). If you want to save - part of a vector, you should do it as "theta[1:2]", not "theta[1]", - "theta[2]". -Update 30 Apr 2003: added time monitoring -Update 29 Apr 2003: - 1. The "attach.all" function (no longer called "attach2") overwrites - so that all components of a list or data frame get attached. - 2. Program now looks in the directory /winbug~1/ rather than /winbug~2/ - 3. Graphics parameters for margins are returned to their original state - at the end of the program. - 4. Added "digits.summary" option to the numerical display. - 5. Added "last.values" output: a list that can be input as "inits" - if you want to run the simulations longer. -Update 13 Apr 2003: fixed new bug in round.bugs(). Now all numbers are - saved in scientific notation. -Update 10 Apr 2003: - 1. It is now possible to enter the data as a list of variable names. - For example, before you had to enter data as, - data <- list (n=8, y=c(28,8,-3,7,-1,1,18,12)) - or - n <- 8 - y <- c(28,8,-3,7,-1,1,18,12) - data <- list (n=n, y=y) - Now you can enter the data as, - n <- 8 - y <- c(28,8,-3,7,-1,1,18,12) - data <- list ("n", "y") - The bugs() function will figure out which method you are using (based - on whether "data" is a list of numbers or a vector of character - strings). - This doesn't look like much, but it's convenient when you're entering - lots of data! - 2. It is now possible to enter the initial values as a function, - so as to automatically a random list of inits for each of the chains. - For example, in the 8-schools example below, we can do: - inits <- function() - list (theta=rnorm(J,0,1), mu.theta=rnorm(1,0,100), sigma.theta=runif(1,0,100)) - - to set up the inits as a function (rather than setting up n.chains - sets of specific initial values). Then, the function call, - schools.sim <- bugs (data, inits, parameters, "schools.txt", n.chains=3, n.iter=1000) - automatically sets up 3 sets of initial values (each a list of - theta, mu.theta, sigma.theta). - 3. Bug in the initial rounding (the function round.bugs()) has been fixed. - Thanks for Mark Clements for finding the bug and fixing it! - Also, we have set the default rounding to 5 digits instead of 2. -Update 01 Apr 2003: use layout() rather than split.screen() for graphical - display -Update 18 Mar 2003: - 1. Get the Bugs configuration information from the original file - (Registry_default.odc) rather than overwriting each time. (Fixes a - bug that occurred when R was interrupted in the middle of a Bugs run.) - 2. Display different colored dots in the right panel of the graphical - display, to show the medians from each chain. -Update 13 Mar 2003: fix minor bug in monitor() -Update 10 Mar 2003: fix bug in pD and DIC calculations -Update 7 Mar 2003: - 1. Fix display.parallel=T option by adding min.width so that very - intervals are still visible. - 2. Compute pD separately for each sequence (which gives much more - reasonable estimates before convergence). -Update 8 Feb 2003: minor fixes in graphical display -Update 6 Feb 2003: - 1. Approximate "effective sample size" n.eff given for each parameter. - 2. More explanatory material displayed. - 3. Use bringToTop() to automatically bring up the graphics window. -Update 4 Feb 2003: - 1. Automatically compute the deviance, DIC, and pD. Bugs will not - always compute DIC and pD, so we do so using the definition, - DIC = E(deviance) + pD, using var(deviance)/2 as an estimate of pD. - (This is derived from the chi^2 distribution. We can't use the - Spiegelhalter et al. definition of DIC because we don't have access - to the deviance function.) - 2. Set default for n.thin so that, after thinning, the total number - saved iterations, n.sims, is approximately 1000. -Update 14 Jan 2003 to run with the new WinBugs1.4. You may see an error - message and need to fix the dos.location assignment in bugs(). -Update 6 Jan 2003: - 1. Fix of bug that occurred with uppercase and lowercase variable names - 2. Set default for n.thin so that no more than about 500 iterations - will be saved from each sequence - 3. New option "display.parallel" added to show 80% inferences from - parallel sequences on the right panel of the graphical display. This - can be useful to understand what is going on when there are - convergence problems. -Update 26 Dec 2002: fix of minwidth in bugs.plot.summary -Update 11 Dec 2002: - 1. Automatic fixing of adaptive phases. Now you no longer need to run - for thousands of iterations when slice or Metropolis sampling is used. - 2. Various minor fixes -Update 10 Dec 2002: - 1. Cool graphical display of convergence and inferences! - 2. New "attach2" function that overwrites so that all components of - the list are attached -Update 29 Nov 2002: - 1. Fix of bug in 24 Nov update. - 2. Fix of bug in 16 Nov update. - 3. Length of chains is now pecified in terms of "n.iter" rather than - "n.keep". -Update 24 Nov 2002: improved treatment of "parameters.to.save". For - example, you can now use "alpha" to indicate an entire array of parameters, - whereas before you had to save "alpha[]" or "alpha[,]" or whatever. -Update 16 Nov 2002: mean, sd, median added to outputs -Update 4 Nov 2002: more error-flagging added -Update 26 Oct 2002: - 1. Parameters saved in order of the "parameters.to.save" vector - (not alphabetical order). - 2. Output saved in both matrix and list form. - 3. With the attach.sims=T setting (which is the default), the simulations - for all the saved parameters are saved as R objects. This is - convenient for later use of the simulations. -Updates to 16 Oct 2002: more error-flagging added, mean/sd added to summary, - fixing scientific notation so Bugs can always read data and inits -Update 21 Sept 2002: "quit=F" option changed to "debug=T" -First version written 18 Sept 2002 by Andrew Gelman, - adapted from the EmBedBugs package by Kenneth Rice +Changes to R2WinBUGS: +===================== + +Update 2.1-5 (12 June 2007): +- proper indexing of CODA files also in R version +- fixed useWINE documentation in bugs help page +- note on supported BUGS versions +- as.bugs.array now returns info on used rule for pD i.e. var(deviance)/2 + or Dbar-Dhat +- some internal fixes related to handling of DIC +- merging and reversing ChangeLog files + +Update 2.1-4 (20 May 2007): +- Depending on coda now (Namespace issues) +- some more fixes for codetools checks +- Vignette has been updated + +Update 2.1-3 (13 May 2007): +- Ported to S-PLUS by Insightful Corp. +- some fixes for codetools checks + +Update 2.0-4 (01 November 2006): +- print.bugs / plot.bugs documentation fixes +- write.model() fix + +Update 2.0-3 (06 October 2006): +- \\. -> [.] in regular expressions + +Update 2.0-2 (26 July 2006): +- changes for DIC, making use of BUGS internal calculations +- some doc fixes + +Update 2.0-1 (26 May 2006): +- some wine patches for 2.2-0 by Gregor Gorjanc + +Update 2.0-0 (08 May 2006): +- bugs() doc fix/updates on scrambling +- bugs.run() has new arg useWINE (by Gregor Gorjanc) +- bugs() and bugs.script() patched for WINEPATH issue +- bugs.script() changed to save log file in ASCII +- new function bugs.log() by Gregor Gorjanc +- new functions as.bugs.array, openbugs and sort.name by + Jouni Kerman and Andrew Gelman +- new function write.model() based on ideas from Jouni Kerman + +Update 1.1-1 (17 Feb 2006): +- WINE tweaks (mainly by Gregor Gorjanc) + +Update 1.1-0 (14 Dec 2005): +- Contribution by Ben Bolker and Yun Yan's rbugs package: + make R2WinBUGS work under WINE + +Update 1.0-1 (14 Nov 2005): +- make inits=NULL work (again ?) + +Update 1.0-0 (05 Aug 2005): +- attach.all(), detach.all(), attach.bugs() and detach.bugs() added/changed + more or less according to Andrew Gelman's current bugs.R + +Update 0.2-9 (26 July 2005): +- bugs has new argument clearWD + +Update 0.2-8 (30 May 2005): +- bugs passed DIC to bugs.script in order to be able to disable it + +Update 0.2-6 (18 May 2005): +- bugs() changes in order to return a file names of coda output files +- new read.bugs() returns a coda mcmc.list object, if codaPkg=TRUE. + +Update 0.2-5 (20 Oct 2004): +- bugs() and bugs.script() have a new argument bin that allows to specify + a number of iterations. After each "bin" iterations the coda files are saved. + +Update 0.2-4 (05 Oct 2004): +- bugs.script() did not work for large n.iter values in update step + (no scientific notation allowed) + +Update 0.2-3 (10 Sept 2004): +- bugs.data.inits split to bugs.inits and bugs.data, the latter exported + from the Namespace. + Now we can use already written data files in bugs(). + +Update 0.2-2 (28 Apr 2004): +- schools data: original (see references) instead of the rounded data + +During the process of packaging R2WinBUGS_0.1 - R2WinBUGS_0.2-1, +quite a lot of changes had been made. Those changes are not +documented anywhere ... + +During the process of packaging R2WinBUGS_0.1, quite a lot of changes had +been made. Those changes are not documented anywhere ... + +Changes prior to R2WinBUGS_0.1: +=============================== + +Update 30 Oct 2003: + 1. Minor change to a return() statement to be compatible with R 1.8 + 2. Just a warning (from Ben Goodrich): if you are running Bugs.R inside + a loop, you have to be careful with the data() and the inits() + functions since they will not necessarily recognize locally-defined + variables. One workaround is to define the variables used in data() + and inits() using global assignments (<<-), but this can sometimes + make the program run slower. +Update 29 Aug 2003: + 1. Fixed "bugs.data.inits" function so you can use data that have the + same names as R functions. + 2. Changed T and F to TRUE and FALSE everywhere in case the variables + T and F are used as data in the main program + 3. Caution: if you are entering the data as a list of variable names + (see 10 Apr 2003 update, item 1), the data to be input into must + be global variables. This can be relevant if you are running bugs() + inside an R function. + 4. Caution: bugs() has difficulty processing ragged arrays. It is + better to save a whole matrix (e.g., "theta") rather than parts + (e.g., "theta[1:10,1]", "theta[1:5,2]"). If you want to save + part of a vector, you should do it as "theta[1:2]", not "theta[1]", + "theta[2]". +Update 30 Apr 2003: added time monitoring +Update 29 Apr 2003: + 1. The "attach.all" function (no longer called "attach2") overwrites + so that all components of a list or data frame get attached. + 2. Program now looks in the directory /winbug~1/ rather than /winbug~2/ + 3. Graphics parameters for margins are returned to their original state + at the end of the program. + 4. Added "digits.summary" option to the numerical display. + 5. Added "last.values" output: a list that can be input as "inits" + if you want to run the simulations longer. +Update 13 Apr 2003: fixed new bug in round.bugs(). Now all numbers are + saved in scientific notation. +Update 10 Apr 2003: + 1. It is now possible to enter the data as a list of variable names. + For example, before you had to enter data as, + data <- list (n=8, y=c(28,8,-3,7,-1,1,18,12)) + or + n <- 8 + y <- c(28,8,-3,7,-1,1,18,12) + data <- list (n=n, y=y) + Now you can enter the data as, + n <- 8 + y <- c(28,8,-3,7,-1,1,18,12) + data <- list ("n", "y") + The bugs() function will figure out which method you are using (based + on whether "data" is a list of numbers or a vector of character + strings). + This doesn't look like much, but it's convenient when you're entering + lots of data! + 2. It is now possible to enter the initial values as a function, + so as to automatically a random list of inits for each of the chains. + For example, in the 8-schools example below, we can do: + inits <- function() + list (theta=rnorm(J,0,1), mu.theta=rnorm(1,0,100), sigma.theta=runif(1,0,100)) + + to set up the inits as a function (rather than setting up n.chains + sets of specific initial values). Then, the function call, + schools.sim <- bugs (data, inits, parameters, "schools.txt", n.chains=3, n.iter=1000) + automatically sets up 3 sets of initial values (each a list of + theta, mu.theta, sigma.theta). + 3. Bug in the initial rounding (the function round.bugs()) has been fixed. + Thanks for Mark Clements for finding the bug and fixing it! + Also, we have set the default rounding to 5 digits instead of 2. +Update 01 Apr 2003: use layout() rather than split.screen() for graphical + display +Update 18 Mar 2003: + 1. Get the Bugs configuration information from the original file + (Registry_default.odc) rather than overwriting each time. (Fixes a + bug that occurred when R was interrupted in the middle of a Bugs run.) + 2. Display different colored dots in the right panel of the graphical + display, to show the medians from each chain. +Update 13 Mar 2003: fix minor bug in monitor() +Update 10 Mar 2003: fix bug in pD and DIC calculations +Update 7 Mar 2003: + 1. Fix display.parallel=T option by adding min.width so that very + intervals are still visible. + 2. Compute pD separately for each sequence (which gives much more + reasonable estimates before convergence). +Update 8 Feb 2003: minor fixes in graphical display +Update 6 Feb 2003: + 1. Approximate "effective sample size" n.eff given for each parameter. + 2. More explanatory material displayed. + 3. Use bringToTop() to automatically bring up the graphics window. +Update 4 Feb 2003: + 1. Automatically compute the deviance, DIC, and pD. Bugs will not + always compute DIC and pD, so we do so using the definition, + DIC = E(deviance) + pD, using var(deviance)/2 as an estimate of pD. + (This is derived from the chi^2 distribution. We can't use the + Spiegelhalter et al. definition of DIC because we don't have access + to the deviance function.) + 2. Set default for n.thin so that, after thinning, the total number + saved iterations, n.sims, is approximately 1000. +Update 14 Jan 2003 to run with the new WinBugs1.4. You may see an error + message and need to fix the dos.location assignment in bugs(). +Update 6 Jan 2003: + 1. Fix of bug that occurred with uppercase and lowercase variable names + 2. Set default for n.thin so that no more than about 500 iterations + will be saved from each sequence + 3. New option "display.parallel" added to show 80% inferences from + parallel sequences on the right panel of the graphical display. This + can be useful to understand what is going on when there are + convergence problems. +Update 26 Dec 2002: fix of minwidth in bugs.plot.summary +Update 11 Dec 2002: + 1. Automatic fixing of adaptive phases. Now you no longer need to run + for thousands of iterations when slice or Metropolis sampling is used. + 2. Various minor fixes +Update 10 Dec 2002: + 1. Cool graphical display of convergence and inferences! + 2. New "attach2" function that overwrites so that all components of + the list are attached +Update 29 Nov 2002: + 1. Fix of bug in 24 Nov update. + 2. Fix of bug in 16 Nov update. + 3. Length of chains is now pecified in terms of "n.iter" rather than + "n.keep". +Update 24 Nov 2002: improved treatment of "parameters.to.save". For + example, you can now use "alpha" to indicate an entire array of parameters, + whereas before you had to save "alpha[]" or "alpha[,]" or whatever. +Update 16 Nov 2002: mean, sd, median added to outputs +Update 4 Nov 2002: more error-flagging added +Update 26 Oct 2002: + 1. Parameters saved in order of the "parameters.to.save" vector + (not alphabetical order). + 2. Output saved in both matrix and list form. + 3. With the attach.sims=T setting (which is the default), the simulations + for all the saved parameters are saved as R objects. This is + convenient for later use of the simulations. +Updates to 16 Oct 2002: more error-flagging added, mean/sd added to summary, + fixing scientific notation so Bugs can always read data and inits +Update 21 Sept 2002: "quit=F" option changed to "debug=T" +First version written 18 Sept 2002 by Andrew Gelman, + adapted from the EmBedBugs package by Kenneth Rice Modified: trunk/R2WinBUGS/R/as.bugs.array.R =================================================================== --- trunk/R2WinBUGS/R/as.bugs.array.R 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/R/as.bugs.array.R 2007-06-13 00:59:08 UTC (rev 30) @@ -1,10 +1,12 @@ -as.bugs.array <- function(sims.array, model.file=NULL, program=NULL, DIC=FALSE, n.iter=NULL, n.burnin=0, n.thin=1) +as.bugs.array <- function(sims.array, model.file=NULL, program=NULL, + DIC=FALSE, DICOutput=NULL, + n.iter=NULL, n.burnin=0, n.thin=1) { - # Jouni Kerman's function to convert a 3-way array to a Bugs object - # - # 'sims.array' is supposed to be a 3-way array with - # n.sims*n.chains*n.parameters simulations, and - # the 3rd component of dimnames(x) should have the parameter names. + ## Jouni Kerman's function to convert a 3-way array to a Bugs object + ## + ## 'sims.array' is supposed to be a 3-way array with + ## n.sims*n.chains*n.parameters simulations, and + ## the 3rd component of dimnames(x) should have the parameter names. d <- dim(sims.array) n.keep <- d[1] n.chains <- d[2] @@ -30,7 +32,7 @@ n.roots <- length(parameters.to.save) left.bracket.short <- as.vector(regexpr("[[]", parameters.to.save)) right.bracket.short <- as.vector(regexpr("[]]", parameters.to.save)) - root.short <- ifelse(left.bracket.short == -1, parameters.to.save, + root.short <- ifelse(left.bracket.short == -1, parameters.to.save, substring(parameters.to.save, 1, left.bracket.short - 1)) dimension.short <- rep(0, n.roots) indexes.short <- vector(n.roots, mode = "list") @@ -51,7 +53,7 @@ } length.short[j] <- prod(n.indexes.short[[j]]) if (length(long.short[[j]]) != length.short[j]){ - stop(paste("error in parameter", root.short[[j]], + stop(paste("error in parameter", root.short[[j]], "in parameters.to.save")) } indexes.short[[j]] <- as.list(numeric(length.short[j])) @@ -71,11 +73,7 @@ summary <- monitor(sims.array, n.chains, keep.all = TRUE) last.values <- as.list(numeric(n.chains)) for (i in 1:n.chains) { - if (is.R()) { - n.roots.0 <- if(!is.null(DIC)) n.roots - 1 else n.roots - } else { - n.roots.0 <- if(DIC) n.roots - 1 else n.roots - } + n.roots.0 <- if(DIC) n.roots - 1 else n.roots last.values[[i]] <- as.list(numeric(n.roots.0)) names(last.values[[i]]) <- root.short[1:n.roots.0] for (j in 1:n.roots.0) { @@ -90,7 +88,7 @@ } } sims <- sims[sample(n.sims), ] - sims.list <- summary.mean <- summary.sd <- summary.median <- vector(n.roots, + sims.list <- summary.mean <- summary.sd <- summary.median <- vector(n.roots, mode = "list") names(sims.list) <- names(summary.mean) <- names(summary.sd) <- names(summary.median) <- root.short for (j in 1:n.roots) { @@ -102,31 +100,28 @@ } else { temp2 <- dimension.short[j]:1 - sims.list[[j]] <- aperm(array(sims[, long.short[[j]]], + sims.list[[j]] <- aperm(array(sims[, long.short[[j]]], c(n.sims, rev(n.indexes.short[[j]]))), c(1, (dimension.short[j]+1):2)) - summary.mean[[j]] <- aperm(array(summary[long.short[[j]], + summary.mean[[j]] <- aperm(array(summary[long.short[[j]], "mean"], rev(n.indexes.short[[j]])), temp2) - summary.sd[[j]] <- aperm(array(summary[long.short[[j]], + summary.sd[[j]] <- aperm(array(summary[long.short[[j]], "sd"], rev(n.indexes.short[[j]])), temp2) - summary.median[[j]] <- aperm(array(summary[long.short[[j]], + summary.median[[j]] <- aperm(array(summary[long.short[[j]], "50%"], rev(n.indexes.short[[j]])), temp2) } } summary <- summary[rank.long, ] - if (is.R()) - is.DIC = !is.null(DIC) - else - is.DIC = DIC - - all <- list(n.chains = n.chains, n.iter = n.iter, n.burnin = n.burnin, + + all <- list(n.chains = n.chains, n.iter = n.iter, n.burnin = n.burnin, n.thin = n.thin, n.keep = n.keep, n.sims = n.sims, - sims.array = sims.array[,,rank.long,drop = FALSE], sims.list = sims.list, - sims.matrix = sims[, rank.long], summary = summary, mean = summary.mean, - sd = summary.sd, median = summary.median, root.short = root.short, - long.short = long.short, dimension.short = dimension.short, + sims.array = sims.array[,,rank.long,drop = FALSE], sims.list = sims.list, + sims.matrix = sims[, rank.long], summary = summary, mean = summary.mean, + sd = summary.sd, median = summary.median, root.short = root.short, + long.short = long.short, dimension.short = dimension.short, indexes.short = indexes.short, last.values = last.values, program=program, - model.file=model.file, is.DIC=is.DIC, DIC=DIC) - if(sum(DIC)) { + model.file=model.file) + + if(DIC && is.null(DICOutput)) { ## calculate DIC from deviance deviance <- all$sims.array[, , dim(sims.array)[3], drop = FALSE] dim(deviance) <- dim(deviance)[1:2] pD <- numeric(n.chains) @@ -135,8 +130,15 @@ pD[i] <- var(deviance[, i])/2 DIC[i] <- mean(deviance[, i]) + pD[i] } - all <- c(all, list(pD = mean(pD), DIC = mean(DIC))) + all <- c(all, list(isDIC=TRUE, DICbyR=TRUE, + pD=mean(pD), DIC=mean(DIC))) + } else if(DIC && !is.null(DICOutput)) { ## use DIC from BUGS + all <- c(all, list(isDIC=TRUE, DICbyR=FALSE, + pD=DICOutput[nrow(DICOutput),4], + DIC=DICOutput[nrow(DICOutput),3])) + } else { + all <- c(all, isDIC=FALSE) } class(all) <- "bugs" - return(all) + all } Modified: trunk/R2WinBUGS/R/bugs.R =================================================================== --- trunk/R2WinBUGS/R/bugs.R 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/R/bugs.R 2007-06-13 00:59:08 UTC (rev 30) @@ -5,18 +5,18 @@ bin=(n.iter - n.burnin) / n.thin, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, bugs.directory="c:/Program Files/WinBUGS14/", - program=c("winbugs", "openbugs", "WinBugs", "OpenBugs"), + program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), working.directory=NULL, clearWD=FALSE, useWINE=.Platform$OS.type != "windows", WINE=Sys.getenv("WINE"), newWINE=FALSE, WINEPATH=NULL) { program <- match.arg(program) - if(program %in% c("openbugs", "OpenBugs")) { + if(program %in% c("openbugs", "OpenBUGS", "OpenBugs")) { if(is.R()) { ## If OpenBUGS, we only call openbugs() and exit... return(openbugs(data, inits, parameters.to.save, model.file, - n.chains, n.iter, n.burnin, n.thin, DIC, bugs.directory, - working.directory, digits)) + n.chains, n.iter, n.burnin, n.thin, DIC=DIC, + bugs.directory, working.directory, digits)) } else { stop ("OpenBUGS is not yet available in S-PLUS") } @@ -72,7 +72,7 @@ return(file.path(getwd(), paste("coda", 1:n.chains, ".txt", sep=""))) sims <- c(bugs.sims(parameters.to.save, n.chains, n.iter, n.burnin, n.thin, DIC), - model.file=model.file, is.DIC=DIC, program=program) + model.file=model.file, program=program) if(clearWD) { file.remove(c("data.txt", "log.odc", "log.txt", "codaIndex.txt", paste("inits", 1:n.chains, ".txt", sep=""), Modified: trunk/R2WinBUGS/R/bugs.plot.summary.R =================================================================== --- trunk/R2WinBUGS/R/bugs.plot.summary.R 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/R/bugs.plot.summary.R 2007-06-13 00:59:08 UTC (rev 30) @@ -1,6 +1,6 @@ "bugs.plot.summary" <- function (sims, ...){ - DIC <- sims$is.DIC + isDIC <- sims$isDIC if (.Device=="windows" || (.Device=="null device" && options("device")=="windows")){ @@ -23,7 +23,7 @@ n.parameters <- nrow(summ) J0 <- unlist(lapply(sims$long.short, length)) - if (DIC) J0 <- J0[1:(length(J0)-1)] # don't display deviance summaries + if (isDIC) J0 <- J0[1:(length(J0)-1)] # don't display deviance summaries J <- J0 total <- ceiling(sum(J+.5)) while ((total > max.length) && max(J)>1){### vielleicht optimieren ... @@ -40,7 +40,7 @@ ystart <- NULL jj <- 1:J[1] n.roots <- length(sims$root.short) - if (DIC) n.roots <- n.roots-1 # don't display deviance summaries + if (isDIC) n.roots <- n.roots-1 # don't display deviance summaries ystart <- numeric(n.roots) for (k in 1:n.roots){ ystart[k] <- pos Modified: trunk/R2WinBUGS/R/bugs.sims.R =================================================================== --- trunk/R2WinBUGS/R/bugs.sims.R 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/R/bugs.sims.R 2007-06-13 00:59:08 UTC (rev 30) @@ -123,8 +123,9 @@ long.short=long.short, dimension.short=dimension.short, indexes.short=indexes.short, last.values=last.values) if(DIC) { + ## Read DIC from BUGS log LOG <- bugs.log("log.txt")$DIC - if(any(is.na(LOG))) { + if(any(is.na(LOG))) { ## Something went wrong --> Use Gelmans tweak deviance <- all$sims.array[, , dim(sims.array)[3], drop = FALSE] if(!is.R()) dimnames(deviance) <- NULL dim(deviance) <- dim(deviance)[1:2] @@ -134,12 +135,14 @@ pD[i] <- var(deviance[, i])/2 DIC[i] <- mean(deviance[, i]) + pD[i] } - all <- c(all, list(pD = mean(pD), DIC = mean(DIC), DICbyR = TRUE)) - } else { - DIC <- LOG[nrow(LOG),4] - pD <- LOG[nrow(LOG),3] - all <- c(all, list(pD = pD, DIC = DIC, DICbyR = FALSE)) + all <- c(all, list(isDIC=TRUE, DICbyR=TRUE, + 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])) } + } else { + all <- c(all, isDIC=FALSE) } all } Modified: trunk/R2WinBUGS/R/openbugs.R =================================================================== --- trunk/R2WinBUGS/R/openbugs.R 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/R/openbugs.R 2007-06-13 00:59:08 UTC (rev 30) @@ -1,20 +1,21 @@ -if (is.R()){ -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)/1000)), +if (is.R()) { + +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)/1000)), DIC = TRUE, bugs.directory = "c:/Program Files/OpenBUGS/", - working.directory=NULL, digits = 5) { - -# switching from bugs() to BRugsFit() notation - if(!require(BRugs)) + working.directory=NULL, digits = 5) +{ + 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(!is.null(DIC)) parameters.to.save <- c(parameters.to.save, "deviance") + if(DIC) parameters.to.save <- c(parameters.to.save, "deviance") parametersToSave <- parameters.to.save if(!is.null(working.directory)) { savedWD <- getwd() @@ -27,7 +28,7 @@ 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 + ## 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) @@ -41,24 +42,27 @@ BRugs::modelCompile(numChains) 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) + } else { + if(is.list(inits) || is.function(inits) || (is.character(inits) && + !any(file.exists(inits)))) { + inits <- BRugs::bugsInits(inits = inits, numChains = numChains, + digits = digits) } BRugs::modelInits(inits) BRugs::modelGenInits() } - BRugs::samplesSetThin(nThin) -# set the adaptive phases - adaptivelines <- scan(system.file("OpenBUGS", "Bugs", "Rsrc", "Registry.txt", package="BRugs"), what="character") + ## BRugs::samplesSetThin(nThin) + ## set the adaptive phases + adaptivelines <- scan(system.file("OpenBUGS", "Bugs", "Rsrc", + "Registry.txt", package="BRugs"), + what="character") factories <- sub(".adaptivePhase", "", - adaptivelines[grep("adaptivePhase",adaptivelines)]) - sapply(factories, BRugs::modelSetAP, max(0, nBurnin-1)) - + adaptivelines[grep("adaptivePhase",adaptivelines)]) + sapply(factories, BRugs::modelSetAP, max(0, nBurnin-1)) + BRugs::modelUpdate(nBurnin) - if(!is.null(DIC)) { + BRugs::samplesSetThin(nThin) + if(DIC) { BRugs::dicSet() on.exit(BRugs::dicClear(), add = TRUE) } @@ -69,21 +73,25 @@ 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(!is.null(DIC)) DIC <- BRugs::dicStats() - bugs.output <- as.bugs.array(samples.array, modelFile, program="OpenBUGS", - n.iter=n.iter, n.burnin=n.burnin, n.thin=n.thin, DIC=DIC) - return(bugs.output) + 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 +## 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" + ## 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))) - return(a[order(match(a.stem, b))]) + a[order(match(a.stem, b))] } } Modified: trunk/R2WinBUGS/R/print.bugs.R =================================================================== --- trunk/R2WinBUGS/R/print.bugs.R 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/R/print.bugs.R 2007-06-13 00:59:08 UTC (rev 30) @@ -12,22 +12,23 @@ if(x$n.thin > 1) cat(", n.thin =", x$n.thin) cat("\n n.sims =", x$n.sims, "iterations saved\n") print(round(x$summary, digits.summary), ...) + if(x$n.chains > 1) { cat("\nFor each parameter, n.eff is a crude measure of effective sample size,") cat("\nand Rhat is the potential scale reduction factor (at convergence, Rhat=1).\n") } - msgDICrule <- ifelse(x$DICbyR, - "(using the rule, pD = var(deviance)/2)\n", - "(using the rule, pD = Dbar-Dhat)\n") - msgDIC <- "DIC is an estimate of expected predictive error (lower deviance is better).\n" - if(length(x$DIC) == 1 && x$DIC) { - cat("\npD =", fround(x$pD, 1), "and DIC =", fround(x$DIC, 1), msgDICrule) - cat(msgDIC) + + if(x$isDIC) { + msgDICRule <- ifelse(x$DICbyR, + "(using the rule, pD = var(deviance)/2)", ## Gelman tweak + "(using the rule, pD = Dbar-Dhat)") ## BUGS + cat(paste("\nDIC info ", msgDICRule, "\n", sep="")) + if(length(x$DIC) == 1) { + cat("pD =", fround(x$pD, 1), "and DIC =", fround(x$DIC, 1)) + } else if(length(x$DIC)>1) { + print(round(x$DIC, 1)) + } + cat("\nDIC is an estimate of expected predictive error (lower deviance is better).\n") } - else if(length(x$DIC)>1) { - cat("\n") - print(round(x$DIC, 1)) - cat(msgDIC) - } invisible(x) } Modified: trunk/R2WinBUGS/man/as.bugs.array.Rd =================================================================== --- trunk/R2WinBUGS/man/as.bugs.array.Rd 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/man/as.bugs.array.Rd 2007-06-13 00:59:08 UTC (rev 30) @@ -1,38 +1,58 @@ \name{as.bugs.array} \alias{as.bugs.array} \title{Convert to bugs object} -\description{Function converting results from Markov chain simulations that are not from BUGS - to be displayed using \code{\link{plot.bugs}}. + +\description{Function converting results from Markov chain simulations, + that might not be from BUGS, to bugs object. Used mainly to display + results with \code{\link{plot.bugs}}. } + \usage{ -as.bugs.array(sims.array, model.file=NULL, program=NULL, - DIC=FALSE, n.iter=NULL, n.burnin=0, n.thin=1) +as.bugs.array(sims.array, model.file=NULL, program=NULL, + DIC=FALSE, DICOutput=NULL, n.iter=NULL, n.burnin=0, n.thin=1) } + \arguments{ \item{sims.array}{3-way array of simulation output, with dimensions n.keep, n.chains, and length of combined parameter vector.} \item{model.file}{file containing the model written in WinBUGS code} \item{program}{the program used} - \item{DIC}{logical; whether DIC is given} - \item{n.iter}{number of total iterations per chain used for generating \code{sims.array}} - \item{n.burnin}{length of burn in, i.e. number of iterations to discarded - at the beginning for generating \code{sims.array}} - \item{n.thin}{thinning rate, a positive integer, used for generating \code{sims.array}} + \item{DIC}{logical; whether DIC should be calculated, see also + argument \code{DICOutput} and details} + \item{DICOutput}{DIC value} + \item{n.iter}{number of total iterations per chain used for generating + \code{sims.array}} + \item{n.burnin}{length of burn in, i.e. number of iterations to + discarded at the beginning for generating \code{sims.array}} + \item{n.thin}{thinning rate, a positive integer, used for generating + \code{sims.array}} } + \details{ -This function takes a 3-way array of simulations and makes it into a \code{\link{bugs}} -object that can be conveniently displayed using \code{print} and -\code{plot} and accessed using \code{attach.bugs}. If the third -dimension of sims() has names, the resulting bugs object will respect -that naming convention. For example, if the parameter names are -\dQuote{alpha[1]}, \dQuote{alpha[2]}, ..., \dQuote{alpha[8]}, \dQuote{mu}, \dQuote{tau}, then -\code{as.bugs.array} will know that alpha is a vector of length 8, and mu and -tau are scalar parameters. These will all be plotted appropriately by -\code{plot} and attached appropriately by \code{attach.bugs}.} -\value{ - A \code{\link{bugs}} object is returned. + +This function takes a 3-way array of simulations and makes it into a +\code{\link{bugs}} object that can be conveniently displayed using +\code{print} and \code{plot} and accessed using \code{attach.bugs}. If +the third dimension of sims() has names, the resulting bugs object will +respect that naming convention. For example, if the parameter names are +\dQuote{alpha[1]}, \dQuote{alpha[2]}, ..., \dQuote{alpha[8]}, +\dQuote{mu}, \dQuote{tau}, then \code{as.bugs.array} will know that +alpha is a vector of length 8, and mu and tau are scalar parameters. +These will all be plotted appropriately by \code{plot} and attached +appropriately by \code{attach.bugs}. + +If \code{DIC=TRUE} then DIC can be either already passed to argument +\code{DICOutput} as it is done in \code{\link{openbugs}} or calculated +from deviance values in \code{sims.array}. + } -\author{Jouni Kerman, \email{ke...@st...} with modification by Andrew Gelman, \email{ge...@st...}, - packaged by Uwe Ligges, \email{li...@st...}.} + +\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 + Ligges, \email{li...@st...}.} + \seealso{\code{\link{bugs}}} \keyword{interface} +\keyword{manip} Modified: trunk/R2WinBUGS/man/attach.all.Rd =================================================================== --- trunk/R2WinBUGS/man/attach.all.Rd 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/man/attach.all.Rd 2007-06-13 00:59:08 UTC (rev 30) @@ -4,78 +4,95 @@ \alias{attach.bugs} \alias{detach.bugs} \title{Attach / detach elements of (bugs) objects to search path} -\description{The database is attached/detached to the search path. See \code{\link{attach}} for details.} + +\description{The database is attached/detached to the search path. See + \code{\link{attach}} for details.} + \usage{ attach.all(x, overwrite = NA, name = "attach.all") attach.bugs(x, overwrite = NA) detach.all(name = "attach.all") detach.bugs() } + \arguments{ - \item{x}{An object, which must be of class \code{bugs} for \code{attach.bugs}.} - \item{overwrite}{If \code{TRUE}, objects with identical names in the Workspace (.GlobalEnv) - that are masking objects in the database to be attached will be deleted. + \item{x}{An object, which must be of class \code{bugs} for + \code{attach.bugs}.} + \item{overwrite}{If \code{TRUE}, objects with identical names in the + Workspace (.GlobalEnv) that are masking objects in the database to + be attached will be deleted. If \code{NA} (the default) and an + interactive session is running, a dialog box asks the user whether + masking objects should be deleted. In non-interactive mode, + behaviour is identical to \code{overwrite=FALSE}, i.e. nothing will + be deleted.} + \item{name}{The name of the environment where \code{x} will be + attached / which will be detached.} +} - If \code{NA} (the default) and an interactive session is running, a dialog box asks the user - whether masking objects should be deleted. - In non-interactive mode, behaviour is identical to \code{overwrite=FALSE}, i.e. nothing will be deleted.} - \item{name}{The name of the environment where \code{x} will be attached / which will be detached.} -} \details{ - While \code{attach.all} attaches all elements of an object \code{x} to a database called \code{name}, - \code{attach.bugs} attaches all elements of \code{x$sims.list} to the database \code{bugs.sims} - itself making use of \code{attach.all}.\cr - \code{detach.all} and \code{detach.bugs} are removing the databases - mentioned above.\cr - \code{attach.all} also attaches \code{n.sims} (the number of - simulations saved from the MCMC runs) to the database.\cr\cr + While \code{attach.all} attaches all elements of an object \code{x} to + a database called \code{name}, \code{attach.bugs} attaches all + elements of \code{x$sims.list} to the database \code{bugs.sims} itself + making use of \code{attach.all}.\cr - Each scalar parameter in the model is attached as vectors of length - \code{n.sims}, each vector is attached as a 2-way array (with first - dimension equal to \code{n.sims}, each matrix is attached as a 3-way - array, and so forth.} + \code{detach.all} and \code{detach.bugs} are removing the databases + mentioned above.\cr \code{attach.all} also attaches \code{n.sims} (the + number of simulations saved from the MCMC runs) to the database.\cr\cr + + Each scalar parameter in the model is attached as vectors of length + \code{n.sims}, each vector is attached as a 2-way array (with first + dimension equal to \code{n.sims}), each matrix is attached as a 3-way + array, and so forth. +} + \note{ - Without detaching, do not use \code{attach.all} or \code{attach.bugs} on another (\code{bugs}) object, - because instead of the given name, an object called \code{name} is attached. - Therefore strange things may happen... + Without detaching, do not use \code{attach.all} or \code{attach.bugs} + on another (\code{bugs}) object, because instead of the given name, an + object called \code{name} is attached. Therefore strange things may + happen \ldots } + \value{ - \code{attach.all} and \code{attach.bugs} invisibly return the \code{\link{environment}}(s).\cr - \code{detach.all} and \code{detach.bugs} detach the \code{environment}(s) named \code{name} - created by \code{attach.all}. + \code{attach.all} and \code{attach.bugs} invisibly return the + \code{\link{environment}}(s).\cr + + \code{detach.all} and \code{detach.bugs} detach the + \code{environment}(s) named \code{name} created by \code{attach.all}. } + \seealso{\code{\link{bugs}}, \code{\link{attach}}, \code{\link{detach}}} + \examples{ # An example model file is given in: model.file <- file.path(.path.package("R2WinBUGS"), "model", "schools.txt") # Some example data (see ?schools for details): -data(schools) +data(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), + list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100), sigma.theta = runif(1, 0, 100)) } -parameters <- c("theta", "mu.theta", "sigma.theta") +parameters <- c("theta", "mu.theta", "sigma.theta") \dontrun{ ## 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 = 1000, +schools.sim <- bugs(data, inits, parameters, model.file, + n.chains = 3, n.iter = 1000, bugs.directory = "c:/Program Files/WinBUGS14/", working.directory = NULL) # Do some inferential summaries attach.bugs(schools.sim) -# posterior probability that the coaching program in school A +# posterior probability that the coaching program in school A # is better than in school C: print(mean(theta[,1] > theta[,3])) -# 50% posterior interval for the difference between school A's +# 50% posterior interval for the difference between school A's # and school C's program: -print(quantile(theta[,1] - theta[,3], c(.25, .75))) -plot(theta[,1], theta[,3]) +print(quantile(theta[,1] - theta[,3], c(.25, .75))) +plot(theta[,1], theta[,3]) detach.bugs() } } Modified: trunk/R2WinBUGS/man/bugs.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.Rd 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/man/bugs.Rd 2007-06-13 00:59:08 UTC (rev 30) @@ -1,9 +1,11 @@ \name{bugs} \alias{bugs} \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 WinBUGS script, calls the model, -and saves the simulations for easy access in R or S-PLUS.} + +\description{The \code{bugs} function takes data and starting values as + input. It automatically writes a WinBUGS 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), @@ -11,11 +13,12 @@ bin=(n.iter - n.burnin) / n.thin, debug=FALSE, DIC=TRUE, digits=5, codaPkg=FALSE, bugs.directory="c:/Program Files/WinBUGS14/", - program=c("winbugs", "openbugs", "WinBugs", "OpenBugs"), + program=c("WinBUGS", "OpenBUGS", "winbugs", "openbugs"), working.directory=NULL, clearWD=FALSE, useWINE=.Platform$OS.type != "windows", WINE=Sys.getenv("WINE"), newWINE=FALSE, WINEPATH=NULL) } + \arguments{ \item{data}{either a named list (names corresponding to variable names in the \code{model.file}) of the data for the WinBUGS model, @@ -32,7 +35,7 @@ parameters to save which should be monitored} \item{model.file}{file containing the model written in 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=="WinBUGS"}, 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.} @@ -62,12 +65,12 @@ \item{codaPkg}{logical; if \code{FALSE} (default) a \code{bugs} object is returned, if \code{TRUE} file names of WinBUGS output are returned for easy access by the \pkg{coda} package through function - \code{\link{read.bugs}} (not used if \code{program="openbugs"}).} + \code{\link{read.bugs}} (not used if \code{program="OpenBUGS"}).} \item{bugs.directory}{directory that contains the WinBUGS executable} \item{program}{the program to use, either - \code{winbugs}/\code{WinBugs} or \code{openbugs}/\code{OpenBugs}, + \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} + the CRAN package \pkg{BRugs}. The \code{openbugs}/\code{OpenBUGS} choice is not available in S-PLUS.} \item{working.directory}{sets working directory during execution of this function; WinBUGS' in- and output will be stored in this @@ -98,7 +101,7 @@ \item A WinBUGS window will pop up and R / S-PLUS will freeze up. The model will now run in WinBUGS. It might take awhile. You will see things happening in the Log window within WinBUGS. When - WinBugs is done, its window will close and R / S-PLUS will work + WinBUGS 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}. } @@ -171,8 +174,8 @@ packaged by Sibylle Sturtz, \email{st...@st...}, and Uwe Ligges.} -\seealso{\code{\link{print.bugs}}, \code{\link{plot.bugs}}, and the - \pkg{coda} package} +\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: @@ -214,5 +217,6 @@ plot(schools.sim) } } + \keyword{interface} \keyword{models} Modified: trunk/R2WinBUGS/man/bugs.data.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.data.Rd 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/man/bugs.data.Rd 2007-06-13 00:59:08 UTC (rev 30) @@ -1,19 +1,27 @@ \name{bugs.data} \alias{bugs.data} \title{Writing input for WinBUGS} -\description{Write file \file{data.txt} for WinBUGS to read.} + +\description{Write file \file{data.txt} for WinBUGS to read - for + internal use.} + \usage{ bugs.data(data, dir = getwd(), digits = 5) } \arguments{ - \item{data}{either a named list (names corresponding to variable names in the \code{model.file}) - of the data for the WinBUGS model, \emph{or} - a vector or list of the names of the data objects used by the model} + \item{data}{either a named list (names corresponding to variable names + in the \code{model.file}) of the data for the WinBUGS model, + \emph{or} a vector or list of the names of the data objects used by + the model} \item{dir}{the directory to write the file \file{data.txt} to} - \item{digits}{number of significant digits used for WinBUGS input, see \code{\link{formatC}}} + \item{digits}{number of significant digits used for WinBUGS input, see + \code{\link{formatC}}} } -\value{ - Does not return anything. -} -\seealso{\code{\link{bugs}}} + +\value{Nothing, but as a side effect, the data file \file{data.txt} is + written} + +\seealso{The main function to be called by the user is \code{\link{bugs}}.} +\keyword{internal} \keyword{file} +\keyword{IO} \ No newline at end of file Modified: trunk/R2WinBUGS/man/bugs.inits.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.inits.Rd 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/man/bugs.inits.Rd 2007-06-13 00:59:08 UTC (rev 30) @@ -1,20 +1,26 @@ \name{bugs.inits} \alias{bugs.inits} \title{Writing input for WinBUGS - intended for internal use only} -\description{Write files \file{inits1.txt}, \file{inits2.txt}, etc., in the working directory -for WinBUGS to read. For internal use only.} + +\description{Write files \file{inits1.txt}, \file{inits2.txt}, etc., in + the working directory for WinBUGS to read - for internal use.} + \usage{ bugs.inits(inits, n.chains, digits) } \arguments{ - \item{inits}{a list with \code{n.chains} elements; each element of the list is - itself a list of starting values for the WinBUGS model, \emph{or} - a function creating (possibly random) initial values} + \item{inits}{a list with \code{n.chains} elements; each element of the + list is itself a list of starting values for the WinBUGS model, + \emph{or} a function creating (possibly random) initial values} \item{n.chains}{number of Markov chains} - \item{digits}{number of significant digits used for WinBUGS input, see \code{\link{formatC}}} + \item{digits}{number of significant digits used for WinBUGS input, see + \code{\link{formatC}}} } -\value{ - Does not return anything. -} + +\value{Nothing, but as a side effect, the inits files \file{inits*.txt} + are written} + \seealso{The main function to be called by the user is \code{\link{bugs}}.} \keyword{internal} +\keyword{IO} +\keyword{file} Modified: trunk/R2WinBUGS/man/bugs.log.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.log.Rd 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/man/bugs.log.Rd 2007-06-13 00:59:08 UTC (rev 30) @@ -10,7 +10,7 @@ \item{file}{Location of the WinBUGS logfile} } \value{ - A list with components + A list with components: \item{stats}{A matrix containing summary statistics for each saved parameter. Comparable to the information in the element \code{summary} of a bugs object as returned by \code{\link{bugs}}.} @@ -24,3 +24,4 @@ } \seealso{The main function that generates the log file is \code{\link{bugs}}.} \keyword{IO} +\keyword{file} Modified: trunk/R2WinBUGS/man/bugs.plot.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.plot.Rd 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/man/bugs.plot.Rd 2007-06-13 00:59:08 UTC (rev 30) @@ -2,23 +2,29 @@ \alias{bugs.plot.summary} \alias{bugs.plot.inferences} \title{Plotting summary information - intended for internal use only} -\description{Plotting summary information - intended for internal use only} +\description{Plotting summary information - intended for internal use} \usage{ bugs.plot.summary(sims, ...) bugs.plot.inferences(sims, display.parallel, ...) } \arguments{ - \item{sims}{an object of class `bugs', see \code{\link{bugs}} for details} - \item{display.parallel}{display parallel intervals in both halves of the summary plots; - this is a convergence-monitoring tool and is not necessary once you have approximate convergence - (default is \code{FALSE})} + \item{sims}{an object of class `bugs', see \code{\link{bugs}} for + details} + \item{display.parallel}{display parallel intervals in both halves of + the summary plots; this is a convergence-monitoring tool and is not + necessary once you have approximate convergence (default is + \code{FALSE})} \item{...}{further arguments to be passed to low-level plot functions} } + \details{ -\code{bugs.plot.summary} (left hand side of plot) and \code{bugs.plot.inferences} (right hand side of plot). + \code{bugs.plot.summary} (left hand side of plot) and + \code{bugs.plot.inferences} (right hand side of plot). } -\value{ -Does not return anything, but prints and plots as side-effects. -} -\seealso{The main function to be called by the user is \code{plot}, see \code{\link{plot.bugs}} for details.} + +\value{Does not return anything, but prints and plots as side-effects.} + +\seealso{The main function to be called by the user is \code{plot}, see + \code{\link{plot.bugs}} for details.} + \keyword{internal} Modified: trunk/R2WinBUGS/man/bugs.run.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.run.Rd 2007-06-12 10:10:26 UTC (rev 29) +++ trunk/R2WinBUGS/man/bugs.run.Rd 2007-06-13 00:59:08 UTC (rev 30) @@ -1,27 +1,31 @@ \name{bugs.run} \alias{bugs.run} -\title{Calling WinBUGS - intended for internal use only} -\description{ -Updates the lengths of the adaptive phases in the WinBUGS registry (using \code{\link{bugs.update.settings}}), -calls WinBUGS and runs it with \file{script.txt}. Intended for internal use only} +\title{Calling WinBUGS} + +\description{Updates the lengths of the adaptive phases in the WinBUGS + registry (using \code{\link{bugs.update.settings}}), calls WinBUGS and + runs it with \file{script.txt} - intended for internal use} + \usage{ -bugs.run(n.burnin, bugs.directory, WINE = "", - useWINE = .Platform$OS.type != "windows", +bugs.run(n.burnin, bugs.directory, WINE = "", + useWINE = .Platform$OS.type != "windows", newWINE = TRUE, WINEPATH = NULL) } \arguments{ \item{n.burnin}{length of bu... [truncated message content] |
From: <gg...@us...> - 2007-06-12 10:10:25
|
Revision: 29 http://svn.sourceforge.net/bugs-r/?rev=29&view=rev Author: ggorjan Date: 2007-06-12 03:10:26 -0700 (Tue, 12 Jun 2007) Log Message: ----------- some code formatting and removal of return() Modified Paths: -------------- trunk/R2WinBUGS/R/bugs.sims.R Modified: trunk/R2WinBUGS/R/bugs.sims.R =================================================================== --- trunk/R2WinBUGS/R/bugs.sims.R 2007-06-12 10:09:18 UTC (rev 28) +++ trunk/R2WinBUGS/R/bugs.sims.R 2007-06-12 10:10:26 UTC (rev 29) @@ -1,9 +1,11 @@ "bugs.sims" <- -function (parameters.to.save, n.chains, n.iter, n.burnin, n.thin, DIC = TRUE){ -## Read the simulations from Bugs into R, format them, and monitor convergence +function (parameters.to.save, n.chains, n.iter, n.burnin, n.thin, DIC=TRUE) +{ + ## Read the simulations from Bugs into R, format them, and monitor convergence sims.files <- paste ("coda", 1:n.chains, ".txt", sep="") - index <- read.table("codaIndex.txt", header = FALSE, sep = "\t") # read in the names of the parameters and the indices of their samples - ## in Splus, read.table interprets the first row of the file as row names, + ## read in the names of the parameters and the indices of their samples + index <- read.table("codaIndex.txt", header = FALSE, sep = "\t") + ## 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]) @@ -35,19 +37,19 @@ long.short <- vector(n.roots, mode = "list") length.short <- numeric(n.roots) ##SS, UL##: Let's optimize the following loops ... - for (j in 1:n.roots){ + for (j in 1:n.roots) { long.short[[j]] <- (1:n.parameters)[root.long==root.short[j]] length.short[j] <- length(long.short[[j]]) if (length.short[j]==0) - stop (paste ("parameter", root.short[[j]], "is not in the model")) - else if (length.short[j]>1){ - dimension.short[j] <- length(indexes.long[[long.short[[j]][1]]]) + stop(paste ("parameter", root.short[[j]], "is not in the model")) + else if (length.short[j]>1) { + dimension.short[j] <- length(indexes.long[[long.short[[j]][1]]]) n.indexes.short[[j]] <- numeric(dimension.short[j]) for (k in 1:dimension.short[j]) n.indexes.short[[j]][k] <- length ( unique (unlist (lapply (indexes.long[long.short[[j]]], .subset, k)))) length.short[j] <- prod(n.indexes.short[[j]]) - if (length(long.short[[j]])!=length.short[j]) stop (paste - ("error in parameter", root.short[[j]], "in parameters.to.save")) + if (length(long.short[[j]])!=length.short[j]) + stop(paste("error in parameter", root.short[[j]], "in parameters.to.save")) indexes.short[[j]] <- as.list(numeric(length.short[j])) for (k in 1:length.short[j]) indexes.short[[j]][[k]] <- indexes.long[[long.short[[j]][k]]] @@ -58,9 +60,11 @@ 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))] + 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 } @@ -118,12 +122,11 @@ sd=summary.sd, median=summary.median, root.short=root.short, long.short=long.short, dimension.short=dimension.short, indexes.short=indexes.short, last.values=last.values) - if(DIC){ + if(DIC) { LOG <- bugs.log("log.txt")$DIC - if(any(is.na(LOG))){ + if(any(is.na(LOG))) { deviance <- all$sims.array[, , dim(sims.array)[3], drop = FALSE] - if(!is.R()) - dimnames(deviance) <- NULL + if(!is.R()) dimnames(deviance) <- NULL dim(deviance) <- dim(deviance)[1:2] pD <- numeric(n.chains) DIC <- numeric(n.chains) @@ -138,11 +141,7 @@ all <- c(all, list(pD = pD, DIC = DIC, DICbyR = FALSE)) } } - return(all) + all } -if (!is.R()){ - .subset <- function(x, index){ - return (x[index]) - } -} +if(!is.R()) .subset <- function(x, index) x[index] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-06-12 10:09:17
|
Revision: 28 http://svn.sourceforge.net/bugs-r/?rev=28&view=rev Author: ggorjan Date: 2007-06-12 03:09:18 -0700 (Tue, 12 Jun 2007) Log Message: ----------- version bump, merged and reversed ChangeLog files, note about supported BUGS versions Modified Paths: -------------- trunk/R2WinBUGS/Changes trunk/R2WinBUGS/DESCRIPTION trunk/R2WinBUGS/man/bugs.Rd Removed Paths: ------------- trunk/R2WinBUGS/Changes0 Modified: trunk/R2WinBUGS/Changes =================================================================== --- trunk/R2WinBUGS/Changes 2007-06-12 09:58:57 UTC (rev 27) +++ trunk/R2WinBUGS/Changes 2007-06-12 10:09:18 UTC (rev 28) @@ -1,51 +1,37 @@ Changes to R2WinBUGS: ===================== -During the process of packaging R2WinBUGS_0.1 - R2WinBUGS_0.2-1, -quite a lot of changes had been made. Those changes are not -documented anywhere ... +Update 2.1-5 (12 June 2007): +- proper indexing of CODA files also in R version +- fixed useWINE documentation in bugs help page +- note on supported BUGS versions +- as.bugs.array now returns info on used rule for pD i.e. var(deviance)/2 +- some internal fixes related to is.null(DIC) +- merging and reversing ChangeLog files +Update 2.1-4 (20 May 2007): +- Depending on coda now (Namespace issues) +- some more fixes for codetools checks +- Vignette has been updated -Update 0.2-2 (28 Apr 2004): -- schools data: original (see references) instead of the rounded data +Update 2.1-3 (13 May 2007): +- Ported to S-PLUS by Insightful Corp. +- some fixes for codetools checks -Update 0.2-3 (10 Sept 2004): -- bugs.data.inits split to bugs.inits and bugs.data, the latter exported - from the Namespace. - Now we can use already written data files in bugs(). +Update 2.0-4 (01 November 2006): +- print.bugs / plot.bugs documentation fixes +- write.model() fix -Update 0.2-4 (05 Oct 2004): -- bugs.script() did not work for large n.iter values in update step - (no scientific notation allowed) +Update 2.0-3 (06 October 2006): +- \\. -> [.] in regular expressions -Update 0.2-5 (20 Oct 2004): -- bugs() and bugs.script() have a new argument bin that allows to specify - a number of iterations. After each "bin" iterations the coda files are saved. +Update 2.0-2 (26 July 2006): +- changes for DIC, making use of BUGS internal calculations +- some doc fixes -Update 0.2-6 (18 May 2005): -- bugs() changes in order to return a file names of coda output files -- new read.bugs() returns a coda mcmc.list object, if codaPkg=TRUE. +Update 2.0-1 (26 May 2006): +- some wine patches for 2.2-0 by Gregor Gorjanc -Update 0.2-8 (30 May 2005): -- bugs passed DIC to bugs.script in order to be able to disable it - -Update 0.2-9 (26 July 2005): -- bugs has new argument clearWD - -Update 1.0-0 (05 Aug 2005): -- attach.all(), detach.all(), attach.bugs() and detach.bugs() added/changed - more or less according to Andrew Gelman's current bugs.R - -Update 1.0-1 (14 Nov 2005): -- make inits=NULL work (again ?) - -Update 1.1-0 (14 Dec 2005): -- Contribution by Ben Bolker and Yun Yan's rbugs package: - make R2WinBUGS work under WINE - -Update 1.1-1 (17 Feb 2006): -- WINE tweaks (mainly by Gregor Gorjanc) - Update 2.0-0 (08 May 2006): - bugs() doc fix/updates on scrambling - bugs.run() has new arg useWINE (by Gregor Gorjanc) @@ -56,25 +42,188 @@ Jouni Kerman and Andrew Gelman - new function write.model() based on ideas from Jouni Kerman -Update 2.0-1 (26 May 2006): -- some wine patches for 2.2-0 by Gregor Gorjanc +Update 1.1-1 (17 Feb 2006): +- WINE tweaks (mainly by Gregor Gorjanc) -Update 2.0-2 (26 July 2006): -- changes for DIC, making use of BUGS internal calculations -- some doc fixes +Update 1.1-0 (14 Dec 2005): +- Contribution by Ben Bolker and Yun Yan's rbugs package: + make R2WinBUGS work under WINE -Update 2.0-3 (06 October 2006): -- \\. -> [.] in regular expressions +Update 1.0-1 (14 Nov 2005): +- make inits=NULL work (again ?) -Update 2.0-4 (01 November 2006): -- print.bugs / plot.bugs documentation fixes -- write.model() fix +Update 1.0-0 (05 Aug 2005): +- attach.all(), detach.all(), attach.bugs() and detach.bugs() added/changed + more or less according to Andrew Gelman's current bugs.R -Update 2.1-3 (13 May 2007): -- Ported to S-PLUS by Insightful Corp. -- some fixes for codetools checks +Update 0.2-9 (26 July 2005): +- bugs has new argument clearWD -Update 2.1-4 (20 May 2007): -- Depending on coda now (Namespace issues) -- some more fixes for codetools checks -- Vignette has been updated +Update 0.2-8 (30 May 2005): +- bugs passed DIC to bugs.script in order to be able to disable it + +Update 0.2-6 (18 May 2005): +- bugs() changes in order to return a file names of coda output files +- new read.bugs() returns a coda mcmc.list object, if codaPkg=TRUE. + +Update 0.2-5 (20 Oct 2004): +- bugs() and bugs.script() have a new argument bin that allows to specify + a number of iterations. After each "bin" iterations the coda files are saved. + +Update 0.2-4 (05 Oct 2004): +- bugs.script() did not work for large n.iter values in update step + (no scientific notation allowed) + +Update 0.2-3 (10 Sept 2004): +- bugs.data.inits split to bugs.inits and bugs.data, the latter exported + from the Namespace. + Now we can use already written data files in bugs(). + +Update 0.2-2 (28 Apr 2004): +- schools data: original (see references) instead of the rounded data + +During the process of packaging R2WinBUGS_0.1 - R2WinBUGS_0.2-1, +quite a lot of changes had been made. Those changes are not +documented anywhere ... + +During the process of packaging R2WinBUGS_0.1, quite a lot of changes had +been made. Those changes are not documented anywhere ... + +Changes prior to R2WinBUGS_0.1: +=============================== + +Update 30 Oct 2003: + 1. Minor change to a return() statement to be compatible with R 1.8 + 2. Just a warning (from Ben Goodrich): if you are running Bugs.R inside + a loop, you have to be careful with the data() and the inits() + functions since they will not necessarily recognize locally-defined + variables. One workaround is to define the variables used in data() + and inits() using global assignments (<<-), but this can sometimes + make the program run slower. +Update 29 Aug 2003: + 1. Fixed "bugs.data.inits" function so you can use data that have the + same names as R functions. + 2. Changed T and F to TRUE and FALSE everywhere in case the variables + T and F are used as data in the main program + 3. Caution: if you are entering the data as a list of variable names + (see 10 Apr 2003 update, item 1), the data to be input into must + be global variables. This can be relevant if you are running bugs() + inside an R function. + 4. Caution: bugs() has difficulty processing ragged arrays. It is + better to save a whole matrix (e.g., "theta") rather than parts + (e.g., "theta[1:10,1]", "theta[1:5,2]"). If you want to save + part of a vector, you should do it as "theta[1:2]", not "theta[1]", + "theta[2]". +Update 30 Apr 2003: added time monitoring +Update 29 Apr 2003: + 1. The "attach.all" function (no longer called "attach2") overwrites + so that all components of a list or data frame get attached. + 2. Program now looks in the directory /winbug~1/ rather than /winbug~2/ + 3. Graphics parameters for margins are returned to their original state + at the end of the program. + 4. Added "digits.summary" option to the numerical display. + 5. Added "last.values" output: a list that can be input as "inits" + if you want to run the simulations longer. +Update 13 Apr 2003: fixed new bug in round.bugs(). Now all numbers are + saved in scientific notation. +Update 10 Apr 2003: + 1. It is now possible to enter the data as a list of variable names. + For example, before you had to enter data as, + data <- list (n=8, y=c(28,8,-3,7,-1,1,18,12)) + or + n <- 8 + y <- c(28,8,-3,7,-1,1,18,12) + data <- list (n=n, y=y) + Now you can enter the data as, + n <- 8 + y <- c(28,8,-3,7,-1,1,18,12) + data <- list ("n", "y") + The bugs() function will figure out which method you are using (based + on whether "data" is a list of numbers or a vector of character + strings). + This doesn't look like much, but it's convenient when you're entering + lots of data! + 2. It is now possible to enter the initial values as a function, + so as to automatically a random list of inits for each of the chains. + For example, in the 8-schools example below, we can do: + inits <- function() + list (theta=rnorm(J,0,1), mu.theta=rnorm(1,0,100), sigma.theta=runif(1,0,100)) + + to set up the inits as a function (rather than setting up n.chains + sets of specific initial values). Then, the function call, + schools.sim <- bugs (data, inits, parameters, "schools.txt", n.chains=3, n.iter=1000) + automatically sets up 3 sets of initial values (each a list of + theta, mu.theta, sigma.theta). + 3. Bug in the initial rounding (the function round.bugs()) has been fixed. + Thanks for Mark Clements for finding the bug and fixing it! + Also, we have set the default rounding to 5 digits instead of 2. +Update 01 Apr 2003: use layout() rather than split.screen() for graphical + display +Update 18 Mar 2003: + 1. Get the Bugs configuration information from the original file + (Registry_default.odc) rather than overwriting each time. (Fixes a + bug that occurred when R was interrupted in the middle of a Bugs run.) + 2. Display different colored dots in the right panel of the graphical + display, to show the medians from each chain. +Update 13 Mar 2003: fix minor bug in monitor() +Update 10 Mar 2003: fix bug in pD and DIC calculations +Update 7 Mar 2003: + 1. Fix display.parallel=T option by adding min.width so that very + intervals are still visible. + 2. Compute pD separately for each sequence (which gives much more + reasonable estimates before convergence). +Update 8 Feb 2003: minor fixes in graphical display +Update 6 Feb 2003: + 1. Approximate "effective sample size" n.eff given for each parameter. + 2. More explanatory material displayed. + 3. Use bringToTop() to automatically bring up the graphics window. +Update 4 Feb 2003: + 1. Automatically compute the deviance, DIC, and pD. Bugs will not + always compute DIC and pD, so we do so using the definition, + DIC = E(deviance) + pD, using var(deviance)/2 as an estimate of pD. + (This is derived from the chi^2 distribution. We can't use the + Spiegelhalter et al. definition of DIC because we don't have access + to the deviance function.) + 2. Set default for n.thin so that, after thinning, the total number + saved iterations, n.sims, is approximately 1000. +Update 14 Jan 2003 to run with the new WinBugs1.4. You may see an error + message and need to fix the dos.location assignment in bugs(). +Update 6 Jan 2003: + 1. Fix of bug that occurred with uppercase and lowercase variable names + 2. Set default for n.thin so that no more than about 500 iterations + will be saved from each sequence + 3. New option "display.parallel" added to show 80% inferences from + parallel sequences on the right panel of the graphical display. This + can be useful to understand what is going on when there are + convergence problems. +Update 26 Dec 2002: fix of minwidth in bugs.plot.summary +Update 11 Dec 2002: + 1. Automatic fixing of adaptive phases. Now you no longer need to run + for thousands of iterations when slice or Metropolis sampling is used. + 2. Various minor fixes +Update 10 Dec 2002: + 1. Cool graphical display of convergence and inferences! + 2. New "attach2" function that overwrites so that all components of + the list are attached +Update 29 Nov 2002: + 1. Fix of bug in 24 Nov update. + 2. Fix of bug in 16 Nov update. + 3. Length of chains is now pecified in terms of "n.iter" rather than + "n.keep". +Update 24 Nov 2002: improved treatment of "parameters.to.save". For + example, you can now use "alpha" to indicate an entire array of parameters, + whereas before you had to save "alpha[]" or "alpha[,]" or whatever. +Update 16 Nov 2002: mean, sd, median added to outputs +Update 4 Nov 2002: more error-flagging added +Update 26 Oct 2002: + 1. Parameters saved in order of the "parameters.to.save" vector + (not alphabetical order). + 2. Output saved in both matrix and list form. + 3. With the attach.sims=T setting (which is the default), the simulations + for all the saved parameters are saved as R objects. This is + convenient for later use of the simulations. +Updates to 16 Oct 2002: more error-flagging added, mean/sd added to summary, + fixing scientific notation so Bugs can always read data and inits +Update 21 Sept 2002: "quit=F" option changed to "debug=T" +First version written 18 Sept 2002 by Andrew Gelman, + adapted from the EmBedBugs package by Kenneth Rice Deleted: trunk/R2WinBUGS/Changes0 =================================================================== --- trunk/R2WinBUGS/Changes0 2007-06-12 09:58:57 UTC (rev 27) +++ trunk/R2WinBUGS/Changes0 2007-06-12 10:09:18 UTC (rev 28) @@ -1,142 +0,0 @@ -During the process of packaging R2WinBUGS_0.1, quite a lot of changes had -been made. Those changes are not documented anywhere ... - - -Changes prior to R2WinBUGS_0.1: -=============================== - -Update 30 Oct 2003: - 1. Minor change to a return() statement to be compatible with R 1.8 - 2. Just a warning (from Ben Goodrich): if you are running Bugs.R inside - a loop, you have to be careful with the data() and the inits() - functions since they will not necessarily recognize locally-defined - variables. One workaround is to define the variables used in data() - and inits() using global assignments (<<-), but this can sometimes - make the program run slower. -Update 29 Aug 2003: - 1. Fixed "bugs.data.inits" function so you can use data that have the - same names as R functions. - 2. Changed T and F to TRUE and FALSE everywhere in case the variables - T and F are used as data in the main program - 3. Caution: if you are entering the data as a list of variable names - (see 10 Apr 2003 update, item 1), the data to be input into must - be global variables. This can be relevant if you are running bugs() - inside an R function. - 4. Caution: bugs() has difficulty processing ragged arrays. It is - better to save a whole matrix (e.g., "theta") rather than parts - (e.g., "theta[1:10,1]", "theta[1:5,2]"). If you want to save - part of a vector, you should do it as "theta[1:2]", not "theta[1]", - "theta[2]". -Update 30 Apr 2003: added time monitoring -Update 29 Apr 2003: - 1. The "attach.all" function (no longer called "attach2") overwrites - so that all components of a list or data frame get attached. - 2. Program now looks in the directory /winbug~1/ rather than /winbug~2/ - 3. Graphics parameters for margins are returned to their original state - at the end of the program. - 4. Added "digits.summary" option to the numerical display. - 5. Added "last.values" output: a list that can be input as "inits" - if you want to run the simulations longer. -Update 13 Apr 2003: fixed new bug in round.bugs(). Now all numbers are - saved in scientific notation. -Update 10 Apr 2003: - 1. It is now possible to enter the data as a list of variable names. - For example, before you had to enter data as, - data <- list (n=8, y=c(28,8,-3,7,-1,1,18,12)) - or - n <- 8 - y <- c(28,8,-3,7,-1,1,18,12) - data <- list (n=n, y=y) - Now you can enter the data as, - n <- 8 - y <- c(28,8,-3,7,-1,1,18,12) - data <- list ("n", "y") - The bugs() function will figure out which method you are using (based - on whether "data" is a list of numbers or a vector of character - strings). - This doesn't look like much, but it's convenient when you're entering - lots of data! - 2. It is now possible to enter the initial values as a function, - so as to automatically a random list of inits for each of the chains. - For example, in the 8-schools example below, we can do: - inits <- function() - list (theta=rnorm(J,0,1), mu.theta=rnorm(1,0,100), sigma.theta=runif(1,0,100)) - - to set up the inits as a function (rather than setting up n.chains - sets of specific initial values). Then, the function call, - schools.sim <- bugs (data, inits, parameters, "schools.txt", n.chains=3, n.iter=1000) - automatically sets up 3 sets of initial values (each a list of - theta, mu.theta, sigma.theta). - 3. Bug in the initial rounding (the function round.bugs()) has been fixed. - Thanks for Mark Clements for finding the bug and fixing it! - Also, we have set the default rounding to 5 digits instead of 2. -Update 01 Apr 2003: use layout() rather than split.screen() for graphical - display -Update 18 Mar 2003: - 1. Get the Bugs configuration information from the original file - (Registry_default.odc) rather than overwriting each time. (Fixes a - bug that occurred when R was interrupted in the middle of a Bugs run.) - 2. Display different colored dots in the right panel of the graphical - display, to show the medians from each chain. -Update 13 Mar 2003: fix minor bug in monitor() -Update 10 Mar 2003: fix bug in pD and DIC calculations -Update 7 Mar 2003: - 1. Fix display.parallel=T option by adding min.width so that very - intervals are still visible. - 2. Compute pD separately for each sequence (which gives much more - reasonable estimates before convergence). -Update 8 Feb 2003: minor fixes in graphical display -Update 6 Feb 2003: - 1. Approximate "effective sample size" n.eff given for each parameter. - 2. More explanatory material displayed. - 3. Use bringToTop() to automatically bring up the graphics window. -Update 4 Feb 2003: - 1. Automatically compute the deviance, DIC, and pD. Bugs will not - always compute DIC and pD, so we do so using the definition, - DIC = E(deviance) + pD, using var(deviance)/2 as an estimate of pD. - (This is derived from the chi^2 distribution. We can't use the - Spiegelhalter et al. definition of DIC because we don't have access - to the deviance function.) - 2. Set default for n.thin so that, after thinning, the total number - saved iterations, n.sims, is approximately 1000. -Update 14 Jan 2003 to run with the new WinBugs1.4. You may see an error - message and need to fix the dos.location assignment in bugs(). -Update 6 Jan 2003: - 1. Fix of bug that occurred with uppercase and lowercase variable names - 2. Set default for n.thin so that no more than about 500 iterations - will be saved from each sequence - 3. New option "display.parallel" added to show 80% inferences from - parallel sequences on the right panel of the graphical display. This - can be useful to understand what is going on when there are - convergence problems. -Update 26 Dec 2002: fix of minwidth in bugs.plot.summary -Update 11 Dec 2002: - 1. Automatic fixing of adaptive phases. Now you no longer need to run - for thousands of iterations when slice or Metropolis sampling is used. - 2. Various minor fixes -Update 10 Dec 2002: - 1. Cool graphical display of convergence and inferences! - 2. New "attach2" function that overwrites so that all components of - the list are attached -Update 29 Nov 2002: - 1. Fix of bug in 24 Nov update. - 2. Fix of bug in 16 Nov update. - 3. Length of chains is now pecified in terms of "n.iter" rather than - "n.keep". -Update 24 Nov 2002: improved treatment of "parameters.to.save". For - example, you can now use "alpha" to indicate an entire array of parameters, - whereas before you had to save "alpha[]" or "alpha[,]" or whatever. -Update 16 Nov 2002: mean, sd, median added to outputs -Update 4 Nov 2002: more error-flagging added -Update 26 Oct 2002: - 1. Parameters saved in order of the "parameters.to.save" vector - (not alphabetical order). - 2. Output saved in both matrix and list form. - 3. With the attach.sims=T setting (which is the default), the simulations - for all the saved parameters are saved as R objects. This is - convenient for later use of the simulations. -Updates to 16 Oct 2002: more error-flagging added, mean/sd added to summary, - fixing scientific notation so Bugs can always read data and inits -Update 21 Sept 2002: "quit=F" option changed to "debug=T" -First version written 18 Sept 2002 by Andrew Gelman, - adapted from the EmBedBugs package by Kenneth Rice Modified: trunk/R2WinBUGS/DESCRIPTION =================================================================== --- trunk/R2WinBUGS/DESCRIPTION 2007-06-12 09:58:57 UTC (rev 27) +++ trunk/R2WinBUGS/DESCRIPTION 2007-06-12 10:09:18 UTC (rev 28) @@ -1,7 +1,7 @@ Package: R2WinBUGS Title: Running WinBUGS and OpenBUGS from R / S-PLUS Date: 2007-05-20 -Version: 2.1-4 +Version: 2.1-5 Author: originally written by Andrew Gelman <ge...@st...>; changes and packaged by Sibylle Sturtz <st...@st...> and Uwe Ligges <li...@st...>. Modified: trunk/R2WinBUGS/man/bugs.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.Rd 2007-06-12 09:58:57 UTC (rev 27) +++ trunk/R2WinBUGS/man/bugs.Rd 2007-06-12 10:09:18 UTC (rev 28) @@ -102,6 +102,12 @@ again. \item If an error message appears, re-run with \code{debug=TRUE}. } + + BUGS version support: + \itemize{ + \item WinBUGS 1.4* (this is the only version that works under Linux) + \item OpenBUGS 2.* (via argument \code{program="OpenBUGS"}) + } } \value{ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-06-12 09:58:55
|
Revision: 27 http://svn.sourceforge.net/bugs-r/?rev=27&view=rev Author: ggorjan Date: 2007-06-12 02:58:57 -0700 (Tue, 12 Jun 2007) Log Message: ----------- note on write permission and file location Modified Paths: -------------- trunk/R2WinBUGS/man/bugs.update.settings.Rd Modified: trunk/R2WinBUGS/man/bugs.update.settings.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.update.settings.Rd 2007-06-12 09:58:15 UTC (rev 26) +++ trunk/R2WinBUGS/man/bugs.update.settings.Rd 2007-06-12 09:58:57 UTC (rev 27) @@ -10,15 +10,20 @@ \item{n.burnin}{length of burn in} \item{bugs.directory}{directory that contains the WinBUGS executable} } + \details{ -Alter the adaptive phases in the WinBUGS updaters (in the \file{Registry.odc} file) -so that all adaptive updating is done during the burnin stage. Otherwise -WinBUGS will not report results if the burnin is less than a minimum value -such as 500 or 4000 (depending on the model). + +Alter the adaptive phases in the WinBUGS updaters (in the +\file{BUGS/System/Rsrc/Registry.odc} file, where BUGS is map of +installed WinBUGS) so that all adaptive updating is done during the +burnin stage. Otherwise WinBUGS will not report results if the burnin is +less than a minimum value such as 500 or 4000 (depending on the +model). Write permission on above mentioned file is needed for this! + } + \value{ Does not return anything. } \seealso{The main function to be called by the user is \code{\link{bugs}}.} -\keyword{internal} - +\keyword{internal} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-06-12 09:58:15
|
Revision: 26 http://svn.sourceforge.net/bugs-r/?rev=26&view=rev Author: ggorjan Date: 2007-06-12 02:58:15 -0700 (Tue, 12 Jun 2007) Log Message: ----------- bugs.Rd - fixed useWINE documentation - some formatting bugs.R - fixed use of is.null(DIC) - some formatting Modified Paths: -------------- trunk/R2WinBUGS/R/bugs.R trunk/R2WinBUGS/man/bugs.Rd Modified: trunk/R2WinBUGS/R/bugs.R =================================================================== --- trunk/R2WinBUGS/R/bugs.R 2007-06-12 09:57:21 UTC (rev 25) +++ trunk/R2WinBUGS/R/bugs.R 2007-06-12 09:58:15 UTC (rev 26) @@ -1,81 +1,83 @@ "bugs" <- -function(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) / 1000)), - bin = (n.iter - n.burnin) / n.thin, - 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 = Sys.getenv("WINE"), - newWINE = FALSE, WINEPATH = NULL){ - +function(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) / 1000)), + bin=(n.iter - n.burnin) / n.thin, + 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=Sys.getenv("WINE"), + newWINE=FALSE, WINEPATH=NULL) +{ program <- match.arg(program) - if (program %in% c("openbugs", "OpenBugs")) - if (is.R()){ - ## If OpenBUGS, we only call openbugs() and exit... - return(openbugs(data, inits, parameters.to.save, model.file, - n.chains, n.iter, n.burnin, n.thin, DIC, bugs.directory, - working.directory, digits)) + if(program %in% c("openbugs", "OpenBugs")) { + if(is.R()) { + ## If OpenBUGS, we only call openbugs() and exit... + return(openbugs(data, inits, parameters.to.save, model.file, + n.chains, n.iter, n.burnin, n.thin, DIC, bugs.directory, + working.directory, digits)) } else { - stop ("OpenBUGS is not yet available in S-PLUS") + stop ("OpenBUGS is not yet available in S-PLUS") } + } ## Checking number of inits, which is NOT save here: if(!missing(inits) && !is.function(inits) && !is.null(inits) && (length(inits) != n.chains)) stop("Number of initialized chains (length(inits)) != n.chains") - if(useWINE) { - if (!is.R()) - stop ("Non-Windows platforms not yet supported in R2WinBUGS for S-PLUS") + if(useWINE) { + if(!is.R()) + stop ("Non-Windows platforms not yet supported in R2WinBUGS for S-PLUS") ## attempt to find wine and winepath - if (!nchar(WINE)) { - WINE <- system("locate wine | grep bin/wine$", intern = TRUE) - WINE <- WINE[length(WINE)] + if(!nchar(WINE)) { + WINE <- system("locate wine | grep bin/wine$", intern=TRUE) + WINE <- WINE[length(WINE)] } - if (!length(WINE)) stop("couldn't locate WINE binary") - if (!nchar(WINEPATH)) { - WINEPATH <- system("locate winepath | grep bin/winepath$", intern = TRUE) - WINEPATH <- WINEPATH[length(WINEPATH)] + if(!length(WINE)) stop("couldn't locate WINE binary") + if(!nchar(WINEPATH)) { + WINEPATH <- system("locate winepath | grep bin/winepath$", intern=TRUE) + WINEPATH <- WINEPATH[length(WINEPATH)] } - if (!length(WINEPATH)) stop("couldn't locate WINEPATH binary") - } - if(!is.null(working.directory)){ - savedWD <- getwd() - setwd(working.directory) - on.exit(setwd(savedWD)) + if(!length(WINEPATH)) stop("couldn't locate WINEPATH binary") } - if(!file.exists(model.file)) stop(paste(model.file, "does not exist.")) - if(file.info(model.file)$isdir) stop(paste(model.file, "is a directory, but a file is required.")) - if(!(length(data) == 1 && is.vector(data) && is.character(data) && data == "data.txt")){ - bugs.data(data, dir = getwd(), digits) + if(!is.null(working.directory)) { + savedWD <- getwd() + setwd(working.directory) + on.exit(setwd(savedWD)) + } + if(!file.exists(model.file)) + stop(paste(model.file, "does not exist.")) + if(file.info(model.file)$isdir) + stop(paste(model.file, "is a directory, but a file is required.")) + if(!(length(data) == 1 && is.vector(data) && is.character(data) && data == "data.txt")) { + bugs.data(data, dir=getwd(), digits) } else if(!file.exists(data)) stop("File data.txt does not exist.") bugs.inits(inits, n.chains, digits) if(DIC) parameters.to.save <- c(parameters.to.save, "deviance") ## Model files with extension ".bug" need to be renamed to ".txt" - if(length(grep("[.]bug$", model.file))){ + if(length(grep("[.]bug$", model.file))) { new.model.file <- sub("[.]bug$", ".txt", model.file) - file.copy(model.file, new.model.file, overwrite = TRUE) - on.exit(try(file.remove(new.model.file)), add = TRUE) - } else new.model.file <- model.file + file.copy(model.file, new.model.file, overwrite=TRUE) + on.exit(try(file.remove(new.model.file)), add=TRUE) + } else { + new.model.file <- model.file + } bugs.script(parameters.to.save, n.chains, n.iter, n.burnin, n.thin, - new.model.file, debug=debug, is.inits=!is.null(inits), - bin = bin, DIC = DIC, useWINE = useWINE, newWINE = newWINE, WINEPATH = WINEPATH) - bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE, WINEPATH = WINEPATH) - + new.model.file, debug=debug, is.inits=!is.null(inits), + bin=bin, DIC=DIC, useWINE=useWINE, newWINE=newWINE, + WINEPATH=WINEPATH) + bugs.run(n.burnin, bugs.directory, WINE=WINE, useWINE=useWINE, + WINEPATH=WINEPATH) if(codaPkg) return(file.path(getwd(), paste("coda", 1:n.chains, ".txt", sep=""))) - - if (is.R()){ - sims <- c(bugs.sims(parameters.to.save, n.chains, n.iter, n.burnin, n.thin, DIC), - model.file = model.file, is.DIC = !is.null(DIC), program = program) - } else { - sims <- c(bugs.sims(parameters.to.save, n.chains, n.iter, n.burnin, n.thin, DIC), - model.file = model.file, is.DIC = DIC, program = program) + sims <- c(bugs.sims(parameters.to.save, n.chains, n.iter, n.burnin, + n.thin, DIC), + model.file=model.file, is.DIC=DIC, program=program) + if(clearWD) { + file.remove(c("data.txt", "log.odc", "log.txt", "codaIndex.txt", + paste("inits", 1:n.chains, ".txt", sep=""), + paste("coda", 1:n.chains, ".txt", sep=""))) } - if(clearWD) - file.remove(c("data.txt", "log.odc", "log.txt", "codaIndex.txt", - paste("inits", 1:n.chains, ".txt", sep=""), - paste("coda", 1:n.chains, ".txt", sep=""))) class(sims) <- "bugs" - return(sims) + sims } Modified: trunk/R2WinBUGS/man/bugs.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.Rd 2007-06-12 09:57:21 UTC (rev 25) +++ trunk/R2WinBUGS/man/bugs.Rd 2007-06-12 09:58:15 UTC (rev 26) @@ -5,143 +5,172 @@ It automatically writes a WinBUGS 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)/1000)), - bin = (n.iter - n.burnin) / n.thin, - 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 = Sys.getenv("WINE"), - newWINE = FALSE, WINEPATH = NULL) +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)/1000)), + bin=(n.iter - n.burnin) / n.thin, + 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=Sys.getenv("WINE"), + newWINE=FALSE, WINEPATH=NULL) } \arguments{ - \item{data}{either a named list (names corresponding to variable names in the \code{model.file}) - of the data for the WinBUGS model, \emph{or} - a vector or list of the names of the data objects used by the model. - If \code{data = "data.txt"}, it is assumed that data have already been written to the working directory - in a file called \file{data.txt}, 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 WinBUGS model, \emph{or} - a function creating (possibly random) initial values. - Alternatively, if \code{inits = NULL}, initial values are generated by WinBUGS} - \item{parameters.to.save}{character vector of the names of the parameters to save which should be monitored} + \item{data}{either a named list (names corresponding to variable names + in the \code{model.file}) of the data for the WinBUGS model, + \emph{or} a vector or list of the names of the data objects used by + the model. If \code{data="data.txt"}, it is assumed that data have + already been written to the working directory in a file called + \file{data.txt}, 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 WinBUGS model, + \emph{or} a function creating (possibly random) initial values. + Alternatively, if \code{inits=NULL}, initial values are generated + by WinBUGS.} + \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 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=="winbugs"}, 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.} + 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{bin}{number of iterations between saving of results - (i.e. the coda files are saved after each \code{bin} iterations); + \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{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), WinBUGS is closed automatically - when the script has finished running, otherwise WinBUGS remains open for further investigation} - \item{DIC}{logical; if \code{TRUE} (default), compute deviance, pD, and DIC. - This is done in WinBUGS 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 WinBUGS input, see \code{\link{formatC}}} - \item{codaPkg}{logical; if \code{FALSE} (default) a \code{bugs} object is returned, - if \code{TRUE} file names of WinBUGS output are returned for easy access by the \pkg{coda} package - through function \code{\link{read.bugs}}. (not used if \code{program = "openbugs"})} + when the script has finished running, otherwise WinBUGS remains open + for further investigation} + \item{DIC}{logical; if \code{TRUE} (default), compute deviance, pD, + and DIC. This is done in WinBUGS 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 WinBUGS input, see + \code{\link{formatC}}} + \item{codaPkg}{logical; if \code{FALSE} (default) a \code{bugs} object + is returned, if \code{TRUE} file names of WinBUGS output are + returned for easy access by the \pkg{coda} package through function + \code{\link{read.bugs}} (not used if \code{program="openbugs"}).} \item{bugs.directory}{directory that contains the WinBUGS executable} - \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{working.directory}{sets working directory during execution of this function; - WinBUGS' in- and output will be stored in this directory; - if \code{NULL}, the current working directory is chosen.} - \item{clearWD}{logical; indicating whether the files \file{data.txt}, - \file{inits[1:n.chains].txt}, \file{log.odc}, \file{codaIndex.txt}, and - \file{coda[1:nchains].txt} should be removed after 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 WinBUGS, - defaults to \code{TRUE} on Windows, and \code{FALSE} otherwise. - If WINE is used, the arguments \code{bugs.directory} and \code{working.directory} must be given in form of Linux paths - rather than Windows paths (if not \code{NULL}). - The \code{useWINE = TRUE} option is not available in S-PLUS.} + \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{working.directory}{sets working directory during execution of + this function; WinBUGS' in- and output will be stored in this + directory; if \code{NULL}, the current working directory is chosen.} + \item{clearWD}{logical; indicating whether the files \file{data.txt}, + \file{inits[1:n.chains].txt}, \file{log.odc}, \file{codaIndex.txt}, + and \file{coda[1:nchains].txt} should be removed after 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 + WinBUGS, defaults to \code{FALSE} on Windows, and \code{TRUE} + otherwise. If WINE is used, the arguments \code{bugs.directory} and + \code{working.directory} must be given in form of Linux paths rather + than Windows paths (if not \code{NULL}). The \code{useWINE=TRUE} + option is not available in S-PLUS.} \item{WINE}{character; name of WINE binary file} \item{newWINE}{Set this one to \code{TRUE} for new versions of WINE.} - \item{WINEPATH}{Path the WINE, it is tried hard to get the information automatically if not given.} + \item{WINEPATH}{Path to WINE binary file, it is tried hard to get the + information automatically if not given.} } \details{ -To run: -\enumerate{ -\item Write a WinBUGS model in a ASCII file. -\item Go into R / S-PLUS. -\item Prepare the inputs to the \code{bugs} function and run it (see Example). -\item A WinBUGS window will pop up and R / S-PLUS will freeze up. The model - will now run in WinBUGS. It might take awhile. You will see - things happening in the Log window within WinBUGS. When WinBugs - 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}. -}} + To run: + \enumerate{ + \item Write a WinBUGS model in a ASCII file. + \item Go into R / S-PLUS. + \item Prepare the inputs to the \code{bugs} function and run it (see + Example). + \item A WinBUGS window will pop up and R / S-PLUS will freeze + up. The model will now run in WinBUGS. It might take awhile. You + will see things happening in the Log window within WinBUGS. When + WinBugs 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}. + } +} + \value{ - If \code{codaPkg = TRUE} the returned values are the names - of coda output files written by WinBUGS containing - the Markov Chain Monte Carlo output in the CODA format. - This is useful for direct access with \code{\link{read.bugs}}. + If \code{codaPkg=TRUE} the returned values are the names + of coda output files written by WinBUGS containing + the Markov Chain Monte Carlo output in the CODA format. + This is useful for direct access with \code{\link{read.bugs}}. - If \code{codaPkg = FALSE}, the following values are returned: + If \code{codaPkg=FALSE}, the following values are returned: \item{n.chains}{see Section \sQuote{Arguments}} \item{n.iter}{see Section \sQuote{Arguments}} \item{n.burnin}{see Section \sQuote{Arguments}} \item{n.thin}{see Section \sQuote{Arguments}} - \item{n.keep}{number of iterations kept per chain (equal to \code{(n.iter-n.burnin) / n.thin})} - \item{n.sims}{number of posterior simulations (equal to \code{n.chains * n.keep})} + \item{n.keep}{number of iterations kept per chain (equal to + \code{(n.iter-n.burnin) / n.thin})} + \item{n.sims}{number of posterior simulations (equal to + \code{n.chains * n.keep})} \item{sims.array}{3-way array of simulation output, with dimensions n.keep, n.chains, and length of combined parameter vector} - \item{sims.list}{list of simulated parameters:\cr - for each scalar parameter, a vector of length n.sims\cr - for each vector parameter, a 2-way array of simulations,\cr + \item{sims.list}{list of simulated parameters: + for each scalar parameter, a vector of length n.sims + for each vector parameter, a 2-way array of simulations, for each matrix parameter, a 3-way array of simulations, etc. - (for convenience, the \code{n.keep * n.chains} simulations in - sims.matrix and sims.list (but NOT sims.array have been randomly permuted)} - \item{sims.matrix}{matrix of simulation output, with \code{n.chains * n.keep} rows and - one column for each element of each saved parameter - (for convenience, the \code{n.keep * n.chains} simulations in - sims.matrix and sims.list (but NOT sims.array have been randomly permuted)} - \item{summary}{summary statistics and convergence information for each - element of each saved parameter.} + (for convenience, the \code{n.keep*n.chains} simulations in + sims.matrix and sims.list (but NOT sims.array) have been randomly + permuted)} + \item{sims.matrix}{matrix of simulation output, with + \code{n.chains*n.keep} rows and one column for each element of + each saved parameter (for convenience, the \code{n.keep*n.chains} + simulations in sims.matrix and sims.list (but NOT sims.array) have + been randomly permuted)} + \item{summary}{summary statistics and convergence information for + each saved parameter.} \item{mean}{a list of the estimated parameter means} \item{sd}{a list of the estimated parameter standard deviations} \item{median}{a list of the estimated parameter medians} - \item{root.short}{names of argument \code{parameters.to.save} and \dQuote{deviance}} + \item{root.short}{names of argument \code{parameters.to.save} and + \dQuote{deviance}} \item{long.short}{indexes; programming stuff} \item{dimension.short}{dimension of \code{indexes.short}} \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 WinBUGS for further iterations} - \item{pD}{an estimate of the effective number of parameters, for calculations see the section \dQuote{Arguments}.} + \item{last.values}{list of simulations from the most recent + iteration; they can be used as starting points if you wish to run + WinBUGS 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}} } + \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. + 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{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.} -\seealso{\code{\link{print.bugs}}, \code{\link{plot.bugs}}, and the \pkg{coda} package} + +\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.} + +\seealso{\code{\link{print.bugs}}, \code{\link{plot.bugs}}, and the + \pkg{coda} package} + \examples{ # An example model file is given in: -model.file <- system.file(package = "R2WinBUGS", "model", "schools.txt") +model.file <- system.file(package="R2WinBUGS", "model", "schools.txt") # Let's take a look: file.show(model.file) @@ -154,17 +183,17 @@ 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)) + 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))) +# 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") @@ -172,9 +201,9 @@ ## 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/", - working.directory = NULL, clearWD = TRUE) + n.chains=3, n.iter=5000, + bugs.directory="c:/Program Files/WinBUGS14/", + working.directory=NULL, clearWD=TRUE) print(schools.sim) plot(schools.sim) } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-06-12 09:57:26
|
Revision: 25 http://svn.sourceforge.net/bugs-r/?rev=25&view=rev Author: ggorjan Date: 2007-06-12 02:57:21 -0700 (Tue, 12 Jun 2007) Log Message: ----------- some formatting Modified Paths: -------------- trunk/R2WinBUGS/R/bugs.log.R trunk/R2WinBUGS/R/print.bugs.R trunk/R2WinBUGS/man/bugs.log.Rd Modified: trunk/R2WinBUGS/R/bugs.log.R =================================================================== --- trunk/R2WinBUGS/R/bugs.log.R 2007-06-12 09:55:29 UTC (rev 24) +++ trunk/R2WinBUGS/R/bugs.log.R 2007-06-12 09:57:21 UTC (rev 25) @@ -3,44 +3,47 @@ if(!file.exists(file)) stop("Log file", file, "does not exist") logfile <- readLines(file) - + + ## --- Stats --- + statsStart <- which(logfile == "Node statistics") + 2 if(!length(statsStart)) stop("Log file", file, "does not contain node statistics.") ## + 2 to remove ## "Node statistics" ## "\t node\t mean\t sd\t MC error\t2.5%\tmedian\t97.5%\tstart\tsample" - + statsEnd <- which(logfile == "dic.stats()") - 1 - ## + 1 to remove + ## - 1 to remove ## "dic.stats()" - + statsTable <- logfile[statsStart:statsEnd] statsTable <- sub("\t", "", statsTable) statsTable <- sapply(strsplit(statsTable, "\t"), "[") colnames(statsTable) <- statsTable[1,] statsTable <- t(apply(statsTable[-1,], 2, as.numeric)) colnames(statsTable) <- c("mean", "sd", "MC error", "2.5%", "median", "97.5%", "start", "sample") - - ## DIC + + ## --- DIC --- + DICStart <- which(logfile == "DIC") + 3 ## + 3 to remove ## "DIC" ## "Dbar = post.mean of -2logL; Dhat = -2LogL at post.mean of stochastic nodes" ## "\tDbar\tDhat\tpD\tDIC\t" - - DICEnd <- grep("history(", logfile, fixed = TRUE) - 1 + + DICEnd <- grep("history(", logfile, fixed=TRUE) - 1 ## - 1 to remove ## "history(+, ..." - - if(!length(DICEnd) || !length(DICStart) || (DICEnd < DICStart)){ + + if(!length(DICEnd) || !length(DICStart) || (DICEnd < DICStart)){ DICTable <- NA - }else{ + } else { DICTable <- logfile[DICStart:DICEnd] DICTable <- sapply(strsplit(DICTable, "\t"), "[") colnames(DICTable) <- DICTable[1,] DICTable <- t(apply(DICTable[-1,], 2, as.numeric)) colnames(DICTable) <- c("Dbar", "Dhat", "pD", "DIC") } - return(list(stats = statsTable, DIC = DICTable)) + list(stats=statsTable, DIC=DICTable) } Modified: trunk/R2WinBUGS/R/print.bugs.R =================================================================== --- trunk/R2WinBUGS/R/print.bugs.R 2007-06-12 09:55:29 UTC (rev 24) +++ trunk/R2WinBUGS/R/print.bugs.R 2007-06-12 09:57:21 UTC (rev 25) @@ -1,29 +1,33 @@ -fround <- function(x, digits) +fround <- function(x, digits) format(round(x, digits), nsmall=digits) - -print.bugs <- function(x, digits.summary = 1, ...){ + +print.bugs <- function(x, digits.summary = 1, ...) +{ if(!is.null(x$model.file)) 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("\n ", 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") print(round(x$summary, digits.summary), ...) - if(x$n.chains > 1){ + if(x$n.chains > 1) { cat("\nFor each parameter, n.eff is a crude measure of effective sample size,") cat("\nand Rhat is the potential scale reduction factor (at convergence, Rhat=1).\n") } - if(length(x$DIC)==1 && x$DIC){ - cat("\npD =", fround(x$pD, 1), "and DIC =", fround(x$DIC, 1), - if(x$DICbyR) "(using the rule, pD = var(deviance)/2)\n" else "(using the rule, pD = Dbar-Dhat)\n") - cat("DIC is an estimate of expected predictive error (lower deviance is better).\n") + msgDICrule <- ifelse(x$DICbyR, + "(using the rule, pD = var(deviance)/2)\n", + "(using the rule, pD = Dbar-Dhat)\n") + msgDIC <- "DIC is an estimate of expected predictive error (lower deviance is better).\n" + if(length(x$DIC) == 1 && x$DIC) { + cat("\npD =", fround(x$pD, 1), "and DIC =", fround(x$DIC, 1), msgDICrule) + cat(msgDIC) } else if(length(x$DIC)>1) { - cat("\n") - print(round(x$DIC, 1)) - cat("DIC is an estimate of expected predictive error (lower deviance is better).\n") + cat("\n") + print(round(x$DIC, 1)) + cat(msgDIC) } invisible(x) } Modified: trunk/R2WinBUGS/man/bugs.log.Rd =================================================================== --- trunk/R2WinBUGS/man/bugs.log.Rd 2007-06-12 09:55:29 UTC (rev 24) +++ trunk/R2WinBUGS/man/bugs.log.Rd 2007-06-12 09:57:21 UTC (rev 25) @@ -1,23 +1,26 @@ \name{bugs.log} \alias{bugs.log} \title{Read data from WinBUGS logfile} -\description{Read data such as summary statistics and DIC information from the WinBUGS logfile.} +\description{Read data such as summary statistics and DIC information + from the WinBUGS logfile} \usage{ bugs.log(file) } \arguments{ - \item{file}{Location of the WinBUGS logfile.} + \item{file}{Location of the WinBUGS logfile} } \value{ A list with components - \item{stats}{A matrix containing summary statistics for each element of each saved parameter. - Comparable to the information in the element \code{summary} of a bugs object as returned by \code{\link{bugs}}.} - \item{DIC}{A matrix containg the DIC statistics as returned from WinBUGS - (which is different from the way \code{\link{bugs}} calculates it).} + \item{stats}{A matrix containing summary statistics for each saved + parameter. Comparable to the information in the element + \code{summary} of a bugs object as returned by \code{\link{bugs}}.} + \item{DIC}{A matrix containing the DIC statistics as returned from + WinBUGS.} } \details{ -In later releases of R2WiNBUGS, this function is considered to read the relevant data from the log file rather than -analysing and calculating the relevant data in R / S-PLUS again. +In later releases of R2WiNBUGS, this function is considered to read the +relevant data from the log file rather than analysing and calculating +the relevant data in R / S-PLUS again. } \seealso{The main function that generates the log file is \code{\link{bugs}}.} \keyword{IO} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-06-12 09:55:27
|
Revision: 24 http://svn.sourceforge.net/bugs-r/?rev=24&view=rev Author: ggorjan Date: 2007-06-12 02:55:29 -0700 (Tue, 12 Jun 2007) Log Message: ----------- no need for return() and this is slightly faster Modified Paths: -------------- trunk/R2WinBUGS/R/decode.parameter.name.R trunk/R2WinBUGS/R/formatdata.R Modified: trunk/R2WinBUGS/R/decode.parameter.name.R =================================================================== --- trunk/R2WinBUGS/R/decode.parameter.name.R 2007-06-12 09:12:59 UTC (rev 23) +++ trunk/R2WinBUGS/R/decode.parameter.name.R 2007-06-12 09:55:29 UTC (rev 24) @@ -18,5 +18,5 @@ indexes <- as.numeric(unlist(strsplit(a, ","))) dimension <- length(indexes) } - return (list (root=root, dimension=dimension, indexes=indexes)) + list(root=root, dimension=dimension, indexes=indexes) } Modified: trunk/R2WinBUGS/R/formatdata.R =================================================================== --- trunk/R2WinBUGS/R/formatdata.R 2007-06-12 09:12:59 UTC (rev 23) +++ trunk/R2WinBUGS/R/formatdata.R 2007-06-12 09:55:29 UTC (rev 24) @@ -20,5 +20,5 @@ } datalist.tofile <- paste("list(", paste(unlist(datalist.string), collapse = ", "), ")", sep = "") - return(datalist.tofile) + datalist.tofile } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gg...@us...> - 2007-06-12 09:12:58
|
Revision: 23 http://svn.sourceforge.net/bugs-r/?rev=23&view=rev Author: ggorjan Date: 2007-06-12 02:12:59 -0700 (Tue, 12 Jun 2007) Log Message: ----------- bugs.script.R - using Dawn's solution for proper indexing of CODA files also for R side - removed one commented and useless line at the top read.bugs.Rd - documented Dawn's solution Modified Paths: -------------- trunk/R2WinBUGS/R/bugs.script.R trunk/R2WinBUGS/man/read.bugs.Rd Modified: trunk/R2WinBUGS/R/bugs.script.R =================================================================== --- trunk/R2WinBUGS/R/bugs.script.R 2007-05-23 17:44:29 UTC (rev 22) +++ trunk/R2WinBUGS/R/bugs.script.R 2007-06-12 09:12:59 UTC (rev 23) @@ -3,7 +3,6 @@ n.thin, model.file, debug=FALSE, is.inits, bin, DIC = FALSE, useWINE = FALSE, newWINE = FALSE, WINEPATH = NULL){ ### Write file script.txt for Bugs to read -### if (n.chains<2) stop ("n.chains must be at least 2") if((ceiling(n.iter/n.thin) - ceiling(n.burnin/n.thin)) < 2) stop ("(n.iter-n.burnin)/n.thin must be at least 2") @@ -17,29 +16,16 @@ coda <- file.path(working.directory, "coda") logfile <- file.path(working.directory, "log.odc") logfileTxt <- file.path(working.directory, "log.txt") - inits <- sapply(paste(working.directory, "/inits", 1:n.chains, ".txt", sep=""), + inits <- sapply(paste(working.directory, "/inits", 1:n.chains, ".txt", sep=""), function(x) native2win(x, , WINEPATH = WINEPATH)) initlist <- paste("inits (", 1:n.chains, ", '", inits, "')\n", sep="") savelist <- paste("set (", parameters.to.save, ")\n", sep="") redo <- ceiling((n.iter-n.burnin)/(n.thin*bin)) - - if (is.R()){ - thinUpdateCommand <- paste("thin.updater (", n.thin, ")\n", - "update (", ceiling(n.burnin/n.thin), ")\n", sep = "") - } else{ - ## In S-PLUS, the handling of the thinning is done differently than in R. - ## bin represents the number of iterations between saves, before thinning, - ## where in R it is the number of iterations between saves, after thinning. - ## This alternative handling of the thinning is done so that the resulting - ## samples have the correct iteration indexes in the output (coda) files. - ## Therefore, if the samples are read into S-PLUS using the coda package, - ## the thinning will be correctly labelled in the resulting mcmc object. - ## In R, the thinning is always labelled as 1, even if thinning was done. - thinUpdateCommand <- paste("update (", n.burnin, ")\n", - "thin.samples (", n.thin, ")\n", sep = "") - bin = bin * n.thin - } - + + thinUpdateCommand <- paste("update (", n.burnin, ")\n", + "thin.samples (", n.thin, ")\n", sep = "") + bin = bin * n.thin + cat( "display ('log')\n", "check ('", native2win(model, WINEPATH=WINEPATH), "')\n", @@ -56,7 +42,7 @@ "stats (*)\n", if(DIC) "dic.stats()\n", "history (*, '", native2win(history, WINEPATH=WINEPATH), "')\n", - "save ('", native2win(logfile, WINEPATH=WINEPATH), "')\n", + "save ('", native2win(logfile, WINEPATH=WINEPATH), "')\n", "save ('", native2win(logfileTxt, WINEPATH=WINEPATH), "')\n", file=script, sep="", append=FALSE) if (!debug) cat ("quit ()\n", file=script, append=TRUE) Modified: trunk/R2WinBUGS/man/read.bugs.Rd =================================================================== --- trunk/R2WinBUGS/man/read.bugs.Rd 2007-05-23 17:44:29 UTC (rev 22) +++ trunk/R2WinBUGS/man/read.bugs.Rd 2007-06-12 09:12:59 UTC (rev 23) @@ -1,19 +1,34 @@ \name{read.bugs} \alias{read.bugs} \title{Read output files in CODA format} -\description{This function reads Markov Chain Monte Carlo output in the CODA format produced by WinBUGS - and returns an object of class \code{\link[coda]{mcmc.list}} for further output analysis - using the \sQuote{coda} package.} + +\description{This function reads Markov Chain Monte Carlo output in the + CODA format produced by WinBUGS and returns an object of class + \code{\link[coda]{mcmc.list}} for further output analysis using the + \pkg{coda} package.} + \usage{ read.bugs(codafiles, ...) } + \arguments{ - \item{codafiles}{character vector of filenames (e.g. returned from \code{\link{bugs}} - in call such as \code{bugs(....., codaPkg = TRUE, .....)}). - Each of the files contains coda output for one chain produced by WinBUGS, - the \emph{directory} name of the corresponding 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}}} + \item{codafiles}{character vector of filenames (e.g. returned from + \code{\link{bugs}} in call such as \code{bugs(....., codaPkg=TRUE, + .....)}). Each of the files contains coda output for one chain + produced by WinBUGS, the \emph{directory} name of the corresponding + 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}}} } -\seealso{\code{\link{bugs}}, \code{\link[coda]{read.coda}}, \code{\link[coda]{mcmc.list}}} + +\details{ + \code{\link{bugs}} (actually it is \code{\link{bugs.script}}) writes + BUGS script in such a way that iteration numbers in resulting CODA + files correspond to iteration numbers before burnin and thinning. +} + +\seealso{\code{\link{bugs}}, \code{\link[coda]{read.coda}}, +\code{\link[coda]{mcmc.list}}} + \keyword{file} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Gregor G. <gre...@bf...> - 2007-06-12 09:11:16
|
Sen to fast! Read at https://sourceforge.net/docs/E09#notice Essentailly, do cd to_top_path_of_bugs-r_SVN svn info ## should return something like (depends on if you have whole bugs-r SVN ## tree or only trunk - latest development) Path: . URL: https://svn.sourceforge.net/svnroot/bugs-r Repository Root: https://svn.sourceforge.net/svnroot/bugs-r Repository UUID: 55f836b9-c822-0410-921b-df7710bb080c Revision: 0 Node Kind: directory Schedule: normal Last Changed Rev: 0 Last Changed Date: 2006-11-21 22:43:23 +0100 (Tue, 21 Nov 2006) ## Now do (in one line) if you have whole SVN tree svn switch --relocate https://svn.sourceforge.net/svnroot/bugs-r https://bugs-r.svn.sourceforge.net/svnroot/bugs-r ## Now do (in one line) if you have only trunk part of SVN tree svn switch --relocate https://svn.sourceforge.net/svnroot/bugs-r/trunk https://bugs-r.svn.sourceforge.net/svnroot/bugs-r/trunk -- Lep pozdrav / With regards, Gregor Gorjanc |
From: Gregor G. <gre...@bf...> - 2007-06-12 09:07:42
|
Read at https://sourceforge.net/docs/E09#notice -- Lep pozdrav / With regards, Gregor Gorjanc |
From: Gregor G. <gre...@bf...> - 2007-06-12 08:34:32
|
Hi John! John P. Burkett wrote: > Hi Gregor, > > Thank you very much for your quick and helpful response. > >> With R2WinBUGS under Linux you must use WinBUGS > > Switching from OpenBugs to WinBUGS14 seems to have solved my initial > problem. However, R still produces some messages that puzzle me. OK. >> Can you please issue traceback() after this error? > > After installing and registering WinBUGS14 and installing the patch for > version 1.4.2, I modified to the R command to read as follows: > > radon.1 <- bugs (radon.data, radon.inits, radon.parameters, > "/home/john/myRfiles/radon.1.bug", n.chains=3, n.iter=10, debug=TRUE, > program="WinBugs", bugs.directory="/home/john/WinBUGS14", useWINE=TRUE, > newWINE=TRUE, WINEPATH=WINEPATH, WINE="/usr/bin/wine") > > That command got this response from R: > fixme:keyboard:RegisterHotKey (0x10024,13,0x00000002,3): stub > fixme:ole:GetHGlobalFromILockBytes cbSize is 13824 > err:ole:CoGetClassObject class {0003000a-0000-0000-c000-000000000046} > not registered > err:ole:CoGetClassObject no class object > {0003000a-0000-0000-c000-000000000046} could be created for context 0x2 Ah, this error messages come from wine part and can be ignored. I do not know where exactly they come from. As you said, bugs returns its output as it should. > Perhaps the messages from R are nothing to worry about. Anyway, WinBUGS > produces output that R can plot and print, giving results similar to > those Gelman and Hill report on p. 351. Do you think anything needs to > be done about the R messages? I am glad there is one more Linux&R2WinBUGS user around! -- Lep pozdrav / With regards, Gregor Gorjanc |
From: Gregor G. <gre...@bf...> - 2007-06-12 08:31:17
|
Hi, A! Andrew Gelman wrote: > Hi, Gregor. I can't remember all the details now, but we want to avoid > saving all these intermediate iterations. That is, if it's saving every > 12th iteration, we don't want to first save all of them, then delete > 11/12; we just want Bugs to save every twelfth. I assume that your > fixed version still does this. Yes it does. The point is only in using proper iteration index i.e. 12 for 12th iteration and not 1, when thinning interval is 12. > P.S. If, in the meantime, it's possible to fix bugs() in R2WinBugs to > run with the new Openbugs, that would be great! That will have to wait for my side, because I can not run OpenBUGS from R2WinBUGS under Linux. Sorry. I do have plan for summer to port this from rbugs package. -- Lep pozdrav / With regards, Gregor Gorjanc ---------------------------------------------------------------------- University of Ljubljana PhD student Biotechnical Faculty www: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department blog: http://ggorjan.blogspot.com Groblje 3 mail: gregor.gorjanc <at> bfro.uni-lj.si SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe tel: +386 (0)1 72 17 861 ---------------------------------------------------------------------- |
From: Andrew G. <ge...@st...> - 2007-06-11 15:03:21
|
Hi, Gregor. I can't remember all the details now, but we want to avoid saving all these intermediate iterations. That is, if it's saving every 12th iteration, we don't want to first save all of them, then delete 11/12; we just want Bugs to save every twelfth. I assume that your fixed version still does this. Andrew P.S. If, in the meantime, it's possible to fix bugs() in R2WinBugs to run with the new Openbugs, that would be great! Gregor Gorjanc wrote: > Hi, > > I have looked at Dawn's change about "thinning" setup in R2WinBUGS and > would like to summarize it here, because it was not really clear (at > least to me) what the change for S-PLUS side was all about. > > Default behavior in R is now to create a BUGS script with the following > BUGS commands for a run with 5000 iterations, 1000 burn-in and thinning > interval 12 (showing only relevant parts): > > ---------------------------------------------------- BUGS script start > > # after model, inits, ... set burnin phase > > thin.updater (12) > update (84) > > # set parameters to monitor > > update(334) > coda() > > ------------------------------------------------------ BUGS script end > > Dawn has changed this in S-PLUS part to: > > ---------------------------------------------------- BUGS script start > > # after model, inits, ... set burnin phase > > update (1000) > thin.updater (12) > > # set parameters to monitor > > update(4000) > coda() > > ------------------------------------------------------ BUGS script end > > In my humble opinion this is better: > - BUGS script is clearer > - CODA files have indices that match iteration number > > This does not affect R2WinBUGS as it has only effect on produced CODA > files. For example, reading CODA files into R from above runs, would > after read.coda() give the following info: > > # Current implementation > Iterations = 85:418 > Thinning interval = 1 > Number of chains = 1 > Sample size per chain = 334 > > # Proposed implementation by Dawn > Iterations = 1001:4985 > Thinning interval = 12 > Number of chains = 1 > Sample size per chain = 333 > > Better, again! > > If there are no objections, I will commit this change. > > -------- Original Message -------- > Date: Thu, 19 Apr 2007 18:39:50 -0400 > From: Andrew Gelman <ge...@st...> > > G > I don't actually understand the question! > A > > Gregor Gorjanc wrote: >> Hi, >> >> In my opinion Dawn's change make sense also for R side. Does anyone have >> any objection for not porting this also to R side? >> >> Gregor >> >> -------- Original Message -------- >> Subject: [Bugs-r-devel] SF.net SVN: bugs-r: [12] >> trunk/R2WinBUGS/R/bugs.script.R >> Date: Tue, 17 Apr 2007 07:21:52 -0700 >> From: woo...@us... >> To: bug...@li... >> >> Revision: 12 >> http://svn.sourceforge.net/bugs-r/?rev=12&view=rev >> Author: woodard_ >> Date: 2007-04-17 07:21:52 -0700 (Tue, 17 Apr 2007) >> >> Log Message: >> ----------- >> In S-PLUS, the handling of the thinning is done differently than in R. >> bin represents the number of iterations between saves, before thinning, >> where in R it is the number of iterations between saves, after thinning. >> This alternative handling of the thinning is done so that the resulting >> samples have the correct iteration indexes in the output (coda) files. >> Therefore, if the samples are read into S-PLUS using the coda package, >> the thinning will be correctly labelled in the resulting mcmc object. >> In R, the thinning is always labelled as 1, even if thinning was done. >> >> Modified Paths: >> -------------- >> trunk/R2WinBUGS/R/bugs.script.R >> >> Modified: trunk/R2WinBUGS/R/bugs.script.R >> =================================================================== >> --- trunk/R2WinBUGS/R/bugs.script.R 2007-04-16 11:21:38 UTC (rev 11) >> +++ trunk/R2WinBUGS/R/bugs.script.R 2007-04-17 14:21:52 UTC (rev 12) >> @@ -21,6 +21,24 @@ >> initlist <- paste("inits (", 1:n.chains, ", '", inits, "')\n", >> sep="") >> savelist <- paste("set (", parameters.to.save, ")\n", sep="") >> redo <- ceiling((n.iter-n.burnin)/(n.thin*bin)) >> + >> + if (is.R()){ >> + thinUpdateCommand <- paste("thin.updater (", n.thin, ")\n", >> + "update (", ceiling(n.burnin/n.thin), ")\n", sep = "") >> + } else{ >> ... >> + thinUpdateCommand <- paste("update (", n.burnin, ")\n", >> + "thin.samples (", n.thin, ")\n", sep = "") >> + bin = bin * n.thin >> + } >> + >> cat( >> "display ('log')\n", >> "check ('", native2win(model), "')\n", >> @@ -28,8 +46,7 @@ >> "compile (", n.chains, ")\n", >> if(is.inits) initlist, >> "gen.inits()\n", >> - "thin.updater (", n.thin, ")\n", >> - "update (", ceiling(n.burnin/n.thin), ")\n", >> + thinUpdateCommand, >> savelist, >> if(DIC) "dic.set()\n", >> rep( >> >> >> This was sent by the SourceForge.net collaborative development platform, >> the world's largest Open Source development site. >> >> ------------------------------------------------------------------------- >> >> This SF.net email is sponsored by DB2 Express >> Download DB2 Express C - the FREE version of DB2 express and take >> control of your XML. No limits. Just data. Click to get it now. >> http://sourceforge.net/powerbar/db2/ >> _______________________________________________ >> Bugs-r-devel mailing list >> Bug...@li... >> https://lists.sourceforge.net/lists/listinfo/bugs-r-devel >> >> > -- Andrew Gelman Professor, Department of Statistics Professor, Department of Political Science Director, Applied Statistics Center Columbia University, New York ge...@st... www.stat.columbia.edu/~gelman Office hours: I'm in my stat dept ofc most Mondays, Tuesdays, and Fridays. On Wednesdays and Thursdays from 12-5, I'm in the Playroom (707 Intl Affairs Bldg). I'm out of town 28 May - 1 Jun, 20-21 Jun, and 9-10 Jul. Statistics department office: Social Work Bldg (Amsterdam Ave at 122 St), Room 1016 phone 212-851-2142, fax 212-851-2164 Political Science department office: International Affairs Bldg (Amsterdam Ave at 118 St), Room 731 phone 212-854-7075, fax 212-222-0598 Mailing address: 1255 Amsterdam Ave, Room 1016 Columbia University New York, NY 10027-5904 212-851-2142 (fax) 212-851-2164 |