I am trying to understand how dinterval() works in JAGS for censored data. I am modeling coarse data where I only have upper and lower bounds for each data point (not the true value). Here is a simple example of how I think it should work:
Some upper and lower bounds for each point:
> head(lim)
L U
[1,] 14.98266 15.68029
[2,] 21.21827 21.91590
[3,] 18.34953 19.04716
[4,] 19.00186 19.69949
[5,] 15.39891 16.09654
[6,] 17.81705 18.51468
A function to write the model (assuming the data come from a normal with a common mean and variance):
playmodel <- function(){
for (i in 1:50){
is.censored[i] ~ dinterval(t[i], lim[i,])
t[i] ~ dnorm(mu,tau)
}
mu ~ dnorm(0,.001)
tau ~ dgamma(.01,.01)
}
filename <- "toymod.bug"
write.model(toymod,filename)
Some functions and assignments for the jags call:
data <- list("lim"=lim)
inits <- list(mu=rnorm(1),tau=rgamma(1,.01,.01),t=as.vector(apply(lim,1,mean)))
#last part is to ensure the starting value is between the upper and lower limit
#each chain will start at the same place for t but this is just for this case
params <- c("mu","tau")
And run the model:
playmodel.jags <- jags(data,inits, params, model.file="toymod.bug", n.chains=3,
n.iter=50000,n.burnin=30000, n.thin=1, DIC=TRUE,
working.directory=NULL,refresh = 50000/50, progress.bar = "text")
What happens when I run this?
1) my estimate of mu hovers right around 0 when it should be 15
2) it will not run if DIC=TRUE:
error: "Error in jags.samples(model, variable.names, n.iter, thin, type = "trace", : Failed to set trace monitor for node deviance
Note: I can get a similar model running in OpenBUGS by omitting the dinterval() line and appending I(Lower,Upper) to dnorm.