[R] R, Coda, and OpenBUGS
Uwe Ligges
ligges at statistik.tu-dortmund.de
Wed Oct 7 15:01:28 CEST 2009
Bill Halteman wrote:
> Hi All,
>
> I am trying to figure out how to use R-Coda with the output from
> OpenBugs. I have installed and loaded the packages BRugs and R2WinBUGS.
> I have successfully run a simple Bayes model in WinBUGS using R2WinBUGS'
> "bugs" and have used "read.bugs" to build the coda object. I can
> successfully switch to OpenBugs and run the same model and get the basic
> summary back. However, I cannot build the coda object. From what I
> have read "read.openbugs" should do the trick. However, I have
> discovered the current version of OpenBUGS (v 3.03) doesn't write any
> output files in spite of setting codaPkg=TRUE in the "bugs" call.
> "Str(openbugs.object)" reveals a large collection of elements, one of
> which is an array that contains the MCMC chains. Is there a function to
> build the coda object?
For BRugs: Sure, the function is called buildMCMC(). From the examples
of ?BRugs:
library(BRugs) # loading BRugs
## Now setting the working directory to the examples' one:
oldwd <- getwd()
setwd(system.file("OpenBUGS", "Examples", package="BRugs"))
## some usual steps (like clicking in WinBUGS):
modelCheck("ratsmodel.txt") # check model file
modelData("ratsdata.txt") # read data file
modelCompile(numChains=2) # compile model with 2 chains
modelInits(rep("ratsinits.txt", 2)) # read init data file
modelUpdate(1000) # burn in
samplesSet(c("alpha0", "alpha")) # alpha0 and alpha should be monitored
modelUpdate(1000) # 1000 more iterations ....
## now let's construct a coda object
## (of class mcmc.list, to be precise)
## for BUGS node "alpha":
alpha <- buildMCMC("alpha")
Best,
Uwe Ligges
> Thanks in advance for any suggestions,
>
> Bill Halteman
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list