# Normal to Lognormal distribution [closed]

I am planning to teach a class on normal and lognormal distribution and I wanted to:

1. Generate a standard normally distributed random vector (mu=0, sigma=1),
2. transform the vector to a non-standard vector (mu=250000, sigma=0.1*mu), and
3. transform the same vector to a vector that follows a lognormal distribution.

However, I think I am missing something, the values of mean and standard deviation are very different. Here is my super-simple code in MATLAB:

% Number of variables
N = 100000;

% Step 1 - Generate random standard normal distributed E
E = randn(N,1);

% Step 2 - Transform to non-standard values
mu_E = 250000;
sigma_E = mu_E * 0.1;
E_non_standard = mu_E + E * sigma_E;

% Step 3 - Transform to lognormal
E_log_non_standard = mu_E + sigma_E * exp(E);

% Step 4 - Compare
figure
hist([E_non_standard E_log_non_standard],100)
legend('E - normal','E - lognormal')


I know I could generate lognormal values directly, but I want to prove the transformation in class.

# Update number 2

% Number of variables
N = 100000;

% Step 1 - Generate random standard normal distributed E
E = randn(N,1);

% Step 2 - Transform to non-standard values
mu_E = 250000;
sigma_E = mu_E * 0.1;
E_non_standard = mu_E + E * sigma_E;

% Step 3 - Transform to lognormal

%mu and sigma transform to normal mu and sigma
sigma_logE = (log((sigma_E/mu_E)^2+1))^0.5;
mu_logE = log(mu_E)-0.5*(sigma_logE)^2;

E_log_non_standard = exp (mu_logE + sigma_logE * E);

% Step 4 - Compare
figure
hist([E_non_standard E_log_non_standard],100)
legend('E - normal','E - lognormal')

• What makes you think the mean and standard deviation should be the same here? Aug 31 '16 at 18:49
• Your result isn't "wrong" per se--it's just not what you claimed it to be. You are computing $\mu + \sigma\exp(X)$ for a standard normal variable $X$: that has a special kind of three-parameter lognormal distribution. To create a lognormal variable you need to compute $\exp(\mu+\sigma X)$ or, equivalently, $\exp(\mu)\exp(\sigma X)$. With your choice of $\mu$, the values will be enormous. Experiment first with values of $\mu$ in the range $[-5,5]$ and $\sigma$ in the range $[0,1]$ so you can understand better what's happening.
– whuber
Aug 31 '16 at 20:36
• What I suggested is equivalent to what @whuber wrote in his comment immediately above, but my formulation makes use of $\mu + \sigma X$ having already been computed and stored as E_non_standard . whuber has added a lot of useful color commentary, though, Aug 31 '16 at 20:49
• I presume you're confusing $\mu$ and $\sigma$ with the mean and standard deviation of the lognormal. They're not. Indeed, as you've already been told in Eric's answer the mean of the lognormal is $e^{\mu+\frac12\sigma^2}$; I'll add that correspondingly the standard deviation is $e^{\mu+\frac12\sigma^2}\,\sqrt{e^{\sigma^2}-1}\,$. Sep 1 '16 at 10:56
• You might benefit from reading the Wikipedia page about the distribution to pick up some basic facts. Sep 1 '16 at 10:59

It appears that you are trying to compare a shifted log-normal R.V. with a normal R.V. by histograms and sample mean and sample variance.

If $X\sim LN(\mu, \sigma^2)$, $E(X) = e^{\mu + \sigma^2/2}$. We can see then, that if $Y \sim N(0,1)$, $E(\mu + \sigma e^Y) = \mu + \sigma e^{\frac{1}{2}}$. So if the means are to match, you'll need to modify the other tranformation accordingly.

I'm guessing that what you are after are equivalent ways of transforming random variables on different scales.

n <- 100
mu <- 2
sigma <- 3
x <- rnorm(n, 0, 1)
x_trans1 <- exp(mu + x*sigma)
x_trans2 <- exp(mu) * exp(x)^sigma

#compare
par(mfrow=c(1, 2))
hist(x_trans1, x_trans2)

• Dear Eric, thanks for helping me out. You totally understood my questions. I have implemented in my code the function "exp(mu + xsigma)" and "exp(mu + xsigma)" when I use it for my values (mu <- 250000 and sigma <- 25000), the results are very of. Would the function not be: mu + sigma*exp(x)?
– Luiz
Aug 31 '16 at 20:13
• I'm not sure what you intend to show by that transformation. What distribution do you have in mind? Is it possible that you are confused about the relationship between normal and lognormal? Note that, if X is normal, log(X) is NOT lognormal (or even well-defined). Aug 31 '16 at 20:21
• and Glen: I think I can see what was doing wrong, sorry for asking such stupid questions. In order to close this discussion, do you agree that if I want to to compare a shifted log-normal R.V. with a normal R.V. by histograms and sample mean and sample variance I should do the following:
– Luiz
Sep 1 '16 at 17:34
• I posted the new code as Update number 2 above.
– Luiz
Sep 1 '16 at 17:54