Using R to simulate a biased 6 sided dice

前端 未结 3 397
执笔经年
执笔经年 2021-01-28 12:45

In R I want to figure the code to simulate a biased 6 sided die being thrown 44 times. The die is biased in the sense that the number 6 is twice as likely to be thrown as any ot

3条回答
  •  忘了有多久
    2021-01-28 13:09

    You need both the replace=TRUE and the prob-argument set to the non-equal probability setting of your choice.

    throws <- sample(1:6, 44, replace=TRUE, prob=c(1,1,1,1,1,2)/7 )
    # Two realizations
    > throws <- sample(1:6, 44, replace=TRUE, prob=c(1,1,1,1,1,2)/7 )
    > table(throws)
    throws
     1  2  3  4  5  6 
    10  5  8  7  3 11 
    > throws <- sample(1:6, 44, replace=TRUE, prob=c(1,1,1,1,1,2)/7 )
    > table(throws)
    throws
     1  2  3  4  5  6 
     7  3  4  8  7 15 
    

    Notice that the outcome is still (pseudo)-random and that it's still possible to have departures from what the naive student of probability might expect. And I cannot resist the pedantic correction that this is for a single die rather than "dice", which is plural.

提交回复
热议问题