rprobabilitybinomial-cdf

R, use binomial distribution with more than two possibilities


I know this is probably elementary, but I seem to have a mental block. Let's say you want to calculate the probability of tossing a 4, 5, or 6 on a roll of one die. In R, it's easy enough:

sum(1/6, 1/6, 1/6)

This gives 1/2 which is the correct answer. However, I have in the back of my mind (where it possibly should remain) that I should be able to use the binomial distribution for this. I've tried various combinations of arguments for pbinom and dbinom, but I can't get the right answer.

With coin tosses, it works fine. Is it entirely inappropriate for situations where there are more than two possible outcomes? (I'm a programmer, not a statistician, so I'm expecting to get killed by the stat guys here.)

Question: How can I use pbinom() or dbinom() to calculate the probability of throwing a 4, 5, or 6 with one roll of a die? I'm familiar with the prob and dice packages, but I really want to use one of the built-in distributions.

Thanks.


Solution

  • As @Alex mentioned above, dice-throwing can be represented in terms of multinomial probabilities. The probability of rolling a 4, for example, is

    dmultinom(c(0, 0, 0, 1, 0, 0), size = 1, prob = rep(1/6, 6)) 
    # [1] 0.1666667
    

    and the probability of rolling a 4, 5, or 6 is

    X <- cbind(matrix(rep(0, 9), nc = 3), diag(1, 3))
    X
    #      [,1] [,2] [,3] [,4] [,5] [,6]
    # [1,]    0    0    0    1    0    0
    # [2,]    0    0    0    0    1    0
    # [3,]    0    0    0    0    0    1
    sum(apply(X, MAR = 1, dmultinom, size = 1, prob = rep(1/6, 6)))
    # [1] 0.5