public static function centralMoment(array $values, int $moment, ?float $mean = null, ?int $n = null) : float
    {
        $n = $n ?? count($values);

        if ($n < 1) {
            throw new InvalidArgumentException('Central moment is undefined for'
                . ' empty set.');
        }

        $mean = $mean ?? self::mean($values, $n);

        $sigma = 0.;

        foreach ($values as $value) {
            $sigma += ($value - $mean) ** $moment;
        }

        return $sigma / $n;
    }
public static function centralMoment(array $values, int $moment, ?float $mean = null, ?int $n = null) : float
    {
        $n = $n ?? count($values);

        if ($n < 1) {
            throw new InvalidArgumentException('Central moment is undefined for'
                . ' empty set.');
        }

        $mean = $mean ?? self::mean($values, $n);

        $sigma = 0.;

        foreach ($values as $value) {
            $sigma += ($value - $mean) ** $moment;
        }

        return $sigma / $n;
    }
public static function centralMoment ( array $ values , int $ moment , ? float $ mean = null , ? int $ n = null ) : float { $ n = $ n ?? count ( $ values ) ; if ( $ n < 1 ) { throw new InvalidArgumentException ( 'Central moment is undefined for' . ' empty set.' ) ; } $ mean = $ mean ?? self :: mean ( $ values , $ n ) ; $ sigma = 0. ; foreach ( $ values as $ value ) { $ sigma += ( $ value - $ mean ) ** $ moment ; } return $ sigma / $ n ; }
Compute the n-th central moment of a set of values.

@param array $values
@param int $moment
@param float|null $mean
@param int|null $n
@throws \InvalidArgumentException
@return float
Compute the n - th central moment of a set of values .