rnorm

Prof Brian Ripley Prof Brian Ripley <ripley@stats.ox.ac.uk>
Tue, 4 May 1999 15:07:25 +0100 (BST)


> Date: Tue, 04 May 1999 09:36:19 -0400
> From: Paul Gilbert <pgilbert@bank-banque-canada.ca>
> To: Brian Ripley <ripley@stats.ox.ac.uk>
> CC: R-devel <R-devel@stat.math.ethz.ch>
> Subject: rnorm
> 
> Brian
> 
> I've been playing a bit with the Wichmann-Hill RNG. I would prefer to have
> normally distributed random numbers and I think I have things generally worked
> out to use Wichmann-Hill and then Box-Muller. In the process, I was looking at
> R's rnorm.c, but could not figure out what transformation is used in R to
> convert uniform rv's to normal rv's. Do you know? It looks like there are
> options in the code, but I couldn't figure out how an option is chosen.
> 
> Paul
> 

Well, I hadn't looked until recently. I find all of that section of code
somewhat less than transparent (and spread across directories, let alone
files).

rnorm.c says

N01type N01_kind = KINDERMAN_RAMAGE;

so that is what you get by default. You can change it from C code as that
is an exported variable.  But the intended mechanism appears to be that it is
part of the choice of RNG in RNGkind, except that is it unused. See 
(nmath/sunif.c)

RNGTAB RNG_Table[] =
{
/* kind Nkind     name    is_seeded seed-length i1_s, *seed-vec */
    { 0, 0, "Wichmann-Hill",    0,      3,      123,    dummy},
    { 1, 0, "Marsaglia-MultiCarry",0,   2,      123,    dummy},
    { 2, 0, "Super-Duper",      0,      2,      123,    dummy},
    { 3, 0, "Mersenne-Twister", 0,  1+624,      123,    dummy},
    { 4, 0, "Rand",             0,      2,      -1,     dummy},
};

where Nkind is of N01type. I think Martin Maechler will need to explain
what he intended here, as well as why he did not use the enumeration
constants for Nkind in this table.  And

head src/include/Random.h 
/* only used by ../main/random.c  & ../nmath/sunif.c
 */

appears to be wrong: it is used in ../nmath/snorm.c too.

Martin: as a general policy I would prefer header files used in a few
places to be explicit, not hidden through Mathlib.h.  The way it is
currently done hides dependencies, as in the missing dependence of snorm.o on
$(top_srcdir)/src/include/Random.h.

[I have committed the dependencies in brief spell while Auckland was 
contactable.]

Brian

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._