[R] Making R talk to Win/OpenBUGS in Linux (again)

Gregor Gorjanc gregor.gorjanc at gmail.com
Fri May 5 13:25:46 CEST 2006


Hello Paul,

> Wow! That was quick.
> 
> One more thing would make my R2WinBUGS experience more perfect.  I
> wish the "bugs" function explained how the user can write out the
> model.txt file from within the R code itself, rather than taking the
> current advice of creating it separately. The process now escribed in
> "bugs" is:
> 
>    1.  Write a WinBUGS model in a ASCII file.
>    2.  Go into R.
> 
> I don't know what the best way to create model.txt might be, but this
> does work, and maybe you have even better examples to show:
> 
> myTextExample <- c("  model {
>        for (j in 1:J){
>          y[j] ~ dnorm (theta[j], tau.y[j])
>          theta[j] ~ dnorm (mu.theta, tau.theta)
>          tau.y[j] <- pow(sigma.y[j], -2)
>        }
>        mu.theta ~ dnorm (0.0, 1.0E-6)
>        tau.theta <- pow(sigma.theta, -2)
>        sigma.theta ~ dunif (0, 1000)
>      }
> ")
> 
>  zz <- file("model.txt","w")
>  writeLines(myTextExample,con=zz)
>  close(zz)
> 
> The only dicey part here is that the user might save the model in the
> wrong directory, but I don't see what prevents that with the current
> advice in "bugs"
> 
> I suggest this because it allows the creation of one file working
> examples in R2WinBUGS.  For the teaching objective, this simplifies
> things a lot!

Perhaps you might try my function, which does this exactly as you
proposed. I added also a print function so you can print model nicely
also in R. You can find documentation
here

http://www.bfro.uni-lj.si/MR/ggorjan/software/R/ggmisc/ggmiscHtml/bugsModel.html

and the function itself lives in my offCRAN package ggmisc, which you
can grab at

http://www.bfro.uni-lj.si/MR/ggorjan/software/R/ggmisc.tar.gz

I already proposed this to Uwe, but he did not find it enough
"interesting" to include it into the R2WinBUGS. Anyway, Jouni Kerman,
has written even better function - fitbugs(). Look at link bellow for
more. I hope fitbugs() will make it into one of next releases of R2WinBUGS.

http://www.stat.columbia.edu/~kerman/Software/index.html

> 
> 
> On 5/4/06, Uwe Ligges <ligges at statistik.uni-dortmund.de> wrote:
> 
>>> Paul Johnson wrote:
>>>
>>
>>>> > Hello, and thanks for the many very rapid responses to my requests for
>>>> > R/WinBUGS conversation.
>>>> >
>>>> > I do not know how to build OpenBUGS in linux, but will snoop around
>>>> > and see if I can't figure out what's wrong with linking R to BRugs.so.
>>>> >
>>>> > In the meanwhile...
>>>> >
>>>> > While we are on the linux/bugs topic, can I please ask for a fix in
>>>> > R2WinBUGS? On my system, the script.txt file is written into the
>>>> > WinBUGS directory,where the user does not ordinarily have write
>>>> > permissions.  If script.txt could be written with the other temporary
>>>> > files, this would be solved.
>>
>>>
>>> Will be fixed for the next release.
>>> We should also add some option to disable running bugs.update.settings()
>>> which really requires write access in the WinBUGS directory.

-- 
Lep pozdrav / With regards,
    Gregor Gorjanc

----------------------------------------------------------------------
University of Ljubljana     PhD student
Biotechnical Faculty
Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si

SI-1230 Domzale             tel: +386 (0)1 72 17 861
Slovenia, Europe            fax: +386 (0)1 72 17 888

----------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
 you have no certainty until you try." Sophocles ~ 450 B.C.




More information about the R-help mailing list