Taka Matzmoto
2006-Jan-27 04:52 UTC
[R] generating random numbers from the logit-normal distribution ?
Hi R users I like to generate random numbers from the logit-normal distribution. Are there available simple commands I can use? I used to generate using exp(rnorm(1000,0,1))/(1+exp(rnorm(1000,0,1))) I am looking for a simple command such as rnorm(). Thanks in advance TM
francoisromain@free.fr
2006-Jan-27 07:40 UTC
[R] generating random numbers from the logit-normal distribution ?
Selon Taka Matzmoto <sell_mirage_ne at hotmail.com>:> Hi R users > > I like to generate random numbers from the logit-normal distribution. > > Are there available simple commands I can use? > > I used to generate using > > exp(rnorm(1000,0,1))/(1+exp(rnorm(1000,0,1)))> I am looking for a simple command such as rnorm(). > > Thanks in advance > > TMHi, Consider writing a function, you can even learn how to use ... rlogitnormal <- function(...){ x <- exp(rnorm(...)) x / (1+x) } then rlogitnormal(1000, 0, 1) Romain
Prof Brian Ripley
2006-Jan-27 07:45 UTC
[R] generating random numbers from the logit-normal distribution ?
On Thu, 26 Jan 2006, Taka Matzmoto wrote:> Hi R users > > I like to generate random numbers from the logit-normal distribution.which is not a standard distribution. I guess you mean a random variable whose logit is normal (but that is not the only meaning in use).> Are there available simple commands I can use? > > I used to generate using > > exp(rnorm(1000,0,1))/(1+exp(rnorm(1000,0,1)))That would be incorrect. I think you mean> xx <- rnorm(1000, 0, 1) > exp(xx)/(1+exp(xx))> I am looking for a simple command such as rnorm().> plogis(rnorm(1000))And if that is not simple enough for you, you can write a function wrapper like> rlgnorm <- function(...) plogis(rnorm(...))-- Brian D. Ripley, ripley at 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 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595