Simulations of the homogeneous Poisson process

require(ggplot2)
## Loading required package: ggplot2

The homogeneous Poisson process is simulated on \([0, 1]\) by simulating a Poisson distributed number of events and by simulating the event times from the uniform distribution on \([0, 1]\).

t <- 1
lambda <- 100
N <- rpois(1, lambda * t)
events <- sort(runif(N))
qplot(events, seq(1, N)) + 
  geom_abline(slope = lambda)

plot of chunk simulation

From the figure above we see that the cumulative number of events (the counting process) follows closely the straight line with slope \(\lambda\). The compensated counting process (in this example it means subtracting the expected number of events) \[X_t = N_t - \lambda t\] can also be plotted. First we plot it at the event times only.

Xt <- seq(1, N) - lambda * events
qplot(events, Xt)

plot of chunk compFig

We can get a more accurate visualization of the sample path of the compensated process by using a little ggplot2 magic. Specifically using the geom segment for showing the piecewise negative linear drift of the process in between jumps. It requires the computation of the left limits \(X_{t-}\) of \(X_t\).

Xtminus <- seq(1, N-1) - lambda * events[-1]
qplot(x = events[-N], 
      y = Xt[-N], 
      xend = events[-1], 
      yend = Xtminus, 
      geom = "segment") + 
  geom_point()

plot of chunk compFig2