[R] lognorm

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Fri Jan 7 13:44:40 CET 2005


On 07-Jan-05 Frederic renaud wrote:
> Hi!
> I 've a problem to have a lognorm distribution with
> mean=1 and var (or sigma)=1.
> 
> rlnorm(1000,0,0)
> rlnorm(1000,1,1)
> rlnorm(1000,0,1)
> ....                     ?
> 
> Can you help me?

Not sure what your problem is.

For rlnorm(1000,0,0), you will get 100 values equal to
exp(X) where X has been sampled from N(0,0), i.e. since
the variance is 0 all X are equal to 0 and exp(X) = 1.
This is what rlnorm(1000,0,0) yields.

In the other two cases, I don't see anything wrong with
the results.

So what is the problem?

Note that rlnorm(N, meanlog=mu, sdlog=s) gives you (as
described above and in "?rlnorm") N random values exp(X)
where X is sampled from N(mu,s^2). mu and s are not the
mean and s.d. of the resulting log-normal variate exp(X).

In terms of the mean mu and s.d. s of the underlying Normal
distribution, the mean and variance of the log-normal
distribution of exp(X) are

  MU = exp(mu + (s^2)/2)

  V = S^2 = (MU^2)*(exp(s^2)-1)^2

so, if you really mean that your problem is how to generate
a log-normal sample with given mean MU and variance V = S^2,
then you have to solve these equations for mu and s.

In particular if (as in your second case) you want MU=1
and S=1, then exp(s^2) - 1 = 1 so

  s = sqrt(log(2)) = 0.8325546

and mu + (s^2)/2 = log(1) = 0 so

  mu = -(s^2)/2 = -0.3465736

With these values of mu and s,

  X <- rlnorm(1000,mu,s)

  mean(X)
  ## [1] 1.054104

  sd(X)
  ## [1] 0.9936088

(for this sample).

However, you're not going to be able to achieve your third
case (MU = 0, V = 1) since this would require mu = -infinity!
You can't make a log-normal random variable with mean 0.
(And in any case it would necessarily have V = 0, not V = 1,
since a log-normal variable cannot be negative, so zero mean
would imply no positive values and hence all values = 0,
hence zero variance).

Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861  [NB: New number!]
Date: 07-Jan-05                                       Time: 12:44:40
------------------------------ XFMail ------------------------------




More information about the R-help mailing list