Hello all: Is it possible to generate quasi-random positive numbers, given a standard deviation and mean? I need all positive values to have the same probability of selection (uniform distribution). Something like: runif(10, min = 0, max = 100) This way I'm generating random positive numbers from a uniform distribution. However, using runif I can't previously select SD and mean (as in rnorm). Alternatively, I'm able to generate a list of quasi-random numbers given a SD and a mean. b <- (sqrt(SD^2*12)+(MEAN*2))/2 a <- (MEAN*2) - b x1 <- runif(N,a,b) However, negative values might be included, since "a" can assume a negative value. Any help? Thanks, Frederico [[alternative HTML version deleted]]
On 05-Aug-2014 10:27:54 Frederico Mestre wrote:> Hello all: > > Is it possible to generate quasi-random positive numbers, given a standard > deviation and mean? I need all positive values to have the same probability > of selection (uniform distribution). Something like: > > runif(10, min = 0, max = 100) > > This way I'm generating random positive numbers from a uniform > distribution. However, using runif I can't previously select SD and mean > (as in rnorm). > > Alternatively, I'm able to generate a list of quasi-random numbers given a > SD and a mean. > > b <- (sqrt(SD^2*12)+(MEAN*2))/2 > a <- (MEAN*2) - b > x1 <- runif(N,a,b) > > However, negative values might be included, since "a" can assume a negative > value. > > Any help? > > Thanks, > FredericoThere is an inevitable constraint on MEAN and SD for a uniform ditribution of positive numbers. Say the parent distribution is uniform on (a,b) with a >= 0 and b > a. Then MEAN = (a+b)/2, SD^2 = ((b-a)^2)/12, so 12*SD^2 = b^2 - 2*a*b + a^2 4*MEAN^2 = b^2 + 2*a*b + a^2 4*MEAN^2 - 12*SD^2 = 4*a*b MEAN^2 - 3*SD^2 = a*b Hence for a >= 0 and b > a you must have MEAN^2 >= 3*SD^2. Once you have MEAN and SD satisfying this constraint, you should be able to solve the equations for a and b. Hoping this helps, Ted. ------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at wlandres.net> Date: 05-Aug-2014 Time: 11:46:52 This message was sent by XFMail
Hi,
As a slight aside, did you mean pseudo-random or quasi-random?
http://en.wikipedia.org/wiki/Pseudorandom_number_generator
http://en.wikipedia.org/wiki/Low-discrepancy_sequence
runif gives a sequence of pseudo-random numbers, for quasi-random numbers you
will need something else, for example the Sobol generator from
http://cran.r-project.org/web/packages/randtoolbox/index.html.
Martyn
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Frederico Mestre
Sent: 05 August 2014 11:28
To: r-help at r-project.org
Subject: [R] Generate quasi-random positive numbers
Hello all:
Is it possible to generate quasi-random positive numbers, given a standard
deviation and mean? I need all positive values to have the same probability of
selection (uniform distribution). Something like:
runif(10, min = 0, max = 100)
This way I'm generating random positive numbers from a uniform distribution.
However, using runif I can't previously select SD and mean (as in rnorm).
Alternatively, I'm able to generate a list of quasi-random numbers given a
SD and a mean.
b <- (sqrt(SD^2*12)+(MEAN*2))/2
a <- (MEAN*2) - b
x1 <- runif(N,a,b)
However, negative values might be included, since "a" can assume a
negative value.
Any help?
Thanks,
Frederico
[[alternative HTML version deleted]]
______________________________________________
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.
________________________________________________________________________
This e-mail has been scanned for all viruses by Star.\ _...{{dropped:3}}