note 79752 added to function.stats-stat-percentile
| From: | yuvaraj dot v at gmail dot com | Date: | Tue, 11 Dec 2007 12:37:44 +0000 |
| Subject: | note 79752 added to function.stats-stat-percentile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133362@lists.php.net to get a copy of this message | ||
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
----
Server IP: 203.199.69.133
Probable Submitter: 125.16.31.10
----
Manual Page -- http://www.php.net/manual/en/function.stats-stat-percentile.php
Edit -- https://master.php.net/note/edit/79752
Del: integrated -- https://master.php.net/note/delete/79752/integrated
Del: useless -- https://master.php.net/note/delete/79752/useless
Del: bad code -- https://master.php.net/note/delete/79752/bad+code
Del: spam -- https://master.php.net/note/delete/79752/spam
Del: non-english -- https://master.php.net/note/delete/79752/non-english
Del: in docs -- https://master.php.net/note/delete/79752/in+docs
Del: other reasons-- https://master.php.net/note/delete/79752
Reject -- https://master.php.net/note/reject/79752
Search -- https://master.php.net/manage/user-notes.php