AllenDowney/ThinkStats2

The intuition behind index calculation could be improved in Percentile2

Closed this issue · 0 comments

index = percentile_rank * (len(scores)-1) // 100

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