# Does the samples mean and the histogram mean have to be the same?

I'm reading this book. Here, he gives me a method for calculating the mean:

Here he introduces a new method of calculating the mean through histogram:

He says that now we will count and index the samples in the histogram, this list:

{7, 8, 0, 9, 2, 10, 4, 1, 6, 0, 8, 7, 6, 0, 0}

Is going to be counted and it will result in:

{{7, 2}, {8, 2}, {0, 4}, {9, 1}, {2, 1}, {10, 1}, {4, 1}, {1, 1}, {6, 2}}

It means there are two 7's in the list, there are two 8's in the list and so on.

Then i've calculated the mean of this list:

{4, 1, 1, 0, 1, 0, 2, 2, 2, 1, 1}

Which is almost as the ordered version of the last list, four 0's, one 1 and so on

The problem is that the mean of the first one is different of the second, while the mean of the first list is 4.53333, the second list is 1.36364, do these means have to be identical?

-
The mean of the same list should be the same, no matter what way you calculate it (given that your calculations are correct). I have not read through the equations, but there seems to be a mistake somewhere. –  Andrew May 28 '12 at 8:06
add comment

## 2 Answers

Yes, they should be identical, you must have done something wrong to get the 1.36364 answer. Perhaps you neglected to multiply the values by their frequencies eg 7x2, 8x2, 0x4, etc.

See:

> (7+8+9+2+10+4+1+6+8+7+6)/15
[1] 4.533333
> (7*2+8*2+9+2+10+4+1+6*2)/(2+2+4+1+1+1+1+1+2)
[1] 4.533333

-
Oh, the frequency is also necessary, isn't it? This is what was strange, when I read it I thought only the frequency was necessary. –  Gustavo Bandeira May 28 '12 at 18:45
add comment

The two methods will have the same result in this case because the values are integers and the bins contain one and only one integer. If the width of the bin were larger so that it could include two or more integers the results could be different. You could view the histogram mean as a crude approximation to the sample mean in that case. It is what you would resort to if you are only given the histogram and not the raw data.

-
What you mean with "the same result"? They should have the same mean? –  Gustavo Bandeira May 28 '12 at 16:12
Yes Gustavo they would have the same means. –  Michael Chernick May 28 '12 at 16:54
add comment