Hi! I keep getting error messaged as I tried to fit gamma distribution in hierarchical model. My goal was to fit semi parametric survival curve to data to get time-to-event. I have length of event (info: infectious period) of individual subject(id). few subjects have censored length of events (1 for censored, 2 for observed). the structure of my model is below. the error is at gamma_lpdf(infp[i]| alphaInf,betaInf).
" Exception: gamma_lpdf: Shape parameter[2] is nan, but must be positive finite!"
data{
int<lower=0> M; // data length
int id[M];
real infp[M];
real cens[M];
}
parameters{
real<lower=0> alpha; // log recovery rate
real<lower=0> beta;
real<lower=0> zalpha[M];
real<lower=0> zbeta[M];
real logsigmaA; // variation
real logsigmaB;
}
model{
vector[M] alphaInf;
vector[M] betaInf;
alpha ~ lognormal(0,5);
beta ~ lognormal(0, 5);
zalpha ~lognormal(0, 1);
zbeta ~ lognormal(0, 5);
logsigmaA ~normal(0,1);
logsigmaB ~normal(0,1);
for ( i in 1:M ) {
alphaInf[i] = alpha + zalpha[id[i]]*exp(logsigmaA) ;
betaInf[i] = log(beta) + zbeta[id[i]]*exp(logsigmaB) ;/
target += cens[i]*gamma_lpdf(infp[i]| alphaInf,betaInf) + (1-cens[i]) *log(1gamma_lcdf(infp[i]| alphaInf,betaInf));
}
}
The data looks like this
$M
[1] 372
$id
[1] 286 205 275 289 296 296 226 233 240 261 261 282 309 333 341 349 373 317 325
$infp
[1] 24 376 360 360 8 352 352 336 352 8 336 376 352 352 360 352 328 328 336 328 328 328
$cens
[1] 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1
I tried log transform and changing prior but it did not help. Should I tried different model where censored animals and non censored it calculated independently. thank you so much in advance