# Simulating the waiting paradox

After seeing this question, I thought I would try to simulate the bus waiting time paradox to help my understanding. However, what I got was the "intuitive" result, rather than that predicted by the theory.

# draw from Poisson distribution and create the cumulative sum for the bus times
buses <- cumsum(rpois(1000,10))
# draw from uniform distribution and sort for the person arrival times
arrivals <- sort(runif(1000)*1000*10)
# find out which bus is the next bus for each arrival
nextbus <- sapply(arrivals, function(x) which((buses-x)>=0)[1])
# calculate waiting times and present summary statistics
summary(buses[nextbus]-arrivals)
Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's
0.02765  2.53200  4.94400  5.48200  7.80200 19.96000       11


As you can see, the mean wait is a little over half of the mean for the Poisson process. What did I do wrong?

• You want the times the buses arrive to compute waiting time (exponential), not how many there are in a given time (Poisson). – Glen_b -Reinstate Monica Nov 5 '14 at 14:51

You should simulate the Poisson process of bus arrival times by a vector of cumulative exponential variates. So buses <- cumsum(rexp(1000, rate=1/10)).