Avoid negative values of random variables from normal distribution

11 次查看(过去 30 天)
Hi
I need to get random variables from normal distribution with a mean=7300; and standard deviation=2500. I use the following code: mean=7300; std=2500; x=mean+std*randn(10000,1)
It is not ok as it gives me negative values. How to tackle this problem??
Waiting for immediate help.
  2 个评论
Matt J
Matt J 2013-7-15
Elaborate on "not ok". Why shouldn't a normal distribution produce negative values?
dpb
dpb 2013-7-15
Change your expectations???
z0 = (0-7300)/2500 < -3
p(z0) > ...well, let's just get it exactly...
>> pZ0=normcdf(-7300/2500, 7300,2500)
pZ0 =
0.0017
>>
So, out of 10000 rnv's one should expect roughly 17 <0.
You can always truncate the distribution at zero, but it's then no longer strictly normally distributed--the left tail area will be undersampled. W/ the percentage this low you can likely select an additional number and find replacements with only one or two more trials but remember you'll thus not retain a "real" normally distributed sample.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2013-7-15
编辑:Jan 2013-7-15
It isn't surpring that you find elements with more than 2.92 standard deviations in a normal distribution. It is not clear how you want to avoid this. Perhaps a rejection helps:
M = 7300; % Avoid shadowing the builtin functions mean and std!
S = 2500;
x = [];
while length(x) < 10000
x = M + S * randn(15000, 1);
x(x <= 0) = [];
end
x = x(1:10000);
But this is a cropped deviation, such that the mean will not equal M anymore.

Community Treasure Hunt

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

Start Hunting!

Translated by