Binomial Distribution

Binomial Distribution

The binomial distribution is also known as a discrete probability distribution, which is used to find the probability of success of an event. The event has only two possible outcomes in a series of experiments. The tossing of the coin is the best example of the binomial distribution. When a coin is tossed, it gives either a head or a tail. The probability of finding exactly three heads in repeatedly tossing the coin ten times is approximate during the binomial distribution.

R allows us to create binomial distribution by providing the following function:

These functions can have the following parameters:

S.NoParameterDescription
1.xIt is a vector of numbers.
2.pIt is a vector of probabilities.
3.nIt is a vector of observations.
4.sizeIt is the number of trials.
5.probIt is the probability of the success of each trial.

Let’s start understanding how these functions are used with the help of the examples

dbinom(): Direct Look-Up, Points

The dbinom() function of R calculates the probability density distribution at each point. In simple words, it calculates the density function of the particular binomial distribution.

Example

# Creating a sample of 100 numbers which are incremented by 1.5.  
x <- seq(0,100,by = 1)  
# Creating the binomial distribution.  
y <- dbinom(x,50,0.5)  
# Giving a name to the chart file.  
png(file = "dbinom.png")  
# Plotting the graph.  
plot(x,y)  
# Saving the file.  
dev.off()  

Output:

Binomial Distribution

pbinom():Direct Look-Up, Intervals

The dbinom() function of R calculates the cumulative probability(a single value representing the probability) of an event. In simple words, it calculates the cumulative distribution function of the particular binomial distribution.

Example

# Probability of getting 20 or fewer heads from 48 tosses of a coin.  
x <- pbinom(20,48,0.5)  
#Showing output  
print(x)  

Output:

Binomial Distribution

qbinom(): Inverse Look-Up

The quinoa() function of R takes the probability value and generates a number whose cumulative value matches the probability value. In simple words, it calculates the inverse cumulative distribution function of the binomial distribution.

Let’s find the number of heads that have a probability of 0.45 when a coin is tossed 51 times.

Example

# Finding number of heads with the  help of qbinom() function   
x <- qbinom(0.45,48,0.5)  
#Showing output  
print(x)  

Output:

Binomial Distribution

rbinom()

The rbinom() function of R is used to generate a required number of random values for a given probability from a given sample.

Let’s see an example in which we find nine random values from a sample of 160 with a probability of 0.5.

Example

# Finding random values    
x <- rbinom(9,160,0.5)  
#Showing output  
print(x)  

Output:

Binomial Distribution

Next Topic: Click Here

Leave a Reply