+34 616 71 29 85 carsten@dataz4s.com
Select Page

# The binomial distribution

What is the probability that you throw one six in three attempts with a six-sided die? This probability example follows a binomial distribution.

See also the page, The binomial distribution in R, with a number of worked examples.

## 4 properties for a binomial distribution

1. Fixed number of trials (n)
2. Two outcomes in a trial, success or failure
3. Trials are independent
4. Probability of success (p) remains constant

The following examples describe the four properties of the binomial distribution and is inspired on Stuart Sidder’s youtube video: Binomial Distribution (Intro).

### Fixed numbers of trials (n)

The number of trials (n) must be fixed. When I throw the die three times, it is a fixed number of trials as it is 3. Throwing a basketball, a number of times till I succeed does not have a fix number of trials, as I might try 4 or 5, well, most likely some 10 times or more before I succeed. So, this probability does not follow the binomial distribution: Let’s see an example that has a fixed number of trials:

### Two outcomes in a trial: Success or failure

We are playing two volleyball matches, so there is fixed number of 2 matches. But there are not two outcomes. It can be Win-Win, Win-Lose, Lose-Lose and Lose-Win. This example does have a fixed number of trials, but they are three and not two as they are win, draw and lose, so, this neither follows the binomial distribution: Let’s see the next table tennis example with 1) fixed number of trials, and 2) two possible outcome, but where something else goes “wrong”:

### Independent trials

This table tennis example playing two matches does have a fixed number of trials (2 matches) and 2 possible outcomes (win/lose), but the probability of getting 2 wins implies two dependent events. I can only get a win-win, if I have won the first match, so these are not independent trials: ### Probability of success (p) remains constant

Flipping tail on a coin and throwing a 6 with a die complies with the first three properties of the binomial distribution: 1) fixed # of trials; 2) two possible outcomes; 3) trials are independent, but the probability for getting a tail is 0.5 and the probability of tossing a 6 is 1/6. The two probabilities are different. They are not constant throughout the trials. This neither follows the binomial distribution: ### Complying with all 4 properties

This is our start-off example of the probability of throwing a 6 when I throw a die 3 times. The number of trials are fixed (3 throws), there are two possible outcomes (I get a 6, or I don’t), the trials are independent (whether I get a 6 in the second throw does not depend on what I got in the first throw) and the probability (p) equals 1/6 in all three trials (1/6 probability of throwing a 6 in each of the throws/trials). So, this example follows the binomial distribution: ## Mean, variance and standard deviation

The mean, variance and standard deviation are calculated by the following formulas:

Mean = mu = np

Variance = sigma squared = npq, where q= 1-p

Standard deviation = Squareroot Variance

Calculations in the binomial distribution

In our experiment where we throw the die 3 times and look at the probability of getting a 6 which is 1/6 for each throw. Let X be the number of 6’s that we throw in the 3 throws. We can throw 0,1,2 and three 6’s. This can be denoted: ## Notations

Let X be the number of tails from flipping a fair coin 5 times. We can denote: For each of the 5 flips there are two possible outcomes (head, tail), so the total possible outcomes are 2 × 2 × 2 × 2 × 2 = 25 = 32

Let’s see what the probabilities are for the different possible outcomes. For example, the probability of flipping 0 tails in 5 flips is 1 out of 32 as it is only the one combination of all five heads. So, the calculation is the number of combinations that result in X=0 (0 tails) out of the total possible outcome: We can denote it the following way, when as we calculate the probability of each of the possible outcomes: I find this Khan Academy videos helpful for more details on the examples described above and for the next one below: Binomial probability example

## Towards the formula

Say that I have a 25% chance of winning in table tennis over my friend Xien Smash Lee, and we play 6 matches. What is my chance of winning 4 out of the 6 matches?

The different combinations of me winning 4 matches can be calculated in different ways:

• Win, Win, Win, Win, Lose, Lose
• Win, Win, Win, Lose, Win, Lose

This is a combinatorial question and we solve with: So, there are 15 different ways I can win 4 games out of 6.

Next step is to find the probability of 4 wins and 2 lost matches and multiply this with the 15 different combination that this event can occur: For each of these 15 combinations we now calculate the probability of 4 wins and 2 lose: For example, the combination Win, Win, Win, Win, Lose, Lose, would be 0.254 times 0.752 = 0.0022. The same calculation would go for each of the 15 different ways, so we multiply the 0.0022 with 15 and get a 0.033 probability.

## The formula for point probability

We stick to the table tennis example above. The 4 wins and two lose are calculated by multiplying the 4 wins with the 2 lose. 4 times wins and 2 times lose which is written 0.254 times 0.752
As we multiply the total number of trials the exponents sum up to the total number of trials. The probability of successes is multiplied the number of times that it occurs. In this case it occurs 4 times, as we want to calculate for 4 successes, or 4 wins. The failure is the remaining 2 matches (6-4=2) that are the probability for lost matches raised to the 2nd.

We now have all the information to do the formula: We therefore have: ## Success and failure

We remember that success expresses the probability that we are looking for and the failure the rest. If we had been looking for the number of lost matches, the success would have been number of lost matches.

## Cumulative probability

What is my probability of losing more than 3 times out of 6 matches against my friend Xien Smash Lee in table tennis?

Let’s recall that I have a 0.25 of winning and a 0.75 chance of losing against Xien. In the previous example the question was about the probability of winning exactly 4 games. Now, we get a question about an interval as the question refers to more than 3, because this includes 4,5 and 6 games. Our statistical software will calculate this for us, but let’s see how it is calculated:

Before we calculated the point probability of me winning 4 matches out of 6. Now, we run the same formula calculating, with the only difference that we add up the point probabilities of 4,5 and 6 that we are being asked about. And we notice that now X is equal to lost matches as that’s what we are being asked about: Visualized in a bar chart: So, I have a 83% probability of losing more than 3 games.

The same idea about adding several probabilities up is called cumulative probability. It is used to answer questions that ask for probability values less than, more than, at least, maximum, minimum, etc., as it includes the probabilities for more than 1 X-value. For example, if we are asked my chances of losing at less than 2 matches, we would add the probabilities for the X-values 1 and 0 => 0.0044+0.0022 = 0.0066. So, I have 0.66% chance of losing less than 2 games against Xien Smash Lee.

## Binomial distribution with R

Below an intro to the R functions dbinom, pbinom, rbinom and qbinom functions. On the page, The binomial distribution in R, I do more worked examples with the binomial distribution in R.

For the next examples, say that X is binomially distributed with n=20 trials and p=1/6 prob of success:

dbinom

dbinom can be used to find values for the probability density function of X, f(x)

# P(X=3)
dbinom(x=3, size = 20, prob = 1/6)

##  0.2378866

Multiple probailities:

# P(X=0) & P(X=1) & P(X=2) & P(X=3)
dbinom(x=0:3, size = 20, prob=1/6)

##  0.02608405 0.10433621 0.19823881 0.23788657

# P( <= 3)
sum( dbinom(x=0:3, size = 20, prob=1/6) )

##  0.5665456

This calculation can also be done with the pbinom function:

### pbinom

pbinom command returns values for the probability distribution function of X, F(x)

# P( <= 3)
pbinom(q=3, size = 20, prob = 1/6, lower.tail = T)

##  0.5665456

### rbinom

rbinom command can be used to take a random sample from a binomial distribution. Say we are producing digital gadgets for a IT company and that we produce 150 widgets per day. Defective gadgets must are returned for reworking. There is a 5% error rate. The number of gadgets that we need to do per 5-days working week can be estimated like this:

rbinom(5,150,0.05)

##   6 12 10  7  9

The rbinom can model Bernoulli trials by setting the ‘size’ (number of trials) equal to on. For example, for the outcome of 10 coin flips:

# 10 coin flips
rbinom(10, 1,.5)

##   0 1 0 0 0 1 0 0 0 0

or for 10 flips of 100 coins:

# 10 flips of 100 coins
rbinom(10,100,.5)

##   44 47 41 55 47 52 50 44 57 54

### qbinom

The qbinom function calculates the inverse binomial distribution inverting the operation performed by pbinom. We provide the function specifying the percentile we want to be at or below and it will generate the number of successes associated with just that cumulative probability, for example:

qbinom(0.25,10,.5)

##  4

### Rpubs

See my Rpubs document for a summary of this page on the binomial distribution.  #### Carsten Grube

Freelance Data Analyst

p
p
p
##### ANOVA & the F-distribution +34 616 71 29 85

Call me Spain: Ctra. 404, km 2, 29100 Coín, Malaga

...........

Denmark: c/o Musvitvej 4, 3660 Stenløse

Drop me a line

What are you working on just now? Can I help you, and can you help me?