1

I have the following model in JAGS but sometimes it does not run, here is the code:

library(rjags)

model1 <- "model {
for (j in 1:nobs){
  y[j] ~ dbeta(lambda[j] + 10^(-323), 1-lambda[j] - 10^(-323)) 
  
  logit(lambda[j]) <- inprod(X[j, ], beta) 
}
beta[1] ~ dnorm(0,0.1)
beta[2] ~ dgamma(1,1)
}"


n_chains = 1
n_adapt = 5000
n_iter = 10000
n_thin = 1
n_burnin = 5000

# generate data
n = 100

Ffun = plogis
design_mat = cbind(1, matrix(seq(0,1,by = 0.2), ncol=1))

gen_data = function(n, beta) {
X = design_mat[sample(nrow(design_mat), size = n, replace = T), ]
lambda = Ffun(X %*% beta)
y = rbeta(n, lambda, 1-lambda)
list(X = X, y = y)
}


for (i in 1:50){
beta = as.matrix(c(-3, 5))
jags_data = gen_data(n, beta)
jags_data$nobs = n
jg_model <- jags.model(textConnection(model1),
                   data = jags_data,
                   n.chains = n_chains,
                   n.adapt = n_adapt)
update(jg_model, n.iter = n_burnin)
result <- coda.samples(jg_model, 
                       variable.names = c("beta"),
                       n.iter = n_iter, 
                       thin = n_thin,
                       n.chains = n_chains)

beta_est = list(apply(result[[1]],2,median))
}

But this sometimes run and sometimes gives this error:

Error in update.jags(object, n.iter, ...) : Error in node beta1 Slicer stuck at value with infinite density

and if I use a truncated Beta as was suggested here it gives the following error:

Error in jags.model(textConnection(model1), data = jags_data, n.chains = n_chains, : Error in node y1 Node inconsistent with parents

ie86
  • 157
  • 5
  • Have you tried adding a slightly larger offset i.e. instead of `10^-323` try `10^-4` . When you tried the `T(,)` method did you try if for the given values at the link or for `T(10^-323, 1-10^-323)`? – user20650 Sep 14 '20 at 12:27
  • @user20650 Thanks but it still gives error occasionally – ie86 Sep 14 '20 at 16:47

0 Answers0