# Rank data from 1 to N (N may not be equal to number of elements in the dataset)

I calculate percentile ranks based on the method at http://www.psychstat.missouristate.edu/introbook/sbk14m.htm

I need to assign ranks to a dataset where ranks are from 1-to-N. Since N may or may not be equal to the size of data, ordinal ranking is not the solution. I wanted to know if the following formula would be right. If not, please suggest. Thanks

         Fb + 0.5 Fw
Rank =  ------------- x N   (notations are similar to those in the URL)
SizeOfData


What this formula computes is the Proportion Estimation based on rankit method. It is what percentile ranks are.

 X    R      F    PE
25  1.0   .0909 .0455
28  2.0   .1818 .1364
29  3.5   .3182 .2727
29  3.5   .3182 .2727
31  5.0   .4545 .4091
32  6.0   .5455 .5000
33  8.0   .7273 .6818
33  8.0   .7273 .6818
33  8.0   .7273 .6818
35  10.0  .9091 .8636
37  11.0 1.0000 .9545


In the data field above of $N=11$ cases, $R$ is rank; in this example, ties were treated by averaging. We might have used other mode of ties treatment.

$F_i=R_i/N$ is fractional rank; this term corresponds to the empirical cumulative proportion (please again be aware that as it is based on ranks, it is sensitive to the way ties were treated).

$PE_i=(R_i-1/2)/N$ is proportion estimation based on rankit method. What is this? It is similar to fractional rank, but it assumes that the data came from continuous distribution. Any empirical distribution, even of fractional values, is de facto discrete, but it often represents a continuous distribution for us.

Now, by convention, in discrete distribution a cumulative proportion is defined as "up to this odserved value including it", whereas in continuous distribution it is "up to this observed value not including it". Consequently, once we've decided to take our empirical data as coming from continuous, not discrete distribution, any fractional rank (the cumulative proportion) must be lessened.

How do we reason to what extent it should shrink? The most intuitive way is the rankit model of uniform binning a continuous data into descrete data. You can always uniformly spread N points within some range. The only tricky issue is what offset to make from the edges of the range. Rankit method of binning makes the offset 1/2 of the interval between any two points. Here is why $R_i$ becomes $R_i-1/2$. This latter expression - the numerator in the formula - is the expected rank of the unobserved value which immediately precedes (i.e. not includes) the observed value $i$ in the continuous distribution corresponding to the collected discrete one.

Other modes of uniform binning exist besides rankit: Blom's (offset 5/8), Tukey's (offset 2/3), Van den Waerden (offset 1), etc.

If in the formulas above you think $N$ is the sum of weights of cases and not the number of cases, everything remains valid. Thus, you could compute fractional rank or proportion estimation based on any arbitrary $N$. When data are weighted, ranks $R$ are computed accordingly, by taking cumulative sum of weights into account. Most statistical software that rank data can make use of caseweights.