[R] Problems with BRugs

R Heberto Ghezzo, Dr heberto.ghezzo at mcgill.ca
Thu Jun 10 17:54:30 CEST 2010


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


More information about the R-help mailing list