How do I genenate random (or pseudo random) numbers from a list with a specified distribution
9 views (last 30 days)
Show older comments
How do I generate random numbers from a list, with the condition that the numbers must have a given distribution?
What Ive done so far:
I was able to generate random numBers with a normal distribution with
y = 2 + .2*randn(10000,1)
Now I want to pick 3 samples from these numbers with size 50 each, each having normal, lognormal and exponential distributions. How will I do it?
Thanks in advance
0 Comments
Answers (2)
Walter Roberson
on 31 May 2011
Usually you cannot do that. Suppose for example that the list was just 0's and 1's representing flips of a coin. You are not going to be able to get an exponential distribution from such a list.
7 Comments
Oleg Komarov
on 31 May 2011
@Raymundo: the uniform distribution is just a trick to sample from any distribution you chose since it enters the cdf from the y axes and returns the values on x axes according to the distribution you've chosen: http://en.wikipedia.org/wiki/Inverse_transform_sampling
Laura Proctor
on 31 May 2011
Although you won't be able to generate the numbers from the exact data you have in y, you can still generate numbers using the data to gather the parameters, like so:
[muhat,sigmahat] = normfit(y)
rn = muhat*ones(50,1) + chol(sigmahat)*randn(50,1);
parmhat = lognfit(y);
rl = lognrnd(parmhat(1),parmhat(2),50,1);
muhat = expfit(y);
re = exprnd(muhat,50,1)
2 Comments
Walter Roberson
on 31 May 2011
Though this does break the fundamental premise of the question that the numbers must be generated "from a list" (i.e., a given list of values must be sub-selected from to achieve the given distribution.)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!