# Trajectory of homogeneous poisson process

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?

• – Glen_b -Reinstate Monica Sep 23 '18 at 23:44
• Just want to point out that @Glen_b provides a link to a great example but do note it is for a Compound Poisson Process (CPP), not a nonhomogenous Poisson Process (NHPP). The plotting the sample path part is the point, not the mathematics in the link. – SecretAgentMan Sep 29 '18 at 4:55
• This is correct; I should have made it clear that it wasn't the precise thing asked for here, but of some value in trying to draw one (but if it were the same thing as asked for here, I'd have closed it as a duplicate). – Glen_b -Reinstate Monica Sep 29 '18 at 5:24
• For many more threads on this topic, search our site for queue simulation. – whuber Oct 30 '19 at 14:36

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]))
segments(
x0 = c(0, arrival_time[-n]),
y0 = c(0, counts[-n]),
x1 = arrival_time,
y1 = c(0, counts[-n])
)


Output:

• Thank you so much!! What if I wanted to combine all 12 months into one plot? is that possible? – SugarMarsh Sep 23 '18 at 23:55

The code below plots the counting process $$\{N(t),t \ge 0\}$$ with rate $$\lambda(t)$$ taken from this example. It plots three arbitrary sample paths {5, 10, 15} from the 2000 generated.

It will work for a stationary Poisson Process (PP) with fixed rate $$\lambda$$ as well.

MATLAB code:

% MATLAB R2018b
% Plots paths p1, p2, p3
p1 = 5; p2 = 10;, p3 = 15;

figure, hold on, box on
s(1) = stairs([0 EventTimes{p1,:}],0:length([EventTimes{p1,:}]),'b-')
s(2) = stairs([0 EventTimes{p2,:}],0:length([EventTimes{p2,:}]),'r-')
s(3) = stairs([0 EventTimes{p3,:}],0:length([EventTimes{p3,:}]),'k-')
plot([EventTimes{p1,:}],zeros(1,length([EventTimes{p1,:}])),'bx')
plot([EventTimes{p2,:}],zeros(1,length([EventTimes{p2,:}])),'rx')

% Cosmetics
title('3 x Sample Paths for NHPP')
xlabel('Time')
ylabel('N(t): Number of events by time t')
set(s,'LineWidth',1.5)


Sample paths plotted below with event times shown (on horizontal axis) for two of them (red & blue).

Update: Based on OP comment, For a fixed $$t$$, $$N(t)\sim\text{Poisson}(m(t))$$ where $$m(t) = \int_0^t \lambda(s)ds$$.

So based on the OP's comment regarding $$N(365)$$, $$N(365)$$ is distributed Poisson with mean $$m(365) = \int_0^{365} \lambda(s)ds$$.

• how would I plot the distribution of the total number of events, so N(t)? – SugarMarsh Sep 29 '18 at 10:46
• How do you want to plot it? For a certain $t$? Can you give me more details? – SecretAgentMan Sep 29 '18 at 14:25
• For the entire period, number of events in 365 days, would it just be hist () – SugarMarsh Sep 29 '18 at 21:43