Binomial distribution in R is a probability distribution used in statistics. The binomial distribution is a discrete distribution and has only two outcomes i.e. success or failure. All its trials are independent, the probability of success remains the same and the previous outcome does not affect the next outcome. The outcomes from different trials are independent. Binomial distribution helps us to find the individual probabilities as well as cumulative probabilities over a certain range.

It is also used in many real-life scenarios such as in determining whether a particular lottery ticket has won or not, whether a drug is able to cure a person or not, it can be used to determine the number of heads or tails in a finite number of tosses, for analyzing the outcome of a die, etc.

**Formula:**

#### Functions for Binomial Distribution

We have four functions for handling binomial distribution in R namely:

**dbinom()**dbinom(k, n, p)

**pbinom()**pbinom(k, n, p)

where n is total number of trials, p is probability of success, k is the value at which the probability has to be found out.

**qbinom()**qbinom(P, n, p)

Where P is the probability, n is the total number of trials and p is the probability of success.

**rbinom()**rbinom(n, N, p)

Where n is numbers of observations, N is the total number of trials, p is the probability of success.

`dbinom()`

Function

This function is used to find probability at a particular value for a data that follows binomial distribution i.e. it finds:

P(X = k)

**Syntax:**

dbinom(k, n, p)

**Example:**

`dbinom(` `3` `, size ` `=` `13` `, prob ` `=` `1` `/` `6` `) ` `probabilities <` `-` `dbinom(x ` `=` `c(` `0` `:` `10` `), size ` `=` `10` `, prob ` `=` `1` `/` `6` `) ` `data.frame(x, probs) ` `plot(` `0` `:` `10` `, probabilities, ` `type` `=` `"l"` `) ` |

*chevron_right*

*filter_none*

**Output :**

> dbinom(3, size = 13, prob = 1/6) [1] 0.2138454 > probabilities = dbinom(x = c(0:10), size = 10, prob = 1/6) > data.frame(probabilities) probabilities 1 1.615056e-01 2 3.230112e-01 3 2.907100e-01 4 1.550454e-01 5 5.426588e-02 6 1.302381e-02 7 2.170635e-03 8 2.480726e-04 9 1.860544e-05 10 8.269086e-07 11 1.653817e-08

The above piece of code first finds the probability at k=3, then it displays a data frame containing the probability distribution for k from 0 to 10 which in this case is 0 to n.

`pbinom()`

Function

The function

is used to find the cumulative probability of a data following binomial distribution till a given value ie it finds **pbinom()**

P(X <= k)

**Syntax:**

pbinom(k, n, p)

**Example:**

`pbinom(` `3` `, size ` `=` `13` `, prob ` `=` `1` `/` `6` `) ` `plot(` `0` `:` `10` `, pbinom(` `0` `:` `10` `, size ` `=` `10` `, prob ` `=` `1` `/` `6` `), ` `type` `=` `"l"` `) ` |

*chevron_right*

*filter_none*

**Output :**

> pbinom(3, size = 13, prob = 1/6) [1] 0.8419226

`qbinom()`

Function

This function is used to find the nth quantile, that is if P(x <= k) is given, it finds k.

**Syntax:**

qbinom(P, n, p)

**Example:**

`qbinom(` `0.8419226` `, size ` `=` `13` `, prob ` `=` `1` `/` `6` `) ` `x <` `-` `seq(` `0` `, ` `1` `, by ` `=` `0.1` `) ` `y <` `-` `qbinom(x, size ` `=` `13` `, prob ` `=` `1` `/` `6` `) ` `plot(x, y, ` `type` `=` `'l'` `) ` |

*chevron_right*

*filter_none*

**Output :**

> qbinom(0.8419226, size = 13, prob = 1/6) [1] 3

`rbinom()`

Function

This function generates n random variables of a particular probability.

**Syntax:**

rbinom(n, N, p)

**Example:**

`rbinom(` `8` `, size ` `=` `13` `, prob ` `=` `1` `/` `6` `) ` `hist(rbinom(` `8` `, size ` `=` `13` `, prob ` `=` `1` `/` `6` `)) ` |

*chevron_right*

*filter_none*

**Output:**

> rbinom(8, size = 13, prob = 1/6) [1] 1 1 2 1 4 0 2 3

## Recommended Posts:

- Performing Binomial Test in R programming - binom.test() Method
- Compute the Negative Binomial Density in R Programming - dnbinom() Function
- Compute the Negative Binomial Cumulative Density in R Programming - pnbinom() Function
- Compute the Value of Negative Binomial Quantile Function in R Programming - qnbinom() Function
- Compute Randomly Drawn Negative Binomial Density in R Programming - rnbinom() Function
- Compute Density of the Distribution Function in R Programming - dunif() Function
- Create a Random Sequence of Numbers within t-Distribution in R Programming - rt() Function
- Perform Probability Density Analysis on t-Distribution in R Programming - dt() Function
- Perform the Probability Cumulative Density Analysis on t-Distribution in R Programming - pt() Function
- Perform the Inverse Probability Cumulative Density Analysis on t-Distribution in R Programming - qt() Function
- Compute Beta Distribution in R Programming - dbeta(), pbeta(), qbeta(), and rbeta() Functions
- Create Random Deviates of Uniform Distribution in R Programming - runif() Function
- Compute the Value of Empirical Cumulative Distribution Function in R Programming - ecdf() Function
- Compute the value of F Cumulative Distribution Function in R Programming - pf() Function
- Compute the value of Quantile Function over F Distribution in R Programming - qf() Function
- Compute the Value of Quantile Function over Weibull Distribution in R Programming - qweibull() Function
- Compute the value of CDF over Studentized Range Distribution in R Programming - ptukey() Function
- Compute the value of Quantile Function over Studentized Distribution in R Programming - qtukey() Function
- Compute the value of PDF over Wilcoxon Signedrank Distribution in R Programming - dsignrank() Function
- Compute the value of CDF over Wilcoxon Signedrank Distribution in R Programming - psignrank() Function

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.