I am trying to simulate the compound Poisson process using the next algorithm that I found in a textbook on stochastic processes.
- Let $S_0 = 0$.
- Generate i.i.d. exponential random variables $X_1, X_2, \ldots$
- Let $S_n=X_1+\cdots + X_n,$ for $n = 1, 2, \ldots$
- For each $k = 0, 1, \ldots,$ let $N_t = k,$ for $S_k\le t\le S_{k+1}$
S <- vector(mode="integer", length=100)
S[1] = 0
## Generation of Exponential random variables with parameter lambda
X <- rexp(n=100, rate=0.1)
for(n in 1:100){
S[n] = sum(X[1:n])
}
But, I am not clear about how to write the step $4$, maybe I need to put the integer between two $S_k$ (the arrival times)? I am interested in the counting process $N_t$.
Furthermore, how do you plot it?
I have something like that, but I am not clear if the arrival times are ok, because, in the first plot on the left, I see that every arrival time is not necessarily in the vertical line of the process, and on the right all the arrival times have the same length, I think that it contradicts the independence of the arrival times.
nro<-10
S<-vector(mode="integer",length = nro)
S[1]=0
##Generation of Exponential random variables with parameter lambda
X<-rexp(n =nro,rate = 2)
for(n in 1:nro)
S[n]=sum(X[1:n])
S<-cumsum(X)
n_func <- function(t, S) sapply(t, function(t) sum(S < t))
t_series <- seq(0, max(S), by = max(S)/nro)
#Plot of the trajectory and add lines in the arrival times
par(mfrow=c(1,2))
plot(t_series, n_func(t_series, S),type =
"s",ylab=expression(N[t]),xlab="t",las=1,cex.lab=0.8,main="Poisson
Process",cex.axis=0.8)
grid()
abline(v = S,col="red",lty=2)
plot(t_series, n_func(t_series, S),type =
"s",ylab=expression(N[t]),xlab="t",las=1,cex.lab=0.8,main="Poisson
Process",cex.axis=0.8)
grid()
abline(v = t_series,col="blue",lty=4)
Best Answer
You want to get a function of $t$ that gives the count of events. So simply do
$S$ is basically the time stamps of each Poisson events in your sample. So you want to just count the number of events that have time stamped before $t$.