User:BetterChance/sandbox

Shape Flexibility First Paragraph
According to the metalog flexibility theorem, any probability distribution with a continuous quantile function can be approximated arbitrarily closely by a metalog. Moreover, in the original paper, Keelin showed that ten-term metalog distributions parameterized by 105 CDF points from 30 traditional source distributions (including the normal, student-t, lognormal, gamma, beta, and extreme-value distributions) approximate each such source distribution within a K-S distance of 0.001 or less. Thus, metalog shape flexibility is virtually unlimited.

Metalog Flexibility Theorem
Theorem: Any probability distribution with a continuous quantile function can be approximated arbitrarily closely by a metalog quantile function.

Proof
Proof: Let $$\delta>0$$ be an arbitrarily small positive number and let $$Q(y)$$ be a continuous quantile function defined on the probability interval $$y$$ ∈ $$(0,1)$$. By the Weierstrass approximation theorem, for every $$\epsilon>0$$ there exists a polynomial $$P(y)$$ such that $$|Q(y)-P(y)|<\epsilon$$ for all $$y$$ ∈ $$[\delta,1-\delta]$$. By setting the $$a_i$$ to zero for all terms that include the factor $$ln\Bigl({y\over{1-y}}\Bigr)$$, the metalog quantile function $$M(y)$$ reduces to a polynomial. Therefore, there exists a metalog distribution $$M(y)$$ such that $$|Q(y)-M(y)|<\epsilon$$ for all $$y$$ ∈ $$[\delta,1-\delta]$$.

While this theorem guarantees the existence of a such a metalog for any continuous quantile function, it does not guarantee its feasibility. It does guarantee, however, that there exists a metalog that is everywhere within $$\epsilon$$ of being feasible for any arbitrarily small positive number $$\epsilon$$, which should be sufficient for most practical applications.

Nor does this theorem provide a procedure for how to find the metalog $$a_i$$ coefficients that correspond to an arbitrary continuous quantile function. Nor does it guarantee rapid convergence as the number of terms increases. But in practice, metalogs do converge rapidly and the coefficients can easily be determined by least squares. For example, we showed in the original paper, Table 8, that metalog distributions parameterized by 105 CDF points from 30 traditional source distributions (including the normal, student-t, lognormal, gamma, beta, and extreme-value distributions) approximate each such source distribution within a K-S distance of 0.001 or less as the number of metalog terms approaches ten.

Parameterization with Moments
Three-term unbounded metalogs can be parameterized in closed form with their first three central moments. Let $$m, v,$$ and $$s$$ be the mean, variance, and skewness, and let $$s_s$$ be the standardized skewness, $$s_s=s/v^{3/2}$$. Equivalent expressions of the moments in terms of coefficients and coefficients in terms of moments are as follows:



\begin{array}{ll} m = a_1 +{a_3\over2} && a_1 = m -{a_3\over2}\\[6pt] v = \pi^2{{a_2}^2\over3}+{{a_3}^2\over{12}}+\pi^2{{a_3}^2\over{36}} && a_2 = {1\over{\pi}}\Bigl[3\Bigl(v-\Bigl({1\over{12}}+{{\pi}^2\over{36}}\Bigr){a_3}^2\Bigr)\Bigr]^{1\over{2}} \\[6pt] s = \pi^2 {a_2}^2{a_3}+\pi^2 {{a_3}^3 \over{24}} && a_3 = 4\Bigl({6v\over{6+\pi^2}}\Bigr)^{1\over{2}}\cos\Bigl[{1\over{3}}\Bigl(\cos^{-1}\Bigl(-{s_s\over{4}}\Bigl(1+{{\pi}^2\over{6}}\Bigr)^{1\over{2}}\Bigr)+4\pi\Bigr)\Bigr]. \\[6pt] \end{array} $$

This equivalence can be derived by noting that the moments equations on the left are a cubic polynomial in terms of coefficients $$a_1, a_2,$$ and $$a_3$$ that can be solved in closed form form as a function of  $$m, v,$$ and $$s$$. Moreover, this solution is unique. In terms of moments, the feasibility condition is $$|s_s|\leq 2.07093$$, which can be shown to be equivalent to the feasibility condition in terms of coefficients: $$a_2>0$$ and $${|a_3|/a_2}<1.66711$$.

This property can be used, for example, to represent the sum of independent, non-identically distributed random variables. Based on cumulants, it is known that for any set of independent random variables, the mean, variance, and skewness of the sum is the sum of the respective means, variances, and skewnesses. Parameterizing a three-term metalog with these central moments yields a continuous distribution that exactly preserves them.