I’m trying to use stan to fit a simple poisson process model, and, maybe, to simulate data as well. Starting with the fitting.

In base R, I’d simply write something like:

```
Y<- (cumsum(rpois(102,lambda=5)))
x<-cumsum(c(0,rep(1,100)))
T <- length(Y)
plot(stepfun(x,Y),xlim = c(0,100), do.points = F)
```

This would return a plot like, with the event at time t on the x axis, and the number of counts Y at each t:

It’s not clear to me how to write the cumulative_sum in stan in such a way that we could either simulate or estimate our lambda parameter. A simple attempt to fit might look like this, provided the data above (this fails):

```
data {
int<lower=0> T; // number of events
int Y[T]; // the observed counts at event time T
}
parameters {
real<lower=-10,upper=10> lambda;
}
model {
// Priors
lambda ~ normal(5, 0.5); // our lambda estimate
for (t in 1:T) {
Y ~ cumulative_sum(poisson(lambda));
}
}
```

This doesn’t work, however. The cumulative_sum and poisson variables don’t play nice together. I’ve tried setting it up with `target +=`

and `poisson_lpmf`

instead of `poisson`

, but wasn’t able to suss out the correct syntax.

Any advice appreciated. Similar to this question which wasn’t followed-up by the original poster.