user1841858
user1841858

Reputation: 1

R2OpenBUGS Error: node not stochastic


I have a specific problem in Running R2OpenBUGS in R. But it runs perfectly well in OpenBUGS.
I want to understand what the problem is.

Here is my code:

model volatility;
const n=180;
{

# likelihood: joint distribution of ys
for (t in 1:n)
{
yisigma2[t] <- 1/exp(theta[t]);
y[t] ~ dnorm(0,yisigma2[t]);
}

prior distributions

mu ~ dnorm(0,0.1);
phistar ~ dbeta(20,1.5);
itau2 ~ dgamma(2.5,0.025);
beta <- exp(mu/2);
phi <- 2*phistar-1;
tau <- sqrt(1/itau2);
theta0 ~ dnorm(mu,itau2);
thmean[1] <- mu + phi*(theta0-mu);
theta[1] ~ dnorm(thmean[1],itau2);
for (t in 2:n)
{
thmean[t] <- mu + phi*(theta[t-1]-mu);
theta[t] ~ dnorm(thmean[t],itau2);

}
}




R Code:
svm.sim <- bugs(data, inits, model.file = "C:/Documents and Settings/code.txt", parameters = c("mu", "phi", "tau"), n.chains = 1, n.iter = 1000, codaPkg = TRUE,debug=TRUE)

and here is the error shown in log of OpenBUGS when I run it from R:



model is syntactically correct
data loaded
model compiled
this component of node is not stochastic phi error pos 25
unable to generate initial values for node of type UpdaterNormal.StdUpdater
model must be initialized before updating
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before DIC can be monitored
model must be initialized before updating
model must be initialized before monitors used
DIC monitor not set


Any help will be greatly appreciated
Thank You and Regards
Dinakar

Upvotes: 0

Views: 1631

Answers (1)

amg
amg

Reputation: 204

I ran your code with a slight modification (see below) and it seemed to work fine. I did specify the value n as data, and let OpenBUGS generate initial values itself. Is it an issue with how you specified your inits?

    sink("stack_model.txt")
    cat("
    model{
    # likelihood: joint distribution of ys 
    for (t in 1:n) 
    { 
    yisigma2[t] <- 1/exp(theta[t])
    y[t] ~ dnorm(0,yisigma2[t])
  }
  mu ~ dnorm(0,0.1)
  phistar ~ dbeta(20,1.5) 
  itau2 ~ dgamma(2.5,0.025)
  beta <- exp(mu/2)
  phi <- 2*phistar-1
  tau <- sqrt(1/itau2)
  theta0 ~ dnorm(mu,itau2) 
  thmean[1] <- mu + phi*(theta0-mu) 
  theta[1] ~ dnorm(thmean[1],itau2) 
  for (t in 2:n) 
  { 
    thmean[t] <- mu + phi*(theta[t-1]-mu) 
    theta[t] ~ dnorm(thmean[t],itau2) 

  } 
}",fill=TRUE)
sink()
win.data<-list(n=180)
svm.sim <- bugs(win.data, inits=NULL, model.file = "stack_model.txt", parameters = c("mu", "phi", "tau"), n.chains = 2, n.iter = 1000, DIC=F, debug=TRUE,  codaPkg =TRUE) 

Upvotes: 0

Related Questions