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

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

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

        $ssd = 0.;

        foreach ($values as $value) {
            $ssd += ($value - $mean) ** 2;
        }

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

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

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

        $ssd = 0.;

        foreach ($values as $value) {
            $ssd += ($value - $mean) ** 2;
        }

        return $ssd / $n;
    }
public static function variance ( array $ values , ? float $ mean = null , ? int $ n = null ) : float { $ n = $ n ?? count ( $ values ) ; if ( $ n < 1 ) { throw new InvalidArgumentException ( 'Variance is undefined for an' . ' empty set.' ) ; } $ mean = $ mean ?? self :: mean ( $ values ) ; $ ssd = 0. ; foreach ( $ values as $ value ) { $ ssd += ( $ value - $ mean ) ** 2 ; } return $ ssd / $ n ; }
Compute the variance of a set of values given a mean and n degrees of
freedom.

@param array $values
@param float|null $mean
@param int|null $n
@throws \InvalidArgumentException
@return float
Compute the variance of a set of values given a mean and n degrees of freedom .