Probability Distribution Function and Shape
> restart;
> with(plots):
The Binomial( n,p ) Distribution
The Binomial( n,p ) distribution is a discrete distribution on the set of integers {0,1,2,..., n }. A conceptual picture of the binomial distribution can be realized by considering n independent flips of a coin that lands heads with probability p . If X is the number of heads observed in the n coin tosses, then the probability that X=k is
f ( k ) = P( X=k ) = binomial( n,k ) , k = 0,1,..., n
where binomial( n,k ) = . The probability P( X=k ) is derived from the facts that any particular sequence of k heads and n-k tails has probability , and there are binomial( n,k ) such equally likely sequences. This variable X is said to have a Binomial( n,p ) distribution, and f ( k ) is the Binomial( n,p ) probability distribution function. More generally, X may be referred to as the total number of "successes" in n independent trials, where a success is obtaining a head on the coin flip.
The following code will draw a probability histogram for the Binomial( n,p ) distribution for your choice of n and p .
> n:=10;
> p:=0.5;
> ProbHist(BinomialPDF(n,p,x),0..10,11);
To see the effect of n on the shape of the Binomial( n,p ) distribution, the following animation will draw a series of probability histograms as n changes from 4 to 50 and p= 0.4 , but you are encouraged to try other values of p .
> p:=0.4;
> for n from 4 to 50 do
> H[n]:=ProbHist(BinomialPDF(n,p,x),-0.5..50.5, 51):
> num:=convert(n, string):
> tracker[n]:=textplot([40,0.2,`n is `.num],color=blue):
> P[n]:=display({H[n], tracker[n]}):
> od:
> display([seq(P[n], n=4..50)], insequence=true, title="Increasing n");
>
To see the effect of p on the shape of the Binomial( n,p ) distribution, the following animation will draw a series of probability histograms as p changes from 0.01 to 0.50 for n =40 , but you are encouraged to try other values of n .
> n:=40;
> for i from 1 to 50 do
> prob[i]:=i/100;
> num:=convert(evalf(prob[i],3),string):
> tracker[i]:=textplot([30,0.4,`p is `.num],color=blue):
> Hp[i]:=ProbHist(BinomialPDF(n,prob[i],x),0..n,(n+1)):
> Pp[i]:=display({Hp[i],tracker[i]}):
> od:
> display([seq(Pp[i], i=1..50)], insequence=true, title="Increasing p");
>