I have this list:
def grades = [5,4,3,2,1,1]
Where index is a grade, and value is an occurrence of the grade:
Grade | Occurrence |
---|---|
0 | 5 |
1 | 4 |
2 | 3 |
3 | 2 |
4 | 1 |
5 | 1 |
How can I calculate the 90th percentile for the grades?
I have this list:
def grades = [5,4,3,2,1,1]
Where index is a grade, and value is an occurrence of the grade:
Grade | Occurrence |
---|---|
0 | 5 |
1 | 4 |
2 | 3 |
3 | 2 |
4 | 1 |
5 | 1 |
How can I calculate the 90th percentile for the grades?
If I understand correctly, a total of 16 grades have been given (5 + 4 + 3 + 2 + 1 + 1 = 16). 90 % are 14.4 grades, so discard the lowest 14 grades and take the smallest remaining (in your example it will be 4).
How to code? There are some ways:
I believe you will learn the most from coding it yourself, so I am not taking that pleasure or learning away from you.
This gets me a whole grade. I was hoping to find an exact value of 90th percentile, but this will do for me.
def grades = [5,4,3,2,1,1]
sum=grades.sum()
per_grade=0
per_value=sum*0.9
grades.eachWithIndex { grade_count, grade ->
per_value-=grade_count
if (per_value<0){per_grade=grade-1}
if (per_value==0){per_grade=grade}
}
out.write(per_grade)