Which algorithm is using by the rnorm
function by default to generate standard-normally distributed random numbers?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- why 48 bit seed in util Random class?
See
?RNGkind
. The default is an inversion algorithm:You can change the algorithm by
You can find what is currently set by looking at
RNGkind()[2]
.The other answer is sufficient, but left me with some more questions; in particular, I didn't see anywhere in the documentation* what on earth the
"Inversion"
algorithm is, so I dived into the source code, which also gives academic references to the papers originating the other possible algorithms, to figure out what exactly is being done.So it seems at base the default
"Inversion"
algorithm generates a high precision floating point number (looks like 53 bits, or the mantissa size for 64-bit floating numbers), then sends it to theqnorm5
function which is a CDF function for the normal distribution.As to how the
qnorm5
function works (given there is no closed form for the Normal CDF nor inverse CDF), I haven't had much luck cracking what seems to be the source code here, but they do give further academic references, namely Beasley, J. D. and S. G. Springer (1977) and Wichura, M.J. (1988); the former being typically used for small quantiles of the CDF and the latter for large (z>7
or so).It may also be interesting to note that (as of this writing) this algorithm appears to be shared by the Julia language, which also shares the
qnorm5
code used byR
.*To be fair, in retrospect, Wichura is mentioned in
?qnorm
which is referenced above. Still it's worthwhile to spell things out in this thread, I think.