In R, I would like to generate a multinomially distributed random number vector of a given size N, for example using rmultinom, but with a maximum size for each of the K boxes. For example:
set.seed(1)
draw = rmultinom(n = 1, size = 1000, prob = c(67,211,264,166,144,52,2,175))
In this case, the size is 1000, specifying the total number of objects that are put into eight boxes (the length of prob), and prob = c(67,211,264,166,144,52,2,175) the vector of probabilities for the eight boxes (which is internally normalized to sum 1). In addition, I would like c(67,211,264,166,144,52,2,175) to be the vector of the maximum size for each of the eight boxes.
However in this case, it is possible to generate numbers that are higher than c(67,211,264,166,144,52,2,175) (for instance in the example above, draw[7,]=4 is higher than 2), whereas I would like each number to be lower or equal to the maximum size of each box specified in prob, in addition to draw summing to size = 1000.
Do you know any function or any simple way to do that? I was not able to find the answer.
Aucun commentaire:
Enregistrer un commentaire