Avoid negative values of random variables from normal distribution
10 ビュー (過去 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
2013 年 7 月 15 日
Elaborate on "not ok". Why shouldn't a normal distribution produce negative values?
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
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!