楼主: ReneeBK
1321 1

[精彩WinBUGS答问]Error in using WinBUGS from R [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4897份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49635 个
通用积分
55.6937
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2014-6-16 01:40:40 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

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 ?

二维码

扫码加我 拉你入群

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

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

关键词:winbugs WINBUG Error Using BUGS following require Error

沙发
ReneeBK 发表于 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.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-23 18:54