*chevron_left*Probability Distributions

# Binomial Distribution

*chevron_right*

*schedule*Mar 10, 2022

The binomial distribution is a discrete distribution which models the number of successes in a fixed number of independent trials. It can be described by two parameters:

$n$ = number of trials

$p$ = probability of success

The following conditions apply for the binomial distribution to be appropriate:

For each trial there are only 2 outcomes: success or failure

Each trial is independent (result of one trial does not affect the result of another)

The number of trials is fixed: $n$

Each trial has the same probability of success: $p$

# Formula

The binomial formula is represented as follows:

where:

$n$ = number of trials

$p$ = probability of success

$q$ = probability of failure = $1 - p$

# Example

Let us toss a coin four times. We define random variable $X$ as the number of heads obtained from the four tosses. Assume that this is a fair coin and the probability of getting a heads is 0.5 and tails is 0.5.

To find the probability of getting exactly 2 heads (i.e. $\mathbb{P}(X=2)$):

By plotting the probability mass function, we can see the probability of getting the various numbers of heads in our four tosses of the coin:

As per our calculation from the formula, we can see that the probability of getting exactly 2 heads in our 4 tosses is 0.375.

The above graph can be plotted using Python's SciPy and Matplotlib libraries:

```
# Import the relevant librariesfrom scipy.stats import binomimport matplotlib.pyplot as plt
```

# Specify n (number of trials) and p (probability of success)n = 4p = 0.5

# Specifying the range

# Calculate the pmf values and store in a listpmf = [binom.pmf(r, n, p) for r in r_vals ]

# Plotting a bar chart with Matplotlib

# Adding the axis labels

plt.show()