note 88558 added to function.stats-stat-percentile

From: Date: Thu, 29 Jan 2009 01:22:05 +0000
Subject: note 88558 added to function.stats-stat-percentile
Groups: php.notes 
Request: Send a blank email to php-notes+get-149924@lists.php.net to get a copy of this message
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 function erf($x) { $pi = 3.1415927; $a = (8*($pi - 3))/(3*$pi*($pi - 4)); $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]) ---- Server IP: 69.147.83.197 Probable Submitter: 216.239.83.205 ---- Manual Page -- http://www.php.net/manual/en/function.stats-stat-percentile.php Edit -- https://master.php.net/note/edit/88558 Del: integrated -- https://master.php.net/note/delete/88558/integrated Del: useless -- https://master.php.net/note/delete/88558/useless Del: bad code -- https://master.php.net/note/delete/88558/bad+code Del: spam -- https://master.php.net/note/delete/88558/spam Del: non-english -- https://master.php.net/note/delete/88558/non-english Del: in docs -- https://master.php.net/note/delete/88558/in+docs Del: other reasons-- https://master.php.net/note/delete/88558 Reject -- https://master.php.net/note/reject/88558 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149924) next »