[R] R crashes when communicating with JAGS

David Wooff d.a.wooff at durham.ac.uk
Thu Aug 11 14:09:58 CEST 2011


There is a thread on this topic already:
http://finzi.psych.upenn.edu/Rhelp10/2010-August/250934.html

I'm rather mystified by a similar problem and wondering whether I've 
overlooked something obvious. I'm running with latest versions of R and 
all packages, and latest version of JAGS running under Windows 7.

Here's the problem. I have some source code. It's given below - standard 
stuff - seeds example from BUGS volume 1. I'm using R2WinBUGS only to 
create the model file, and R2jags as a front end to JAGS. I have the 
same problem whether or not I use R2jags.

1. If I start RGUI and source the code from a source file. R crashes 
when it tries to execute jags().

   Problem Event Name:	APPCRASH
   Application Name:	Rgui.exe
   Application Version:	2.131.56322.0
   Application Timestamp:	4e171fac
   Fault Module Name:	StackHash_486a
   Fault Module Version:	6.1.7601.17514
   Fault Module Timestamp:	4ce7ba58
   Exception Code:	c0000374
   Exception Offset:	000ce653
   OS Version:	6.1.7601.2.1.0.768.3
   Locale ID:	2057
   Additional Information 1:	486a
   Additional Information 2:	486a33f7a181da7ba2feae88b7ee12b6
   Additional Information 3:	9e02
   Additional Information 4:	9e02b3fab8ac2ab41c0e936dfef5c6d4

2. If I start RGUI and cut and paste the code from a source file. 
Everything works fine.

3. If, after (2) I source the code - and other examples from source 
files - everything works fine.

This seems to indicate that there is some kind of initialization which 
needs to happen before JAGS will work; that this initialization is 
carried out when typing commands into the console, but not carried out 
when sourcing identical commands from a source file.

I have tried delaying issuing the jags command when sourcing (using 
readline()) in case the issue was with readiness of the bugs model being 
written to file; but the crash still happens with any such delay.

I'd be most grateful for tips to circumvent this behaviour.

Cheers,

David

Here's the test code:
#-------------------------------------------
    require(R2WinBUGS)
    require(rjags)
    require(R2jags)
    ## write model file:
    print(list.modules())
    write.model(con="blah.bug",model=function() {
       for( i in 1 : N ) {
          r[i] ~ dbin(p[i],n[i])
          b[i] ~ dnorm(0.0,tau)
          logit(p[i]) <- alpha0 + alpha1 * x1[i] + alpha2 * x2[i] +
          alpha12 * x1[i] * x2[i] + b[i]
       }
       alpha0 ~ dnorm(0.0,1.0E-6)
       alpha1 ~ dnorm(0.0,1.0E-6)
       alpha2 ~ dnorm(0.0,1.0E-6)
       alpha12 ~ dnorm(0.0,1.0E-6)
       tau ~ dgamma(0.001,0.001)
       sigma <- 1 / sqrt(tau)
    })
    g<-jags(model.file='blah.bug',
               data = list(r = c(10, 23, 23, 26, 17, 5, 53, 55, 32, 46, 
10, 8, 10, 8, 23, 0, 3, 22, 15, 32, 3),
       n = c(39, 62, 81, 51, 39, 6, 74, 72, 51, 79, 13, 16, 30, 28, 45, 
4, 12, 41, 30, 51, 7),
       x1 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1),
       x2 = c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 
1, 1),
       N = 21),
               parameters=c('alpha0', 'alpha1','alpha2','alpha12','tau'),
               inits=list(alpha0 = 0, alpha1 = 0, alpha2 = 0, alpha12 = 
0, tau = 1) ,
               n.iter=10000)
#-------------------------------------------


-- 
Dr David Wooff,
Director, Statistics and Mathematics Consultancy Unit,
& Senior Lecturer in Statistics, University of Durham.
Department of Mathematical Sciences, Science Laboratories,
South Road, Durham, DH1 3LE, UK. email: d.a.wooff at dur.ac.uk
Tel. 0191 334 3121, Fax 0191 334 3051.
Web: http://maths.dur.ac.uk/stats/people/daw/daw.html



More information about the R-help mailing list