0

I want to generate data from a log-normal distribution, with mean zero and variance equal to 1, in R.

I have tried this so far:

(rlnorm(n = 100000, mean = 0, sdlog = 1) - exp(1/2))/(exp(1)*(exp(1)-1))

Using the wikipedia page, to get the mean and variance on the standard scale. I think that I have centred correctly, as when I calculate the sample mean for this generated data I get a value close to zero. However, the sample variance is not close to 1.

Dylan Dijk
  • 277
  • 1
  • 6
  • The mean specified in the log-normal distribution is the mean of the normal distribution with the same location and scale parameters before the exponential transformation. Try `x <- log(rlnorm(1e6, 0, 1)); mean(x); var(x)`. – jblood94 May 15 '23 at 10:17

1 Answers1

0

Can just use the formula of the mean and variance for the log-normal distribution on the log scale using the moments on the standard scale, to generate data with variance equal to 1 on the standard scale.

And then centre.

data = ((rlnorm(meanlog = log(1/sqrt(2)), sdlog = sqrt((log(2))), n = 100000) - 1))

mean(data)
var(data)
Dylan Dijk
  • 277
  • 1
  • 6