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
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.
sample(1:6, size = 44, replace = TRUE, prob = c(rep(1, 5), 2))
You can use sample and specify probabilities for each number.
sample(x = 1:6, size = 44, replace = T, prob = c(rep(1/7, 5), 2/7))