AllenDowney / ThinkStats2

Text and supporting code for Think Stats, 2nd Edition
http://allendowney.github.io/ThinkStats2/
GNU General Public License v3.0
4.02k stars 11.28k forks source link

The intuition behind index calculation could be improved in Percentile2 #124

Closed zakir8251 closed 2 years ago

zakir8251 commented 5 years ago

https://github.com/AllenDowney/ThinkStats2/blob/e43e7c10e9389cab35173eba753f53facea4b130/book/book.tex#L2907

def Percentile2(scores, percentile_rank): scores.sort() index = percentile_rank * (len(scores)-1) // 100 return scores[index]

Instead of index = percentile_rank (len(scores)-1) // 100 A more intuitive formula is:- index = (percentile_rank (len(scores)) // 100) -1 or even better:- index = percentile_rank * (len(scores)) // 100 return[index-1] #since indexes start with 0