[R-sig-Geo] Help - calling OpenBugs through R2OpenBugs problem
ROONEYJ4 at tcd.ie
Wed Nov 27 21:13:30 CET 2013
Has anyone looked at this problem below ?
Even if nobody has an answer I'd be keen to know if the problem replicated for others.
From: r-sig-geo-bounces at r-project.org [r-sig-geo-bounces at r-project.org] On Behalf Of James Rooney [ROONEYJ4 at tcd.ie]
Sent: 23 November 2013 16:30
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] Help - caling OpenBugs thourgh R2OpenBugs problem
I am working on a Bayesian spatial smoothing project - and have implemented the BYM model, similar to the description in Chapter 11 of the ASDAR book. However, I have been having a huge problem calling OpenBugs from within R and I cannot figure out why. I would veyr much liek to do this as it would speed up the whole process. I'm stared at this for a omnth or two now to no avail so I'm hoping that somebody might spot a mistake. Basically when I call OpenBugs from R using the bugs command through R2OpenBugs - it throws a non-specific error and tells me to heck the bugs log file. The problem is Bugs does not generate one. This is made all the weirder by the fact that if I manually start up bugs and start it running using the data and inits files gnerated by R2OpenBugs - it runs fine without complaint. This is how I have been working so far. But I want to parallelize Bugs using Snow - so I need R2OpenBugs to work properly. I'm hoping someone here can help!!!
I've made a simulation to recreate the problem. My apologies it is a little complex, but I wanted to use the shapefile I'm actually working with which is freely downloadable for those willing to take a look.
So here goes.
1. Go here for the shapefile:
2. Click on the word "Disclaimer" to access the shapefiles (should you agree with the disclaimer!!). After clicking through the Disclaimer stuff, the file to download is: "Census2011_Electoral_Divisions_generalised20m.zip"
3. Set up a directory for this and save the shapefiles there.
4. You will need a bugs model. Cut and paste the below into a txt file and save it to your directory under the name "spatial_CAR.txt"
for(i in 1:N)
log(theta[i])<-alpha + u[i] + v[i]
5. Now open R and paste in the R code below. Remember to set your working directory to the same directory you saved the shapefiles and bugs model into. Also you might need to modify the path to OpenBugs on your machine.
6. Run the code. For me the final line throws the error:
"Error in bugs.run(n.burnin, OpenBUGS.pgm, debug = debug, WINE = WINE, :
Look at the log file in C:......<SNIP>................./R2OpenBugs Simulation and
try again with 'debug=TRUE' to figure out what went wrong within OpenBUGS."
I cannot figure out why!!! The log file does not exist!! If you manually open bugs and use the data and init files it works. Why ? No idea!!!!
Any and all help much appreciated!!!
Apologies for the length of this!!
setwd("....your working directory here......")
#Read in Spatial Polygon Data Frame
# Detect neighbours
nb<-poly2nb(SPolyDF,queen=T,snap=0.1) # snap at 100m distance
# Create nb weights
# Create BUGS CAR weights
# Simulate some count data for observed and expected cases
SPolyDF$obs<-sample.int(100, N, TRUE)
SPolyDF$exp<-sample.int(100, N, TRUE)
# Prep Data for OpenBugs
d<-list(N = N, observed = SPolyDF$obs, expected = SPolyDF$exp, adj=nbBugs$adj, weights=nbBugs$weights, num=nbBugs$num)
# Specify dir where bugs lives
BugsDir<-"C:/Program Files (x86)/OpenBUGS/OpenBUGS322"
# Define initial values for bugs
# Define working directory as current directory
# Openbugs call
R-sig-Geo mailing list
R-sig-Geo at r-project.org
More information about the R-sig-Geo