1function kappa = moment_cumulant_from_raw(m)
2% kappa = moment_cumulant_from_raw(m)
4% Converts the power (raw) moments m_n = E[X^n] of a random variable X into its
5% cumulants kappa_n, the coefficients of the cumulant generating function
6% log E[exp(sX)] =
sum_{n>=1} kappa_n s^n / n!.
8% The conversion inverts the exponential-formula recursion
10% m_n =
sum_{k=1}^{n} nchoosek(n-1,k-1) * kappa_k * m_(n-k)
12% equivalently kappa_n =
sum_{pi in
P(n)} (|pi|-1)! (-1)^(|pi|-1) prod_{B in pi}
13% m_|B| over the set partitions of {1,...,n}. The first cumulants are
14% kappa_1 = m_1, kappa_2 = m_2 - m_1^2 (the variance) and kappa_3 = m_3 -
15% 3 m_1 m_2 + 2 m_1^3 (the third central moment). The conversion
is not
16% restricted to discrete random variables.
19% m: vector of length n+1 holding m_0,...,m_n, i.e. m(i)
is the moment of
20% order i-1 and m(1) = 1
23% kappa: vector of length n+1 holding kappa_0,...,kappa_n, with the same
24% orientation as m. Element 1
is kappa_0 = 0, the value of the
25% cumulant generating function at the origin, and not m_0 = 1
28% kappa = moment_cumulant_from_raw([1, 2, 6, 22]);
31% V.
P. Leonov and A. N. Shiryaev. On a method of calculation of
32% semi-invariants. Theory of Probability and its Applications,
41 acc = acc + nchoosek(i-1,k-1) * kappa(k+1) * mcol(i-k+1);
43 kappa(i+1) = mcol(i+1) - acc;