# [R] Is my understanding of rlnorm correct?

From: phil colbourn <philcolbourn_at_gmail.com>
Date: Sun, 04 May 2008 14:05:09 +1000

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

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.