# Negative Binomial Distribution

• /
• Blog
• /
• Negative Binomial Distribution

The negative binomial distribution is a discrete probability distribution that describes the probability of a given number of failures occurring before a given number of successes in a sequence of independent and identically distributed Bernoulli trials. It is often used to model the number of failures that occur before a certain number of successes in a sequence of independent trials, such as the number of times a coin needs to be flipped before getting heads a certain number of times.

## Properties of Negative Binomial Distribution:

The negative binomial distribution is defined by two parameters: the number of successes (r) and the probability of success (p). It has several important properties, including:

• Discrete values: The negative binomial distribution only takes on integer values. This means that the number of successes in a given number of trials can only be an integer, such as 0, 1, 2, etc.
• Two possible outcomes: The negative binomial distribution assumes that each trial has only two possible outcomes: success or failure. The probability of success on each trial is constant across all trials.
• Independence of trials: The trials are independent; the outcome of one trial does not affect the outcome of other trials. This means that the probability of success is the same for each trial.

## Mean and variance:

The mean and variance of the negative binomial distribution are given by:

Mean:

$$\Large{\mu = r\frac{1-p}{p}}$$

Variance:

$$\Large{\sigma^2 = r\frac{1-p}{p^2}}$$

• Where μ is the mean,
• $$σ^2$$ is the variance,
• r is the number of successes, and
• p is the probability of success.

## Probability Mass Function (PMF) - Negative Binomial Distribution

The probability mass function (PMF) of the negative binomial distribution gives the probability of a given number of failures occurring before a given number of successes. The formula for the PMF is as follows:

$$P(X = x) = {{x+r-1}\choose{r-1}}p^r(1-p)^x$$

Where:

P(X = x) is the probability of x failures occurring before r successes

$${x+r-1}\choose{r-1}$$ is the binomial coefficient, which represents the number of ways to choose x failures from a sequence of x+r-1 trials

p is the probability of success

r is the number of successes

x is the number of failures

## Negative Binomial Distribution Calculator:

### Negative Binomial Distribution

 function factorial(n) { if (n === 0) return 1; let fact = 1; for (let i = 1; i <= n; i++) { fact *= i; } return fact; } function combinations(n, r) { return factorial(n) / (factorial(r) * factorial(n - r)); } function negative_binomial_distribution(r, p, x) { return combinations(x - 1, r - 1) * Math.pow(p, r) * Math.pow(1 - p, x - r); } function calculateProbability() { const r = parseInt(document.getElementById("r").value); const p = parseFloat(document.getElementById("p").value); const x = parseInt(document.getElementById("x").value); const option = document.getElementById("option-selection").value; const resultContainer = document.getElementById("result"); let probability; if (option === "exact") { probability = negative_binomial_distribution(r, p, x); resultContainer.textContent = "Exact Probability: " + probability.toFixed(4); } else if (option === "ge") { probability = 0; for (let i = x; i <= 100; i++) { probability += negative_binomial_distribution(r, p, i); } resultContainer.textContent = "Greater than or equal to x Probability: " + probability.toFixed(4); } else if (option === "le") { probability = 0; for (let i = r; i <= x; i++) { probability += negative_binomial_distribution(r, p, i); } resultContainer.textContent = "Less than or equal to x Probability: " + probability.toFixed(4); } drawNegativeBinomialDistribution(r, p, x, option); } function drawNegativeBinomialDistribution(r, p, x, option) { const xValues = Array.from({ length: 101 }, (_, i) => i); const yValues = xValues.map(x => negative_binomial_distribution(r, p, x)); const trace = { x: xValues, y: yValues, type: "bar", marker: { color: "rgba(55, 128, 191, 0.6)" } }; const data = [trace]; const layout = { title: "Negative Binomial Distribution", xaxis: { title: "X Value", dtick: 5 }, yaxis: { title: "Probability" }, showlegend: false, hovermode: "closest", margin: { t: 40, r: 10, b: 80, l: 60 }, shapes: getShadedRegion(r, p, x, option) }; Plotly.newPlot("bar-plot", data, layout); } function getShadedRegion(r, p, x, option) { let shapes = []; if (option === "exact") { shapes.push({ type: "rect", xref: "x", yref: "y", x0: x - 0.5, x1: x + 0.5, y0: 0, y1: negative_binomial_distribution(r, p, x), fillcolor: "rgba(128, 0, 128, 0.3)", line: { width: 0 } }); } else if (option === "ge") { for (let i = x; i <= 100; i++) { shapes.push({ type: "rect", xref: "x", yref: "y", x0: i - 0.5, x1: i + 0.5, y0: 0, y1: negative_binomial_distribution(r, p, i), fillcolor: "rgba(128, 0, 128, 0.3)", line: { width: 0 } }); } } else if (option === "le") { for (let i = r; i <= x; i++) { shapes.push({ type: "rect", xref: "x", yref: "y", x0: i - 0.5, x1: i + 0.5, y0: 0, y1: negative_binomial_distribution(r, p, i), fillcolor: "rgba(128, 0, 128, 0.3)", line: { width: 0 } }); } } return shapes; } 

## Applications of Negative Binomial Distribution

The negative binomial distribution has a variety of applications in fields such as finance, engineering, and biology. Some examples include:

• Modelling the number of defaults on a loan before a certain number of payments are made
• Modelling the number of defects in a manufactured product before a certain number of units are produced

## Conclusion

In conclusion, the negative binomial distribution is a useful tool for modelling the probability of a given number of failures occurring before a given number of successes in a sequence of independent and identically distributed Bernoulli trials.

Posted on December 28, 2022 by  Quality Gurus

Similar Posts:

November 18, 2021

## Negative Team Dynamics

Negative Team Dynamics

November 4, 2021

## Causes of Poor Software Quality

Causes of Poor Software Quality

September 5, 2023

## Bias, Linearity, and Stability in Measurement System Analysis

Bias, Linearity, and Stability in Measurement System Analysis

32 Courses on SALE!