Fitting a model with a Poisson process

Hi all, I’m trying to fit a model that includes a Poisson process

\begin{equation} \begin{split} X_t & = PoissonProcess(\lambda) \hspace{12pt} 0 \leq t \leq 100 \\ Y_i &\sim Normal(X_i, 0.05 ) \hspace{12pt} i = 1, \cdots 100 \end{split} \end{equation}

For illustration, see the picture below. The Poisson process X_t with rate \lambda generates 3 arrivals, at t=(20,50,80), which corresponds to dividing the timeline into 4 pieces. We observe only Y as noisy versions of the 4 means (0,1,2,3). Then given the data we want to do inference on at least \lambda, but X_t or the arrival times would be ideal.

poissonpic


Here’s what I have so far. It’s complaining about

  1. passing the array “int x[]” on line 3, and more importantly
  2. passing the poisson distribution to the normal distribution, near the end

Are these two insurmountable? Please let me know.

//Setting up the poisson model
functions {
    real cusum(int n, int x[]){
      int x2[n];
      x2[1] = x[1];
      for(i in 2:n){
        x2[i] = x2[i-1] + x[i];
      }
      return x2;
    }
  }
data {
    int<lower=0> T; // how long the time series is
    real Y[T]; // the observed data
  }
parameters {
  real<lower=0> lambda; // poisson rate
}
model {
  real lambda_vec[T];

  lambda ~ gamma(0.08,1); //prior
  lambda_vec = rep_array(lambda, T);


  Y ~ normal(cusum(poisson(lambda_vec)), 0.05);
  
}

We have a built-in cumulative_sum function, so you don’t need to write that one. That would require n == size(x).

This isn’t legal Stan code. I’m not quite sure what you’re trying to do here. Do you want poisson to be the Poisson log probability mass function? If so, it needs a variate. If you wanted those to be latent, that’s not something Stan can do unless they’re small and can be marginalized out.