The Binomial distribution

646 Views Asked by At

I am trying to understand the cumulative binomial distribution.

If someone can help with this two questions I'll be grateful

  1. What is the exact probability F of observing K or more successes when a success probability P is expected?
    Can one write an analytical expression for F as a function of P, K, and N

  2. Can one Write a computer routine (MATLAB) that performs the computation of F?

Thanks!

2

There are 2 best solutions below

1
On

The probability of having exactly $x$ successes is

$$ P(X = x) = {N \choose x}p^x(1 - p)^{N-x}. $$

Therefore, the probability of having $k$ or more successes is

$$ P(X \ge k) = \sum_{x=k}^NP(X = x) = \sum_{x=k}^N {N \choose x}p^k(1 - p)^{N-x}. $$

Unless you select very specific values of $N$ and $p$ I do not think there's a closed expression for this. In MATLAB this is done with a simple for loop over different values of $x$. Alternatively you can use the built-in function binocdf

0
On

You and @Ian mention the binomial CDF in Matlab. R statistical software (available without cost from www.r-project.org) has similar capabilities.

The name of a binomial CDF in R is pbinom and the binomial PDF (or PMF) is dbinom. Here is how to use them to make a PDF and CDF table for $\mathsf{Binom}(n = 5, p = .4).$ (You can ignore numbers in brackets.)

n = 5;  k = 0:n;  p = .4
pdf = dbinom(k,n,p);  cdf = pbinom(k,n,p)
cbind(k, pdf, cdf)
     k     pdf     cdf
[1,] 0 0.07776 0.07776
[2,] 1 0.25920 0.33696
[3,] 2 0.34560 0.68256
[4,] 3 0.23040 0.91296
[5,] 4 0.07680 0.98976
[6,] 5 0.01024 1.00000

Thus for $X \sim \mathsf{Binom}(n = 5, p = .4),$ one has

$$P(X = 3) = {5 \choose 3}(.4)^3(.6)^2 = 0.23040.$$ and $$P(X \le 3) = P(X = 0) + P(X = 1) + P(X = 2) + P(X = 3) = 0.91296.$$

dbinom(3, 5, .4)
## 0.2304
pbinom(3, 5, .4) 
## 0.91296

Also, $P(X \le 3) = 1 - P(X > 3) = 0.91296.$

1 - pbinom(3, 5, .4, lower=F)
## 0.91296
1- sum(dbinom(4:5, 5, .4))
## 0.91296
sum(dbinom(0:3, 5, .4))
## 0.91296

Here are PDF and CDF plots of $\mathsf{Binom}(n = 5, p = .4).$ The required R code is shown below the figure (but the code uses special graphics statements in R that may not be transparent to a new user of R).

enter image description here

mlab="BINOM(5, .4)"
par(mfrow=c(1,2))  # enables two panels per plot
 plot(k, pdf, ylim=c(0,.4), type="h", lwd=2, main=mlab)
   abline(h = 0, col="green2")
   abline(v = 3.5, col="red", lty="dashed")
 plot(c(-1,k,n+1), c(0, cdf, 1), ylab="cdf", xlab="k", type="s", lwd=2, 
      xlim=c(-.5,5.5), xaxs="i", main=mlab)
   points(k, cdf, pch=20, col="blue")
   abline(h=0:1, col="green2")
   abline(v = 3.5, col="red", lty="dashed")
par(mfrow=c(1,1))