LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
moment_cumulant_from_raw.m
1function kappa = moment_cumulant_from_raw(m)
2% kappa = moment_cumulant_from_raw(m)
3%
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!.
7%
8% The conversion inverts the exponential-formula recursion
9%
10% m_n = sum_{k=1}^{n} nchoosek(n-1,k-1) * kappa_k * m_(n-k)
11%
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.
17%
18% Input:
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
21%
22% Output:
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
26%
27% Example:
28% kappa = moment_cumulant_from_raw([1, 2, 6, 22]);
29%
30% Reference:
31% V. P. Leonov and A. N. Shiryaev. On a method of calculation of
32% semi-invariants. Theory of Probability and its Applications,
33% 4(3):319-329, 1959.
34
35mcol = m(:);
36n = length(mcol)-1;
37kappa = zeros(n+1,1);
38for i = 1:n
39 acc = 0;
40 for k = 1:(i-1)
41 acc = acc + nchoosek(i-1,k-1) * kappa(k+1) * mcol(i-k+1);
42 end
43 kappa(i+1) = mcol(i+1) - acc;
44end
45if isrow(m)
46 kappa = kappa.';
47end
48end