2024-02-05

Introduction

The five-number summary is a statistical summary of a dataset that provides a concise description of its distribution.It consists of five values: the minimum, the first quartile (Q1), the median (Q2), the third quartile (Q3), and the maximum.

Together, these five values provide a comprehensive summary of the dataset’s central tendency, variability, and range. They offer valuable insights into the distribution of the data, helping analysts understand the overall pattern and characteristics of the dataset without having to examine every single data point individually.

The five-number summary is often used in exploratory data analysis and is particularly useful for comparing different datasets or identifying outliers.

The Five Values:

  • Minimum: This value indicates the smallest observation in the dataset. It provides information about the lower boundary of the dataset.
  • First Quartile (Q1): This is the median of the lower half of the dataset. In other words, it’s the value below which 25% of the data points fall. It’s also known as the 25th percentile. Q1 gives insight into the spread of the lower end of the dataset.
  • Median (Q2): The median is the middle value of the dataset when it’s arranged in ascending order. It divides the dataset into two equal parts, with half of the observations falling below it and the other half above it. The median is a robust measure of central tendency, meaning it’s less influenced by extreme values or outliers compared to the mean. It’s often used to represent the central tendency of the dataset.

  • Third Quartile (Q3): Similar to Q1, Q3 is the median of the upper half of the dataset. It’s the value below which 75% of the data points fall. It’s also known as the 75th percentile. Q3 provides insight into the spread of the upper end of the dataset.
  • Maximum: This value indicates the largest observation in the dataset. It provides information about the upper boundary of the dataset.

The equation for finding the position of Median can be written as \[PosMedian = \frac{n+1}{2}\] where n is the total number of values.

Boxplot

The five-number summary is often visualized using a graphical tool called a box plot, also known as a box-and-whisker plot. A box plot provides a visual representation of the distribution of the dataset and displays the five-number summary along with any potential outliers.

  • Box: The box in the plot represents the interquartile range (IQR), which is the range between the first quartile (Q1) and the third quartile (Q3). It visually depicts where the middle 50% of the data lies. The length of the box corresponds to the spread of this middle portion of the dataset.
  • Median Line: A vertical line inside the box represents the median (Q2) of the dataset. It divides the box into two equal parts, indicating the center of the data distribution.

  • Whiskers: Whiskers extend from the edges of the box to the minimum and maximum values of the dataset, excluding any potential outliers. The length of the whiskers provides information about the spread of the data beyond the interquartile range.
  • Outliers: Data points that fall outside the whiskers are considered outliers. These points are plotted individually to highlight their deviation from the rest of the dataset. Outliers can signify unusual observations or data entry errors and may warrant further investigation.

Let’s look at an example to explore more about this topic. We have a dataset of different cars which includes their model name, year of build, country of origin and MPG.

Plotted above is a histogram which tells us the frequency of cars in a particular range set of their representative mileage. \[ Mileage = \frac{miles}{gallon}\]

We can plot a boxplot to see the different components of it.

The values within the box above are in the Interquartile Range. The dots above that are the outliers. The horizontal line within the box is the median.

We can also plot a side by side boxplot for comparing different Origins.

As we can see from above, the American cars are the least efficient of the bunch, European cars are in somewher in the middle, while the Japanese cars are the most efficient as they give the most mileage.

The histogram plotly code:

cars = read.csv(“auto-mpg.csv”)

cars[‘origin’][cars[‘origin’] == 1] <- “American”

cars[‘origin’][cars[‘origin’] == 2] <- “European”

cars[‘origin’][cars[‘origin’] == 3] <- “Japanese”

fig <- plot_ly(data = cars, x = carsmpg , type = “histogram”, color = as.factor(carsorigin)) %>%

layout(xaxis = list(title = “Miles per Gallon”), yaxis = list(title = “No. of cars”))

fig