楼主: autozhao
19838 18

R中运行R2WinBUGS,及BRugs问题。 [推广有奖]

  • 9关注
  • 11粉丝

已卖:262份资源

副教授

36%

还不是VIP/贵宾

-

威望
0
论坛币
562 个
通用积分
8.9693
学术水平
8 点
热心指数
14 点
信用等级
4 点
经验
25728 点
帖子
409
精华
0
在线时间
1200 小时
注册时间
2008-10-23
最后登录
2025-6-19

楼主
autozhao 发表于 2010-6-20 02:43:24 |AI写论文
5论坛币
我在R中安装了R2WinBUGs和BRugs包,试运行了http://www.stat.columbia.edu/~gelman/bugsR/runningbugs.html
上的程序,分别报错
1,
Error in file(con, "rb") : 无法打开链结
此外: 警告信息:
In file(con, "rb") :
  无法打开文件'c:/Program Files/WinBUGS14//System/Rsrc/Registry.odc': No such file or directory
错误于bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE,  :
  WinBUGS executable does not exist in c:/Program Files/WinBUGS14/
此外: 警告信息:
In list.files(bugs.directory) :
  list.files: 'c:/Program Files/WinBUGS14/'目录不可读


2,
Carriage returns added to model file schools.bug
invalid or unexpected token scanned error pos 106 (error on line 10)
model must be checked before data is loaded
错误于samplesSetLastChain(numChains) :
  it is required to have 1 <= last <= nchains
此外: 警告信息:
In readChar(modelFile, 10^3) : 在non-UTF-8 MBCS语言环境里只能读取字节

3,错误于bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE,  :
  Look at the log file and
try again with 'debug=TRUE' to figure out what went wrong within Bugs
.

问题1。是我把WinBUGS和OpenBugs都装在了D盘,除了重装,有没有什么解决办法?
2。如何修改下载的这程序包里的源程序?
3。以上报错的解决办法?
4。运行中WinBUGS程序快速闪过,看不清内容,如何处理?
刚刚接触R,望高手不吝赐教!

最佳答案

soccy 查看完整内容

如果使用R2WinBUGS包的话,两个主要functions: bugs和openbugs都有“bugs.directory=”这个选项。如果你的bugs在d盘,可以用bugs(..., bugs.directory="d:/Program Files/WinBUGS14/",...)。试试看。
关键词:R2WinBUGS winbugs WINBUG BRugs BUGS 运行 BRugs

沙发
soccy 发表于 2010-6-20 02:43:25
如果使用R2WinBUGS包的话,两个主要functions: bugs和openbugs都有“bugs.directory=”这个选项。如果你的bugs在d盘,可以用bugs(..., bugs.directory="d:/Program Files/WinBUGS14/",...)。试试看。

藤椅
soccy 发表于 2010-6-23 17:32:28
我的回答帮助你解决问题了吗?

板凳
autozhao 发表于 2010-6-23 18:41:33
soccy 发表于 2010-6-20 06:28
如果使用R2WinBUGS包的话,两个主要functions: bugs和openbugs都有“bugs.directory=”这个选项。如果你的bugs在d盘,可以用bugs(..., bugs.directory="d:/Program Files/WinBUGS14/",...)。试试看。
十分十分感谢您的答复,对不起,是我对您的答复,回复的慢了,本来我还想还有没有别人能给出什么结果的,呵呵。。
今天我又花点时间看怎么在MATLAB在调用winBUGS或者OpenBUGS来着,也是出了一堆问题,问题在这里http://www.pinggu.org/bbs/thread-841095-1-1.html

我按照您的方法,在命令里加入了bugs.directory="d:/Program Files/WinBUGS14/",结果提示:
错误于bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE,  :
  Look at the log file and
try again with 'debug=TRUE' to figure out what went wrong within Bugs.


总之十分感谢您。

报纸
autozhao 发表于 2010-6-23 19:29:33
另外我得到的log文件如下,我用的是网上给的例子,怎么check model还会有错呢?
check(C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/schools.bug.txt)
invalid or unexpected token scanned
data(C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/data.txt)
command #Bugs:data cannot be executed (is greyed out)
compile(3)
inits(1,C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/inits1.txt)
command #Bugs:inits cannot be executed (is greyed out)
inits(2,C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/inits2.txt)
command #Bugs:inits cannot be executed (is greyed out)
inits(3,C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/inits3.txt)
command #Bugs:inits cannot be executed (is greyed out)
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(1)
update(500)
command #Bugs:update cannot be executed (is greyed out)
set(theta)
command #Bugs:set cannot be executed (is greyed out)
set(mu.theta)
command #Bugs:set cannot be executed (is greyed out)
set(sigma.theta)
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(500)
command #Bugs:update cannot be executed (is greyed out)
coda(*,C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/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:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/history.odc)
command #Bugs:history cannot be executed (is greyed out)
save(C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/log.odc)
save(C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/RtmpKs0B7c/log.txt)

地板
soccy 发表于 2010-6-23 20:38:50
由于Matlab不是自由软件,我很少接触。我个人认为BUGS/JAGS与R的组合是比较理想的Bayesian分析平台(而且学习材料比较多)。

7
epoh 发表于 2010-6-23 21:05:09
1.在c碟,新建文件夹"Bugs",
作为working.directory

放进两文件schools.bug,schools.dat

2.注意你的winbugs安装路径
若不是"C:/Program Files/WinBUGS14/"

请依二楼soccy兄所言修改

3.in R 运行底下程序:

library(R2WinBUGS)
schools <- read.table ("c:/Bugs/schools.dat", header=TRUE)
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")
inits <- function() {list (theta=rnorm(J,0,100), mu.theta=rnorm(1,0,100), sigma.theta=runif(1,0,100))}
parameters <- c("theta", "mu.theta", "sigma.theta")
schools.sim <- bugs (data, inits=inits, parameters, "schools.bug", n.chains=3, n.iter=1000,debug=TRUE,
                     DIC=TRUE,bugs.directory = "C:/Program Files/WinBUGS14/",working.directory = "c:/Bugs")

print (schools.sim,digits=3)
plot (schools.sim)


Bugs.rar (628 Bytes)

8
autozhao 发表于 2010-6-24 00:47:25
十分感谢soccy与epoch二位仁兄的帮助。后来我把那个model自己重新存了一个文件,结果check model时就通过了,不知是不是网站上的schools.bug文件有什么错误。当然,epoch提供的Bugs文件同样好用。
另外,感觉通过在R下文件->改变工作目录 的方式指定working.directory的方法更方便一些。
而且,在R下运行,R的反应会很慢啊,还是全部命令都编好后运行,效率较高,不然得等半天才可以用R进行下一步分析。
现在又有一个问题,WinBUGS软件,我看到的例子大部分都是参数估计,不知可否进行预测。如,估计出SV模型的参数之后,如何进行out of sample的分析?是否这时需要在R的环境下编程实现。
望高手指点一二,不胜感激。

9
epoh 发表于 2010-6-24 07:15:57
1.schools.bug 就是网上提供的文件.
2.要做预测,可参考这个帖子;
   http://www.pinggu.org/bbs/thread-807868-1-1.html
只要修改一下winbugs程序

10
soccy 发表于 2010-6-24 07:59:25
建议读一下《Data Analysis Using Regression And Multilevel Hierarchical Models》这本书。书中361-363提到了如何作简单预测。如果要使用BUGS作Bayesian分析的话,这本书一定要看一看。

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

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