I have looked at the code available in the Math package for percentile. I compared the result obtained with percentile from Excel and found that it doesnt match. So i wrote my own percentile function and verified the result with the Excel's percentile.
For those of you who need the percentile calculation of Excel in php..
function mypercentile($data,$percentile){
if( 0 < $percentile && $percentile < 1 ) {
$p = $percentile;
}else if( 1 < $percentile && $percentile <= 100 ) {
$p = $percentile * .01;
}else {
return "";
}
$count = count($data);
$allindex = ($count-1)*$p;
$intvalindex = intval($allindex);
$floatval = $allindex - $intvalindex;
sort($data);
if(!is_float($floatval)){
$result = $data[$intvalindex];
}else {
if($count > $intvalindex+1)
$result = $floatval*($data[$intvalindex+1] - $data[$intvalindex]) + $data[$intvalindex];
else
$result = $data[$intvalindex];
}
return $result;
}
The above code may not be elegant.. but it solves my problem..
yuvaraj
stats_stat_percentile
(PECL stats:1.0.0-1.0.2)
stats_stat_percentile — Not documented
Descrierea
float stats_stat_percentile
( float $df
, float $xnonc
)
Avertizare
Această funcţie nu este documentată în prezent; este disponibilă numai lista sa de argumente.
Parametri
- df
-
- xnonc
-
Valorile întroarse
stats_stat_percentile
yuvaraj dot v at gmail dot com
11-Dec-2007 04:37
11-Dec-2007 04:37
