Imagine we have a normal distribution with mean 25 and standard deviation of 5. How can we calculate the expected value of the 10% largest samples?
Context: I'm trying to estimate the loss caused by a stockout. We assume that sales are normally distributed and on average we sell per month 25 pieces with a standard deviation of 5. Now if we say that our minimum stock should be 25 pieces + 5 pieces than we have a minimum stock of mu + sigma. This should be sufficient for 68%+32%/2 = 84% of the months. In 16% of the months our minimum stock will not suffice. I would like to calculate the cost as probability we are out of stock (=16%) * expected amount of pieces we would have been able to sell more * price per piece (=1000$). It's this expected amount of pieces we would have been able to sell more that is an unknown for me.
The probability density function (pdf) is $$ f(x) = \frac{1}{5 \sqrt{2\pi}} e^{-\frac12 \left( \frac{x - 25}{5} \right)^2 }. $$
In Mathematica:
PDF[NormalDistribution[25, 5], x]Next we need to find the value $z$ so that the values $[25 + 5z, \infty)$ are the upper 10% of your distribution. The tool to use here is the error function (erf), which satisfies: $$ \int_{n - z \sigma}^{n + z \sigma} f(x)\ dx = \text{erf}(z / \sqrt2 ) $$ You want 80% of values to lie between $[\mu - z\sigma, \mu + z \sigma]$, so you want the $z$ such that $0.8 = \text{erf}(z / \sqrt2 )$. We can numerically solve for $z$ with
InverseErf[.8] * Sqrt[2]which gives $z = 1.28$.
Finally we need to find the expected value of values which fall in $[25 + 5z, \infty)$:
$$ \frac{\int_{25 + 5z}^\infty x\ f(x)\ dx}{\int_{25 + 5z}^\infty f(x)\ dx} = 33.8$$
In Mathematica:
Integrate[ PDF[NormalDistribution[25, 5], x] * x, {x, 25 + 5 InverseErf[.8] * Sqrt[2], Infinity}] / Integrate[ PDF[NormalDistribution[25, 5], x] , {x, 25 + 5 InverseErf[.8] * Sqrt[2], Infinity}]