From: phil colbourn <philcolbourn_at_gmail.com>

Date: Sun, 04 May 2008 14:05:09 +1000

R-help_at_r-project.org 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. Received on Sun 04 May 2008 - 04:09:28 GMT

Date: Sun, 04 May 2008 14:05:09 +1000

rlnorm takes two 'shaping' parameters: meanlog and sdlog.

So to generate random values that fit a lognormal distribution I would do this:

rlnorm(N , meanlog = log(mean) , sdlog = log(sd))

But when I check the mean I don't get it when sdlog>0. Interestingly I found that the median is close to what I want the mean to be.

* > par( mfrow = c(2,2) )
** > set.seed( 1 )
** > x <- 1:100000
** > y <- rlnorm( x , meanlog = log(100) , sdlog = log(2) )
** > plot( x , y )
*

> hist( y , breaks = 100)

> summary( y )

Min. 1st Qu. Median Mean 3rd Qu. Max. 4.292 62.360 100.100 127.100 159.300 1989.000

I noticed on wikipedia lognormal page that the median is exp(mu) and that the mean is exp(mu + sigma^2/2)

http://en.wikipedia.org/wiki/Log-normal_distribution

So, does this mean that if i want a mean of 100 that the meanlog value needs to be log(100) - log(sd)^2/2?

It seems to give me the result I am after.

* > par( mfrow = c(2,2) )
** > set.seed( 1 )
** > x <- 1:100000
** > y <- rlnorm( x , meanlog = log(100) , sdlog = log(2) )
** > plot( x , y )
*

> hist( y , breaks = 100)

> summary( y )

Min. 1st Qu. Median Mean 3rd Qu. Max.
4.292 62.360 100.100 127.100 159.300 1989.000

* > set.seed( 1 )
** > y <- rlnorm( x , meanlog = log(100) - log(2)^2/2 , sdlog = log(2) )
** > plot( x , y )
*

> hist( y , breaks = 100)

> summary( y )

Min. 1st Qu. Median Mean 3rd Qu. Max. 3.376 49.040 78.690 99.970 125.300 1564.000

[[alternative HTML version deleted]]

R-help_at_r-project.org 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. Received on Sun 04 May 2008 - 04:09:28 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Sun 04 May 2008 - 05:30:33 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*