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?
> args(rlnorm)function (n, meanlog = 0, sdlog = 1) NULL 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? > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
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 ------------------------------
Fred, If you want to produce log normal values you can do it by using rlnorm, and you have to provide the mean and variance of the process in log scale, wich means after log transform. Or you can produce them with rnorm and exponentiate. Check: > set.seed(1) > rlnorm(100, 0, 1)->vec > set.seed(1) > rnorm(100, 0, 1)->vec2 > all.equal(exp(vec2),vec) [1] TRUE In both cases I'm using mean=0 and var=1. Regards EJ Frederic renaud wrote:> This values come from R. I 've read the doc but... > If I've understood, I must write > rlnorm(10000,0,0)) to have a mean = 1 and Var =1 > but that doesn't work (log 1 =0) > > --- Ernesto Jardim <ernesto at ipimar.pt> wrote: > > >>Where did you get those values ? >> >> > mean(rlnorm(10000,0,1)) >>[1] 1.667496 >> > var(rlnorm(10000,0,1)) >>[1] 4.666731 >> >>Look at previous emails, they are more explicit. The >>basis is that you >>must give the mean and variance in log scale. >> >>EJ >> >> >>Frederic renaud wrote: >> >>>yes but >>>mean(rlnorm(10000,0,1)) ne 0 >>>and var(rlnorm(10000,0,1)) ne 1 >>> >>>??? >>> >>> >>> >>>--- Ernesto Jardim <ernesto at ipimar.pt> wrote: >>> >>> >>> >>>>>args(rlnorm) >>>> >>>>function (n, meanlog = 0, sdlog = 1) >>>>NULL >>>> >>>>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? >>>>> >>>>>______________________________________________ >>>>>R-help at stat.math.ethz.ch mailing list >>>>>https://stat.ethz.ch/mailman/listinfo/r-help >>>>>PLEASE do read the posting guide! >>>> >>>>http://www.R-project.org/posting-guide.html >>>> >>> >>> >>> >>>__________________________________________________ >> > > > > > __________________________________