R上でWinBUGSを動かすためにR2WinBUGSというパッケージを使っています。
一度、WinBUGSで動作確認が取れたコードをRに移植してRの文法に置き換えたものが以下のコードになります。問題は、このコードの最後にあるbugs関数を使ったあとにWinBUGSが立ち上がるのですが、WinBUGSで一時ファイルが開けないというエラーメッセージが出てしまいます。
一時ファイルのフォルダには確かにここで指定されている"model.bug.txt"というファイルが存在するので、開けないという問題が何を指しているのかよくわかりません。
どなたか、R2WinBUGSを使ってMCMCを回したことのある方、教えて頂ければ幸いです。
R
1library(R2WinBUGS) 2 3model <- function() 4{ 5 for (i in 1:N) 6 { 7 y[i] ~ dpois(lambda[i]) 8 log(lambda[i]) <- b[1] + b[2]*i 9 } 10 for (j in 1:2) 11 { 12 b[j] ~ dnorm(0.0, 1.0E-6) 13 } 14} 15 16#filename <- file.path(tempdir(),"model.bug")#####この部分を書き直した##### 17filename <- file("C:\Rstudio\model.bug", "w") 18write.model(model, filename) 19 20#Data 21y <- c(15,11,14,17,5,11,10,4,8,10,7,9,11,3,6,1,1,4) 22N <- 18 23data <- list("y","N") 24 25#parameter setting 26parameter <- c("b") 27 28#initial value setting 29initial <- function(){ 30 list(b=c(0,0)) 31} 32 33#Start WinBUGS 34result <- bugs(data=data, inits = initial, parameters = parameter, 35 model.file="model.bug", n.chains = 3, n.iter = 10000, n.burnin=1000, n.thin = 2, 36 bugs.directory = "C:\Program Files\WinBUGS14", 37 working.directory = "C:\Rstudio",codaPkg = TRUE, debug=T) 38
また、WinBUGS側でのエラーは以下のようなものになります。
display(log)
check(C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/model.bug.txt)
cannot open C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/model.bug.txt
data(C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/data.txt)
command #Bugs:data cannot be executed (is greyed out)
compile(3)
inits(1,C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/inits1.txt)
command #Bugs:inits cannot be executed (is greyed out)
inits(2,C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/inits2.txt)
command #Bugs:inits cannot be executed (is greyed out)
inits(3,C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/inits3.txt)
command #Bugs:inits cannot be executed (is greyed out)
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(2)
update(500)
command #Bugs:update cannot be executed (is greyed out)
set(b)
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(4500)
command #Bugs:update cannot be executed (is greyed out)
coda(,C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/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:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/history.odc)
command #Bugs:history cannot be executed (is greyed out)
save(C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/log.odc)
save(C:/Users/Ÿ©—m/AppData/Local/Temp/RtmpueOG7F/log.txt)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/01 06:49
2018/02/01 07:33