Properties of the Distribution
Calculation of Mean, Variance, and Moment Generating Function
Calculating E( X ), the expectation or mean of the Binomial( n,p ) distribution.
> restart;
> with(plots):
> f:=x->BinomialPDF(n,p,x);
> EX:=simplify(sum(x*f(x),x=0..n));
This is Maple's final simplified form. However, cancelling common factors of the numerator and denominator in the above expression reveals that E( X )= np .
Calculating Var( X ), the variance of the Binomial( n,p ) distribution,
we will employ the formula: Var( X ) = E( ) -
> E_X_SQ:=simplify(sum(x^2*f(x),x=0..n));
The above expression for E( ) clearly simplifies as .
> VarX:=simplify(n*p*(n*p+1-p)-(n*p)^2);
Therefore, Var( X ) for a Binomial( n,p ) distribution is .
The Moment Generating Function (MGF) can be easily calculated via Maple.
Recall the moment generating function of a random variable X is defined
as M ( t ) = E( ), provided this expectation exists.
> simplify(sum(exp(t*x)*f(x),x=0..n));
This is Maple's final simplified form. However, cancelling common factors of the numerator and denominator in the above expression reveals that
M ( t ) =
We will define M ( t ) as a function of t .
> M:=t->(1-p+p*exp(t))^n;
The moment generating function provides us alternative ways to calculate the
mean and variance by way of the formula.
(0) = E( ) , where ( t ) denotes the r th derivative of M ( t ) with respect to t .
This formula holds as long as M ( t ) exists in an open interval containing zero.
See, for example, Mathematical Statistics and Data Analysis by John A. Rice for
more on the moment generating function.
> M_p:=diff(M(t),t);
> simplify(M_p);
> simplify(subs(t=0,M_p));
And therefore if X is a Binomial( n,p ) variable, then E( X ) = np , which agrees with
what we found earlier. Now turning to the second moment.
> M_pp:=diff(M_p,t);
> simplify(subs(t=0,M_pp));
>
Therefore E( ) = , which again is in agreement with the value
calculated previously. The variance is now quickly calculated as
Var( X ) = E( ) -
=
=
=
Special Properties of the Binomial( n,p ) Distribution
You probably noticed in the previous animations that as n grew larger with p remaining a fixed value, the probability histogram for the Binomial( n,p ) distribution seemed to become increasingly bell-shaped (i.e., normal). Look again at the animation for n varying from 4 to 50 with an overlayed normal curve.
> p:=0.2;
> for n from 4 to 50 do
> H[n]:=ProbHist(BinomialPDF(n,p,x),0..50,51):
> N[n]:=plot(NormalPDF(n*p,n*p*(1-p),x),x = 0..50):
> num:=convert(n, string):
> tracker[n]:=textplot([40,0.4,`n is `.num],color=blue):
> P[n]:=display({H[n],N[n],tracker[n]}):
> od:
> display([seq(P[n], n=4..50)], insequence=true,title="Normal Approximation to the Binomial as n increases");
>
>
Indeed, as n becomes larger, for fixed p , the Binomial( n,p ) distribution becomes increasingly better approximated by the Normal( , ) distribution.