The Multinomial Distribution in R

The Multinomial Distribution in R, when each result has a fixed probability of occuring, the multinomial distribution represents the likelihood of getting a certain number of counts for each of the k possible outcomes.

The probability that outcome 1 occurs exactly x1 times, outcome 2 occurs precisely x2 times, etc. can be calculated using the formula below if a random variable X has a multinomial distribution.

How to Calculate Relative Frequencies in R? – Data Science Tutorials

Probability = n! * (p1x1 * p2x2 * … * pkxk) /  (x1! * x2! … * xk!)

where:

  • n: total number of events
  • x1: number of times outcome 1 occurs
  • p1: the probability that outcome 1 occurs in a given trial

The dmultinom() function in R can be used to compute a multinomial probability and has the following syntax.

dmultinom(x=c(1, 5, 6), prob=c(.3, .6, .1))

where:

  • x: a vector displaying the frequency of each result
  • prob: a vector displaying each outcome’s probability (the sum must be 1)

The practical application of this function is demonstrated in the examples that follow.

Dealing With Missing values in R – Data Science Tutorials

Example 1:

There are three candidates running for mayor; candidate A receives 10% of the vote, candidate B receives 40%, and candidate C receives 50%.

What is the likelihood that 3 people chose candidate A, 4 chose candidate B, and 5 chose candidate C out of a random sample of 10 voters?

To respond to this, we can use the R code listed below.

Now we can calculate the multinomial probability

dmultinom(x=c(3, 4, 5), prob=c(.1, .4, .5))
[1] 0.022176

The likelihood that precisely 3 individuals voted for A, 4 for B, and 5 for C are 0.022176.

How to perform a one-sample t-test in R? – Data Science Tutorials

Example 2:

Assume that an urn holds five yellow marbles, three red marbles, and two pink marbles.

What is the likelihood that all four of the balls will be yellow if we randomly choose four balls from the urn with replacement?

To respond to this, we can use the R code listed below:

Let’s calculate the multinomial probability

dmultinom(x=c(4, 0, 0), prob=c(.5, .3, .2))
[1] 0.0625

It is 0.0625 times more likely that all four balls will be yellow.

How to do Conditional Mutate in R? – Data Science Tutorials

Example 3

Let’s say two pupils compete in a game of chess. The odds of student A winning a particular game are 0.6, student B winning a particular game is 0.2, and the odds of a draw in a particular game are 0.2.

What is the likelihood that player A wins four times, player B wins four times, and they tie twice if they play ten games?

To respond to this, we can use the R code listed below

Separate a data frame column into multiple columns-tidyr Part3 (datasciencetut.com)

Now will calculate multinomial probability

dmultinom(x=c(4, 4, 2), prob=c(.6, .2, .2))
[1] 0.02612736

About 0.02612736 percent of the time, player A wins four times, player B wins four times, and they tie twice.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

nineteen + 8 =