Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "Slicer stuck at value with infinite density" running binomial-beta model in JAGS

Tags:

jags

rjags

I'm trying to run a binomial-beta model in JAGS (see example code below). I keep getting the error: Error: The following error was encountered while attempting to run the JAGS model:

Error in node a0
Slicer stuck at value with infinite density

which I am struggling to make sense of. I thought perhaps the initial conditions were sending the beta distribution into infinite regions of parameter space but after some investigation that doesn't seem to be the case. Any thoughts on what this error means or how to adjust the code to accomodate it?

I've put my code below along with some made up sample data. This is the kind of data I might expect in my dataset.

#Generate some sample data
counts = c(80,37,10,43,55,23,53,100,7,11)
 n = c(100,57,25,78,55,79,65,100,9,11)
consp = c(1.00, 0.57, 0.25, 0.78, 0.55, 0.79, 0.65, 1.00, 0.09, 0.11)
treat = c(0.5,0.5,0.2,0.9,0.5,0.2,0.5,0.9,0.5,0.2)

#Model spec
model1.string <-"model{
for (i in 1:length(counts)){
counts[i] ~ dbin(p[i],n[i])
p[i] ~ dbeta( ( mu[i] * theta[i]) , ((1-mu[i])*theta[i]))
mu[i] <- ilogit(m0 + m1*consp[i] + m2*treat[i])
theta[i] <- exp(n0 + n1*consp[i])
}
m0 ~ dnorm(0, 1)
m1 ~ dnorm(0, 1)
m2~ dnorm(-1, 1)
k0 ~ dnorm(1, 1)
k1 ~ dnorm(0, 1)
}"

#Specify number of chains
chains=5
#Generate initial conditions
inits=replicate(chains, list(m0 = runif(1, 0.05, 0.25),
m1 = runif(1, 0,0.2),
m2=runif(1,-1,0),
k0 = runif(1, 0.5, 1.5),
k1 = runif(1, 0, 0.3)),simsplify = F)

#Run
model1.spec<-textConnection(model1.string)
results <- autorun.jags(model1.string,startsample = 10000,
data = list('counts' = counts,
'n' = n,
'consp'=consp,
"treat"=treat),
startburnin=5000, 
psrf.target=1.02,
n.chains=5,
monitor = c("m0", "m1", "m2","k0", "k1"), inits = inits),
like image 511
C Yeates Avatar asked Nov 21 '25 05:11

C Yeates


1 Answers

The slice sampler (which is used by JAGS) doesn't work when the probability density of the sampled variable is infinite at a point. This can happen with the Beta distribution at 0 or 1.

A work around is to truncate the node that creates the problem, as in:

p[i] ~ dbeta( ( mu[i] * theta[i]) , ((1-mu[i])*theta[i])) I(0.001,0.999)

(I don't really remember the syntax, but JAGS definitively allows truncated random variables)

like image 150
altroware Avatar answered Nov 23 '25 13:11

altroware



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!