我使用R2WinBUGS包时出错

时间:2013-02-26 05:04:58

标签: r winbugs

全部 我使用R软件包R2WinBUGS与R.Rowever一起运行Winbugs程序 无法正常工作。附上以下代码

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)

但是,此代码有以下错误

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)

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

WANHAI

1 个答案:

答案 0 :(得分:2)

您的数据是字符串列表。而是使用:

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