The Waiting Time Paradox, or, Why Is My Bus Always Late? | Pythonic Perambulations
Image Source: Wikipedia License CC-BY-SA 3.0
If you, like me, frequently commute via public transit, you may be familiar with the following situation:
You arrive at the bus stop, ready to catch your bus: a line that advertises arrivals every 10 minutes. You glance at your watch and note the time... and when the bus finally comes 11 minutes later, you wonder why you always seem to be so unlucky.
Naïvely, you might expect that if buses are coming every 10 minutes and you arrive at a random time, your average wait would be something like 5 minutes.<br>In reality, though, buses do not arrive exactly on schedule, and so you might wait longer.<br>It turns out that under some reasonable assumptions, you can reach a startling conclusion:
When waiting for a bus that comes on average every 10 minutes, your average waiting time will be 10 minutes.
This is what is sometimes known as the waiting time paradox.
I've encountered this idea before, and always wondered whether it is actually true... how well do those "reasonable assumptions" match reality?<br>This post will explore the waiting time paradox from the standpoint of both simulation and probabilistic arguments, and then take a look at some real bus arrival time data from the city of Seattle to (hopefully) settle the paradox once and for all.
The Inspection Paradox¶
If buses arrive exactly every ten minutes, it's true that your average wait time will be half that interval: 5 minutes.<br>Qualitatively speaking, it's easy to convince yourself that adding some variation to those arrivals will make the average wait time somewhat longer, as we'll see here.
The waiting time paradox turns out to be a particular instance of a more general phenomenon, the inspection paradox, which is discussed at length in this enlightening post by Allen Downey: The Inspection Paradox Is Everywhere.
Briefly, the inspection paradox arises whenever the probability of observing a quantity is related to the quantity being observed.<br>Allen gives one example of surveying university students about the average size of their classes. Though the school may truthfully advertise an average of 30 students per class, the average class size as experienced by students can be (and generally will be) much larger. The reason is that there are (of course) more students in the larger classes, and so you oversample large classes when computing the average experience of students.
In the case of a nominally 10-minute bus line, sometimes the span between arrivals will be longer than 10 minutes, and sometimes shorter, and if you arrive at a random time, you have more opportunities to encounter a longer interval than to encounter a shorter interval. And so it makes sense that the average span of time experienced by riders will be longer than the average span of time between buses, because the longer spans are over-sampled.
But the waiting time paradox makes a stronger claim than this: when the average span between arrivals is $N$ minutes, the average span experienced by riders is $2N$ minutes.<br>Could this possibly be true?
Simulating Wait Times¶
To convince ourselves that the waiting time paradox is making a reasonable claim, let's start by simulating a stream of buses that arrive at an average of 10 minutes.<br>For the sake of numerical accuracy, we will simulate a large number of bus arrivals: one million buses (or approximately 19 years of round-the-clock 10-minute headways):
In [1]:
import numpy as np
N = 1000000 # number of buses<br>tau = 10 # average minutes between arrivals
rand = np.random.RandomState(42) # universal random seed<br>bus_arrival_times = N * tau * np.sort(rand.rand(N))
Just to confirm we've done things correctly, let's check that the mean interval is close to $\tau = 10$:
In [2]:
intervals = np.diff(bus_arrival_times)<br>intervals.mean()
Out[2]:
9.9999879601518398
With these bus arrivals simulated, we can now simulate the arrival of a large number of passengers to the bus stop during this span, and compute the wait time that each of them experiences.<br>Let's encapsulate this in a function for later use:
In [3]:
def simulate_wait_times(arrival_times,<br>rseed=8675309, # Jenny's random seed<br>n_passengers=1000000):<br>rand = np.random.RandomState(rseed)
arrival_times = np.asarray(arrival_times)<br>passenger_times = arrival_times.max() * rand.rand(n_passengers)
# find the index of the next bus for each simulated passenger<br>i = np.searchsorted(arrival_times, passenger_times, side='right')
return arrival_times[i] - passenger_times
We can then simulate some wait times and compute the average:
In [4]:
wait_times = simulate_wait_times(bus_arrival_times)<br>wait_times.mean()
Out[4]:
10.001584206227317
The average wait time is also close to 10 minutes, just as the waiting time paradox predicted.
Digging Deeper: Probabilities & Poisson Processes¶
How can we understand what's going on here?
Fundamentally, this is an instance of...