generating random numbers from the logit-normal distribution ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

generating random numbers from the logit-normal distribution ?

Taka Matzmoto
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: generating random numbers from the logit-normal distribution ?

Romain François
Selon Taka Matzmoto <[hidden email]>:

> 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
Hi,



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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: generating random numbers from the logit-normal distribution ?

Prof Brian Ripley
In reply to this post by Taka Matzmoto
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,                  [hidden email]
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html