[R-sig-Geo] Resolved -> RE: Help - calling OpenBugs through R2OpenBugs problem
James Rooney
ROONEYJ4 at tcd.ie
Sun Dec 1 18:05:34 CET 2013
Dear all,
With thanks to Virgilio, we have resolved this issue. The problem was with my specification of the pathway to the bugs directory. My code was:
BugsDir<-"C:/Program Files (x86)/OpenBUGS/OpenBUGS322/"
.....when I should have had........:
BugsDir<-"C:/Program Files (x86)/OpenBUGS/OpenBUGS322/OpenBugs.exe"
Apparently my original code was enough for R2OpenBugs to not complain about not finding the executable, but not enough for it to run correctly!
Many thanks anyone who attempted to help here. Special thanks to Virgilio for helping me find the problem!
James
________________________________________
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: 27 November 2013 21:13
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] Help - calling OpenBugs through R2OpenBugs problem
Dear Virgilio,
Many thanks for taking a look at it!
That 'debug = TRUE' is already set!!!! It doesn't make any difference!!
I'm running R in Windows 7 through Parallels on a Macbook Pro (OSx Mavericks). I have shut down OsX and booted purely into windows and it doesn't make any difference.
I've experienced this problem under both R 2.15 and R 3.01. It also happens both in R Studio and in the standard R interface. I have Openbugs version 3.2.2. Running latest version of the packages used.
My thinking is that something is crashing OpenBugs when it attempts to open - but I cant' figure out how or why. I wonder is there a file size limit for passing things into OpenBugs ?
Appreciate any help!
James
________________________________________
From: Virgilio Gómez-Rubio [virgilio.gomez at uclm.es]
Sent: 27 November 2013 20:29
To: James Rooney
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] Help - calling OpenBugs through R2OpenBugs problem
Dear James,
I'll be happy to look into this but I will need more information about
your system. Also, could you run the code using 'debug=TRUE' as seen in
the error message?
Best wishes,
Virgilio
On mié, 2013-11-27 at 20:13 +0000, James Rooney wrote:
> Hi everyone,
>
> 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.
>
> Many thanks,
>
> James
>
> ________________________________________
> 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
>
> Hi all,
>
> 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:
> http://www.cso.ie/en/census/census2011boundaryfiles/
>
> 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"
>
> model
> {
>
> for(i in 1:N)
> {
> observed[i]~dpois(mu[i])
> log(theta[i])<-alpha + u[i] + v[i]
> mu[i]<-expected[i]*theta[i]
> u[i] ~dnorm(0,tau)
> }
>
> v[1:N]~car.normal(adj[],weights[],num[],precv)
>
> alpha ~dflat()
> tau ~dgamma(0.001,0.001)
> precv ~dgamma(0.1,0.1)
> }
>
> 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!!
>
> James
>
>
> R Code:
>
> library(rgdal)
> library(spdep)
> library(R2OpenBUGS)
>
> setwd("....your working directory here......")
>
> #Read in Spatial Polygon Data Frame
> SPolyDF<-readOGR(".","Census2011_Electoral_Divisions_generalised20m",TRUE)
>
> # Detect neighbours
> nb<-poly2nb(SPolyDF,queen=T,snap=0.1) # snap at 100m distance
>
> # Create nb weights
> nb.w<-nb2listw(nb,zero.policy=T,style="B")
>
> # Create BUGS CAR weights
> nbBugs<-listw2WB(nb.w)
>
> # Simulate some count data for observed and expected cases
> N<-nrow(SPolyDF)
> 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
> inits<-list(
> list(u=rep(0,N),v=rep(0,N),alpha=0,tau=0.0001,precv=0.002)
> ,list(u=rep(0,N),v=rep(0,N),alpha=0.1,tau=0.0002,precv=0.001))
>
> # Define working directory as current directory
> wdir=getwd()
>
> # Openbugs call
> MCMCres<-bugs(data=d,inits=inits,parameters.to.save =c("theta","alpha","tau","precv"),
> n.iter=1000,model.file="spatial_CAR.txt",n.chains=2,n.burnin=100,n.thin=1,
> OpenBUGS.pgm=BugsDir,working.directory=wdir,codaPkg=F,debug=T)
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list