Reputation: 3
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 other individual number.
I can do this for an unbiased dice but not sure what to do for this one.
Thanks
Upvotes: 0
Views: 4600
Reputation: 263381
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.
Upvotes: 3
Reputation: 5471
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))
Upvotes: 0
Reputation: 9923
sample(1:6, size = 44, replace = TRUE, prob = c(rep(1, 5), 2))
Upvotes: 0