Solved – Trajectory of homogeneous poisson process

poisson processrsimulation

I am trying to simulate number of claims in next 12 months using a homogeneous poisson process following the R codes:

lambda <- 17
# the length of time horizon for the simulation T_length <- 31
last_arrival <- 0
arrival_time <- c()
inter_arrival <- rexp(1, rate = lambda)
while (inter_arrival + last_arrival < T_length) { 
last_arrival <- inter_arrival + last_arrival 
arrival_time <- c(arrival_time,last_arrival) 
inter_arrival <- rexp(1, rate = lambda)

And I get a list with around 500 elements, then I repeat this for each of the twelve months, how do I plot the trajectory of the counting process?

Best Answer

The following code plots a line chart with the appropriate jumps.

n <- length(arrival_time)
counts <- 1:n

plot(arrival_time, counts, pch=16, ylim=c(0, n))
points(arrival_time, c(0, counts[-n]))
  x0 = c(0, arrival_time[-n]),
  y0 = c(0, counts[-n]),
  x1 = arrival_time,
  y1 = c(0, counts[-n])

Output: enter image description here