0

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.

Lc_decg
  • 187
  • 1
  • 10
  • 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 Sep 15 '18 at 22:54
  • Also, you can write the likelihood as `stay ~ weibull(shape, exp(-scale / shape));` – Ben Goodrich Sep 15 '18 at 22:55
  • 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 Sep 17 '18 at 09:57
  • 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 Sep 17 '18 at 12:42
  • 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 Sep 17 '18 at 14:23
  • See https://github.com/stan-dev/stan/wiki/Prior-Choice-Recommendations . The exponential is easy because it only has one (rate) parameter. – Ben Goodrich Sep 18 '18 at 03:45

1 Answers1

1

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.

Ben Goodrich
  • 4,870
  • 1
  • 19
  • 18
  • It's the OPs model, so the priors have to reflect what the OP believes about the parameters before seeing the data. I don't have any particular insight into this data generating process, but I usually use exponential priors on hyperparameters that are standard deviations. – Ben Goodrich Sep 16 '18 at 00:47
  • I see what you mean now. @Lc_decg are you asking about syntax? – Ben Goodrich Sep 16 '18 at 13:07