From: Rhys on 4 Feb 2010 06:21 Hi, generating 30 random normally distributed numbers with NormalRnd = normrnd(0.4,0.1,30,1); Is there an easy way to constrain normrnd so I only get values 2SD around the mean? I just want 30 normally distributed values between 0.2 and 0.6. Ive searched the newsgroup, and google for 'constrain normrnd' and 'normrnd 2 standard deviations' with no luck. tried this, but question whether its leptokurtic... (0.4- 0.2) * normrnd(1,0.25,30,1) + 0.2 Grateful for any pointers thanks
From: Wayne King on 4 Feb 2010 07:25 "Rhys " <rhyswork**ANTISPAM**@yahoo.co.uk> wrote in message <hkeaj1$m8q$1(a)fred.mathworks.com>... > Hi, > > generating 30 random normally distributed numbers with > NormalRnd = normrnd(0.4,0.1,30,1); > > Is there an easy way to constrain normrnd so I only get values 2SD around the mean? I just want 30 normally distributed values between 0.2 and 0.6. > > Ive searched the newsgroup, and google for 'constrain normrnd' and 'normrnd 2 standard deviations' with no luck. > > tried this, but question whether its leptokurtic... > > (0.4- 0.2) * normrnd(1,0.25,30,1) + 0.2 > > Grateful for any pointers > > thanks Hi Rhys, if you really want to have something that follows a normal probability law centered around 0.4 that does not exceed your interval [0.2,0.6], then I think you need to reduce sigma, but if you have a reason to keep your specifications as you have them, then can't you just select out of NormalRnd those values that satisfy your constraints? NormalRnd = normrnd(0.4,0.1,30,1); Indices = find(NormalRnd >=0.2 & NormalRnd <=0.6); NormalRnd=NormalRnd(Indices); hist(NormalRnd) Wayne
From: John D'Errico on 4 Feb 2010 08:10 "Rhys " <rhyswork**ANTISPAM**@yahoo.co.uk> wrote in message <hkeaj1$m8q$1(a)fred.mathworks.com>... > Hi, > > generating 30 random normally distributed numbers with > NormalRnd = normrnd(0.4,0.1,30,1); > > Is there an easy way to constrain normrnd so I only get values 2SD around the mean? I just want 30 normally distributed values between 0.2 and 0.6. > > Ive searched the newsgroup, and google for 'constrain normrnd' and 'normrnd 2 standard deviations' with no luck. > > tried this, but question whether its leptokurtic... > > (0.4- 0.2) * normrnd(1,0.25,30,1) + 0.2 > > Grateful for any pointers What you are asking for is a truncated normal distribution. There are several ways to generate such numbers, all equally valid. The simplest is a rejection method. Simply generate a random sample, then discard those which fail your criteria. If you need more, then generate additional samples to fill in those you have lost. This is an entirely valid method. A second approach uses the cumulative normal. +/-2*sigma lies at the points normcdf(2) ans = 0.977249868051821 normcdf(-2) ans = 0.0227501319481792 So simply generate UNIFORM random samples in an appropriate interval, then invert the normal CDF at those points. p = normcdf(-2); U = rand(30,1)*(1-2*p) + p; G = norminv(U); The vector G is assured to lie in the proper interval, and to follow a truncated normal over that domain. John
From: Rhys on 4 Feb 2010 09:30 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hkeeb1$lef$1(a)fred.mathworks.com>... > "Rhys " <rhyswork**ANTISPAM**@yahoo.co.uk> wrote in message <hkeaj1$m8q$1(a)fred.mathworks.com>... > > Hi, > > > > generating 30 random normally distributed numbers with > > NormalRnd = normrnd(0.4,0.1,30,1); > > > > Is there an easy way to constrain normrnd so I only get values 2SD around the mean? I just want 30 normally distributed values between 0.2 and 0.6. > > > > Ive searched the newsgroup, and google for 'constrain normrnd' and 'normrnd 2 standard deviations' with no luck. > > > > tried this, but question whether its leptokurtic... > > > > (0.4- 0.2) * normrnd(1,0.25,30,1) + 0.2 > > > > Grateful for any pointers > > > > thanks > > Hi Rhys, if you really want to have something that follows a normal probability law centered around 0.4 that does not exceed your interval [0.2,0.6], then I think you need to reduce sigma, but if you have a reason to keep your specifications as you have them, then can't you just select out of NormalRnd those values that satisfy your constraints? > > NormalRnd = normrnd(0.4,0.1,30,1); > Indices = find(NormalRnd >=0.2 & NormalRnd <=0.6); > NormalRnd=NormalRnd(Indices); > hist(NormalRnd) > > Wayne Thanks Wayne, Youre code is the methods Im going to use, although Ill calculate say 60, do your code and then just take 30 from that, as after the indicies bit, I dont have 30 data points. I guess, having thought about it more, if your cutting the tails off it will never be a normal distribution, but so long as it's good enough for stats tests etc to hold. regards Rhys
From: Rhys on 4 Feb 2010 09:32 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hkeh09$e5g$1(a)fred.mathworks.com>... > "Rhys " <rhyswork**ANTISPAM**@yahoo.co.uk> wrote in message <hkeaj1$m8q$1(a)fred.mathworks.com>... > > Hi, > > > > generating 30 random normally distributed numbers with > > NormalRnd = normrnd(0.4,0.1,30,1); > > > > Is there an easy way to constrain normrnd so I only get values 2SD around the mean? I just want 30 normally distributed values between 0.2 and 0.6. > > > > Ive searched the newsgroup, and google for 'constrain normrnd' and 'normrnd 2 standard deviations' with no luck. > > > > tried this, but question whether its leptokurtic... > > > > (0.4- 0.2) * normrnd(1,0.25,30,1) + 0.2 > > > > Grateful for any pointers > > What you are asking for is a truncated normal > distribution. There are several ways to generate > such numbers, all equally valid. > > The simplest is a rejection method. Simply > generate a random sample, then discard those > which fail your criteria. If you need more, then > generate additional samples to fill in those you > have lost. This is an entirely valid method. > > A second approach uses the cumulative normal. > +/-2*sigma lies at the points > > normcdf(2) > ans = > 0.977249868051821 > > normcdf(-2) > ans = > 0.0227501319481792 > > So simply generate UNIFORM random samples > in an appropriate interval, then invert the > normal CDF at those points. > > p = normcdf(-2); > U = rand(30,1)*(1-2*p) + p; > G = norminv(U); > > The vector G is assured to lie in the proper > interval, and to follow a truncated normal over > that domain. > > John Thanks very much John, that gives me something to read more about, and a couple of solutions, exactly what I was looking for.
|
Next
|
Last
Pages: 1 2 Prev: rolling GARCH with forecasts Next: Measure force from a pneumatic piston chamber |