Re: [PHP] 95th percentile of an array.

2011-01-30 Thread Adam Richardson
On Sun, Jan 30, 2011 at 10:39 PM, Adam Richardson wrote:

> On Sun, Jan 30, 2011 at 8:44 PM, Marc Trudel  wrote:
>
>> Just out of curiosity, wouldnt it be better to use floor($n) instead of
>> round($n-0.5)?
>>
>
> Hi Marc,
>
> I don't think so, although I could have missed something (I just quick
> cranked out the example.)  The definition I linked to involves rounding (2.5
> would round to 3, and 2.4 would round to 2), so I just included the rounding
> in the equation.  Let me know if you see something I botched.
>
> Thanks,
>
> Adam
>
> --
> Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> http://nephtaliproject.com
>

Hi again Marc,

One other note.  Maybe you were suggesting that the equation should have
been reduced to floor($n) instead round($n - .5).

I purposely tried to stay true to the equation/algorithm provided in the
link so it would be easy for the OP to see exactly where I got the equation
from and how I mapped it to PHP code (although I did have to adjust the
equation for zero indexes used in arrays.)

That all said, if you wanted to reduce the equation to floor($n) to produce
a more succinct representation, then you could certainly make that change
and it would produce the same result.

Thanks,

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] 95th percentile of an array.

2011-01-30 Thread Adam Richardson
On Sun, Jan 30, 2011 at 8:44 PM, Marc Trudel  wrote:

> Just out of curiosity, wouldnt it be better to use floor($n) instead of
> round($n-0.5)?
>

Hi Marc,

I don't think so, although I could have missed something (I just quick
cranked out the example.)  The definition I linked to involves rounding (2.5
would round to 3, and 2.4 would round to 2), so I just included the rounding
in the equation.  Let me know if you see something I botched.

Thanks,

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] 95th percentile of an array.

2011-01-30 Thread Marc Trudel
Just out of curiosity, wouldnt it be better to use floor($n) instead of
round($n-0.5)?

On Sun, Jan 30, 2011 at 5:48 AM, Paul Halliday wrote:

> On Sat, Jan 29, 2011 at 2:28 PM, Adam Richardson 
> wrote:
> > For the nearest rank computation, you could use the following:
> >
> > $arr =
> >
> array(12,89,65,23,90,99,9,15,56,67,3,52,78,12,10,88,77,77,77,77,77,77,77);
> > sort($arr);
> > $score_representing_95th_percentile = $arr[round((95/100) * count($arr) -
> > .5)];
> > echo $score_representing_95th_percentile; // 90
> >
>
> Perfect, exactly what I was looking for.
>
> thank you.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Marc Trudel-BĂ©lisle
*Chief Technical Officer*
www.wizcorp.jp


Re: [PHP] 95th percentile of an array.

2011-01-29 Thread Paul Halliday
On Sat, Jan 29, 2011 at 2:28 PM, Adam Richardson  wrote:
> For the nearest rank computation, you could use the following:
>
> $arr =
> array(12,89,65,23,90,99,9,15,56,67,3,52,78,12,10,88,77,77,77,77,77,77,77);
> sort($arr);
> $score_representing_95th_percentile = $arr[round((95/100) * count($arr) -
> .5)];
> echo $score_representing_95th_percentile; // 90
>

Perfect, exactly what I was looking for.

thank you.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 95th percentile of an array.

2011-01-29 Thread Adam Richardson
For the nearest rank computation, you could use the following:

$arr =
array(12,89,65,23,90,99,9,15,56,67,3,52,78,12,10,88,77,77,77,77,77,77,77);
sort($arr);
$score_representing_95th_percentile = $arr[round((95/100) * count($arr) -
.5)];
echo $score_representing_95th_percentile; // 90

That said, there are many ways to calculate percentile (I tend to think in
Z-scores, myself), and nearest rank has its issues, depending on your needs:
http://en.wikipedia.org/wiki/Percentile

Hopefully the example and the link
give you enough to get what you need working.

Adam

On Sat, Jan 29, 2011 at 11:15 AM, Paul Halliday wrote:

> What is the quickest way to do this? Will stats_stat_percentile work?
> If so, does anyone have examples of its operation?
>
> Keep in mind that my math is terrible. Use small words :)
>
> Thanks.
>
> --
> Paul Halliday
> http://www.pintumbler.org
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com