error in using WinBUGS from R -


the code following:

require(brugs) require(r2winbugs) model<-function(){   for(i in 1:n){   y[i] ~ dnorm(x[i], sigma.y)   }   x[1] ~ dnorm(theta[1], sigma.y)   theta[1] <- 0   for(j in 2:n){     x[j] ~ dnorm(theta[j], sigma.x)     theta[j] <- b*x[j-1] # row wrong,  # right when set theta[j] <- 1*x[j-1]   }   ~ dunif(0, 1)   b ~ dunif(-1, 1)   sigma.y ~ dgamma(0.1, 0.1)   sigma.x ~ dgamma(0.1, 0.1) } data <- list( n <- 100, y <- rnorm(100)) data=list(n=100,y=rnorm(100))  inits=function(){   list(sigma.x = rgamma(1,0.1,0.1), sigma.y = rgamma(1, 0.1, 0.1), = dnorm(1, 0, 1), b = dnorm(1, -1, 1)) } parameters=c("a", "b", "x")  write.model(model, con = "model.bug") modelcheck("model.bug") # model syntactically correct ret.sim <- bugs(data, inits, parameters, "model.bug",                 n.chains = 1, n.iter = 1000,                 program= "winbugs",                 working.directory = null,                 debug = t) 

i don't know why, program correct when replace theta[j] <- b*x[j-1] theta[j] <- 1*x[j-1], have defined b ~ dunif(-1, 1). indeed, need set theta[j] <- - b*x[j-1] in final model, , turns out wrong when try add a , b it. find problem ?

the problems in priors b (and a). don't know data perhaps range of current priors not include true values of , b. think if use continuous distribution(s):

a ~ dnorm(0,1) b ~ dnorm(0,1) 

your problem might solved?

n.b. if trying create ar(1) model winbugs might want check out tsbugs package.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -