Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

r - the error when I use R2WinBUGS packages

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)                   

}

and the R codes

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...