Estimating a Probability

Time of arrival of individuals A and B Individual A arrives at a random time between 10 and 11:30pm and B arrives at a random time between 10:30 and 12:00am

What is the probability that individual B arrives before A?

What is the expected difference in the two arrival times?

We assume A and B are independent and uniformly distributed on times (10.5 and 12) for B and (10 to 11.5) for A

The probability is expressed as P(B < A)

We simulate a large number of values (1000) from the distribution of (A,B) independently

A = runif(1000, 10, 11.5)

B = runif(1000, 10.5, 12)

The probability P(B < A) is estimated by the proportion of simulated pairs (A,B) where A is a smaller than B. We count the number of pairs where A < B by the sum function and divide this by the total number of simulations

prob = sum(B < A)/1000
prob
## [1] 0.206

The estimated probability that B arrives before A P(B < A) is 0.225

plot(A, B)
polygon(c(10.5, 11.5, 11.5, 10.5),
        c(10.5, 10.5, 11.5, 10.5), density = 10, angle = 135)

The Monte Carlo estimate of the probability is the proportion of points that fall in the shaded region.

Let’s now compute the standard error (SE) of a proportion of this estimate

sqrt(prob * (1 - prob)/1000)
## [1] 0.01278921

Applying a normal approximation for the sampling distribution of p there is a 95% confidence that the probability B will arrive earlier than A is between

0.225 - 1.96 * 0.0132
## [1] 0.199128
0.225 + 1.96 * 0.0132
## [1] 0.250872

What is the expected difference in the two arrival times?

E(B - A)

difference = B - A

The Monte Carlo estimate of E(B - A) is the mean of these differences. The estimated standard error of this sample mean estimate is the standard deviation of the differences divided by the square root of the simulation sample size

mc.est = mean(difference)
se.est = sd(difference)/sqrt(1000)
c(mc.est, se.est)
## [1] 0.53367780 0.01926714

So we estimate that B will arrive 0.5 hours later than A; since the standard error is only 0.02 hours, there is a 95% confidence that the true difference is within 0.04 hours of this estimate