Binomial Distribution.mws
High School Modules > Advanced Topics
The Binomial Distribution
Exploration of Binomial distribution and binomially distributed probabilities.
[Directions : Execute the Code Resource section first. Although there will be no output immediately, these definitions are used later in this worksheet.]
0. Code
Warning, the name changecoords has been redefined
> |
pc := COLOR(RGB, .95,.3,.45):
bc := COLOR(RGB, .45,.3,.95):
ec := COLOR(RGB, .70, .65,.50):
rc := COLOR(RGB, .38, .31,.28 ):
|
> |
bin := (k,n) -> binomial(n,k)/2^n:
|
> |
FairBiPlot := proc(n)
local f,k,c,d,h,P,Q;
c := COLOR(RGB, .3, .3, .6 );
P := plot( bin(floor(x+.5),n), x =(-.5)..(n+.5), filled = true, color = c );
for k from 1 to n do
if( k < n/2) then h := bin(k+1,n); else h := bin(k-1,n); fi;
Q||k := plot( [[k-.5,0],[k-.5,h]], color = white, linestyle = 3): od;
display( [P, seq(Q||k, k = 1..n)]);
end proc:
|
> |
BiPlot := proc(n, p)
local f,k,c,d,h,P,Q;
c := COLOR(RGB, .4, .1, .6 );
for k from 0 to n do
h := binomial(n,k)*(p^k)*((1-p)^(n-k));
P||k := plot( [[k-.5,0],[k+.5,0],[k+.5,h],[k-.5,h],[k-.5,0]],
filled = true, color = c );
if (k < n/2)
then Q||k := plot( [[k+.5,0],[k+.5,h]],
color = white, linestyle = 3):
else Q||k := plot( [[k-.5,0],[k-.5,h]],
color = white, linestyle = 3): fi;
od;
display( [ seq(P||k, k = 0..n), seq(Q||k, k = 0..n) ]);
end proc:
|
1. Binomials & Probabilities
There are many cases where something is done, and there are exactly two outcomes :
Experiment
Possible Outcomes
coin flip heads / tails
test question true / false
medical test positive / negative
functionality working / broken
The binomial distribution applies to these cases where are exactly two outcomes. If there is only one instance of the experiment, it is very simple. We will let p be the probability of one outcome in one try, and q = 1-p is then the probability of the other outcome.
> |
`Fair coin`; p := .5; q := 1- p;
|
> |
`2% Chance of a part being defective`; p := .02; q := 1- p;
|
> |
`1/6 Chance of a getting a 5 when you roll one die`; p := 1/6; q := 1- p;
|
Where it gets interesting is when there are multiple instances of the experiment. For example, if we flip a coin or run an experiment four times we get something like this.
> |
p:= 'p': q := 'q':
(p+q)^4: % = expand(%);
|
Remember that p + q = 1 - always for a binomial situation. So we get this.
although this may look like something out of algebra (which it actually is!) - there are a number of interesting observations one can make just from the examination of this equation :
There is only one way of getting p four times
There are four different ways of getting 3 p's and 1 q.
There are six different ways of getting 2 p's and 2 q's.
There are four different ways of getting 1 p and 3 q's.
There is only one way of getting q four times
Furthermore, you can use these observations to find probabilities. Each of the terms in the expression above represent the probability of getting a certain number of p's and q's when the experiment is run four times. For example, the probability of getting 3 p's and 1 q in one single way is
. But since there are 4 different ways this can occur,
P(3 p's, 1 q) =
.
Look at these other examples for other numbers of trials and make the same kinds of observations.
> |
1 = expand( (p+q)^12 );
|
2. The Binomial Distribution
We can plot all of those probabilities onto graph if we know what p is. Lets begin with a simple case, of p = .5 . This is the case of a fair coin.
Examples : Fair Coin
In each case the graph is symmetrical.
Examples : Fair Coin
If the coin or the experiment is not fair, then it will change the distribution. Lets see what affect it has.
In a sense the plot is skewed by the value of p. The graphs are not symmetrical.
3. Binomial Probabilities.
We can compute some binomial probabilities using this formula
> |
Binomial_Formula := binomial(n,k)*(p^k)*((1-p)^(n-k));
|
Example
: Find the probability of getting 6 heads in 9 flips of a fair coin.
> |
subs( {n = 9, k = 6, p = .5}, Binomial_Formula);
evalf(%);
|
Example
: Find the probability of getting 3 heads in 7 flips of an unfair coin where the probability of getting a heads of one flip is 4/9.
> |
subs( {n = 7, k = 3, p = 4/9}, Binomial_Formula);
evalf(%);
|
Example
: 5% of a product are defective. If a sample of 4 is taken, what is the probability of getting 1 defective product?
> |
subs( {n = 4, k = 1, p = .05}, Binomial_Formula);
evalf(%);
|
4. Mean & Standard Deviation
The mean and standard deviation for a binomial distribution are given below.
> |
mean := n*p; stdev := sqrt(n*p*(1-p));
|
Example
: A blood test is performed for a certain protein. It comes out positive in 18% of patients. An experiment is run with 20 volunteers. What is the mean and standard deviation?
> |
subs( { n=20, p = .18}, {'mean'=mean, 'stdev'=stdev });
|
Lets take a look at where these numbers fit on the graph of a distribution. Lets take the case of an experiment with 7 trials, where p = .40.
> |
subs( { n=7, p = .4}, {'mean'=mean, 'stdev'=stdev });
|
> |
2.8 + 1.296148140;
2.8 - 1.296148140;
|
> |
display( BiPlot( 7, .4),
plot( [[2.8,0],[2.8,.35]], color = yellow, thickness = 3),
plot( [[1.5,0],[1.5,.3]], color = red, thickness = 2),
plot( [[4.1,0],[4.1,.3]], color = red, thickness = 2));
|
The yellow line indicates the mean, and the red lines indicate a standard deviation above and below the mean. The standard deviation is the distance from the yellow line to either of the two red lines.
2002 Waterloo Maple Inc & Gregory Moore, all rights reserved.