Lc_decg
Lc_decg

Reputation: 189

bayesian survival analysis wth rstan

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.

Upvotes: 0

Views: 869

Answers (1)

Ben Goodrich
Ben Goodrich

Reputation: 4990

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.

Upvotes: 1

Related Questions