PHP 7.0.6 Released

stats_kurtosis

(PECL stats >= 1.0.0)

stats_kurtosisComputes the kurtosis of the data in the array

Description

float stats_kurtosis ( array $a )
Warning

This function is currently not documented; only its argument list is available.

Parameters

a

Return Values

User Contributed Notes

Angel J. Salinas
4 months ago
// If you don't have the php_stats library, you can use this function:
public static function getKurtosis( $values )
{
  $numValues = count( $values );
  if ( $numValues == 0 ) {
    return 0.0;
  }
 
  // Use function from php_stats library if available
  if ( function_exists( 'stats_kurtosis' ) ) {
    return stats_kurtosis( $values );
  }
 
  $mean = array_sum( $values ) / floatval( $numValues );
  $add2 = 0.0;
  $add4 = 0.0;
 
  foreach ( $values as $value ) {
    if ( ! is_numeric( $value ) ) {
      return false;
    }
    $dif = $value - $mean;
    $dif2 = $dif * $dif;
    $add2 += $dif2;
    $add4 += ( $dif2 * $dif2 );
  } // foreach values
 
  $variance = $add2 / floatval( $numValues );
  return ( $add4 * $numValues ) / ( $add2 * $add2 ) - 3.0;
}
To Top