Average in a rating between 1 and 5

A user can vote on these numbers:

1, 2, 3, 4, 5

Then it's displayed as groups like this:

1 - 5 votes
2 - 3 votes
3 - 1 vote
4 - 17 votes
5 - 2 votes

Now I want the avarage rating score, like 3.9 or whatever it will be.

What I tried and failed:

Multiply all rows in the groups like:

1 - 1 * 5 votes
2 - 2 * 3 votes
3 - 3 * 1 vote
4 - 4 * 17 votes
5 - 5 * 2 votes

and then a sum of them where I get 52. Then I divide it with 15 which is the sum of all the valid scores. 52/15 = 3.46.

If I do that with the same votes on each, I can see how this is not correct:

1 - 1 * 1 votes
2 - 2 * 1 votes
3 - 3 * 1 vote
4 - 4 * 1 votes
5 - 5 * 1 votes

The result with my way would be 15/15 and that's 1 but it should be 3 in this case.

Any ideas?


Solution 1:

Everybody is showing you how to compute the weighted average, but not why.

What you have is 28 votes. The average of 28 values is the sum of those values, divided by 28. In this case, that means:

$$\frac{1+1+1+1+1+2+2+2+3+4+\cdots+4+5+5}{28}$$

This, we see, is the same as:

$$\frac{1\cdot 5 + 2\cdot 3+ 3\cdot 1 + 4\cdot 17+5\cdot 2}{28}$$

Solution 2:

I don't know where you pulled that $15$ denominator, but you're trying to do the weighted average. If you have a bunch of values $a_i$ to take the average from, all with a importance weight $w_i$, the weighted average is defined as follows : $$ \frac{ \sum_{i = 1}^n w_i \cdot a_i }{ \sum_{i = 1}^n w_i } $$

Note that the weights used in the numerator must be the same as the weights used in the denominator. In your problem the $a_i$ are the possible scores to give and the $w_i$ are the number of persons that gave that score. In your first case you get, $$ \frac{ 1\cdot5+2\cdot3+3\cdot1+4\cdot17+5\cdot2 }{ 5 + 3 + 1 + 17 + 2 } = \frac{92}{28} $$

In the second case, you get $$ \frac{ 1+2+3+4+5 }{ 1+1+1+1+1 } = \frac{15}{5} = 3 $$

Solution 3:

You should divide by the total number of voters, not the total of the scores: $$\bar{x}=\frac{5\cdot1+3\cdot2+1\cdot3+17\cdot4+2\cdot5}{5+3+1+17+2}$$ $$=\frac{92}{28}\approx 3.29$$

To see why this is reasonable, suppose everyone voted for the same number (say $2$). Then you would certainly want the average to come out as $2$. It won't if you compute it your way.

Generally, if $v_i$ votes are cast for the score $s_i$, then the average score is $$\bar{s} = \frac{v_1s_1+v_2s_2+\cdots+v_ns_n}{v_1+v_2+\cdots+v_n}$$ This is called a weighted average; each score is weighted by the number of votes for it, then the weighted scores are added and the sum divided by the total of the weights. A bigger number of votes for a particular score gives the score more prominence in the average.

Addendum: Another way to look at the weighted average is to just rewrite it as $$\bar{s} = (\tfrac{v_1}{v_1+v_2+\cdots+v_n})s_1 + (\tfrac{v_2}{v_1+v_2+\cdots+v_n})s_2 + \cdots + (\tfrac{v_n}{v_1+v_2+\cdots+v_n})s_n$$ Here you can see that each score is weighted by the fraction of votes it got out of the total. Each of the weights is between 0% and 100% and they add up to 100%. So the weighted average will be somewhere between the smallest and the largest score.