# Binomial Distribution in R Programming

In this article, we will talk about the Binomial distribution in R programming. The binomial distribution is a type of probability distribution. As it is a discrete distribution, it will only have 2 outcomes as the output, i.e., success or failure. All the trials in binomial distribution are independent. In Binomial distribution, the probability of success remains the same, and the previous outcome does not affect the upcoming outcome.

With the help of Binomial distribution, we can find individual probabilities and the cumulative probabilities of our data over a certain range.

There are various real-life scenarios of Binomial distribution, which are as follows:

1. An xyz name drug can cure a person or not.
2. Did you win the lucky draw coupon or not?
3. To identify the number of heads and tails in a number of tosses.
4. To analyze the outcome of a die.
And so on.

The formula of Binomial distribution is as follows:

``````Description of above parameters:

p = probability of success
q = probability of failure
r = 0, 1, 2, 3, 4, ……., n
p+q = 1
``````

Like another type of probability distribution, even Binomial distribution has 4 in-built functions to generate the Binomial distribution. They are as follows:

``````dbinom(x, size, prob)
pbinom(x, size, prob)
qbinom(p, size, prob)
rbinom(n, size, prob)

Description of above parameters:
x = vector of numbers
p = vector of probabilities
n = total number of observations
size = total number of trials
prob = It is the probability of success of each trial
dbinom, pbinom, qbinom, and rbinom are the various functions of the binomial distribution.
``````

a) dbinom() function in R programming:

• dbinom() is a Binomial distribution function.
• When we use the dbinom() function, it enables us to calculate the probability density values.
• Syntax of dbinom is as follows:
``````dbinom(x, y, prob)

Description of above parameters:

dbinom = Binomial distribution function
x = vector
y = number of trials
prob = probability of success for each trial
``````

EXAMPLE:

CODE:

``````# BINOMIAL DISTRIBUTION IN R PROGRAMMING
# dbinom

information <- seq(0,30,by = 1)
data <- dbinom(information,30,0.5)
plot(information,data)
``````

OUTPUT:

b) pbinom() function in R programming:

• pbinom() is a Binomial distribution function.
• When we use the pbinom() function in R programming, we will get the values of the cumulative frequency of the data.
• Syntax of pbinom is as follows:
``````pbinom(x, size, prob)

Description of above parameters:

pbinom = Binomial distribution function
x = vector
size = number of trials
prob = probability of success for each trial
``````

EXAMPLE:

CODE:

``````# BINOMIAL DISTRIBUTION IN R PROGRAMMING
# pbinom

data <- pbinom(30,60,0.5)
print(data)
``````

OUTPUT:

c) qbinom() function in R programming:

• qbinom() is a Binomial distribution function.
• When we use the qbinom() function, we will get the value of the quantile probability of the data values.
• It provides the single data value, and the cumulative probability matches the probability value.
• Syntax of qbinom function is as follows:
``````qbinom(p, size, prob)

Description of above parameters:

p = vector of probabilities
size = total number of trials
prob = It is the probability of success of each trial
``````

EXAMPLE:

CODE:

``````# BINOMIAL DISTRIBUTION IN R PROGRAMMING
# qbinom

data <- qbinom(0.5,50,0.5)
print(data)
``````

OUTPUT:

d) rbinom() function in R programming:

• rbinom() is a Binomial distribution function.
• When we use the rbinom() function in a Binomial distribution, it will generate random numbers.
• Syntax of rbinom() function is as follows:
``````rbinom(n, size, prob)

Description of above parameters:

x = vector of numbers
p = vector of probabilities
n = total number of observations
size = total number of trials
prob = It is the probability of success of each trial
``````

EXAMPLE:

CODE:

``````# BINOMIAL DISTRIBUTION IN R PROGRAMMING
# qbinom

data <- rbinom(10,50,0.5)
print(data)
``````

OUTPUT: