Wednesday, April 17, 2013

Discrete PMFs part 2. Binomial distribution. PMF proof and mean.

Now the binomial distribution. You'll see it's related to the Bernoulli for obvious reasons. It's defined as:
$$
 B(n,p)=\left\{
\begin{array}{ll}
\left( {\begin{array}{*{20}c} n \\ x \\ \end{array}} \right) P^{x}(1-P)^{n-x} \quad x=0,1,2,...,n\\
0,\quad \qquad \qquad \qquad otherwise
\end{array}
\right.
$$
Where:
$$\left( {\begin{array}{*{20}c} n \\ x \\ \end{array}} \right)=\frac{{n!}}{{x!\left( {n - x} \right)!}}$$
Is the binomial coefficient. Before I explain the importance of it, let's worry about the other part. Now, the Bernoulli distribution was really just concerned with one success and one failure. However, what if we're worried about many successes and failures? Let's say we want to run four different trials? Well, that looks like:
$$P^{x}(1-P)^{4-x}$$
Where $x$ is the number of success, and hence $(4-x)$ is the number of failures. But as you'll notice, this isn't the actual probability. Let's say that there were two successes. This would look like:
$$(P)^{2}(1-P)^2=(P)(P)(1-P)(1-P)$$
But, notice that this is the probability of getting two successes in a row, and then two failures. Another option would be:
$$(P)(1-P)(P)(1-P)$$
This is the the same amount of successes and failures, but a completely different order. Since order does matter for us, this is where the binomial coefficient comes in. It counts up all the different orders in which we can get a certain number of successes and failures. So the full equation becomes:
$$\left( {\begin{array}{*{20}c} n \\ x \\ \end{array}} \right) P^{x}(1-P)^{n-x}$$
Which is the probability of getting a certain number of successes in any order, multiplied the number of orders you can possibly get. For instance, flipping a coin twice and getting one head and one tail would be:
$$\left( {\begin{array}{*{20}c} 2 \\ 1 \\ \end{array}} \right) (\frac{1}{2})^{1}(1-\frac{1}{2})^{1}$$
Now, the binomial coefficient for these values equals:
$$\frac{{2!}}{{1!\left( {1} \right)!}}=\frac{2}{1}=2$$
And, multiplying this by the probability side gives:
$$(2)(\frac{1}{2})(\frac{1}{2})=(\frac{1}{2})$$
Which makes sense. The probability of getting a head then a tail in one order is $\frac{1}{4}$, yet there are two different ways to get it. Heads first, and heads second. So it becomes one half.

Alright, good stuff. But what about showing it's a probability function? It's obvious that it has $0\leq P$, since it's the same as the Bernoulli distribution (but this time with more successes and failures). But how do we know it adds up to one? Well, let's sum up all of the terms. That gives:
$$\sum_{0}^{n}\left( {\begin{array}{*{20}c} n \\ x \\ \end{array}} \right) P^{x}(1-P)^{n-x}$$
Remember we're summing up the $x$ terms, since the number of trials is set. What varies is the number or successes and failures. So, we have:
$$(1-P)^{n}+nP(1-P)^{n-1}+...+nP^{n-1}(1-p)+P^{n}$$
The first term is the event of failing every trial, the next one is all the events of succeeding once and failing $n-1$ times, all the way up to succeeding  $n$ times. Well, now we can use the binomial theorem, which states that:
$$(x+y)^{n}=\left( {\begin{array}{*{20}c} n \\ 0 \\ \end{array}} \right)x^{n}y^{0}+\left( {\begin{array}{*{20}c} n \\ 1 \\ \end{array}} \right)x^{n-1}y^{1}+...+\left( {\begin{array}{*{20}c} n \\ n-1 \\ \end{array}} \right)x^{1}y^{n-1}+\left( {\begin{array}{*{20}c} n \\ n \\ \end{array}} \right)x^{0}y^{n}$$
As you'll notice, if we use $y=1-P$ and $x=P$, this is exactly the same as our old equation. Well, reducing it to $(x+y)^n$ gives:
$$(x+y)^n=(P+1-P)^{n}=1^n=1$$
So this shows it's total probability is $1$, which is what we were trying to prove. Now what about the expectation and variance? Let's start with the expectation. That is:
$$\sum_{0}^{n}x\left( {\begin{array}{*{20}c} n \\ x \\ \end{array}} \right)P^{x}(1-P)^{n-x}$$
Writing it out gives:
 $$(0)\left( {\begin{array}{*{20}c} n \\ 0 \\ \end{array}} \right)P^{0}(1-P)^{n}+(1)\left( {\begin{array}{*{20}c} n \\ 1 \\ \end{array}} \right)P^{1}(1-P)^{n-1}+...+\left( {\begin{array}{*{20}c} n \\ n-1 \\ \end{array}} \right)P^{n-1}(1-P)^{1}+\left( {\begin{array}{*{20}c} n \\ n \\ \end{array}} \right)P^{n}(1-P)^{0}$$
Now, we can use this fact:
$$\frac{x(n)!}{(x)!(n-x)!}=\frac{(n)!}{(x-1)!(n-x)!}=n\left[\frac{(n-1)!}{(x-1)!(n-x)!}\right]$$
Now, the denominator of the fraction can be changed to $(x-1)!([n-1]-[x-1])!$, since simplifying the latter factorial still gives $(n-x)!$. Alright, well using this with our previous equation (since this is the coefficient of all of these), and simplifying a bit, we get:
$$nP\left[(1-P)^{n-1}+(n-1)P(1-P)^{n-2}+...+(n-1)P^{n-2}(1-P)+P^{n-1}\right]$$
Now, we can see the inside is the binomial coefficent:
$$\sum_{y=0}^{n-1}\left( {\begin{array}{*{20}c} n-1 \\ y \\ \end{array}} \right) P^{y}(1-P)^{n-1-y}=(P+(1-P))^{n-1}=(1)^{n-1}=1$$
Where $y=x-1$. So the equation reduces to $nP$, which is the mean.

For variance we have I'll save it for another blog post.

No comments:

Post a Comment