Re: [R] Problems with BRugs

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Sat, 12 Jun 2010 18:28:57 +0200

With BRugsFit() of the current verison of BRugs, the not given inits are not generated automatically (which may change with the next version).

Hence you need to do it manually as in:

library("BRugs")
modelCheck("test.bug")
modelData(bugsData(Data))
modelCompile(numChains=1)
modelInits(bugsInits(Inits))
modelGenInits()
modelUpdate(1000)
samplesSet(Parameters)
modelUpdate(10000)
p1.sim <- samplesStats("*")

Best,
Uwe Ligges

On 10.06.2010 17:54, R Heberto Ghezzo, Dr wrote:
> Hello, I am trying to run some examples from the book of P.Congdon. If I run the following script
> # Program 7.2 Bayesian Statistical Modelling - Peter Congdon
> #
> library(R2WinBUGS)
> setwd("c:/temp/R")
> mo<- function() {
> rho ~ dbeta(1,1)
> th ~ dgamma(0.001,0.001)
> Y[1] ~ dpois(th)
> for (t in 2:14) {Y[t] ~ dpois(mu[t])
> for (k in 1:Y[t-1]+1) {B[k,t] ~ dbern(rho)}
> B.s[t]<- sum(B[1:Y[t-1]+1,t])-B[1,t]
> mu[t]<- B.s[t] +th*(1-rho)}
> }
> write.model(mo,con="test.bug")
> Data<-
> list(Y=c(0,1,2,3,1,4,9,18,23,31,20,25,37,45))
> Inits<- function() {
> list(rho=0.8,th=5)
> }
> Parameters<- c("rho","mu")
> #
> p1.sim<- bugs(model.file="test.bug",
> Data,
> Inits,
> n.chains=1,
> Parameters,
> n.burnin = 1000,
> n.iter = 10000,
> n.thin=2,
> program="WinBUGS",
> bugs.directory=Sys.getenv("DirWinBUGS")
> )
> #
> and this works OK given answers similar to the book
> But changing library to BRugs, write.model to witeModel and the call to

>> #
>> p1.sim<- BRugsFit("test.bug",

> + Data,
> + Inits,
> + numChains=1,
> + Parameters,
> + nBurnin = 1000,
> + nIter = 10000,
> + nThin=2
> + )
> I get :
>

> model is syntactically correct
> data loaded
> model compiled
> [1] "C:\\Users\\User\\AppData\\Local\\Temp\\RtmphLlekC/inits1.txt"
> Initializing chain 1: initial values loaded but this or another chain contain uninitialized variables
> model must be initialized before updating
> can not calculate deviance for this model
> Error in samplesSet(parametersToSave) :
> model must be initialized before monitors used
>> #

> I tried several forms of the Inits and it does not work
> Can somebody tell me where is the mistake I am making?
> Thanks for any help
> Heberto Ghezzo
> Montreal
> ______________________________________________
> 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.


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. Received on Sat 12 Jun 2010 - 16:31:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Jun 2010 - 16:40:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive