{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import math\n",
"import matplotlib.pyplot as plt\n",
"from scipy.stats import norm\n",
"from scipy.stats import lognorm"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Reminder. A flat pdf between x1 and x2 has \n",
"variance (x2-x1)/12."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" For the product of random variables, I know
\n",
" how to calculate the mean $m$ and the variance $v$.
\n",
" (The variance at least approximately with
\n",
" \"propagation of errors\")
\n",
" \n",
" Equations in
\n",
" https://en.wikipedia.org/wiki/Log-normal_distribution
\n",
" give the mean and the variance of the lognormal
\n",
" in the terms of two parameters $\\mu$ and $\\sigma$ as
\n",
" $m =$ exp($\\mu + \\sigma^2/2$) and
\n",
" $v =$ (exp($\\sigma^2$) - 1)exp($2\\mu + \\sigma^2)$ = $m^2$ (exp($\\sigma^2$) - 1)
\n",
" Can then solve for
\n",
" $\\sigma^2 = \\log(1 + v/m^2)$ and
\n",
" exp($\\mu$) = $m$ exp(-$\\sigma^2/2$) \n",
" \n",
" The corresponding parameters of the scipy parametrization are
\n",
" loc = 0
\n",
" s = $\\sigma$
\n",
" scale = exp($\\mu$) \n",
" \n",
" I will superimpose to the data a \"guessed\" curve with the
\n",
" three parameters above. I will also fit the data to a lognormal
\n",
" (without fixing loc=0) and compare.\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# initialize random number generator\n",
"np.random.seed(3862)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"