'Generate non-homogeneous Poisson process in R

I am attempting to use a thinning algorithm (described below) to generate the first 10 time units of a non-homogeneous Poisson process in R. The intensity function λ(t) = 3 + 4/(t+1)

Thinning algorithm:

Step 1: t = 0, I = 0.

step 2: Generate a random number U.

step 3: t = t − 1/λ (log U). If t > T , stop.

step 4: Generate a random number U.

step 5: If U <= λ(t)/λ, set I = I + 1, S(I) = t.

step 6: Go to Step 2

t = time

I = number of events that have occurred by time t.

S(I) = the most recent event time

The final value of I represents the number of events at time T, and S(1), . . . , S(I) are the event times.

I have some example code from a lecture that I'm trying to use to figure this out, but I have not come very far. Any ideas on what I can try to do? (I'm a noob to coding, so if you have any ideas keep that in mind when explaining)

PoissonTime<-function(s,lambdat,lambda)
 {
  t<-s
  repeat{
    U<-runif(2)
    t<-t-log(U[1])/lambda
    if (U[2]<=lambdat/lambda)
    {Ts=t;break;}
  }
  return(Ts)
}

#### An intensity function for Poisson process

lambdat<-function(t,TT)
{
  rho<-t/TT
  lambdat<- 3 + (4/(t+1))
  return(lambdat)
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source