0
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ see stats.stackexchange.com/questions/308730/… $\endgroup$ – Glen_b Sep 23 '18 at 23:44
  • $\begingroup$ 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. $\endgroup$ – SecretAgentMan Sep 29 '18 at 4:55
  • $\begingroup$ 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). $\endgroup$ – Glen_b Sep 29 '18 at 5:24
1
$\begingroup$

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: enter image description here

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

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:

% 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')    
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). SamplePaths


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$.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.