[R] random numbers

2007-06-30 Thread Ross Boylan
Although this query was inspired by distributed random number
generation, one of the questions (#2 below) is a single-machine issue.

I call C++ code from R to generate simulated data.  I'm doing this on a
cluster, and use rmpi and rsprng.  While rsprng randomizes R-level
random numbers (e.g., from runif), it has no effect on the C code, which
is completely SPRNG and MPI ignorant.

Currently I generate a seed to pass into the C code, using
as.integer(runif(1, max=.Machine$integer.max)-.Machine$integer.max/2)
It seems to work.

Any comments on this approach?  Here are some issues I see:

1) The much simpler method of using the consecutive integers as seeds
also seemed to work.  This also has the advantage of repeatability.  I
avoided it because I was concerned it wouldn't be random enough.  Would
consecutive integers as in
  parLapply(cluster, seq(nSimulations), function(i) myfunction(seed=i))
be sufficient?

I suppose I could also generate all the random seeds on the master.

2) This got me thinking about how to generate random integers that span
the whole range of 32 bit signed integers.  The method show above only
spans half the range, since .Machine$integer.max = 2^31.  It also makes
some assumptions about the relation between the value in  .Machine
$integer.max and the seed for random numbers.  Interestingly,
integer.max was 2^31 despite running on a 64 bit powerpc, albeit under
the mostly 32 bit OS-X (I think Leopard--not the current one; Darwin
Kernel 7.9.0).

My understanding is that random number generators internally produce 32
bit integers, which then get converted into the desired distribution.
I'm a little surprised there doesn't seem to be a way to get at them.
Or is one supposed to do runif()*2^32-2^31?

3) Vagaries of the underlying C++ random number generator could also
complicate life.

__
R-help@stat.math.ethz.ch 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.


Re: [R] random numbers

2007-06-30 Thread Dirk Eddelbuettel

On 30 June 2007 at 12:12, Ross Boylan wrote:
| I call C++ code from R to generate simulated data.  I'm doing this on a
| cluster, and use rmpi and rsprng.  While rsprng randomizes R-level
| random numbers (e.g., from runif), it has no effect on the C code, which
| is completely SPRNG and MPI ignorant.
| 
| Currently I generate a seed to pass into the C code, using
| as.integer(runif(1, max=.Machine$integer.max)-.Machine$integer.max/2)
| It seems to work.
| 
| Any comments on this approach?  Here are some issues I see:

I may be missing something but given that rsprng is running on your cluster,
you are bound to also have sprng itself -- so why don't you use that from C
or C++  for this purpose?

Hth, Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
  -- Thomas A. Edison

__
R-help@stat.math.ethz.ch 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.


Re: [R] random numbers

2007-06-30 Thread Ross Boylan
On Sat, 2007-06-30 at 14:50 -0500, Dirk Eddelbuettel wrote:
 On 30 June 2007 at 12:12, Ross Boylan wrote:
 | I call C++ code from R to generate simulated data.  I'm doing this on a
 | cluster, and use rmpi and rsprng.  While rsprng randomizes R-level
 | random numbers (e.g., from runif), it has no effect on the C code, which
 | is completely SPRNG and MPI ignorant.
 | 
 | Currently I generate a seed to pass into the C code, using
 | as.integer(runif(1, max=.Machine$integer.max)-.Machine$integer.max/2)
 | It seems to work.
 | 
 | Any comments on this approach?  Here are some issues I see:
 
 I may be missing something but given that rsprng is running on your cluster,
 you are bound to also have sprng itself -- so why don't you use that from C
 or C++  for this purpose?
 
 Hth, Dirk
Doing so would add considerable complexity, at least as far as I know.

Sometimes I run within an MPI session and sometimes not.  My
understanding is that SPRNG will not work if MPI is absent.  I think
someone on the SPRNG list told me that there wasn't a good way to handle
this at run-time.  Unfortunately, a lot of SPRNG options seem to be
compile-time settings.

Using SPRNG would also complicate my build process, as I'd need autoconf
magic to support it.

Part of the issue is that I want something I can redistribute, not just
something that will work for me on a  one-off basis.

One simple solution would be to build several versions of the library.
A not so simple solution would be to build various random number
generators as separate libraries, and dynamically load the appropriate
one.

__
R-help@stat.math.ethz.ch 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.


[R] Random numbers from skewed distributions

2007-06-25 Thread Anup Nandialath
Dear Friends,

I was wondering if there is any package to get random numbers from the Burr 10 
distribution. I checked the rmutil and actuar package. Both seems to implement 
the Burr 12 distribution.

thanks in advance
Regards

Anup

   
-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


[R] random numbers selection - simple example

2007-06-06 Thread Jenny Barnes
Dear R-help,

Which random number generator function would you recommend for simply picking 
15 
random numbers from the sequence 0-42? I want to use replacement (so that the 
same number could potentially be picked more than once).

I have read the R-help archives and the statistics and computing book on modern 
Applied statistics with S but the advice seems to be for much form complicated 
examples, there must be a simpler way for what I am trying to do?

If anybody can help me I would greatly appreciate your advice and time,

Best Wishes,

Jenny


~~
Jennifer Barnes
PhD student: long range drought prediction 
Climate Extremes Group
Department of Space and Climate Physics
University College London
Holmbury St Mary 
Dorking, Surrey, RH5 6NT
Web: http://climate.mssl.ucl.ac.uk

__
R-help@stat.math.ethz.ch 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.


Re: [R] random numbers selection - simple example

2007-06-06 Thread Jenny Barnes
You're all stars - thanks for the replies - I will go ahead and use 
sample...
I need to do this about 10,000 times - any suggestions for this or simply put 
it 
in a loop 10,000 times outputting each time to an array?

Best Wishes,

Jenny 




  use sample(c(0:42), 15, replace=T)

hope it helps,
kevin

- Original Message -
From: Jenny Barnes [EMAIL PROTECTED]
Date: Wednesday, June 6, 2007 10:30 am
Subject: [R] random numbers selection - simple example

 Dear R-help,
 
 Which random number generator function would you recommend for 
 simply picking 15 
 random numbers from the sequence 0-42? I want to use replacement 
 (so that the 
 same number could potentially be picked more than once).
 
 I have read the R-help archives and the statistics and computing 
 book on modern 
 Applied statistics with S but the advice seems to be for much form 
 complicated 
 examples, there must be a simpler way for what I am trying to do?
 
 If anybody can help me I would greatly appreciate your advice and 
 time,
 Best Wishes,
 
 Jenny
 
 
 ~~
 Jennifer Barnes
 PhD student: long range drought prediction 
 Climate Extremes Group
 Department of Space and Climate Physics
 University College London
 Holmbury St Mary 
 Dorking, Surrey, RH5 6NT
 Web: http://climate.mssl.ucl.ac.uk
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.htmland provide commented, minimal, self-contained, 
 reproducible code.
 

~~
Jennifer Barnes
PhD student: long range drought prediction 
Climate Extremes Group
Department of Space and Climate Physics
University College London
Holmbury St Mary 
Dorking, Surrey, RH5 6NT
Tel: 01483 204149
Mob: 07916 139187
Web: http://climate.mssl.ucl.ac.uk

__
R-help@stat.math.ethz.ch 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.


Re: [R] random numbers selection - simple example

2007-06-06 Thread Sarah Goslee
Assuming you want only integers, see
?sample

Sarah

On 6/6/07, Jenny Barnes [EMAIL PROTECTED] wrote:
 Dear R-help,

 Which random number generator function would you recommend for simply picking 
 15
 random numbers from the sequence 0-42? I want to use replacement (so that the
 same number could potentially be picked more than once).

 I have read the R-help archives and the statistics and computing book on 
 modern
 Applied statistics with S but the advice seems to be for much form complicated
 examples, there must be a simpler way for what I am trying to do?

 If anybody can help me I would greatly appreciate your advice and time,

 Best Wishes,

 Jenny




-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@stat.math.ethz.ch 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.


Re: [R] random numbers selection - simple example

2007-06-06 Thread Ted Harding
On 06-Jun-07 14:30:44, Jenny Barnes wrote:
 Dear R-help,
 
 Which random number generator function would you recommend for
 simply picking 15 random numbers from the sequence 0-42? I want
 to use replacement (so that the same number could potentially be
 picked more than once).

R has the function sample() which samples a given number of items
from a given set, without replacement by default, but with replacement
if you specify this. Enter

  ?sample

for more information. In the above case

  sample((0:42), 15, replace=TRUE)

will do what you seem to describe above. Example:

 sample((0:42), 15, replace=TRUE)
 [1] 26 38  1 41 11 30 22 37 28  0  0 25 10 39 27

if you want them in random order (i.e. as they come off the line),
or

 sort(sample((0:42), 15, replace=TRUE))
 [1]  1  3  5  8  8 10 16 17 21 25 30 30 33 34 40

if you want them sorted.

Best wishes,
Ted.

 I have read the R-help archives and the statistics and computing
 book on modern Applied statistics with S but the advice seems to
 be for much form complicated examples, there must be a simpler way
 for what I am trying to do?
 
 If anybody can help me I would greatly appreciate your advice and time,
 
 Best Wishes,
 
 Jenny


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 06-Jun-07   Time: 16:24:15
-- XFMail --

__
R-help@stat.math.ethz.ch 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.


Re: [R] random numbers selection - simple example

2007-06-06 Thread Daniel Nordlund
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 On Behalf Of Jenny Barnes
 Sent: Wednesday, June 06, 2007 7:55 AM
 To: r-help@stat.math.ethz.ch
 Subject: Re: [R] random numbers selection - simple example
 
 You're all stars - thanks for the replies - I will go ahead and use
 sample...
 I need to do this about 10,000 times - any suggestions for this or simply put 
 it
 in a loop 10,000 times outputting each time to an array?
 
 Best Wishes,
 
 Jenny
 
 
 
 
   use sample(c(0:42), 15, replace=T)
 
 hope it helps,
 kevin

You could try something like the following

s-matrix(sample(c(0:42), 1*15, replace=TRUE), 1, 15)

which will give you a 1 row matrix with 1 sample of size 15 per row.

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA

__
R-help@stat.math.ethz.ch 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.


[R] Random numbers from noncentral t-distribution

2006-06-30 Thread Long Qu
Hi there: 
   
  I'd thought these two versions of noncentral t-distribution are essentially 
the same: 
   qqplot(rt(1000,df=20,ncp=3),qt(runif(1000),df=20,ncp=3))

  But, the scales of the x-axis and the y-axis are quite different according to 
the QQ-plot. 
   
  Did I make any mistakes somewhere? 
   
   
  Thanks, 
  Long
   


-
 Mp3·è¿ñËÑ-иèÈȸè¸ßËÙÏ   
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] Random numbers from noncentral t-distribution

2006-06-30 Thread Thomas Lumley
On Fri, 30 Jun 2006, Long Qu wrote:

 Hi there:

  I'd thought these two versions of noncentral t-distribution are essentially 
 the same:
   qqplot(rt(1000,df=20,ncp=3),qt(runif(1000),df=20,ncp=3))

  But, the scales of the x-axis and the y-axis are quite different according 
 to the QQ-plot.

  Did I make any mistakes somewhere?


No, I think we did.

We have
 rt
function (n, df, ncp = 0)
{
 if (ncp == 0)
 .Internal(rt(n, df))
 else rnorm(n, ncp)/(rchisq(n, df)/sqrt(df))
}

and the rchisq() in the denominator should be inside the sqrt().


-thomas

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Random numbers from noncentral t-distribution

2006-06-30 Thread Long Qu
Thank you very much for your kind reply. It solved the problem of rt( ). :D
   
  But it seems that the qt( ) also have problems: 
  I modified the rt( ) function as you suggested,
  rt - function (n, df, ncp = 0)
{
if (ncp == 0)
.Internal(rt(n, df))
else rnorm(n, ncp)/sqrt(rchisq(n, df)/df)
}

  Then I increase the number of random variables to 1, and made a QQ-plot:
   qqplot(rt(1,df=20,ncp=3),qt(runif(1),df=20,ncp=3))

  I've got some spurious points at lower-left corner. It seems that qt( ) 
results were truncated. 
   
  I also tried this with another df and ncp: 
   pt(-.75,df=2,ncp=1)
[1] 0.05726429
 sum(qt(1:1/10001,df=2,ncp=1)  -.75)
[1] 0
where I'd expected the last number should be  550 or so, not 0. 
  
 
   
  Thanks again, the modified rt( ) is now OK for my work. 
  Long 
   
  
Thomas Lumley [EMAIL PROTECTED] wrote£º
  On Fri, 30 Jun 2006, Long Qu wrote:

 Hi there:

 I'd thought these two versions of noncentral t-distribution are essentially 
 the same:
  qqplot(rt(1000,df=20,ncp=3),qt(runif(1000),df=20,ncp=3))

 But, the scales of the x-axis and the y-axis are quite different according to 
 the QQ-plot.

 Did I make any mistakes somewhere?


No, I think we did.

We have
 rt
function (n, df, ncp = 0)
{
if (ncp == 0)
.Internal(rt(n, df))
else rnorm(n, ncp)/(rchisq(n, df)/sqrt(df))
}

and the rchisq() in the denominator should be inside the sqrt().


-thomas



-
ÇÀ×¢ÑÅ»¢Ãâ·ÑÓÊÏä-3.5GÈÝÁ¿£¬20M¸½¼þ£¡ 
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] Random numbers from noncentral t-distribution

2006-06-30 Thread Thomas Lumley
On Sat, 1 Jul 2006, Long Qu wrote:

 Thank you very much for your kind reply. It solved the problem of rt( ). :D

  But it seems that the qt( ) also have problems:

Yes, there does seem to be a problem near zero. A clearer version is
   curve(qt(x,df=20,ncp=3),from=0,to=0.004)
   curve(qt(10^x,df=20,ncp=3),from=-10,to=-2,n=1000)

The fix is less obvious here. I'll file it as a bug.

-thomas

Thomas Lumley   Assoc. Professor, Biostatistics
[EMAIL PROTECTED]   University of Washington, Seattle

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Random numbers negatively correlated?

2006-06-27 Thread Christian Hennig
Dear list,

I did simulations in which I generated 1
independent Bernoulli(0.5)-sequences of length 100. I estimated
p for each sequence and I also estimated the conditional probability that 
a one is followed by another one (which should be p as well).
However, the second probability is significantly smaller than 0.5 (namely
about 0.494, see below) and of course smaller than the direct estimates of 
p as well, indicating negative correlation between the random numbers.

See below the code and the results.
Did I do something wrong or are the numbers in 
fact negatively correlated? (A type I error is quite unlikely with a
p-value below 2.2e-16.)

Best,
Christian

set.seed(123456)
n - 100
p - 0.5
simruns - 1
est - est11 - numeric(0)
for (i in 1:simruns){
#if (i/100==round(i/100)) print(i)
 x - rbinom(n,1,p)
 est[i] - mean(x)
 x11 - 3*x[2:n]-x[1:(n-1)]
 est11[i] - sum(x11==2)/sum(x11==2 | x11==(-1))
 # x11==(-1): 0 follows 1, x11==2: 1 follows 1.
}

 print(mean(est))
[1] 0.499554
 print(sd(est)/sqrt(simruns))
[1] 0.0004958232
# OK

 print(mean(est11))
[1] 0.4935211
 print(sd(est11)/sqrt(simruns))
[1] 0.0007136213
# mean(est11)+2*sd(mean)  0.495

 print(sum(estest11))
[1] 5575
 binom.test(5575,1)

Exact binomial test

data:  5575 and 1
number of successes = 5575, number of trials = 1, p-value 
2.2e-16


*** --- ***
Christian Hennig
University College London, Department of Statistical Science
Gower St., London WC1E 6BT, phone +44 207 679 1698
[EMAIL PROTECTED], www.homepages.ucl.ac.uk/~ucakche

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Random numbers negatively correlated?

2006-06-27 Thread Thomas Lumley
On Tue, 27 Jun 2006, Christian Hennig wrote:

 Dear list,

 I did simulations in which I generated 1
 independent Bernoulli(0.5)-sequences of length 100. I estimated
 p for each sequence and I also estimated the conditional probability that
 a one is followed by another one (which should be p as well).
 However, the second probability is significantly smaller than 0.5 (namely
 about 0.494, see below) and of course smaller than the direct estimates of
 p as well, indicating negative correlation between the random numbers.

 See below the code and the results.
 Did I do something wrong or are the numbers in
 fact negatively correlated? (A type I error is quite unlikely with a
 p-value below 2.2e-16.)

I think you did something wrong, and that there is a problem with 
overlapping blocks of two.

If you do
   x-matrix(rbinom(1e6,1,p),ncol=2)
   tt-table(x[,1],x[,2])

you get much better looking results. In this case you have 500,000 
independent pairs of numbers that can be 01, 10, 11, 00. A test for 
independence seems fine.

 tt

  0  1
   0 125246 124814
   1 125140 124800
 fisher.test(tt)

 Fisher's Exact Test for Count Data

data:  tt
p-value = 0.8987
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
  0.9896745 1.0119211
sample estimates:
odds ratio
   1.000735


In your case the deficit in est11 is suspiciously close to 0.5/n. Changing 
n to 1000 and using the same seed I get
 mean(est11)-0.5
[1] -0.0005534743
10 times smaller, and still close to 0.5/n.

Now, consider what happens in a case where we can see all the 
possibilities, n=3

x1/0  1/1 
000   -   -
001   -   -
010   1   0
011   0   1
100   1   0
101   1   0
110   1   1
111   2   0

So that if each of these three triplets has the same probability your 
est11 would be 2/8 rather than 4/8, and est11 is not an unbiased estimate 
of the long-run conditional probability. The bias is of order 1/n, so you 
need n to be of larger order than  sqrt(simruns).


-thomas

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Random numbers negatively correlated?

2006-06-27 Thread Thomas Lumley
On Tue, 27 Jun 2006, Thomas Lumley wrote:

I got the table wrong, it should read

  x1/0  1/1  est11
  000   -   - -
  001   -   - -
  010   1   0 0
  011   0   1 1
  100   1   0 0
  101   1   0 0
  110   1   1 0.5
  111   0   2 1

So the explanation is slightly more complicated. The problem is that 
although sum(x11==2)/n and sum(x11==2 | x11==(-1))/n are unbiased 
estimators their ratio is not an unbiased estimator, but has mean 5/12 
(which is 0.5-0.5/n).

-thomas

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Random numbers

2005-12-21 Thread Carl
Hi All.
I have R code whose functionality is being replicated within a C+ 
program. The outputs are to be compared to validate the conversion 
somewhat - however (as is always the case) I have stuffed my code with 
random number calls.

Random uniform numbers in C+ are being produced using the (Boost) 
mersenne-twister generators (mt11213b  mt19937) - which is the default 
type of generator in R (if I read things correctly). If it was all 
within R I would just set the seed for reproducibility.

Basically - how do I specify in C+ for a set of random uniform numbers 
such that they are the same as from R? I have considered the possibility 
of storing/using the R generated random numbers in the C+ version for 
validation purposes - but there are a lot of them, and that strikes me 
as a generally ugly way of doing things.

thanks in advance
C

-- 
~
Carl Donovan
Lecturer in statistics
Ph +44 1334 461802
The Observatory
Buchanan Gardens
University of St Andrews
St Andrews
Fife
KY16 9LZ
Scotland

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Random numbers

2005-12-21 Thread Duncan Murdoch
On 12/21/2005 9:47 AM, Carl wrote:
 Hi All.
 I have R code whose functionality is being replicated within a C+ 
 program. The outputs are to be compared to validate the conversion 
 somewhat - however (as is always the case) I have stuffed my code with 
 random number calls.
 
 Random uniform numbers in C+ are being produced using the (Boost) 
 mersenne-twister generators (mt11213b  mt19937) - which is the default 
 type of generator in R (if I read things correctly). If it was all 
 within R I would just set the seed for reproducibility.
 
 Basically - how do I specify in C+ for a set of random uniform numbers 
 such that they are the same as from R? I have considered the possibility 
 of storing/using the R generated random numbers in the C+ version for 
 validation purposes - but there are a lot of them, and that strikes me 
 as a generally ugly way of doing things.

I'd say the only reasonable way to do this is to call the R generators 
rather than trying to duplicate them.  R tries hard to keep its 
generators consistent from version to version, but if you have an 
independent implementation of the same algorithm, it's going to be very 
hard to validate that you've really got things exactly identical.

The Writing R Extensions manual tells how to call the R generators from 
other programs.  You can do it without going through interpreted R code, 
so there shouldn't be much in the way of a performance penalty.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Random numbers

2005-12-21 Thread Bob Wheeler
You can use Marsaglia's multiply with carry. I haven't looked at the C 
code in R recently, but doubt if it has changed. The C code is very 
neat, using 6 #defines:

static const double RANDCONST=2.32830643654e-10;

unsigned long zSeed=362436069, wSeed=521288629;
#define zNew  ((zSeed=36969*(zSeed65535)+(zSeed16))16)
#define wNew  ((wSeed=18000*(wSeed65535)+(wSeed16))65535)
#define IUNIFORM  (zNew+wNew)
#define UNIFORM   ((zNew+wNew)*RANDCONST)
#define setseed(A,B) zSeed=(A);wSeed=(B);
#define getseed(A,B) A=zSeed;B=wSeed;

See Marsaglia's DIEHARD page for more details: 
http://www.stat.fsu.edu/pub/diehard/

Carl wrote:
 Hi All.
 I have R code whose functionality is being replicated within a C+ 
 program. The outputs are to be compared to validate the conversion 
 somewhat - however (as is always the case) I have stuffed my code with 
 random number calls.
 
 Random uniform numbers in C+ are being produced using the (Boost) 
 mersenne-twister generators (mt11213b  mt19937) - which is the default 
 type of generator in R (if I read things correctly). If it was all 
 within R I would just set the seed for reproducibility.
 
 Basically - how do I specify in C+ for a set of random uniform numbers 
 such that they are the same as from R? I have considered the possibility 
 of storing/using the R generated random numbers in the C+ version for 
 validation purposes - but there are a lot of them, and that strikes me 
 as a generally ugly way of doing things.
 
 thanks in advance
 C
 

-- 
Bob Wheeler --- http://www.bobwheeler.com/
ECHIP, Inc. --- Randomness comes in bunches.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] random numbers within a given range

2004-12-27 Thread Rajdeep Das
Dear Colleagues,

Is there a way to get random numbers within a given range?

Regards and thanks in advance,

Raj
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] random numbers within a given range

2004-12-27 Thread Peter Dalgaard
Rajdeep Das [EMAIL PROTECTED] writes:

 Is there a way to get random numbers within a given range?

Yes. What distribution? If uniform, see help(Uniform).

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Random Numbers

2003-12-16 Thread Silvia Perez Martin
Hello

I´m a student from Spain. I couldn´t find something about R and I was asking 
if someone could tell me which generator of random numbers use rnorm and 
runif. I think I have discovered that in runif they use the inversion 
method, but I don´t find any clue where they use the Super-duper
algorithm or the Marsaglia one, as I have read.

Thanks and sorry for my english.

_
Deja tu CV y recibe ofertas personalizadas de trabajo en tu buzón.
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Random Numbers

2003-12-16 Thread Spencer Graves
Have you looked at ?set.seed?  This provides some detail in R 1.8.1 
for Windows. 

hope this helps. 
spencer graves
p.d.  No hay que desculparse por su inglés.  Está claro. 

Silvia Perez Martin wrote:

Hello

I´m a student from Spain. I couldn´t find something about R and I was 
asking if someone could tell me which generator of random numbers use 
rnorm and runif. I think I have discovered that in runif they use 
the inversion method, but I don´t find any clue where they use the 
Super-duper
algorithm or the Marsaglia one, as I have read.

Thanks and sorry for my english.

_
Deja tu CV y recibe ofertas personalizadas de trabajo en tu buzón.
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Random Numbers

2003-12-16 Thread Ravi Varadhan
Take a look at the help for RNGkind as follows:

?RNGkind


Ravi.

- Original Message -
From: Silvia Perez Martin [EMAIL PROTECTED]
Date: Tuesday, December 16, 2003 12:45 pm
Subject: [R] Random Numbers

 Hello
 
 Im a student from Spain. I couldnt find something about R and I 
 was asking 
 if someone could tell me which generator of random numbers use 
 rnorm and 
 runif. I think I have discovered that in runif they use the 
 inversion 
 method, but I dont find any clue where they use the Super-duper
 algorithm or the Marsaglia one, as I have read.
 
 Thanks and sorry for my english.
 
 _
 Deja tu CV y recibe ofertas personalizadas de trabajo en tu buzn.
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help


__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Random Numbers

2003-12-16 Thread Thomas Lumley
On Tue, 16 Dec 2003, Silvia Perez Martin wrote:

 Hello

 I´m a student from Spain. I couldn´t find something about R and I was asking
 if someone could tell me which generator of random numbers use rnorm and
 runif. I think I have discovered that in runif they use the inversion
 method, but I don´t find any clue where they use the Super-duper
 algorithm or the Marsaglia one, as I have read.


All the random number generators work by transforming a common stream of
random  32-bit integers.  The user can choose what generator to use for
this common stream.  The default  is Mersenne-Twister.
?RNGkind will tell you how to choose other generators.

In addition, the user can choose how rnorm() transforms this stream of
32-bit numbers to the Normal distribution.  This is also covered in
?RNGkind.  The default is inversion.

Finally, users can supply either their own generator for the stream of
32-bit numbers or for the transformation to a Normal distribution.

-thomas

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Random numbers

2003-08-03 Thread dcum007
Thank you to all who helped me with the generation of random numbers. I have 
read much and learned even more. I even found some code that I have translated 
into java and am getting seemingly random output. :)

I was wondering if there were any libraries for R which test the 'randomness' 
of the generators. A birthday-spacings test or serial correlation test perhaps?

Thank you for your help.

David

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Random Numbers

2003-07-21 Thread dcum007
Thank you to all who replied to my previous question regarding the generation 
of random numbers. 

I have read up on the literature and learnt a whole lot more. In my research I 
found code for many generators which I have translated into java for my 
project. I'm now at the stage of testing these generators and was wondering if 
there were any inbuilt (or if someone has written libraries for) testing 
commands in R. 

Are there any libraries for R that have the serial correlation test, the 
birthday spacing test or any of the other tests for randomness??
Thank you all
David

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help