#native_company# #native_desc#
#native_cta#

Skewness, Kurtosis and average statistical function

By dhk
on April 19, 2001

Version: 1.0

Type: Function

Category: Math Functions

License: GNU General Public License

Description: Skewness, Kurtosis, and also average function by using array methodology

<?php
/* 
In this code fraction, there r 3 function that run on mean or average and skewness and kurtosis. 
Program by : [email protected] 
Date : Feb.18,2001 
*/ 

function mean(&$array) { 
$average = 0; 
while (list($key, $val)=each($array)) $average += $val; 
reset($array); 
$average /= count($array);  
return $average; 
} 
function skewnessandkurtosis($array, &$skew, &$kurt) { 
$skew = "N/A"; 
$kurt = "N/A"; 
$amount = count($array); 
if ($amount > 2) { 
for ($i = 0, $m2 =0,$m3=0,$m4=0; $i < $amount; $i++) { 
$array [$i] -= mean($array); 
$m2 += pow($array[$i], 2); 
$m3 += pow($array[$i], 3); 
$m4 += pow($array[$i], 4); 
} 
$m2 /= $amount; 
$m3 /= $amount; 
$m4 /= $amount; 
$skew = $m3 / pow($m2, 1.5); 
$skew *= sqrt($amount*($amount-1))/ ($amount-2); 
if ($amount > 3) { 
$kurt = ($m4/ pow($m2, 2))-3; 
$kurt = (($amount+1)*$kurt)+6; 
$kurt *= ($amount-1)/(($amount-2)*($amount-3)); 
} 
} 
}
?> 




<? 
// and also example on how 2 use is here 

$samplearray = array(1.8,1.9,1.2,1.5,1.7); 
skewnessandkurtosis($samplearray, $skew, $kurt); 
echo "<p>Data average = ". mean($samplearray)."</p>"; 
echo "<p>skewness = $skew </p>"; 
echo "<p>kurtosis=$kurt</p>"; 
?>