[R] Problems with BRugs

Uwe Ligges ligges at statistik.tu-dortmund.de
Sat Jun 12 18:28:57 CEST 2010


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.



More information about the R-help mailing list