1

How can I only use the random uniform generator to create a multinomial distribution with the following probabilities: ((0.2, 0.1, 0.3, 0.4).

Alex
  • 15
  • 2

2 Answers2

1

You can use the sample() function to sample from distributions with customized probabilities. In your case:

x <- sample(1:4, size = 100, replace = TRUE, prob = c(.2, .1, .3, .4))

This gives 100 numbers from 1 to 4 with the probabilities you provided.

sample() uses the random number generator from R, so I'm not sure if you count this as using the random uniform generator.

Thomas
  • 51
  • 3
0

generate some number between [0,1] uniformly, if it is in [0,0.2], assign it to the first value (call it x1), if it is between [0.2,0.3],x2, [0.3,0.6] x3, [0.7,1] x4. Then it is ensured, for example, the probability of x1 is 0.2.

caden Hong
  • 147
  • 1
  • 10