Monday, February 27, 2017

Probability: Difference between "exactly..." and "at least..."

In probability, I have to pay close attention to the problem statement because I easily make errors. As an example, let's say I toss a fair coin n times. What is the probability of
  1. Exacly 1 head
  2. At least 1 head
The figure below has n as the x axis and the two different probabilites as y axis. As you can see, the "exactly 1 head" probability decreases with n while the "at least 1 head" probability increases with n.

Matlab script for generating the plot:
n = 1:16;
pExactly1 = n./2.^n;
plot(n, pExactly1); grid on
hold on
pAtLeast1 = 1-(1-0.5).^n;
plot(n, pAtLeast1)
legend('exactly 1 heads', 'at least 1 heads')
xlabel('n'); ylabel('p')
Note that you can also get probability of at least 1 heads with this sum: pExactly1Head + pExactly2Heads + ... + pExactlyNHeads, where
pExactlyKHeads = nchoosek(n,k) * ph^k * (1-ph)^(n-k)
Even simpler: 1 - pExactly0Heads = 1 - nchoosek(n,0) * ph^0 * (1-ph)^(n-0).

For more information, visit Khan Academy.

No comments: