evalclass/precrec

Having trouble understanding normalized rank calculation

Opened this issue · 1 comments

I read all the instruction and vignettes available for precrec package, but I am having trouble understanding, how normalized rank is being calculated for basic mode. It would be really helpful, if you can include small introduction or explanation about it in the documentation or here.

I am looking forward for your reply.

Great work!!

Thank you.

Hi,

Normalized ranks are calculated as (ranks - 1)/(n - 1). Below is an example of R code to calculate normalized ranks in precrec.

> ranks <- c(3, 2, 1, 4)
> ranks
[1] 3 2 1 4
>
> n <- length(ranks)
> n
[1] 4
>
> (ranks - 1) / (n - 1)
[1] 0.6666667 0.3333333 0.0000000 1.0000000

Please notice the ranks in the example above are given higher ranks (as 1 is the best rank) for higher scores. It is different from the default R rank function.

> scores <- c(20, 75, 100, 1)
>
> # R's default rank function
> rank(scores)
[1] 2 3 4 1
>
> # precrec's rank function
> precrec::.rank_scores(scores)$ranks
[1] 3 2 1 4