DEV Community

Cover image for USE AND ENJOY THE BINOMIAL DISTRIBUTION MODEL
anna lapushner
anna lapushner

Posted on

USE AND ENJOY THE BINOMIAL DISTRIBUTION MODEL

In statistics and probability theory, the term “binomial” often refers to the binomial distribution, which is a discrete probability distribution.

𝑃(𝑋=𝑥)=(𝑛𝑥)𝑝𝑥(1−𝑝)𝑛−𝑥

A binomial is a mathematical expression consisting of two terms connected by a plus or minus sign. In algebra, a simple example of a binomial is a + b, where a and b are terms that can represent numbers, variables, or more complex expressions.

The binomial distribution models the number of successes in a fixed number of independent trials of a binary experiment (an experiment with two possible outcomes: success or failure). Each trial has the same probability of success, denoted by p.

Key properties of a binomial distribution include:

  1. Number of Trials (n): The fixed number of independent trials.
  2. Probability of Success (p): The probability of success on a single trial.
  3. Probability of Failure (q): The probability of failure on a single trial, where q = 1 - p.
  4. Random Variable (X): The number of successes in n trials.


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.stats as stats
from scipy.stats import binom

%matplotlib inline

# Standard notation
# P = binomial probability
# x = number of times for a specific outcome within n trials
# n = number of trials
# p = probability of success on a single trial
# q = probability of failure on a single trial
# k = an array of n, the number of trials
# p_of_k = probabilty of successes for each trial
# am = at most = Define at most successes
# Probability mass function = .pmf()
# Probability density function = .pdf()
# The probability mass function of the binomial distribution is
# f(x)=P[X=x]=(nx)px(1−p)n−x

n = (10)
p = (0.8)
k = np.arange(0,11)
am = (6)

p_of_k = binom.pmf(n,n,p)
p_of_k

x = binom.pmf(k,n,p)
x

barl = plt.bar(k, x, color='hotpink')
plt.title(('When p =  ' + str(p) + ' and at most ' + str(am) + ' successes'), fontsize=13, color='r')
plt.legend((p, ''), fontsize=10)
plt.xlabel('Number of Successes', fontsize=10, color='r')
plt.ylabel('Probability of Successes', fontsize=10, color='royalblue')
for i in range(0, am):
    barl[i].set_color('r')


Enter fullscreen mode Exit fullscreen mode

Anna_Lapushner_binomial_distribution_MIT_Inferential_Statistics

The binomial distribution is widely used in various fields, including biology, finance, and engineering, to model binary outcomes.

Top comments (0)