MathPHP\Statistics\RandomVariable::centralMoment PHP Method

centralMoment() public static method

It is the expected value of a specified integer power of the deviation of the random variable from the mean. https://en.wikipedia.org/wiki/Central_moment ∑⟮xᵢ - μ⟯ⁿ μn = ---------- N
public static centralMoment ( array $X, array $n ) : number
$X array list of numbers (random variable X)
$n array n-th central moment to calculate
return number n-th central moment
    public static function centralMoment(array $X, $n)
    {
        if (empty($X)) {
            return null;
        }
        $μ = Average::mean($X);
        $∑⟮xᵢ − μ⟯ⁿ = array_sum(array_map(function ($xᵢ) use($μ, $n) {
            return pow($xᵢ - $μ, $n);
        }, $X));
        $N = count($X);
        return $∑⟮xᵢ − μ⟯ⁿ / $N;
    }