Given $X \sim N(0, 1)$ and $Y = e^X$ I have calculated the PDF of $Y$ to be $f_Y(y) = \frac{1}{\sqrt{2\pi}}y^{-\frac{3}{2}\ln(y)}$. But when I plot it against the values I get in practice from a random number generator the curves don't look similar. What am I doing wrong?
Derivation of the PDF:
It is known that if $Y = r(X)$ where $r$ is strictly monotone increasing that $r$ has an inverse $s$ and that:
$$f_Y(y) = f_X(s(y))\frac{ds(y)}{dy}$$
Separately for standard normal distributions we know that:
$$f_X(x) = \frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2}$$
in this case $s(y) = \ln(y)$
$$f_Y(y) = \frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}(\ln(y))^2}\frac{1}{y}$$ $$f_Y(y) = \frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}\ln(y)\ln(y)}\frac{1}{y}$$ $$f_Y(y) = \frac{1}{\sqrt{2\pi}}(e^{\ln(y)})^{-\frac{1}{2}\ln(y)}\frac{1}{y}$$ $$f_Y(y) = \frac{1}{\sqrt{2\pi}}y^{-\frac{1}{2}\ln(y)}\frac{1}{y}$$ $$f_Y(y) = \frac{1}{\sqrt{2\pi}}y^{-\frac{1}{2}\ln(y)}y^{-1}$$ $$f_Y(y) = \frac{1}{\sqrt{2\pi}}y^{-\frac{3}{2}\ln(y)}$$
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
import matplotlib
import math
matplotlib.use("TkAgg") # without this nothing appears?!
import matplotlib.pyplot as plt
import numpy as np
import sys
def pdf_ch2e13(y):
return (1/math.sqrt(2 * math.pi) * (y**(-3 * math.log(y, math.e) / 2)))
def pdf_ch2e13_hist():
x = [np.random.normal() for i in range(100000)]
y = [math.e**i for i in x]
fig = plt.figure()
ax2 = fig.add_subplot(111)
r = np.linspace(0.0001, 10)
hist, bins = np.histogram(y, list(r) + [float("inf")], density=True)
ax2.plot(r, [pdf_ch2e13(x) for x in r], color="red", lw=3)
ax2.plot(r, list(hist), color="blue", lw=3)
ax2.set_ylabel('e^(random_normal)')
plt.show()
pdf_ch2e13_hist()



I made a simple algebra mistake in the last step of the PDF derivation:
$$f_Y(y) = \frac{1}{\sqrt{2\pi}}y^{-\frac{1}{2}\ln(y)}y^{-1} \neq \frac{1}{\sqrt{2\pi}}y^{-\frac{3}{2}\ln(y)}$$
Instead I should have done:
$$f_Y(y) = \frac{1}{\sqrt{2\pi}}y^{-\frac{1}{2}\ln(y)}y^{-1} = \frac{1}{\sqrt{2\pi}}y^{-\frac{1}{2}\ln(y) - 1}$$