Avoid negative values of random variables from normal distribution
10 views (last 30 days)
Show older comments
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 Comments
Matt J
on 15 Jul 2013
Elaborate on "not ok". Why shouldn't a normal distribution produce negative values?
dpb
on 15 Jul 2013
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.
Answers (1)
Jan
on 15 Jul 2013
Edited: Jan
on 15 Jul 2013
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!