How do I genenate random (or pseudo random) numbers from a list with a specified distribution

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

回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 5 月 31 日

0 投票

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 件のコメント

Oleg Komarov
Oleg Komarov 2011 年 5 月 31 日
@Raymundo: maybe you're trying to sample from a given distribution by taking the inverse cdf of a uniform [0 1]?
Walter Roberson
Walter Roberson 2011 年 5 月 31 日
I agree, that would make much more sense to do.
Raymundo Addun
Raymundo Addun 2011 年 5 月 31 日
Dear Oleg and Walter,
No, not really interested in the uniform distribution. I just thought it might be possible to have a sample distribution (the 50 cases) different from a population distribution (the 10000 cases). Ok, if I cannot chose the distribution Id like to have in the sample, can I at least have a sample ¨not equal¨ in distribution as the population with a given significance level of equality (in a normality test for example)?
ray
Walter Roberson
Walter Roberson 2011 年 5 月 31 日
Sub-selections are more likely than not to have a different mean. But getting the mean different _enough_ to be significant might be difficult; my intuition is that it would sometimes be impossible, but I would need to think about that more.
Walter Roberson
Walter Roberson 2011 年 5 月 31 日
What if you "reverse engineer" kstest2() in order to determine how you would have to subsample in order to get a sufficiently high confidence for your purposes?
Oleg Komarov
Oleg Komarov 2011 年 5 月 31 日
@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
Raymundo Addun
Raymundo Addun 2011 年 6 月 1 日
Oleg: its easy to generate a sample with a given distribution even without using the CDF inverse method. I really am not sure how might I solve my problem using the CDF inverse. Could you elaborate your idea . I already have a normally distributed population generated through the randn command.

サインインしてコメントする。

Laura Proctor
Laura Proctor 2011 年 5 月 31 日
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)
Here's a link to all the random number generator functions.

2 件のコメント

Walter Roberson
Walter Roberson 2011 年 5 月 31 日
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.)
Raymundo Addun
Raymundo Addun 2011 年 5 月 31 日
indeed, i need a sample from the list.

サインインしてコメントする。

質問済み:

2011 年 5 月 31 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by