Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Binomial (n,p)(n, p) probabilities involve powers and factorials, both of which are difficult to compute when nn is large. This section is about simplifying the computation of the entire distribution. The result also helps us understand the shape of binomial histograms.

🎥 See More
Loading...

6.5.1Consecutive Odds Ratios

Fix nn and pp, and let P(k)P(k) be the binomial (n,p)(n, p) probability of kk. That is, let P(k)P(k) be the chance of getting kk successes in nn independent trials with probability pp of success on each trial.

The idea is to start at the left end of the distribution, with the term

P(0) = (1p)nP(0) ~ = ~ (1-p)^n

Then we will build up the distribution recursively from left to right, one possible value at a time.

To do this, we have to know how the probabilities of consecutive values are related to each other. For k1k \ge 1, define the kkth consecutive odds ratio

R(k)=P(k)P(k1)R(k) = \frac{P(k)}{P(k-1)}

These ratios help us calculate P(k)P(k) recursively.

P(0)=(1p)nP(1)=P(0)P(1)P(0)=P(0)R(1)P(2)=P(1)R(2)\begin{align*} P(0) &= (1-p)^n \\ \\ P(1) &= P(0) \cdot \frac{P(1)}{P(0)} = P(0)R(1) \\ \\ P(2) &= P(1)R(2) \end{align*}

and so on.

Even though we already have a formula for the binomial probabilities, building the distribution using consecutive ratios is better computationally and also helps us understand the shape of the distribution.

🎥 See More
Loading...

6.5.2Binomial Consecutive Odds Ratios

How is this more illuminating than plugging into the binomial formula? To see this, fix k1k \ge 1 and calculate the ratio R(k)R(k).

R(k)=(nk)pk(1p)nk(nk1)pk1(1p)nk+1=nk+1kp1p   (after cancellation)\begin{align*} R(k) &= \frac{\binom{n}{k}p^k(1-p)^{n-k}} {\binom{n}{k-1}p^{k-1}(1-p)^{n-k+1}} \\ \\ &= \frac{n-k+1}{k} \cdot \frac{p}{1-p} ~~~ \text{(after cancellation)} \end{align*}

Notice that the formulas for R(k)R(k) are simple. This makes it easy to compute P(k)P(k) recursively. For example, if n3n \ge 3, we can compute P(3)P(3) as

P(3)=(1p)n(n1+11p1p)(n2+12p1p)(n3+13p1p)P(3) = (1-p)^n \big( \frac{n - 1 + 1}{1} \cdot \frac{p}{1-p} \big) \big( \frac{n - 2 + 1}{2} \cdot \frac{p}{1-p} \big) \big( \frac{n - 3 + 1}{3} \cdot \frac{p}{1-p} \big)

6.5.3Shapes of Binomial Histograms

Now observe that comparing R(k)R(k) to 1 tells us whether the histogram is going up, staying level, or going down at kk.

R(k)>1    P(k)>P(k1)R(k)=1    P(k)=P(k1)R(k)<1    P(k)<P(k1)\begin{align*} R(k) > 1 &\iff P(k) > P(k-1) \\ R(k) = 1 &\iff P(k) = P(k-1) \\ R(k) < 1 &\iff P(k) < P(k-1) \end{align*}

Note also that the form

R(k)=(n+1k1)p1pR(k) = \big( \frac{n+1}{k} - 1 \big) \cdot \frac{p}{1-p}

tells us the the ratios are a decreasing function of kk. In the formula, nn and pp are the parameters of the distribution and hence constant. It is kk that varies, and kk appears in the denominator.

This implies that once R(k)<1R(k) < 1 for some kk, it will remain less than 1 for all larger kk. In other words, once the histogram starts going down, it will keep going down. It cannot come back up again.

That is why binomial histograms are either non-increasing or non-decreasing, or they go up and come down. But they can’t look like waves on the seashore. They can’t go up, come down, and go up again.

🎥 See More
Loading...

Let’s visualize this for a n=23n = 23 and p=0.7p = 0.7, two parameters that have no significance other than being our choice to use in this example.

n = 23
p = 0.7
k = range(n+1)
bin_23_7 = stats.binom.pmf(k, n, p)
bin_dist = Table().values(k).probabilities(bin_23_7)
Plot(bin_dist)
<matplotlib.figure.Figure at 0x10f4a5780>
# It is important to define k as an array here,
# so you can do array operations
# to find all the ratios at once.
k = np.arange(1, n+1, 1)
((n - k + 1)/k)*(p/(1-p))
array([53.66666667, 25.66666667, 16.33333333, 11.66666667, 8.86666667, 7. , 5.66666667, 4.66666667, 3.88888889, 3.26666667, 2.75757576, 2.33333333, 1.97435897, 1.66666667, 1.4 , 1.16666667, 0.96078431, 0.77777778, 0.61403509, 0.46666667, 0.33333333, 0.21212121, 0.10144928])

What Python is helpfully telling us is that the invisible bar at 1 is 53.666... times larger than the even more invisible bar at 0. The ratios decrease after that but they are still bigger than 1 through k=16k = 16. The histogram rises till it reaches its peak at k=16k = 16. You can see that R(16)=1.1666>1R(16) = 1.1666 > 1. Then the ratios drop below one, so the histogram starts going down.

6.5.4Mode of the Binomial

A mode of a discrete distribution is a possible value that has the highest probability. There may be more than one such value, so there may be more than one mode.

We have seen that once the ratio R(k)R(k) drops below 1, it stays below 1, so the histogram keeps falling. To identify the mode, therefore, we will find all values of kk such that R(k)1R(k) \ge 1.

Let q=1pq = 1-p. Every value kk for which R(k)1R(k) \ge 1 must satisfy

(n+1k1)pq  1\big( \frac{n+1}{k} - 1 \big) \frac{p}{q} ~ \ge ~ 1

That is,

n+1k  qp+1 = 1p\frac{n+1}{k} ~ \ge ~ \frac{q}{p} + 1 ~ = ~ \frac{1}{p}

which is equivalent to

k  (n+1)pk ~ \le ~ (n+1)p

We have shown that for all kk in the range 0 through the integer part of (n+1)p(n+1)p, the histogram rises; for larger kk, it falls.

Therefore the peak of the histogram is at the largest kk in this range. That’s the integer part of (n+1)p(n+1)p.

So the integer part of (n+1)p(n+1)p is a mode of the binomial.

Because the odds ratios are non-decreasing in kk, the only way in which there can be more than one mode is if there is a kk such that R(k)=1R(k) = 1. In that case, P(k)=P(k1)P(k) = P(k-1) and therefore both kk and k1k-1 will be modes. To summarize:

The mode of the binomial (n,p)(n, p) distribution is the integer part of (n+1)p(n+1)p. If (n+1)p(n+1)p is an integer, then (n+1)p1(n+1)p - 1 is also a mode.

To see that this is consistent with what we observed in our numerical example above, let’s calculate (n+1)p(n+1)p in that case.

(n+1) * p
16.799999999999997

The integer part of (n+1)p(n+1)p is 16, which is the mode that we observed.

But in fact, npnp is a more natural quantity to calculate. For example, if you are counting the number of heads in 100 tosses of a coin, then the distribution is binomial (100,1/2)(100, 1/2) and you naturally expect np=50np = 50 heads. You don’t want to be worrying about 101×(1/2)101 \times (1/2).

In fact you don’t have to worry when nn is large, because then npnp and (n+1)p(n+1)p are pretty close. In a later section we will examine a situation in which you can use npnp to get an approximation to the shape of the binomial distribution when nn is large.