Simulate a binominal distribution Random number generators initially provide uni
ID: 3201030 • Letter: S
Question
Simulate a binominal distribution Random number generators initially provide uniformly distributed random numbers in a interval of unit length, but often we need to sample from other distributions. Suppose that we wish to simulate a random variable n drawn from P_binom(n, N = 3, p). We can do this by partitioning the unit segment into four bins of width (1 - p)^3, 3p(1 - p)^2, 3p^2(1 - p) and p^3, corresponding to n = 0, 1, 2, 3. The width of each bin is thus proportional to the probability of occurrence. To sample from P_binom (n, N, p) one thus simply draws a uniformly distributed random number and finds the bin index into which that number falls. Write a function binom setup that accepts a value of p and returns a list of locations of the bin edges appropriate for N = 5. Write another function binom_dist that accepts the list of bin edges as input and returns a single binomially distributed random variable.Explanation / Answer
(1-p)3,3p(1-p)2,3p2(1-p)2 are binomial distribution held so that they can be single variable