Binomial distribution

Binomial Experiment

A binomial experiment (or Bernoulli trial) is a statistical experiment that has the following properties:

  • The experiment consists of n repeated trials.
  • The trials are independent.
  • The outcome of each trial is either success (s) or failure (f).

Binomial Distribution

We define a binomial process to be a binomial experiment meeting the following conditions:

  • The number of successes is \(x\).
  • The total number of trials is \(n\).
  • The probability of success of 1 trial is \(p\).
  • The probability of failure of 1 trial \(q\), where \(q=1-p\).
  • \(b(x,n,p)\) is the binomial probability, meaning the probability of having exactly \(x\) successes out of \(n\) trials.

The binomial random variable is the number of successes, \(x\), out of \(n\) trials.

The binomial distribution is the probability distribution for the binomial random variable, given by the following probability mass function:

$$b(x,n,p) = \frac{n!}{x!(n-x)!}p^xq^{n-x}$$

Python code for the Binomial distribution

import math

def bi_dist(x, n, p):
    b = (math.factorial(n)/(math.factorial(x)*math.factorial(n-x)))*(p**x)*((1-p)**(n-x))
    return(b)

Using numpy

import numpy as np

n = 10 #number of coin toss
p = 0.5 #probability
samples = 1000 #number of samples
s = np.random.binomial(n, p, samples)

Using the stats module from scipy

from scipy.stats import binom

n = 10 #number of coin toss
p = 0.5 #probability
samples = 1000 #number of samples
s = binom.rvs(n, p, size=samples)

Cumulative probabilities

A cumulative probability refers to the probability that the value of a random variable falls within a specified range. Frequently, cumulative probabilities refer to the probability that a random variable is less than or equal to a specified value.

A fair coin is tossed 10 times.

Probability of getting 5 heads

The probability of getting heads is:

$$b(x=5, n=10, p=0.5)=0.246$$

Probability of getting at least 5 heads

The probability of getting at least heads is:

$$b(x\geq 5, n=10, p=0.5)= \sum_{r=5}^{10} b(x=r, n=10, p=0.5)$$
$$b(x\geq 5, n=10, p=0.5)= 0.623$$

Probability of getting at most 5 heads

The probability of getting at most heads is:

$$b(x\leq 5, n=10, p=0.5)= \sum_{r=0}^{5} b(x=r, n=10, p=0.5)$$
$$b(x\leq 5, n=10, p=0.5)= 0.623$$