Hi everyone,
I’m just trying to adapt the example code in the Stan manual to fit a censored Gamma model
// simple censored gamma
data {
int<lower=0> Nseen;
array[Nseen] real<lower=11> y;
int<lower=0> Nmiss;
}
parameters {
real mu;
real sigma;
}
transformed parameters{
real<lower=0> a;
real<lower=0> b;
a = square(mu/sigma);
b = mu/square(sigma);
}
model {
mu ~ gamma(10, .6);
sigma ~ exponential(0.3);
y ~ gamma(a, b);
target += gamma_lcdf(11 | a, b)*Nmiss;
}
I generate some fake data like this:
gg <- rgamma(800, 15^2/2.5^2, 15/2.5^2)
gg_trunc <- gg[gg>11]
hist(gg_trunc, xlim = c(0, 100))

And then sample it like this:
censor_model_vec <- cmdstan_model(stan_file = "truncated/gamma_censor_vec.stan")
censor_model_vec_samp <- censor_model_vec$sample(data = list(
Nseen = length(gg_trunc),
y = gg_trunc,
Nmiss = (length(gg) - length(gg_trunc))),
parallel_chains = 4)
censor_model_vec_samp <- censor_model_vec$sample(data = list(Nseen = length(gg_trunc),
y = gg_trunc,
Nmiss = (length(gg) - length(gg_trunc))),
parallel_chains = 4)
The resulting samples have VERY bad diagnostics, in terms of Rhat and ESS
variable mean median sd mad q5 q95 rhat ess_bulk ess_tail
lp__ -1898.03 -1898.40 4.09 5.23 -1903.53 -1891.77 2.98 4 33
mu 15.02 15.00 0.45 0.63 14.54 15.62 3.51 4 11
sigma 3.44 3.43 0.07 0.08 3.36 3.53 3.58 4 11
a 19.09 19.15 0.46 0.65 18.46 19.67 2.74 4 23
b 1.27 1.27 0.01 0.01 1.25 1.29 2.73 4 11
Have I done something wrong? I predict I’ve missed some obvious point of how to correctly work with the censored data. Thanks for any advice!
Created on 2022-06-22 by the reprex package (v2.0.0)