C# percentile rank algorithm

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Has anyone written a percentile rank algorithm that they can share or
know of a good resource that defines the algorithm. I'm starting a
project that involves percentile ranks, logistic and linear regression.
If not c# any language or pseudo code would be very useful. Thank you.

Joe
 
Joe said:
Has anyone written a percentile rank algorithm that they can share or
know of a good resource that defines the algorithm. I'm starting a
project that involves percentile ranks, logistic and linear regression.
If not c# any language or pseudo code would be very useful. Thank you.

Joe

Forgive me if I'm wrong but isn't percentile rank just counting how many
of the values are below or equal the specific value you're looking at in
terms of percentage of the entire list of values ?

Ie. if you have a value of 50, and there are 75 values in the list, and
30 of those are 50 or below, wouldn't this mean that the percentile rank
of 50 in this list is (30/75)*100 = 40%?

I'd assume sorting the list, then running through it and assigning
percentile ranks would be the best way. You'd have to handle duplicate
values though:

1, 1, 2, 2, 3, 3, 4

would have percentile ranks of:

25%, 25%, 50%, 50%, 75%, 75%, 100%

(if I'm not wrong about what a percentile rank is)

pseudo-code for the above:

- sort list
- loop through all elements from start to finish (lowest to highest)
- find all duplicates of the value you're looking at
- calculate percentile rank as number of values below the value
(index of the loop), plus the number of duplicates, divided by
the number of elements in the list
- skip past duplicates
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top