Measures of Position in Statistics: Mean, Median and Mode

Measures of position, also known as position indices, or measures of central tendency, are values that summarize the position of a statistical distribution, providing a single figure that encapsulates the most important aspects of the data. In this brief discussion, we will explore some of the most common and practical indices, such as the various types of means, the median, quartiles, and percentiles.

Measures of Central Tendency

A mean is a measure of the central tendency of a set of values.

Arithmetic Mean

The arithmetic mean, as we all learned in school, is the sum of the values in a data set divided by the number of values.

In statistics, a parameter of a population is represented by a Greek letter, while a descriptive measure of a sample is denoted with a Roman letter.

For the mean, we use the symbol \( \mu \) for the mean of a population of values, and the letter \( \overline X \) (read as “x-bar”) for the mean of a sample of values.

Note: For this discussion, we will consistently refer to population parameters.

Here is the formula to calculate the population mean:

\( \mu = \frac {\Sigma X}{N} \\ \\ \)

In R, the function is mean(). A simple example:

variable = c(-3,1,2,4,5,2,8);
mean(variable);

[1] 2.714286

The Mean of Grouped Data

Let’s imagine we have n data points grouped into k classes. We’ll call xc the central value of each class and fi the observed frequency of each class.

The formula to calculate the mean in this case is:

\( \bar x = \frac{\sum^{k}_{i=1} x_c f_i}{N} \ \ \)

Let’s look at an example:

Classxcfixc * fi
4<x86530
8<x121011110
12<x201614224
20<x28247168
Total37532
our example data

Let’s use the formula and calculate the mean:

\( \bar x = \frac{(65) + (1011) + (1614) + (247)}{37} \ \ = \frac{532}{37} = 14.38 \)

The Weighted Mean

The weighted mean, or weighted average, is an arithmetic mean where each value is weighted according to its importance within the group.
Each value in the group (X) is multiplied by the appropriate weight factor \( \omega \) and the various products are summed and divided by the sum of the weights:

\( \mu_{w} = \frac{\Sigma(w X)}{\Sigma w} \)

Let’s look at an example. Imagine a sporting discipline where the jury’s score for each exercise is “weighted” with a certain difficulty coefficient. We would have these scores for the various exercises:

Jury ScoreCoefficient
9.34
9.82.8
8.83.3

Let’s multiply each score by its respective coefficient:

(9.3 * 4) + (9.8 * 2.8) + (8.8 * 3.3) = 93.68

The sum of the coefficients (i.e., the “weights”) is:

4 + 2.8 + 3.3 = 10.1

And calculate the weighted mean:

93.68 / 10.1 = 9.275

The Geometric Mean

Given a set of positive numbers x1,x2,…,xn the geometric mean is the nth root of the product of the n numbers. In formula:

\( \ \newcommand{\vc}[3]{\overset{#2}{\underset{#3}{#1}}} Geometric \ Mean = \sqrt[n]{\vc{\Pi}{n}{i=i} \ x_{i}} \)

N.B. The capital Greek letter pi is the symbol for product. The formula therefore equals this:

\( \\ Geometric \ Mean = \sqrt[n]{x_{1} x_{1} … x_{n}} \\ \\ \)

R doesn’t have a built-in function for calculating the geometric mean, but calculating this measure of position is very simple. Let’s look at an example:

data = c(2,9,12) # My values
n = length(data) # the number of values
 
# prod calculates the product of vector elements
# Calculate the geometric mean
prod(data)^(1/n)

The Harmonic Mean

The harmonic mean of a dataset x1, x2, …, xn is the reciprocal of the arithmetic mean of the reciprocals of the data. In formula:

\( Harmonic \ mean = \frac{1}{\frac{1}{n} \vc{\Sigma}{n}{i=i} \frac{1}{x_{i}}} \\ \\ \)

Similarly, for the harmonic mean, there is no specific built-in function available. However, since the harmonic mean is the reciprocal of the mean of the reciprocals of the data, the calculation is straightforward:

 1/mean(1/data)

Using the very simple example mentioned above:

data = c(2,9,12) # My values
n = length(data) # The number of values

# Calculate the harmonic mean
1/mean(1/data)

The Trimmed Mean

A trimmed mean (e.g., at 5%) is an arithmetic mean of all ordered values after excluding the lowest 5% and the highest 5% from the dataset. In the example chosen, this mean is obtained by calculating the arithmetic mean of the central 90% of the population in the sorted series of observations.

In R, the trimmed mean can be calculated by specifying the trim=proportionToExclude option in the mean() function, where proportionToExclude is the proportion (between 0 and 1) of the smallest and largest values to exclude before calculating the arithmetic mean.

A simple R example to clarify:

variable = c(-3,1,2,4,5,2,5,0.8,2.4,6,8);
mean(variable, trim=0.05);  ### 5% trimmed mean

[1] 3.018182

The Median

The median of a group of elements is the value of the central element when all the elements in the group are arranged in ascending or descending order of value.

In practice, the median of a dataset is the value that divides the series into two equal parts: as many values above the median as below it.

To find the median, the rule known as even-odd rule is used:

Even-Odd Rule

If a series has an odd number of values, the median is the middle value of the series; if the series has an even number of values, the median is the arithmetic mean of the two middle values.


In practice, the formula for finding the median can be summarized as follows:

\( Med = X_{(n/2)+(1/2)} \)


The median can be calculated in R using the median() function:

var = c(0,1,2,3,6,7,11,14);
median(var);

[1] 4.5
The Median of Grouped Data

For grouped data, you must:
1. Determine which class contains the median value
and then
2. Use interpolation to determine the position of the median within that class. 

The class that contains the median is the first class whose cumulative frequency equals or exceeds half the total number of observations. Once this class is identified, the specific value of the median is determined using the formula:

\( Med = C_{I} + (\frac{\frac{N}{2}- fc_{p}}{f_{c}})i \)

where:

CI = lower boundary of the class containing the median
N = total number of observations in the frequency distribution
fcp = cumulative frequency of the class preceding the one containing the median
fc = number of observations in the class containing the median
i = width of the class interval

As always, an example illustrates how the operational reality is simpler than it first appears. Let’s consider a distribution divided into frequency classes. In our example, we are dealing with height classes:

Height (cm)FrequenciesCumulative Frequencies
150 – 16044
160 – 170812
170 – 1801022
180 – 190830
190 – 200434

The class containing the median is the first class whose cumulative frequency equals or exceeds half the total number of observations, which, as seen in the table, is 34/2 = 17.

The median class, containing the value 17, is therefore the 170–180 class.

We can then easily extract all the values to insert into our interpolation formula:

CI = lower boundary of the class containing the median = 170
N = total number of observations in the frequency distribution = 34
fcp = cumulative frequency of the class preceding the one containing the median = 12
fc = number of observations in the class containing the median = 10
i = width of the class interval = (180 – 170) = 10

\( Med = C_{I} + (\frac{\frac{N}{2}- fc_{p}}{f_{c}})i \\ \)

therefore

\( Med = 170 + (\frac{(34/2) – 12}{10}) * 10 = 175 cm \)

The median value of the median class (170–180 cm) is 175 cm.

Tips for Better Clarity

For non-standardized intervals, ensure the interval width is adjusted proportionally to avoid misinterpretation of the results.


For this reason, for example, in the case of a skewed distribution, the median is a more reliable indicator than the mean, which will always be “pulled” toward the tail of the distribution. In a skewed distribution, the median will always fall between the mean and the mode.

The Mode

The mode of a dataset is the value that appears most frequently.

For example, consider the frequency of scores in a test:

scorefrequency
55
6 << this is the mode11
78
87
93

A distribution like this is called unimodal.
In the case of a small dataset where no measured value repeats, there is no mode.
When two non-adjacent values both have the same maximum frequency, the distribution is said to be bimodal.
Distributions with several modes are called multimodal.

In R, we can find the mode very easily using the which.max() instruction:

var = c(3,6,7,7,9,11,12,12,12,14,15,16,17,22,29,31);
frequency=tabulate(var);
which.max(frequency);

[1] 12
Mode of Grouped Data

For grouped data in a frequency distribution with equal class intervals, first identify the class containing the mode by finding the class with the highest number of observations. Then use the formula:

\( Mode = C_{I} + (\frac{d_{1}}{d_{1}+d_{2}})i \)

where:

CI = lower boundary of the class containing the mode
d1 = difference between the frequency of the modal class and the frequency of the previous class
d2 = difference between the frequency of the modal class and the frequency of the next class
i = class interval width

Relationship Between Mean, Median, and Mode

In the case of grouped data represented by a frequency curve, the difference between the values of the mean, median, and mode reveals the shape of the curve in terms of symmetry.

For a symmetric unimodal distribution, the mean, median, and mode coincide, meaning they have the same value.

In the case of a positively skewed distribution, the mean is the largest value, and the median is larger than the mode.
Thus:

Positive skewness = tail on the right = Mean > Median > Mode

asimmetria positiva

In the case of negative skewness, the mean has the smallest value, and the median is smaller than the mode.
Thus, in summary:

Negative skewness = tail on the left = Mean < Median < Mode

asimmetria negativa

A well-known measure of skewness, which uses the observed difference between the mean and the median of a group of values, is Pearson’s skewness index, which we will explore in more detail when introducing the concept of variability measures, as it includes the standard deviation in the denominator. For now, we can anticipate it as:

\( Skewness = \frac{3(\mu – Med)}{\sigma} \)

Quartiles, Deciles, and Percentiles

Quartiles, deciles, and percentiles are similar to the median as they divide a distribution of measurements according to the proportion of observed frequencies.

While the median divides the distribution into two halves, quartiles divide it into four quarters; deciles into ten tenths; percentiles into 100 hundredths. For ungrouped data, the formula for the median is modified depending on the desired fraction:

\( Q_{1} \ (first\ quartile) = X_{(\frac{n}{4} + \frac{1}{2})} \\ D_{3} \ (third\ decile) = X_{(\frac{3n}{10} + \frac{1}{2})} \\ P_{60} \ (sixtieth\ percentile) = X_{(\frac{60n}{100} + \frac{1}{2})} \\ \)

In R, they can be calculated as follows:

var = c(3,6,7,7,9,11,12,12,14,15,16,17,22,29,31);
quantile(var, probs=c(0.25,0.50,0.75)); ### quartiles

 25%  50%  75% 
 8.0 12.0 16.5 

quantile(var, probs=c(1:9)/10); ### deciles

 10%  20%  30%  40%  50%  60%  70%  80%  90% 
 6.4  7.0  9.4 11.6 12.0 14.4 15.8 18.0 26.2 
Quartiles, Deciles, and Percentiles for Grouped Data

In this case, you must first determine the class containing the point corresponding to the desired fraction, referencing cumulative frequencies, and then interpolate. For example:

\( Q_{1} \ (first\ quartile) = C_{1} + (\frac{\frac{n}{4} – fc_{p}}{f_{c}})i \\ D_{2} \ (second\ decile) = C_{1} + (\frac{\frac{3n}{10} – fc_{p}}{f_{c}})i \\ P_{60} \ (sixtieth\ percentile) = C_{1} + (\frac{\frac{60n}{100} – fc_{p}}{f_{c}})i \\ \)

An Overview: The Very Useful 5 Numbers

There is a summary description of data that allows us to immediately visualize key measures:

  1. The minimum value of our data
  2. The value of the first quartile
  3. The median
  4. The value of the third quartile
  5. The maximum value

The 5 numbers are often an excellent starting point for analyzing the characteristics of a distribution. In R, we have a specific command called (appropriately) fivenum():

var = c(3,6,7,7,9,11,12,12,14,15,16,17,22,29,31);
fivenum(var);

[1]  3.0  8.0 12.0 16.5 31.0

Let’s Help Ourselves with a Clever Graph: The Boxplot 

The boxplot (or box diagram) is a type of graph invented by the great John Tukey to provide a clear overview of a dataset at a glance. 

The boxplot can be oriented horizontally or vertically and appears as a rectangle divided into two parts, with two lines extending from it. The rectangle (the “box”) is bounded by the first and third quartiles and is divided internally by the median. The “whiskers” represent the minimum and maximum values. 

Note: The presence of “whiskers” is the reason this diagram is often called a box-and-whisker plot or box-and-whisker diagram.

This way, the four equally populated intervals defined by the quartiles are graphically represented.
Using a simple data distribution, here is how to call the boxplot function in R:

dati <- c(24,17,21,23,15,30,24,21,24,19,25,28,22,20,14,19,26,29,23,25,24,18,27,21);
boxplot(dati,ylab="",col=gray(0.8));

Adding some labels here and there for better clarity, the result is this:

esempio

An extremely effective "snapshot" of the observed value distribution.

A Practical SEO Case: Mean or Median for Sessions?

Measures of position really click when we bring them onto the data we look at every day. Picture the daily organic sessions of a page over two weeks, with one realistic detail: an isolated spike on Black Friday.

210  235  198  252  221  243  209  267  231  215  248  226  239  2400

I compute the two measures in R:

sessions <- c(210, 235, 198, 252, 221, 243, 209, 267, 231, 215, 248, 226, 239, 2400)
mean(sessions)              # 385.3
median(sessions)            # 233
mean(sessions, trim = 0.10)   # 233

The mean says 385 sessions a day; the median says 233. And here is the lesson: no normal day came anywhere near 385 — that figure is an artefact of Black Friday alone, which by itself drags the mean up by more than 150 sessions. The median, indifferent to the spike, describes the typical day. Tellingly, it matches the trimmed mean at 10% (233), which we met just above: dropping the tails before averaging is another way not to be fooled by an extreme value. Reporting “385 sessions a day on average” to a client would be arithmetically correct and practically misleading.

The operational rule is simple and reaches well beyond SEO: when the distribution has long tails or anomalous values — seasonal spikes, viral days, bots — the median (or the trimmed mean) describes the centre better than the mean. The mean stays irreplaceable when the data are symmetric and free of outliers.

Try It Yourself

To make the mechanism stick, here is the session duration (in seconds) of ten visits to a page, with one suspicious value — perhaps a bot left open:

45  52  48  61  55  300  49  58  53  47

The task: compute the mean and median with mean() and median(), then the quartiles with quantile(x, c(0.25, 0.5, 0.75)), and decide which measure you would report as the “typical duration”.

To check your work: the mean is 76.8 s (inflated by the 300), the median 52.5 s; the quartiles are Q1 = 48.25 and Q3 = 57.25, with an interquartile range of just 9 seconds. The mean nearly doubles the real duration of most visits: the median, once again, is the honest measure.

With mean, median, mode and quartiles we can say where a distribution concentrates. But that is only half the story: two sets of data can have the exact same mean and barely resemble each other, depending on how much the values scatter around that centre. Measuring that spread — the variance, the standard deviation, the interquartile range we have just touched on — is the step that finally gives our measures of position their depth: we cover it in the measures of dispersion.


Further Reading

Means, medians and their pitfalls are among the protagonists of The Art of Statistics by David Spiegelhalter: a book that shows, through real cases, when a measure of position illuminates the data and when it betrays them.

Leave a Reply

Your email address will not be published. Required fields are marked *