Hi all,
I am having issues with right-censored data. I have followed the section on how to format censored data from the nimble user guide. I have also provided valid initial values for my censored data so I'm unsure why my mcmc sampler is giving me errors for every single censored data point. I sadly can't share data, but I will share code below.
Thanks in advance for your help!
library(nimble)
library(coda)
nimbCode <- nimbleCode({
shape ~ dunif(0, 10)
for(i in 1:ninds) {
lambda[i] <- exp(beta0 + beta2*x[i])
censored[i] ~ dinterval(t[i], c[i])
t[i] ~ dweib(shape, lambda[i])
}
beta0 ~ dunif(-50, 50)
beta1 ~ dnorm(0, 1)
beta2 ~ dnorm(0, 1)
})
# Build NIMBLE model
nimbMod <- nimbleModel(
nimbCode,
const = list(ninds = nrow(dat),
c = dat$c),
data = list(t = dat$daysMonitored,
x = dat$treatment,
censored = dat$censored),
inits = list(shape = 0.5,
beta0 = 5,
beta1 = 0,
beta2 = 0,
t = dat$daysMonitoredInit)) # initialize censored data with valid values
comp.mod <- compileNimble(nimbMod)
conf.mod <- configureMCMC(comp.mod, monitors = c('beta0', 'beta2', 'shape'),
enableWAIC = TRUE)
mod.mcmc <- buildMCMC(conf.mod)
c.mod <- compileNimble(mod.mcmc)
mcmc.out <- runMCMC(c.mod,
niter=10000,
nburnin=1000,
nchains=4,
thin = 1,
WAIC=TRUE)
post.samples <- mcmc.list(sapply(mcmc.out$samples,
as.mcmc,simplify=FALSE))
sum <- summary(post.samples)
plot(post.samples, trace=TRUE, density=FALSE)
gelman.plot(post.samples)
autocorr.plot(post.samples)
## posterior summary
summary(post.samples)
## model assessment using WAIC value
mcmc.out$WAIC
# simulate new datasets
deps <- comp.mod$getDependencies(c("beta0", "beta1", "beta2", "shape"),
downstream = TRUE, self = FALSE)
comp.mod$simulate(deps, includeData = TRUE)