Open In App

How to Use the Multinomial Distribution in R

Last Updated : 18 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Multinomial Distribution: It can be regarded as the generalization of the binomial distribution. The multinomial distribution is defined as the probability of securing a particular count when the individual count has a specific probability of happening.

Let us consider an example in which the random variable Y has a multinomial distribution. Then, we can calculate the probability that outcome 1 occurs exactly y1 times, outcome 2 occurs exactly y2 times, the outcome 3 occurs exactly y3 times can be found with the help of the below formula.

Probability = n! * (p1y1 * p2y2 * … * pkyk) /  (y1! * y2! … * yk!)

Here,

n: It represents the total number of events

y1: It signifies that the number of times the outcome 1 will take place

y2: It signifies that the number of times the outcome 2 will take place

……………………………..

……………………………..

……………………………..

yk: It signifies that the number of times the outcome k will take place

p1: It represents the probability of the outcome 1 occurs for a given trial

p2: It represents the probability of the outcome 1 occurs for a given trial

……………………………..

……………………………..

……………………………..

pk: It represents the probability of the outcome k occurs for a given trial

dmultinom() function: It is used to calculate the multinomial probability.

Syntax: dmultinom(x=c(parameter1, parameter2, parameter3), prob=c(parameter4, parameter5, parameter6)) 

Here,

  • x: It represents a vector that stores the frequency of each outcome
  • prob: It represents a vector that stores the probability of each outcome (the sum must be 1)

Example 1:

An Election for president took place having three potential candidates. The first candidate was able to get 20% of the votes, the second candidate was able to get 30% of the votes, and the third candidate was able to secure 50% of the votes. If 20 voters are selected randomly determine the probability that 4 voted for the candidate first, 6 voted for the second candidate, and 10 voted for the third candidate?

R




# Compute the multinomial probability
dmultinom(x=c(4, 6, 10), prob=c(.2, .3, .5))


Output:

Output

The probability that exactly 4 people voted for the first candidate, 6 voted for the second candidate, and 10 voted for the third candidate is 0.04419421.

Example 2:

Suppose a bag contains 3 red balls, 5 black balls, and 2 blue balls. Suppose that two balls are selected randomly from the bag, with replacement, what is the probability that all 2 balls are black? 

R




# Compute the multinomial probability
dmultinom(x=c(2, 0, 0), prob=c(.3, .5, .2))


Output:

Output

The probability that all the two balls are black comes out to be equal to 0.09.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads