Section 7.2 Binomial Distribution
Consider a sequence of n independent Bernoulli trials with the likelihood of a success p on each individual trial stays constant from trial to trial with If we let the variable measure the number of successes obtained when doing a fixed number of trials n with then the resulting distribution of probabilities is called a Binomial Distribution.
Now, let’s determine the actual probability function for this distribution.
Proof.
Since successive trials are independent, then the probability of X successes occurring within n trials is given by
Theorem 7.2.2. Verification of Binomial Distribution Formula.
Proof.
Using the Binomial Theorem with a = p and b = 1-p yields
The following interactive cell illustrates the range of choices for a Binomial setup with fixed N and fixed p:
xxxxxxxxxx
# Binomial distribution over 0 .. N
# N and p need to be given
var('x')
layout=dict(top=[['N','p']])) (
def _(N=input_box(10,width=5,label='$$ N $$'),
p=input_box(3/10,width=5,label='$$ p $$')):
f = binomial(N,x)*p^x*(1-p)^(N-x)
def __(X = slider(0,N,1)):
Px = f(x=X)
Pxapprox = Px.n(digits=8)
formula = ("\\binom{%s}"%str(N)+"{%s}"%str(X)
+"({%s})"%str(p)+"^{%s}"%str(X)
+"(1-{%s})"%str(p)+"^{%s}"%str(N-X))
pretty_print(html("P(X = %s"%str(X)+") = $ %s $"%str(formula)
+" = $ %s $"%str(latex(Px))
+"$ \\approx %s $"%str(Pxapprox)))
G = polygon([(0,0), (1,0), (1,1), (0,1)],
thickness=10,color='blue',alpha=0.7,zorder=1)
if X > 0:
R =[j for j in range(N)]
selected = sample(R, X)
for k in selected:
xk = sqrt(k)*cos(k)/N^(4/5)+0.5
yk = sqrt(k)*sin(k)/N^(4/5)+0.5
G += circle((xk,yk),0.05,fill=True,
facecolor='red',zorder=3)
G += text('p',(xk,yk))
for k in range(N):
xk = sqrt(k)*cos(k)/N^(4/5)+0.5
yk = sqrt(k)*sin(k)/N^(4/5)+0.5
G += circle((xk,yk),0.05,zorder=2,fill=True,
facecolor="white")
show(G, axes=0, figsize=(4,4) )
Example 7.2.3. Flipping a coin a fixed number of times.
Let’s consider a simple example for flipping coins. Indeed, suppose you flip a coin exactly 20 times and need to determine the probability of getting exactly 10 heads.
This is binomial with n = 20, p = 1/2 and you are looking for f(10). With these values
Note that the mean for this distribution is also 10 so one might expect 10 heads in general
If you rather would prefer to determine the probability of getting 10 or fewer heads requires F(10) = f(0) + f(1) + ... + f(10). There is no "nice" formula for F but this calculation can be performed using a graphing calculator, such as the TI-84 with F(x) = binomcdf(n,p,x). In this case, F(10) = binomcdf(20,1/2,10) = 0.588.
Checkpoint 7.2.4. WebWork - Binomial.
Example 7.2.5. Testing critical components.
Often one will test a critical system components for failure and toward that end collect a sample of 100 of these components from the manufacturer. Suppose the component is listed as having a p = 0.01 probability of breaking and you want to know the likelihood that at most 1 of the tested components actually fails when tested. You find it reasonable to presume that different components succeed or fail independently of each other. So, you can model this situation with a binomial distribution.
If measures the number of components that fail when tested, the specific probability function is given by
The probability that at most one component fails is then given by
xxxxxxxxxx
# Binomial calculator
def _(p=input_box(3/10,width=15),n=input_box(10,width=15)):
R = range(n+1)
f(x) = binomial(n,x)*p^x*(1-p)^(n-x)
acc = 0
print("Binomial Calculator")
for k in R:
prob = f(x=k)
acc = acc+prob
print('f(%s) = '%k,' %.8f'%prob,
' and F(%s) = '%k,' %.8f'%acc)
Here is another calculator that you might like!
xxxxxxxxxx
# Calculator for Binomial
print("Binomial Distribution Calculator")
pretty_print(html("n = fixed number of trials"))
pretty_print(html("p = probability of success on each trial"))
def _(n = input_box(default=10,width=10,label="n"),
p = input_box(default=0.3,width=10,label="p"),
x=input_box(default=4,width=10,label="x")):
prob = binomial(n,x)*p^x*(1-p)^(n-x)
pretty_print(html("$P(X=%s)$"%str(x)+"$=%s$"%str(prob)))
binoms = [binomial(n,k)*p^k*(1-p)^(n-k) for k in range(x+1)]
G = bar_chart([binomial(n,k)*p^k*(1-p)^(n-k) for k in range(n+1)]) # show all
G += bar_chart(binoms,color='green') # show till x
show(G,figsize=(3,2))
F = 0 # accumulate probabilities from the bottom till x
for k in range(x+1):
F += binomial(n,k)*p^k*(1-p)^(n-k)
end
pretty_print(html("$P(X \\le %s)$"%str(x)+"$=%s$"%str(F)))
Theorem 7.2.6. Binomial Distribution Statistics.
Proof.
For the variance 2,
Using the change of variables and yields a binomial series
The skewness 3 and kurtosis 4 can be found similarly using formulas involving E[X(X-1)(X-2)] and E[X(X-1)(X-2)(X-3)]. The complete determination is performed using Sage below.
The following uses Sage to symbolically confirm the general formulas for the Binomial distribution.
xxxxxxxxxx
var('x,n,p')
assume(x,'integer')
f(x) = binomial(n,x)*p^x*(1-p)^(n-x)
mu = sum(x*f,x,0,n)
M2 = sum(x^2*f,x,0,n)
M3 = sum(x^3*f,x,0,n)
M4 = sum(x^4*f,x,0,n)
print('Mean = ',mu)
v = (M2-mu^2).factor()
print('Variance = ',v)
stand = sqrt(v)
sk = ((M3 - 3*M2*mu + 2*mu^3)).factor()/stand^3
print('Skewness = ',sk)
kurt = (M4 - 4*M3*mu + 6*M2*mu^2 -3*mu^4).factor()/stand^4
print('Kurtosis = ',(kurt-3).factor(),'+3')
Theorem 7.2.7. Binomial Limiting Distribution.
Proof.
For skewness, take the limit of the skewness result above
Similarly for kurtosis
Checkpoint 7.2.8. WebWork - Binomial.
The Census Bureau reports that 82% of Americans over the age of 25 are high school graduates. A survey of randomly selected residents of certain county included 1260 who were over the age of 25, and 1086 of them were high school graduates.
(a) Find the mean and standard deviation for the number of high school graduates in groups of 1260 Americans over the age of 25.
Mean =
Standard deviation =
(b) Is that county result of 1086 unusually high, or low, or neither?
(Enter HIGH or LOW or NEITHER)
xxxxxxxxxx
n = 10
p = 0.3
X = 0:n # the space R of the random variable
mu = n*p # the formula for mean of the Binomial Distributions
sdev = sqrt(n*p*(1-p)) # the formula for the standard deviation
if(n < 101){
dbinom( X, n, p ) # print out a bunch of actual probs if N reasonable
}
Pbinom = dbinom(X, n, p ) # create the probability function over X
Psample = rbinom(10^6, n, p) # to create a histogram, sample a lot
Xtop=max(Psample) # for scaling the x-axis. Shift by 1/2 below.
hist(Psample, prob=TRUE, br=(-1:Xtop)+0.5, col="skyblue2", xlab="X",
main="Binomial Probability Function vs Approximating 'Bell Curve'")
points(X, Pbinom, pch=19, col="darkgreen") # to create actual (x,f(x))
Pnormal <- function(X){dnorm(X, mean=mu, sd=sdev)} # overlap bell curve
curve(Pnormal, col="red", lwd=2, add=TRUE)
You can of course get specific values and graph the Binomial Distribution using R as well...
xxxxxxxxxx
n <- 10
p <- 0.3
paste('Probability Function')
dbinom(0:n, n, p) # gives the probability function
paste('Distribution function')
pbinom(0:n, n, p) # gives the distribution function
paste('A random sample')
rbinom(15, n, p) # gives a random sample of 15 items from b(n,p)
x <- dbinom(0:n, size=n, prob=p)
barplot(x,names.arg=0:n, main=sprintf(paste('n=',n,' and p= ',p)))