Mac OS X 上で OpenBUGS+R2OpenBUGS を使用する

「Mac OS X 上で、WinBUGS+R2WinBUGS を使用する」に刺激されて「Mac OS X 上で、OpenBUGS+R2OpenBUGS を使用する」を試みた。

実際に参考にしたWeb情報は次です。

  1. Running WinBUGS on MacOSX via Wine
  2. Running OpenBUGS on Mac Using Wine
  3. OpenBUGS

pc の環境は OS X Mountain Lion で macport と XQuartz がインストールされている。この状態から始めた。

1. Wine のインストール

 web-1 に従って macport を使ってwine をインストールした。

2. OpenBUGS のインストール

  web-2 に従って OpenBUGS をインストールした。起動を試したところ次のエラーメッセージが現れたが、よくわからないので構わず次に進めた。

$ wine ~/.wine/Program\ Files/OpenBUGS/OpenBUGS322/OpenBUGS.exe
fixme:ole:RemUnknown_QueryInterface No interface for iid {00000019-0000-0000-c000-000000000046}
err:ole:CoReleaseMarshalData IMarshal::ReleaseMarshalData failed with error 0x8001011d
$
3. パッケージ R2OpenBUGS  のインストール

R を実行しコンソール画面から次を入力してインストールした。

install.packages('R2OpenBUGS',type='source')

4. Rによる OpenBUGS + R2OpenBUGS の実行

 wine-OpenBUGS.R を実行した。bugs を実行したところで同じメッセージが現れたが結果を得ることができた。

#Load the OpenBUGS Package - make sure XQuartz is running
library(R2OpenBUGS)

#schools data in the R2OpenBUGS library
data(schools)

#define the model
nummodel <- function(){
  for (j in 1:J){
    y[j] ~ dnorm (theta[j], tau.y[j])
    theta[j] ~ dnorm (mu.theta, tau.theta)
    tau.y[j] <- pow(sigma.y[j], -2)}
  mu.theta ~ dnorm (0.0, 1.0E-6)
  tau.theta <- pow(sigma.theta, -2)
  sigma.theta ~ dunif (0, 1000)
}

# write the model code out to a file
write.model(nummodel, "nummodel.txt")
model.file1 = paste(getwd(),"nummodel.txt", sep="/")
## and let's take a look:
file.show("nummodel.txt")

#prepare the data for input into OpenBUGS
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")

#initialization of variables
inits <- function(){
  list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100), sigma.theta = runif(1, 0, 100))}
  
#set the WINE working directory and the directory to OpenBUGS 
#- change the OpenBUGS.exe location as necessary
WINE="/opt/local/bin/wine"
WINEPATH="/opt/local/bin/winepath"
OpenBUGS.pgm="/Users/satouy/.wine/drive_c/Program Files/OpenBUGS/OpenBUGS322/OpenBUGS.exe"

#these are the parameters to save
parameters = c("theta", "mu.theta", "sigma.theta")

#run the model
schools.sim <- bugs(data, inits, model.file = model.file1,
                    parameters=parameters,
                    n.chains = 3, 
                    n.iter = 5000, 
                    OpenBUGS.pgm=OpenBUGS.pgm,
                    WINE=WINE,
                    WINEPATH=WINEPATH
                    useWINE=T)

#R will pause. When model is complete a prompt will reappear
print(schools.sim)
Inference for Bugs model at "/Users/satouy/Dropbox/workR/winBUGS/OpenBUGS/nummodel.txt", 
Current: 3 chains, each with 5000 iterations (first 2500 discarded)
Cumulative: n.sims = 7500 iterations saved
            mean  sd  2.5%  25%  50%  75% 97.5% Rhat n.eff
theta[1]    11.2 8.9  -2.8  5.5  9.8 15.7  32.9    1   410
theta[2]     7.5 6.5  -4.9  3.4  7.4 11.5  20.8    1   420
theta[3]     5.8 8.0 -12.3  1.3  6.4 10.5  21.0    1  1200
theta[4]     7.1 6.7  -6.3  3.0  7.1 11.2  20.9    1   610
theta[5]     4.9 6.3  -8.8  1.0  5.5  9.1  16.4    1   680
theta[6]     5.8 6.8  -9.2  1.7  6.1 10.1  18.3    1   490
theta[7]    10.4 7.2  -2.1  5.6  9.7 14.6  26.3    1   300
theta[8]     8.1 8.0  -7.1  3.4  7.8 12.4  25.7    1   420
mu.theta     7.6 5.4  -2.7  4.1  7.6 11.0  18.6    1   310
sigma.theta  6.7 5.9   0.2  2.3  5.3  9.4  21.8    1   540
deviance    60.5 2.3  57.0 59.2 60.1 61.6  66.2    1  1600

For each parameter, n.eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor (at convergence, Rhat=1).

DIC info (using the rule, pD = Dbar-Dhat)
pD = 2.9 and DIC = 63.4

この結果の正しさを確認するため VMFusion5 の Windows7 にインストールした OpenBUGS で実行した。その結果は同じであった。したがって、メッセージを出力したが正しく動いていることが確認できた。

お願い

このメッセージを解決する方法を知りたいのですが、教えていただければ幸いです。

$ wine ~/.wine/Program\ Files/OpenBUGS/OpenBUGS322/OpenBUGS.exe
fixme:ole:RemUnknown_QueryInterface No interface for iid {00000019-0000-0000-c000-000000000046}
err:ole:CoReleaseMarshalData IMarshal::ReleaseMarshalData failed with error 0x8001011d

その後 ( Jan 2015 )

Mac OS X Mavericks へのアップデートい伴い、Macport を使わなくなった。検索して次を見つけた。

  1.  Installing OpenBUGS or WinBUGS in Mac OS X using Wineskin http://archives.aidanfindlater.com/blog/2010/07/22/installing-openbugs-in-mac-os-x-using-winebottler/
  2. WindowsアプリをMac 上で簡単に動かせるツールWineskin
    http://safx-dev.blogspot.jp/2012/07/windowsmacwineskin.html

インストールは無事成功した。 上記のテストプログラムの中で, WINE, WINEPATH, OpenBUGS.prg を次のように変更すれば動くことを確認した。

WINE="/usr/local/bin/wine"
WINEPATH="/usr/local/bin/winepath"
OpenBUGS.pgm="/Users/satouy/Applications/Wineskin/OpenBUGS.app/Contents/Resources/drive_c/Program Files/OpenBUGS/OpenBUGS323/OpenBUGS.exe"

目次へ