Application Center - Maplesoft

App Preview:

High School Advanced Topics - The Binomial Distribution

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

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

>    restart;

>    with(plots):

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;

`Fair coin`

p := .5

q := .5

>    `2% Chance of a part being defective`; p := .02; q := 1- p;

`2% Chance of a part being defective`

p := .2e-1

q := .98

>    `1/6 Chance of a getting a 5 when you roll one die`; p := 1/6; q := 1- p;

`1/6 Chance of a getting a 5 when you roll one die`

p := 1/6

q := 5/6



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(%);

(p+q)^4 = p^4+4*p^3*q+6*p^2*q^2+4*p*q^3+q^4


Remember that p + q = 1 - always for a binomial situation. So we get this.

>    1 = expand( (p+q)^4 );

1 = p^4+4*p^3*q+6*p^2*q^2+4*p*q^3+q^4


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
p^3*q . But since there are 4 different ways this can occur,
            P(3 p's, 1 q) =
4*p^3*q .

                
Look at these other examples for other numbers of trials and make the same kinds of observations.

>    1 = expand( (p+q)^2 );

1 = p^2+2*p*q+q^2

>    1 = expand( (p+q)^5 );

1 = p^5+5*p^4*q+10*p^3*q^2+10*p^2*q^3+5*p*q^4+q^5

>    1 = expand( (p+q)^8 );

1 = p^8+8*p^7*q+28*p^6*q^2+56*p^5*q^3+70*p^4*q^4+56*p^3*q^5+28*p^2*q^6+8*p*q^7+q^8

>    1 = expand( (p+q)^12 );

1 = p^12+12*q*p^11+66*q^2*p^10+220*q^3*p^9+495*q^4*p^8+792*q^5*p^7+924*q^6*p^6+792*q^7*p^5+495*q^8*p^4+220*q^9*p^3+66*q^10*p^2+12*q^11*p+q^12
1 = p^12+12*q*p^11+66*q^2*p^10+220*q^3*p^9+495*q^4*p^8+792*q^5*p^7+924*q^6*p^6+792*q^7*p^5+495*q^8*p^4+220*q^9*p^3+66*q^10*p^2+12*q^11*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

>    FairBiPlot(3);

[Maple Plot]

>    FairBiPlot(4);

[Maple Plot]

>    FairBiPlot(5);

[Maple Plot]

>    FairBiPlot(8);

[Maple Plot]

>    FairBiPlot(12);

[Maple Plot]

>    FairBiPlot(20);

[Maple Plot]

 
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.

>    BiPlot( 5, .35);

[Maple Plot]

>    BiPlot( 5, .65);

[Maple Plot]


In a sense the plot is skewed by the value of p. The graphs are not symmetrical.

>    BiPlot( 7, .4);

[Maple Plot]

>    BiPlot( 9, .2);

[Maple Plot]

>    BiPlot( 15, .7);

[Maple Plot]


  3. Binomial Probabilities.


We can compute some binomial probabilities using this formula
                        

>    Binomial_Formula :=  binomial(n,k)*(p^k)*((1-p)^(n-k));

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(%);

.1953125e-2*binomial(9,6)

.164062500



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(%);

40000/4782969*binomial(7,3)

.2927052214



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(%);

.4286875e-1*binomial(4,1)

.17147500


 

  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));

mean := n*p

stdev := (n*p*(1-p))^(1/2)



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 });

{mean = 3.60, stdev = 1.718138528}


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 });

{mean = 2.8, stdev = 1.296148140}

>    2.8 + 1.296148140;
2.8 -  1.296148140;

4.096148140

1.503851860

>    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));

[Maple Plot]


    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.