Hi, To generate random numbers between 0 and 1, do you use rnorm followed by dnrom? for ex, for 10 variables a = rnorm(10)> a[1] -0.87640764 -0.95842391 -1.33434559 -0.63844932 -1.69829393 0.80010865 [7] -0.01026882 -0.23887516 2.29912600 -1.38352143> dnorm(a)[1] 0.27171985 0.25202507 0.16378878 0.32538464 0.09432211 0.28966637 [7] 0.39892125 0.38772103 0.02838403 0.15320103 Regards,
Uniformly distributed random numbers between 0 and 1? Try ?runif> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of carol white > Sent: Wednesday, October 21, 2009 2:26 PM > To: r-help at stat.math.ethz.ch > Subject: [R] random numbers between 0 and 1 > > Hi, > To generate random numbers between 0 and 1, do you use rnorm followed by > dnrom? for ex, for 10 variables > > a = rnorm(10) > > a > [1] -0.87640764 -0.95842391 -1.33434559 -0.63844932 -1.69829393 > 0.80010865 > [7] -0.01026882 -0.23887516 2.29912600 -1.38352143 > > dnorm(a) > [1] 0.27171985 0.25202507 0.16378878 0.32538464 0.09432211 0.28966637 > [7] 0.39892125 0.38772103 0.02838403 0.15320103 > > > Regards, > > ______________________________________________ > 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.
I would suggest to use the generator at http://submoon.freeshell.org/pix/valium/dilbert_rng.jpg and subtract 8.5. Best, Gabor On Wed, Oct 21, 2009 at 9:25 PM, carol white <wht_crl at yahoo.com> wrote:> Hi, > To generate random numbers between 0 and 1, do you use rnorm followed by dnrom? for ex, for 10 variables > > a = rnorm(10) >> a > ?[1] -0.87640764 -0.95842391 -1.33434559 -0.63844932 -1.69829393 ?0.80010865 > ?[7] -0.01026882 -0.23887516 ?2.29912600 -1.38352143 >> dnorm(a) > ?[1] 0.27171985 0.25202507 0.16378878 0.32538464 0.09432211 0.28966637 > ?[7] 0.39892125 0.38772103 0.02838403 0.15320103 > > > Regards, > > ______________________________________________ > 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. >-- Gabor Csardi <Gabor.Csardi at unil.ch> UNIL DGM
On Wed, Oct 21, 2009 at 8:37 PM, G?bor Cs?rdi <csardi at rmki.kfki.hu> wrote:> I would suggest to use the generator at > http://submoon.freeshell.org/pix/valium/dilbert_rng.jpg > and subtract 8.5.You may laugh (indeed I did) but some medical trials have used (and poss still do) telephone-a-human random numbers. When deciding to give medicine or placebo the doctor calls the phone number and asks for a random number, which is read out, and this decides what the patient gets. I suppose this could be implemented in R with an interface to a speech recognition engine and a telephone... but runif(100) is easier. Barry
On 22/10/2009, at 8:25 AM, carol white wrote:> Hi, > To generate random numbers between 0 and 1, do you use rnorm > followed by dnrom? for ex, for 10 variables > > a = rnorm(10) >> a > [1] -0.87640764 -0.95842391 -1.33434559 -0.63844932 -1.69829393 > 0.80010865 > [7] -0.01026882 -0.23887516 2.29912600 -1.38352143 >> dnorm(a) > [1] 0.27171985 0.25202507 0.16378878 0.32538464 0.09432211 0.28966637 > [7] 0.39892125 0.38772103 0.02838403 0.15320103Well, this will give you random (in some sense) numbers between 0 and 1. (Actually they will be between 0 and dnorm(0) = approx. 0.3989.) Just what the *distribution* of these numbers would be is obscure to me. You should also be aware that the values of dnorm() could be *larger* than 1, if the standard deviation were specified to be something smaller than the default value of 1. (Note that dnorm() is a ***density***, not a probability function.) Anyway this is a very convoluted way of going at the problem. Why not just generate random numbers between 0 an 1 ``directly'', using runif()? cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}