Achaz von Hardenberg
2008-Oct-06 22:54 UTC
[R] random normally distributed values within range
Hi all, I need to create 100 normally distributed random values (X) which can not exceed a specific range (i.e. 0<X<Y). With rnorm I cannot specify Max and min values among which values have to stay, like in runif so does some other simple way exist to do this with normally distributed random values? thanks a lot in advance, Dr. Achaz von Hardenberg ------------------------------------------------------------------------ -------------------------------- Centro Studi Fauna Alpina - Alpine Wildlife Research Centre Servizio Sanitario e della Ricerca Scientifica Parco Nazionale Gran Paradiso, Degioz, 11, 11010-Valsavarenche (Ao), Italy
Pedro.Rodriguez at sungard.com
2008-Oct-06 23:52 UTC
[R] random normally distributed values within range
Hi Achaz, Maybe you are interested in the generalized beta distribution? To the best of my knowledge, there is no way to restrict the values of normal deviates, since one may end up with a different distribution. Regards, Pedro -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Achaz von Hardenberg Sent: Monday, October 06, 2008 6:55 PM To: r-help at r-project.org Subject: [R] random normally distributed values within range Hi all, I need to create 100 normally distributed random values (X) which can not exceed a specific range (i.e. 0<X<Y). With rnorm I cannot specify Max and min values among which values have to stay, like in runif so does some other simple way exist to do this with normally distributed random values? thanks a lot in advance, Dr. Achaz von Hardenberg ------------------------------------------------------------------------ -------------------------------- Centro Studi Fauna Alpina - Alpine Wildlife Research Centre Servizio Sanitario e della Ricerca Scientifica Parco Nazionale Gran Paradiso, Degioz, 11, 11010-Valsavarenche (Ao), Italy ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On 7/10/2008, at 11:54 AM, Achaz von Hardenberg wrote:> Hi all, > I need to create 100 normally distributed random values (X) which can > not exceed a specific range (i.e. 0<X<Y). > With rnorm I cannot specify Max and min values among which values > have to stay, like in runif so does some other simple way exist to do > this with normally distributed random values?Presumably you want a truncated normal distribution. Duncan Murdoch posted some neat code on this list, back in the end of July this year, to generate samples from such a distribution. See: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/137154.html cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
one could also use the "Truncate"-methods of package distr; cf. http://tolstoy.newcastle.edu.au/R/e5/help/08/09/1870.html If the situation is extreme Peter Daalgard gave some sophisticated code at http://tolstoy.newcastle.edu.au/R/e5/help/08/09/1892.html Best, Matthias Rolf Turner wrote:> > On 7/10/2008, at 11:54 AM, Achaz von Hardenberg wrote: > >> Hi all, >> I need to create 100 normally distributed random values (X) which can >> not exceed a specific range (i.e. 0<X<Y). >> With rnorm I cannot specify Max and min values among which values >> have to stay, like in runif so does some other simple way exist to do >> this with normally distributed random values? > > Presumably you want a truncated normal distribution. Duncan Murdoch > posted some neat code on this list, back in the end of July this year, > to generate samples from such a distribution. > > > See: > > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/137154.html > > cheers, > > Rolf Turner > > ###################################################################### > Attention:\ This e-mail message is privileged and confid...{{dropped:9}} > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Dr. Matthias Kohl www.stamats.de