使用R2WinBUGS软件包时的错误 [英] the error when I use R2WinBUGS packages

查看:142
本文介绍了使用R2WinBUGS软件包时的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部, 我使用R包R2WinBUGS来运行带有R的Winbug.但是,该程序 无法正常工作.附加以下代码

all, I employ the R packages R2WinBUGS to run Winbugs with R.However,the program is not able to work well.The following codes attached

panel.bug:

model{
   for(i in 1:N){
       for(t in 1:T){
           y[i,t]~dnorm(mu[i,t],tau)
           mu[i,t]<-alpha+gamma1*a[i,t]+gamma2*b[i,t]+gamma3*c[i,t]+gamma4*d[i,t]+gamma5*e[i,t]+gamma6*f[i,t]
             }
     }

       gamma1~dnorm(1,25)
       gamma2~dnorm(1,25)
       gamma3~dnorm(1,25)
       gamma4~dnorm(1,25)
       gamma5~dnorm(1,25)
       gamma6~dnorm(1,25)
       alpha~dnorm(0,16) 
       tau~dgamma(1,1.75)
       sigma.tau<-1/sqrt(tau)                   

}

和R代码

library(R2WinBUGS)
N=50
T=4
y=rnorm(50*4, mean = 0, sd = 1)
a=rnorm(50*4, mean = 0.1, sd = 1)
b=rnorm(50*4, mean = 0.2, sd = 1)
c=rnorm(50*4, mean = 0.3, sd = 1)
d=rnorm(50*4, mean = 0.4, sd = 1)
e=rnorm(50*4, mean = 0.5, sd = 1)
f=rnorm(50*4, mean = 0.6, sd = 1)

data=list("N","T","y","a","b","c","d","e","f")
inits = function() {list(alpha=0.99,gamma1=0.89,gamma2=0.2, gamma3=0.4, gamma4=0.1,     gamma5=1.1, gamma6=0.7,tau=0.1)}
parameter <- c("alpha","gamma1","gamma2","gamma3","gamma4","gamma5","gamma6","tau") 
msv.sim <- bugs(data,inits, parameter,model.file="c:/Bugs/msv/panel.bug",n.chains=2,
           n.thin=20,n.iter=1100,n.burnin=100,codaPkg=TRUE,debug=TRUE,DIC=TRUE,
           bugs.directory="C:/Program Files/WinBUGS14/",working.directory =  "c:/Bugs/msv/")
attach.bugs(msv.sim)
print(msv.sim,digits=4)

但是,此代码存在如下错误

However,this codes have some errors as following

display(log)
check(c:/Bugs/msv//panel.bug.txt)
model is syntactically correct
data(c:/Bugs/msv/data.txt)
expected key word structure
compile(2)
inits(1,c:/Bugs/msv/inits1.txt)
command #Bugs:inits cannot be executed (is greyed out)
inits(2,c:/Bugs/msv/inits2.txt)
command #Bugs:inits cannot be executed (is greyed out)
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(20)
update(5)
command #Bugs:update cannot be executed (is greyed out)
set(alpha)
command #Bugs:set cannot be executed (is greyed out)
set(gamma1)
command #Bugs:set cannot be executed (is greyed out)
set(gamma2)
command #Bugs:set cannot be executed (is greyed out)
set(gamma3)
command #Bugs:set cannot be executed (is greyed out)
set(gamma4)
command #Bugs:set cannot be executed (is greyed out)
set(gamma5)
command #Bugs:set cannot be executed (is greyed out)
set(gamma6)
command #Bugs:set cannot be executed (is greyed out)
set(tau)
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(50)
command #Bugs:update cannot be executed (is greyed out)
coda(*,c:/Bugs/msv/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/msv/history.odc)
command #Bugs:history cannot be executed (is greyed out)
save(c:/Bugs/msv/log.odc)
save(c:/Bugs/msv/log.txt)

任何建议将不胜感激. 非常感谢.

Any suggestions will be appreciated. Thanks very much.

wanhai

推荐答案

您的数据是一个字符串列表.而是使用:

Your data is a list of character strings. Instead use:

 data<-list(N=N,T=T,y=y,a=a,b=b,c=c,d=d,e=e,f=f)

这篇关于使用R2WinBUGS软件包时的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆