The Mode, Screen 4

Below it i mentioned :

The median is 1 — a value easier to grasp by non-technical people compared to 1.04. But this is a lucky case, because the middle two values in the sorted distribution could have been [1, 2], and then the median would have been 1.5.’

This is a typo , coz median=1.5

Hello @sharathnandalike,

Actually, the median is equal to 1 (not a typo).

The goal here is to show that the mean and the median are not suitable to calculate the average number of kitchens in a house. To do so:

  • We computed the mean, and since it is a decimal number, it is not suitable to represent the average number of kitchens in a house. (third paragraph of the screen)

mean(houses$Kitchen AbvGr) = 1.04

  • We computed the median. But we showed that even if it is not a decimal number, it is not suitable because of the risk of decimal numbers when the size of distribution is odd since, in this case, we compute the mean of the two middle numbers reference (forth paragraph of the screen).

median(houses$`Kitchen AbvGr`)=1

Thank you to point this out, we’ll clarify it.

Don’t hesitate to come back to me if you have more question.

Hello John. Welcome back to the New Year.

In the below table, how the median of 0,1,2,3 could be 1. Here the no. of values is even & since we are taking the middle value , it is average of 1,2 ie; average of middle 2 nos. which is (1+2)/2 = 1.5

A tibble: 4 x 2

Kitchen AbvGr frequency
1 0 3
2 1 2796
3 2 129
4 3 2

1 Like

Hello @sharathnandalike,

The Happiest new year to you. My best wishes!

You’re right if we’re looking at the frequency table as the distribution. Here the distribution is Kitchen AbvGr.

To calculate the median, we don’t need the frequency table, we just order the distribution and depending on if the length of the distribution is either odd or even, we take either the value at the middle, or the mean of the two values at the middle.

In the case of the Kitchen AbvGr distribution, the size of the distribution is 2930, if you look at the two values at the middle, you will see that they are 1’s. That’s why the average yields 1.

Kitchens  <-  houses$`Kitchen AbvGr`
Kitchens_sorted  <-  sort(Kitchens)

# Find the median 
middle_indices  <-  c(length(rooms_sorted) / 2,
                      (length(rooms_sorted) / 2) + 1
) # 2930 is even so we need two indices.
middle_values  <-  rooms_sorted[middle_indices]

Process reminder.

For the Median:

  • Arrange the distribution in increasing order.
  • If the length of distribution is even, take the mean of the two values at the middle.
  • Otherwise (the length of the distribution is odd), take the value at the middle.

For the Mode :

  • Calculate the frequency table of the distribution.
  • Arrange the frequency table by frequencies in descending order.
  • Take the first value.