0
votes

I want to construct stan(rstan) code for survival analysis using weibull distribution. But my stan code always can't work. If Anyone knows how to deal with my problem, please teach me.

My data is like that

Movement:(time that took oranisum behavior) Treat: experimental treament that have two categorical variable "A", "B" r_Day: random effects considering day-specific effects

And My stan code is like below.

data {
     int N; // all data
     int D; // day
     int <lower = 0, upper = 1> Treat[N]; 
     int <lower = 0> Movment[N];
     int <lower = 1, upper = D> Day[N];
     }

 parameters {
      real <lower = 0> shape; // shape parameter
      vector[2] beta; 
      real r_Day[D];
      real <lower = 0> sigma_D; 
      }

transformed parameters{
    vector[N] scale; // scale parameter
    for(n in 1:N) scale[n] = beta[1] + beta[2]*Treat[n] + r_Day[Day[n]];
    }


model {
    for(n in 1:N) Movment[n] ~  weibull(shape, exp(-(scale[n]/shape))) ;
    for (d in 1:D) r_Day[d] ~ normal(0, sigma_D);
}

But this code always get error "Log probability evaluates to log(0), i.e. negative infinity. Stan can't start sampling from this initial value. Rejecting initial value:" and samplings stop.

Please teach me how to deal with this errors.

1
You can write the transformed parameters block in one line with vector[N] scale = beta[1] + beta[2] * Density + sigma_D *r_Day[Day]; if you define Density in the data block. - Ben Goodrich
Also, you can write the likelihood as stay ~ weibull(shape, exp(-scale / shape)); - Ben Goodrich
Sorry. I edited some codes, because I wrote mistaken code. Yes, what I want to confirm is the syntax. Is this suitable code ? - Lc_decg
I think it is valid syntax, but it is slower than necessary and still likely defines an improper posterior distribution due to the lack of proper priors on the common parameters. - Ben Goodrich
For the coefficients in the linear predictor and standard deviation in the random effects, I defined non-informative prior(uniform(0, 10e+4)) as stan default setting. But I don't know what types of priors is suitable for the shape parameter. You commented the use of exponential priors, and is there recomended priors? This is the first time to analysis data with weibull distribution. And my major is ecology, there few people analyzing data with weibull distribution. So If you give me some advices, it's so helpful for anaysis. - Lc_decg

1 Answers

1
votes

This is likely due to the fact that you declare sigma_D in the parameters block but do not use it and do not put a prior on it. Thus, the distribution you define is improper. I presume you meant to scale r_Day by sigma_D, but you should still put proper priors on all the parameters.