an elegant sampler
Following an X validated question on how to simulate a multinomial with fixed average, W. Huber produced a highly elegant and efficient resolution with the compact R code tabulate(sample.int((k-1)*n, s-n) %% n + 1, n) + 1 where k is the number of classes, n the number of draws, and s ...
[Read more...]