全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 winbugs及其他软件专版
1294 1
2014-06-16

The code is following:


require(BRugs)

require(R2WinBUGS)

model<-function(){

  for(i in 1:N){

  y ~ dnorm(x, 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] # this row wrong,

# it would be right when I set theta[j] <- 1*x[j-1]

  }

  a ~ 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), a = dnorm(1, 0, 1), b = dnorm(1, -1, 1))

}

parameters=c("a", "b", "x")


write.model(model, con = "model.bug")

modelCheck("model.bug")

# model is 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, the program will be correct when I replace theta[j] <- b*x[j-1] with theta[j] <- 1*x[j-1], but I have defined b ~ dunif(-1, 1). Indeed, I need to set theta[j] <- a - b*x[j-1] in the final model, and it turns out to be wrong when I try to add a and b into it. Anyone find where the problem is ?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-6-16 02:36:09
The problems is in your priors for b (and most likely a). I don't know your data but perhaps the range of your current priors do not include true values of a and b. I would think that if you use a continuous distribution(s):

a ~ dnorm(0,1)
b ~ dnorm(0,1)
your problem might be solved?

n.b. If you are trying to create a AR(1) model for WinBUGS you might want to check out the tsbugs package.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群