Skip to main content

Module moments

Module moments 

Source
Expand description

One-pass, mergeable central moments with standard errors.

§Accumulator

Moments keeps the count n, the mean, and the centred power sums M_p = Σ (x_i - mean)^p for p = 2..=8. Two accumulators A, B combine with the arbitrary-order pairwise update of P. Pébay, “Formulas for robust, one-pass parallel computation of covariances and arbitrary-order statistical moments”, Sandia report SAND2008-6212 (2008), which generalises the second-order update of T. F. Chan, G. H. Golub and R. J. LeVeque, “Updating formulae and a pairwise algorithm for computing sample variances”, Stanford report STAN-CS-79-773 (1979). With δ = mean_B - mean_A and n = n_A + n_B,

M_p = M_p^A + M_p^B
    + Σ_{k=1}^{p-2} C(p,k) δ^k [ (-n_B/n)^k M_{p-k}^A + (n_A/n)^k M_{p-k}^B ]
    + (n_A n_B δ / n)^p [ n_B^{1-p} - (-n_A)^{1-p} ].

Adding one sample is a merge with n_B = 1, M^B = 0. The update is exact in real arithmetic; in floating point the result depends on the order of merges, so it is deterministic for a fixed order (bit-identical) and agrees across different splittings to rounding. crate::rng::run_particles merges in chunk order, which fixes the order independently of the thread count.

§Conventions

Central moments are the method-of-moments estimates μ_p = M_p / n (no n - 1 correction), as used for fitting Pearson distributions: standard deviation σ = μ_2^(1/2), skewness γ = μ_3 / μ_2^(3/2), kurtosis β = μ_4 / μ_2^2 (not excess kurtosis: a Gaussian has β = 3). For a depth distribution these are Rp, ΔRp, γ, β.

§Standard errors

Large-sample standard errors from the asymptotic covariance of sample central moments, H. Cramér, Mathematical Methods of Statistics (Princeton, 1946), §27.7:

n Cov(m_j, m_k) = μ_{j+k} - μ_j μ_k - j μ_{j-1} μ_{k+1} - k μ_{j+1} μ_{k-1}
                + j k μ_{j-1} μ_{k-1} μ_2,

propagated to σ, γ and β by the delta method (first-order Taylor expansion), with the population moments replaced by their estimates up to μ_8. The standard error of the mean is σ / n^(1/2). No normality is assumed; for a Gaussian these reduce to the familiar (6/n)^(1/2) for γ and (24/n)^(1/2) for β (checked in a test). They are asymptotic, so treat them as approximate for small n or heavy tails.

Structs§

MomentSummary
The first four moments of a sample, with standard errors.
Moments
Mergeable accumulator of the count, mean and centred power sums up to order 8. See the module docs for the update formula.