[R] Random sample from log-normal distribution

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Sat Nov 18 18:12:24 CET 2006


On 18-Nov-06 Megh Dal wrote:
> Dear all R users,
> 
> Please forgive me if my question is too trivial.
> Suppose I have two variables, (x,y) which is
> log-normally distributed with expected value (mu1,
> mu2) and some variance-covariance matrix. Now I want
> to draw a random sample of size 1000 from this
> distribution. Is there any function available to do
> this?
> 
> Thanks and regards,
> Megh

Browsing around, I have found R code listed at

  http://www.internal.eawag.ch/~reichert/sysanal.r

This lists several functions. One is 'randsamp'
which can generate a random sample from either a
normal or a lognormal distribution. You may find
it useful to extract the "lognormal" part of the
code (which seems to be effectively independent
of the "normal" part of the code), and adapt it
to suit your purposes.

Caveat: I have not tried this code, but it looks
as though it does it correctly -- i.e. you specify
the vector of means of the components of the lognormal
random vector, the vector of their standard deviations,
and the matrix of their correlations (easily derivable
from the matrix of their covariances using the SDs),
and you get a result with n rows, each row being a
sample from the MV lognormal with specified means and
covariances. (You can omit the line which calculates
the density function using another function 'calc.pdf').

NB: The source should be acknowledged!

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 18-Nov-06                                       Time: 17:12:21
------------------------------ XFMail ------------------------------



More information about the R-help mailing list