Re: [R] random numbers with constraints

2021-01-28 Thread Abby Spurdle
I recognize the problems with global data. And my code could certainly be improved. However, I also note that the random numbers (ignoring transformations), need to be constant, while computing the rate. Otherwise, my algorithm wouldn't work well. As it is, rounding operations can cause "jumps".

Re: [R] random numbers with constraints

2021-01-28 Thread Martin Maechler
> Abby Spurdle > on Thu, 28 Jan 2021 08:48:06 +1300 writes: > I note that there's a possibility of floating point errors. > If all values have one digit after the decimal point, you could replace: > qexp (p, rate) with round (qexp (p, rate), 1). > However, sometimes u

Re: [R] random numbers with constraints

2021-01-28 Thread Denis Francisci
Thanks again for your help, One digit after the decimal point is enough for my purposes; so, I can round the qexp function, even if possible errors in floating points are not a problem. Thank you very very much, Denis Il giorno mer 27 gen 2021 alle ore 20:48 Abby Spurdle ha scritto: > I note

Re: [R] random numbers with constraints

2021-01-27 Thread Abby Spurdle
I note that there's a possibility of floating point errors. If all values have one digit after the decimal point, you could replace: qexp (p, rate) with round (qexp (p, rate), 1). However, sometimes uniroot will fail, due to problems with input. On Thu, Jan 28, 2021 at 5:02 AM Denis Francisci wr

Re: [R] random numbers with constraints

2021-01-27 Thread Denis Francisci
Wonderful! This is exactly what I need! Thank you very much!! Denis Il giorno mer 27 gen 2021 alle ore 10:58 Abby Spurdle ha scritto: > u <- runif (410) > u <- (u - min (u) ) / diff (range (u) ) > > constrained.sample <- function (rate) > { plim <- pexp (c (9.6, 11.6), rate) > p <- plim

Re: [R] random numbers with constraints

2021-01-27 Thread Abby Spurdle
u <- runif (410) u <- (u - min (u) ) / diff (range (u) ) constrained.sample <- function (rate) { plim <- pexp (c (9.6, 11.6), rate) p <- plim [1] + diff (plim) * u qexp (p, rate) } diff.sum <- function (rate) sum (constrained.sample (rate) ) - 4200 rate <- uniroot (diff.sum, c (1,

Re: [R] random numbers with constraints

2021-01-27 Thread Ralf Goertz
Am Wed, 27 Jan 2021 09:03:15 +0100 schrieb Denis Francisci : > Hi, > I would like to generate random numbers in R with some constraints: > - my vector of numbers must contain 410 values; > - min value must be 9.6 and max value must be 11.6; > - sum of vector's values must be 4200. > Is there a way

[R] random numbers with constraints

2021-01-27 Thread Denis Francisci
Hi, I would like to generate random numbers in R with some constraints: - my vector of numbers must contain 410 values; - min value must be 9.6 and max value must be 11.6; - sum of vector's values must be 4200. Is there a way to do this in R? And is it possible to generate this series in such a way

Re: [R] random numbers

2012-02-19 Thread Petr Savicky
On Sun, Feb 19, 2012 at 08:39:13PM -0800, Ryan Murphy wrote: > Hello, > > Is there a way to create random numbers that fit a certain specified > requirement other than distributional characteristics. > In particular, I would like to create simulated income distributions with > certain gini coeffic

[R] random numbers

2012-02-19 Thread Ryan Murphy
Hello, Is there a way to create random numbers that fit a certain specified requirement other than distributional characteristics. In particular, I would like to create simulated income distributions with certain gini coefficient Ryan -- Ryan Murphy 2012 B.A. Economics and Mathematics

Re: [R] Random numbers with PDF of user-defined function

2010-04-29 Thread Duncan Murdoch
On 29/04/2010 5:40 AM, Nick Crosbie wrote: Hi, In S+/R, is there an easy way to generate random numbers with a probability distribution specified by an exact user-defined function? For example, I have a function: f(x) = 1/(365 * x), which should be fitted for values of x between 1 and 100,000

Re: [R] Random numbers with PDF of user-defined function

2010-04-29 Thread Robert A LaBudde
At 05:40 AM 4/29/2010, Nick Crosbie wrote: Hi, In S+/R, is there an easy way to generate random numbers with a probability distribution specified by an exact user-defined function? For example, I have a function: f(x) = 1/(365 * x), which should be fitted for values of x between 1 and 100,000

[R] Random numbers with PDF of user-defined function

2010-04-29 Thread Nick Crosbie
Hi, In S+/R, is there an easy way to generate random numbers with a probability distribution specified by an exact user-defined function? For example, I have a function: f(x) = 1/(365 * x), which should be fitted for values of x between 1 and 100,000 How do I generate random numbers with a prob

Re: [R] Random numbers for a group

2009-12-15 Thread Ted Harding
On 15-Dec-09 13:35:36, Jorge Ivan Velez wrote: > Dear Maithili, > Here are two suggestions: > ># data set > x <- read.table(textConnection("Name no_of_instances > AAA 12 > AA17 > A 0 > BBB 11 > BB 6 > B 0 > C 8 > D 3"), header = TRUE) > closeAllConnections() > x >

Re: [R] Random numbers for a group

2009-12-15 Thread Jorge Ivan Velez
Dear Maithili, Here are two suggestions: # data set x <- read.table(textConnection("Name no_of_instances AAA 12 AA17 A 0 BBB 11 BB 6 B 0 C 8 D 3"), header = TRUE) closeAllConnections() x # option 1 do.call(c,with(x, tapply(no_of_instances, Name, runif))) # option

[R] Random numbers for a group

2009-12-15 Thread Maithili Shiva
Dear R helpers I have following table Name no_of_instances    AAA                             12                                AA                               17                                A                                  0                              

Re: [R] random numbers in C

2009-11-13 Thread Duncan Murdoch
On 11/13/2009 11:41 AM, Thomas Unternaehrer wrote: I need some random numbers in my C program. Here a small example: #include void rand (int* n) { int len = *n; for (int i = 0; i < len; i++) Rprintf("%1.5f

Re: [R] random numbers in C

2009-11-13 Thread Thomas Unternaehrer
Ups... I've overlooked that part. Thanks a lot for the fast response! On Fri, Nov 13, 2009 at 6:05 PM, Duncan Murdoch wrote: > On 11/13/2009 11:41 AM, Thomas Unternaehrer wrote: > >> I need some random numbers in my C program. Here a small example: >> >> >> //

[R] random numbers in C

2009-11-13 Thread Thomas Unternaehrer
I need some random numbers in my C program. Here a small example: #include void rand (int* n) { int len = *n; for (int i = 0; i < len; i++) Rprintf("%1.5f ", unif_rand()); } dyn.load("rand.dll") .C("rand",

Re: [R] random numbers between 0 and 1

2009-10-21 Thread Rolf Turner
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.2991260

Re: [R] random numbers between 0 and 1

2009-10-21 Thread Barry Rowlingson
On Wed, Oct 21, 2009 at 8:37 PM, Gábor Csárdi 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 d

Re: [R] random numbers between 0 and 1

2009-10-21 Thread Gábor Csárdi
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 wrote: > Hi, > To generate random numbers between 0 and 1, do you use rnorm followed by > dnrom? for ex, for 10 variables >

Re: [R] random numbers between 0 and 1

2009-10-21 Thread Erik Iverson
Uniformly distributed random numbers between 0 and 1? Try ?runif > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of carol white > Sent: Wednesday, October 21, 2009 2:26 PM > To: r-h...@stat.math.ethz.ch > S

[R] random numbers between 0 and 1

2009-10-21 Thread carol white
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.

[R] Random numbers of multivariate power exponential distribution!

2009-08-04 Thread jeremias leao
Dear, R help How can I generate random numbers of the multivariate power exponential distribution. Regards, Jeremias Leão. [[elided Yahoo spam]] [[alternative HTML version deleted]] _