stats_stat_percentile

(PECL stats >= 1.0.0)

stats_stat_percentileNot documented

Description

float stats_stat_percentile ( float $df , float $xnonc )
Warning

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

Parameters

df

xnonc

Return Values

Коментарии

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..

<?php
function mypercentile($data,$percentile){
    if( 
$percentile && $percentile ) {
       
$p $percentile;
    }else if( 
$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
2007-12-11 06:37:44
http://php5.kiev.ua/manual/ru/function.stats-stat-percentile.html
If you are looking to infer the percentile from a z-score, you can use this function.
It's far from precise but does the job on most circumstances.
The error function ( erf() )is based on the approximation on wikipedia: 
http://en.wikipedia.org/wiki/Error_function

<?php
function erf($x)
{
       
$pi 3.1415927;
       
$a = (8*($pi 3))/(3*$pi*($pi));
       
$x2 $x $x;

       
$ax2 $a $x2;
       
$num = (4/$pi) + $ax2;
       
$denom $ax2;

       
$inner = (-$x2)*$num/$denom;
       
$erf2 exp($inner);

        return 
sqrt($erf2);
}

function 
cdf($n)
{
        if(
$n 0)
        {
                return (
erf($n sqrt(2)))/2;
        }
        else
        {
                return (
erf($n sqrt(2)))/2;
        }
}

// EXAMPLE
$sample 90;
$avg 75;
$stddev 12;

$zscore = ($sample $avg) / $stddev;
print 
'Percentile: ' cdf($zscore) * 100 "\n";
?>

Where $n is the z-score

The function cdf() returns the approximed cumulative standard normal distribution ([0..1])



[EDIT BY danbrown AT php DOT net: Contains a bugfix provided by (Ed) on 24-FEB-2010 which fixes the definition of $a in erf() with the note that it is "out by a factor of -1" in the original code.]
2009-01-28 19:22:05
http://php5.kiev.ua/manual/ru/function.stats-stat-percentile.html

    Поддержать сайт на родительском проекте КГБ