全部,我使用R包R2WinBUGS用R运行Winbugs。但是,程序不能正常工作。附上以下代码
面板错误:
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)
任何建议将不胜感激。非常感谢。
万海