I'm trying to fit a simple exponential model for left censored data using RSTAN to replicate something I did in JAGS.
The JAGS model is:
model{
for(i in 1:N){
isAboveLOD[i] ~ dinterval(x[i], LOD[i])
x[i] ~ dexp(lambda)
}
lambda ~ dgamma(0.001, 0.001)
}
A full explanation of the simulated data can be found at http://jamescurran.co.nz/2014/06/bayesian-modelling-of-left-censored-data-using-jags/, but the essence of it is that the data had 9691 censored values (out of 10,000) and that the data was originally sampled from an Exp(1.05) distribution, with left censoring performed at log(29).
When I run this model with RSTAN, I essentially get no movement in the chain, and hence the estimate of lambda is way off (0.3 in my first run). I'm sure the error is elementary, but I'd like your advice. My RSTAN code (including data simulation) is given below.
expCode = '
data {
int<lower=0> nObs;
int<lower=0> nCens;
real<lower=0> yObs[nObs];
real<lower=0> U;
}
parameters {
real<lower=0, upper=U> yCens[nCens];
real<lower=0> lambda;
}
model {
for (n in 1:nObs)
yObs[n] ~ exponential(lambda);
for (n in 1:nCens)
yCens[n] ~ exponential(lambda);
lambda ~ gamma(0.001, 0.001);
}
'
set.seed(35202)
x = rexp(10000, rate = 1.05)
## set all the censored values to NA's
x[x < log(29)] = NA
yObs = x[!is.na(x)]
yCens = x[is.na(x)]
dataList = list(nObs = length(yObs), nCens = length(yCens), U = log(29), yObs = yObs)
library(rstan)
fit = stan(model_code = expCode, data = dataList, iter = 1000, chains = 1)