Supposed I toss 10 dice many times (let's say, 10000 times), and I want to know the probability of the sum on 10 dice falling into a range (10 to 20, 20 to 30, ..., 50 to 60). How can I divide the value into range and calculate the probability of each range? Below is what I have til now:
K=10
all_comb = rep(list(1:6),K) # set up the dice
dice <- expand.grid(all_comb) #list all possible combinations
dice.sums <- rowSums(dice) #calculate sum of each combination
all_prob = c() #calculate the probability of each possible sum (from 10 to 60)
for (i in 1:(60-10+1) ){
a = mean( dice.sums == c(10:60)[i] )
all_prob = c(all_prob,a)
}
print(all_prob)
I hope someone can tell me how to do this. Thank you very much!
If you create a
tableofdice.sums, then you will get the frequency of each possible sum. Dividing this table by its total will give you the probability of each sum. The rest is just data wrangling to get it into the correct format, for whichdplyrwill be useful: