Skip to content

Errors when saving output from WinBUGS to R

4 messages · yiyiwang, Uwe Ligges

#
Dear all

I used R2WinBUGS package's bugs() function to generate MCMC results. Then I
tried to save the simulation draws in R, using read.bugs() function. Here is
a simple test:
######################
library(coda)
library(R2WinBUGS)
#fake some data to test
beta0=1
beta1=1.5
beta2=-1
beta3=2
N=200
x1=rnorm(N, mean=0,sd=1)
x2=rnorm(N, mean=0,sd=1)
x3=rnorm(N, mean=0,sd=1)
lambda2= exp(beta0+ beta1*x1+ beta2 * x2 + beta3 * x3)
y=rep(NA,N)
for (i in 1: N) {
y[i]=rpois(1,lambda2[i])
}
#generate inputs required by winbugs
data <- list(Y20=y,x1=x1, x2=x2, x3=x3, N=N)
inits<- function(){
list(beta0=0, beta1=0, beta2=0, beta3=0)}
parameters <- c("beta0", "beta1", "beta2", "beta3")
#call winbugs using bugs() function
model <- bugs(data, inits, parameters,
model.file="C:/Jinmodel/test_codes/model_poisson.txt", n.chains=1,
n.iter=30, n.burnin=0,n.thin=1, codaPkg=TRUE, DIC=TRUE, debug=TRUE,
bugs.directory="C:/Users/Yiyi/Desktop/winbugs14/WinBUGS14") 
###########################################
 
I can get pretty good traceplots & parameter estimate outputs in WinBUGS.
However, when I switched back to the R Console (by pressing ESC key), a
warning message occurred:  
Warning message:
running command '"C:/Users/Yiyi/Desktop/winbugs14/WinBUGS14/WinBUGS14.exe"
/par "C:/Users/Yiyi/AppData/Local/Temp/Rtmpgdvr4Z/script.txt"' had status 93 

I ignored this message  & typed in the following code to save the outputs
into R:
################### 
myres <- read.bugs(model)
 ####################
An error message occurred: Error in is.vector(X) : object 'model' not found

I've been trying to solve this mystery for several weeks but couldn't make
any breakthough. 
 
Any suggestions are highly appreciated!
 
Best,
 
Yiyi
 
p.s. 0) the program is running in a Windows 7 Home Premium, 64-bit operating
system machine. 
             R version:   2.13.2, WinBUGS 14
       1) some old posts suggest running the software as the administrator
(to kill the warning message). Can anyone shed more light on how to log in
as the administrator? I am the sole user of my own laptop, not using the
pc's at my office.  So I doubt administrator is the issue.
       2) The second time I run the bugs() function, no warning message of
status 93 emerged.
       3) perhaps the warning message & the error message are somehow
related??



--
View this message in context: http://r.789695.n4.nabble.com/Errors-when-saving-output-from-WinBUGS-to-R-tp4644899.html
Sent from the R help mailing list archive at Nabble.com.
#
On 03.10.2012 17:51, yiyiwang wrote:
.... which is the explanation. Just close WinBUGS regularly rather than 
interrupting the R function that executes WinBUGS and waits for its results.

You may also want to update to a recent version of R.

Best,
Uwe Ligges


 > , a
#
Sorry for any cross messaging. Here are what I've tried and more info. The
error sticks :(

I installed the latest R2.15.1 (64bit) on my machine, per Uwe's comments.
The same error happened. Log file of WinBUGS look perfectly normal:
###########################
display(log)
check(C:/Jinmodel/test_codes/model_poisson.txt)
model is syntactically correct
data(C:/Users/Yiyi/AppData/Local/Temp/RtmpSAhD25/data.txt)
data loaded
compile(1)
model compiled
inits(1,C:/Users/Yiyi/AppData/Local/Temp/RtmpSAhD25/inits1.txt)
model is initialized
gen.inits()
command #Bugs:gen.inits cannot be executed (is greyed out)
thin.updater(1)
update(0)
set(beta0)
set(beta1)
set(beta2)
set(beta3)
set(deviance)
dic.set()
update(30)
coda(*,C:/Users/Yiyi/AppData/Local/Temp/RtmpSAhD25/coda)
stats(*)

Node statistics
	 node	 mean	 sd	 MC error	2.5%	median	97.5%	start	sample
	beta0	1.652	0.7417	0.3092	1.025	1.381	4.121	1	30
	beta1	1.383	0.1343	0.05416	0.8926	1.442	1.49	1	30
	beta2	-0.8984	0.1197	0.0496	-1.008	-0.9378	-0.4977	1	30
	beta3	1.745	0.2898	0.1212	0.7972	1.874	1.988	1	30
	deviance	2461.0	4410.0	1458.0	745.0	880.1	23240.0	1	30
dic.stats()

DIC
Dbar = post.mean of -2logL; Dhat = -2LogL at post.mean of stochastic nodes
	Dbar	Dhat	pD	DIC	
Y20	2461.040	1205.070	1255.970	3717.010	
total	2461.040	1205.070	1255.970	3717.010	
history(*,C:/Users/Yiyi/AppData/Local/Temp/RtmpSAhD25/history.odc)
#######################################



--
View this message in context: http://r.789695.n4.nabble.com/Errors-when-saving-output-from-WinBUGS-to-R-tp4644899p4644936.html
Sent from the R help mailing list archive at Nabble.com.
#
So have you closed WinBUGS regularly (and not via Esc in R) now?

Uwe Ligges
On 03.10.2012 21:29, yiyiwang wrote: