焦静分享 http://blog.sciencenet.cn/u/jiaojiaojing 华师生态研二,以后从事理论生态学道路。

博文

winbugs

已有 12674 次阅读 2009-3-19 20:02 |个人分类:未分类|系统分类:科研笔记| winbugs

最近发现研究了metapopulation以后,涉及到了Gibber抽样和MCMC方法,这不,就涉及到了安装winbugs与R嵌合使用的问题,我研究了一个winbugs最经典的例子,但是winbugs好像很慢的,这个好奇怪啊,点了R后,R一直在运行状态,实在等不及了,就关掉了winbugs,然后报错了,说是什么找不到错误路径,想一个问题,是不是R和winbugs连用的时候,运行时间很久啊。我先把我的程序发上来吧,大家帮着看看。


先把这个程序用winbugs写好,保存在R软件运行的路径。以txt形式。


model {
     for (j in 1:J){
       y[j] ~ dnorm (theta[j], tau.y[j])
       theta[j] ~ dnorm (mu.theta, tau.theta)
       tau.y[j] <- pow(sigma.y[j], -2)
     }
     mu.theta ~ dnorm (0.0, 1.0E-6)
     tau.theta <- pow(sigma.theta, -2)
     sigma.theta ~ dunif (0, 1000)
   }
install.packages("arm")
install.packages("BRugs")
install.packages("Matrix")
install.packages("lme4")


然后再把一个schools.txt的文件也保存好,最后在R里面调用。程序为:


library("arm")


schools<-read.table("schools.dat",header=T)
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")
inits1<-list(theta=y,mu.theta=0,sigma.theta=1)
inits2<-list(theta=y,mu.theta=0,sigma.theta=10)
inits3<-list(theta=y,mu.theta=0,sigma.theta=100)
inite<-list(inits1,inits2,inits3)


> schools.sim<-bugs(data,inits,parameters,"schools.txt",n.chains=3,n.iter=3,debug=TRUE)


然后运行好久,没结果,我就把winbugs窗口关了,出来这个结果:

错误于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.


请问,我是运行过程有问题,还是说我过程没问题,仅仅是要再等等别关就好了啊,比较迷茫ing!



https://blog.sciencenet.cn/blog-90740-221349.html


下一篇:了解自己,挑战自己
收藏 IP: .*| 热度|

0

发表评论 评论 (2 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-14 01:47

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部