楼主: 空sutra
3525 5

[问答] 困扰了数天的问题,R2Winbugs求助!附代码 [推广有奖]

  • 1关注
  • 3粉丝

已卖:240份资源

本科生

9%

还不是VIP/贵宾

-

威望
0
论坛币
884 个
通用积分
2.2407
学术水平
1 点
热心指数
2 点
信用等级
1 点
经验
4209 点
帖子
35
精华
0
在线时间
85 小时
注册时间
2014-8-3
最后登录
2020-6-15

楼主
空sutra 发表于 2015-3-16 15:25:45 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
在R中运行了:
bugs.sim<-bugs(data,inits=NULL,parameters,noyear,n.chains=1,n.iter=40000,n.burnin=1000,bugs.directory="D:/winbugs14/WinBUGS14/",working.directory="C:/BUGS",debug=TRUE)
之后,在winbugs的Log中得到如下信息:
display(log)
check(C:/BUGS/noyear.bug.txt)
model is syntactically correct
data(C:/BUGS/data.txt)
undefined variable
compile(1)
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(39)
update(26)
command #Bugs:update cannot be executed (is greyed out)
set(beta)
command #Bugs:set cannot be executed (is greyed out)
set(p1)
command #Bugs:set cannot be executed (is greyed out)
set(p2)
command #Bugs:set cannot be executed (is greyed out)
set(p3)
command #Bugs:set cannot be executed (is greyed out)
set(deviance)
command #Bugs:set cannot be executed (is greyed out)
dic.set()
command #Bugs:dic.set cannot be executed (is greyed out)
update(1000)
command #Bugs:update cannot be executed (is greyed out)
coda(*,C:/BUGS/coda)
command #Bugs:coda cannot be executed (is greyed out)
stats(*)
command #Bugs:stats cannot be executed (is greyed out)
dic.stats()

DIC
history(*,C:/BUGS/history.odc)
command #Bugs:history cannot be executed (is greyed out)
save(C:/BUGS/log.odc)
save(C:/BUGS/log.txt)


请问是哪里出了问题,是给的原始数据的问题吗。。?但是检查了好几遍,实在是不知道问题在哪里了。。请各位仁兄帮忙!十分感谢!!

代码在2楼
二维码

扫码加我 拉你入群

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

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

关键词:R2WinBUGS winbugs WINBUG BUGS bug

沙发
空sutra 发表于 2015-3-16 15:29:23
为方便解答,给出代码:
  1. model{
  2.   
  3.   for (y in 1:N.years.sites){  
  4.     for (d in 1:response.day){  
  5.       events[d,y] ~ dpois(p[d,y])  # raw data is {0/1} for each day
  6.       p[d,y] <- max(p0[d,y],.001) # trick to avoid crashing from low values
  7.       p0[d,y] <- a[d] * risk[d,y]
  8.       risk[d,y] <- exp(beta[1]*temp.cum[d,y] + beta[2]*frost7[d,y] +
  9.                          beta[3]*precip7[d,y] )   # risk function that can include any covariates of interest, time-dependent or otherwise
  10.       
  11.       risk2[d,y] <- min(risk[d,y], 100)
  12.      # events.pred[d,y] <- 1 - pow(exp(-sum(a[1 : d])), risk2[d,y] )
  13.     }}}

  14. for (d in 1:N.days){  #
  15.   a[d] <- p1/ (1+exp((2.2/p3) * (p2-d)))     # baseline function used in this study (could be modeled otherwise for different applications, or left non-parametric)
  16.   
  17.   #p1 <- 1 # max
  18.   #p2 <- 200 # point of inflection
  19.   #p3 <- 20 # time between .1 and .5 and .5 and .9
  20.   
  21. }  
  22. p1~dlnorm(p1.sp, p1.tau)
  23. p3~dlnorm(p3.sp, p3.tau)

  24. p2~dlnorm(p2.sp, p2.tau)


  25. ## Priors (BUGS normal distributions use precision instead of variance, where precision = 1/variance)
  26. p1.sp ~ dnorm(0,.001)
  27. p2.sp ~ dnorm(3,.001)
  28. p3.sp ~ dnorm(50,.001)

  29. p1.tau ~ dgamma(.01,.01)
  30. p2.tau ~ dgamma(.01,.01)
  31. p3.tau ~ dgamma(.01,.01)

  32. # Overall species baseline curve
  33. for (d in 1:N.days){    a.sp[d] <- p1.sp/ (1+exp((2.2/p3.sp) * (p2.sp-d)))   }   


  34. for(pp in 1:n.beta){
  35.   beta[pp] ~ dnorm(beta0[pp], beta.tau[pp])
  36. }

  37. for(pp in 1:n.beta){
  38.   beta0[pp]~ dnorm(0,.001)  
  39.   beta.tau[pp] <- pow(beta.sigma[pp], -2)
  40.   beta.sigma[pp] ~ dunif(0,10)
  41. }

  42. } # end model
复制代码


数据则是用csv格式做的,有多个文档,已经转换成vector;
data<-list("event","light","prep","temp.cum","N.sites","response.day","n.beta","N.days")
parameters<-c("beta","p1","p2","p3")
inits<-function(){list()}

已经读了论坛里大量的关于winbugs的帖子,仍然想不通问题在哪里。。真心求助!

藤椅
空sutra 发表于 2015-3-16 15:33:07
不知道能不能艾特出大神。。。好吧发现不能艾特。。算了。。

板凳
空sutra 发表于 2015-3-16 20:15:06
自己解决了该问题。。确实是原始数据的问题

报纸
撒哈拉lu 发表于 2017-12-5 20:53:51
空sutra 发表于 2015-3-16 20:15
自己解决了该问题。。确实是原始数据的问题
你好!我现在也遇到这样的问题了,请问您说的原始数据问题是什么意思呢?格式还是什么,如果是格式需要什么格式呢

地板
heng9840 发表于 2021-9-29 11:03:52
撒哈拉lu 发表于 2017-12-5 20:53
你好!我现在也遇到这样的问题了,请问您说的原始数据问题是什么意思呢?格式还是什么,如果是格式需要什 ...
同问啊,请问是什么问题呢

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 08:41