PHP Doku:: Not documented - function.stats-stat-percentile.html

Verlauf / Chronik / History: (23) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzMathematische ErweiterungenStatisticsStatistic Funktionenstats_stat_percentile

Ein Service von Reinhard Neidl - Webprogrammierung.

Statistic Funktionen

<<stats_stat_paired_t

stats_stat_powersum>>

stats_stat_percentile

(PECL stats >= 1.0.0)

stats_stat_percentileNot documented

Beschreibung

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

Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verfügung.

Parameter-Liste

df

xnonc

Rückgabewerte


3 BenutzerBeiträge:
- Beiträge aktualisieren...
vijayhrd at gmail dot com
26.09.2010 11:36
and what is $x? in the first function.
aboulang2002 at yahoo dot com
29.01.2009 2:22
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*(4 - $pi));
       
$x2 = $x * $x;

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

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

        return
sqrt($erf2);
}

function
cdf($n)
{
        if(
$n < 0)
        {
                return (
1 - erf($n / sqrt(2)))/2;
        }
        else
        {
                return (
1 + 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.]
yuvaraj dot v at gmail dot com
11.12.2007 13:37
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(
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



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)