Probability Sum in R -


i'm trying run probability codes in r without using dice package. know when there 2 vectors, it's possible use outer command generate matrix calculate sums , values dice rolls. there similar can same thing 5 dice rolls?

i'm working on rolling 5 six-sided dice in r , generating code calculate probability of getting between 15 , 20 sum of rolls.

any suggestions?

you simulation:

set.seed(1020) nn<-1e6 #number simulations #on each simulation, check whether sum of 5 #  independently rolled (6-sided) dice less #  2.5 away 17.5--equivalently, #  sum between 15 & 20; probability #  percentage of time happens, #  or equivalently, mean of indicator function > mean(replicate(nn,abs(sum(sample(6,5,t))-17.5)<=2.5)) [1] 0.556971 

the actual solution 4332/7776=.5570988, can found (inefficient, cares because 6^5=7776) loop:

tot<-0l (i1 in 1:6){   (i2 in 1:6){     (i3 in 1:6){       (i4 in 1:6){         (i5 in 1:6){           s<-i1+i2+i3+i4+i5           tot<-tot+(s>=15&s<=20)         }       }     }   } } > tot/6^5 [1] 0.5570988 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -