Inhomogeneous Poisson Process with single rate change - Divergent Transitions


I am attempting to model a poisson process with a rate change. I am relatively new to stan (and coding in general) so forgive me for any obvious mistakes or poor syntax.

data {
  real<lower=0> T;                //total observation time
  int<lower=1> N;                 //number of observations
  vector[N] D;                    //inter arrival time data

parameters {
  real<lower=0> lambda1;          //Early rate
  real<lower=0> lambda2;          //Late rate
  real<lower=0> s;                //Time of rate change
transformed parameters {
  real<lower=0> N1;               //Number of arrival before rate change
  N1 = 0;
  for (i in 1:N) {
    if (cumulative_sum(D)[i] < s) {
      N1 = i;
model {
  target += -N1*log(1/lambda1) - lambda1*s;
  target += -(N-N1)*log(1/lambda2) - lambda2*(T-s);
  lambda1 ~ exponential(580);
  lambda2 ~ exponential(580);
  s ~ uniform(0,T);

My point was that even if I run this model with simulated data:
simuldata <- rep(0,23)
simuldata[1:10] <- rexp(10,0.001)
simuldata[11:23] <- rexp(13,0.002444)
I have divergent transitions. Is it possible to reduce these divergent transitions? I feel it could be related to the transformed parameter N1, but I haven’t been able to make any progress


1 Like

Can you supply your R call to Stan? I wanted to make sure I had this right, is T = sum(D)?