STATHARBOR ANALYTICS · INTRODUCTION TO STATISTICS · CHAPTER 3
Describing Data
Once data have been collected, the first step in analysis is to describe and visualise them. Descriptive statistics provide summaries of the central tendency, variation and distribution shape of the data. Effective graphics help detect outliers, skewness and patterns that suggest relationships between variables.
Measures of Central Tendency
Mean: For a sample of observations , the sample mean is The mean summarises the balance point of the data but is sensitive to extreme values.
Median: The median is the middle value when the data are sorted. It is robust to outliers and skewness.
Mode: The most frequently occurring value. Useful for categorical variables but less so for continuous data.
Measures of Variability
Variance and Standard Deviation: The sample variance is and the sample standard deviation is . Dividing by yields an unbiased estimate of the population variance.
Interquartile Range (IQR): The difference between the 75th and 25th percentiles (). The IQR measures the spread of the middle 50% of the data and is robust to outliers.
Range: The difference between the maximum and minimum values. Sensitive to outliers.
Visualising Data
Graphs reveal information that summary statistics cannot. Common plots include:
Histogram: Displays the distribution of a single continuous variable by grouping observations into bins. Useful for assessing shape (e.g. skewness, bimodality).
Boxplot: Summarises the distribution using the median, quartiles and outliers. Facilitates comparison across groups.
Scatterplot: Shows the relationship between two quantitative variables. Look for linearity, clusters and outliers.
Bar chart: Represents counts or proportions for categorical variables.
Example: Heights of Students
Imagine a dataset of heights (in centimetres) for a sample of 30 students:
168, 172, 165, 175, 169, 170, 166, 173, 171, 174, 167, 169, 170, 175, 172, 168, 169, 171, 170, 173, 174, 168, 169, 166, 172, 170, 168, 171, 175, 169.
Worked example
Descriptive statistics in R:
heights <- c(168,172,165,175,169,170,166,173,171,174,
167,169,170,175,172,168,169,171,170,173,
174,168,169,166,172,170,168,171,175,169)
mean_height <- mean(heights)
median_height <- median(heights)
sd_height <- sd(heights)
summary(heights)
Descriptive statistics in Python:
import numpy as np
heights = np.array([168,172,165,175,169,170,166,173,171,174,
167,169,170,175,172,168,169,171,170,173,
174,168,169,166,172,170,168,171,175,169])
mean_height = np.mean(heights)
median_height = np.median(heights)
sd_height = np.std(heights, ddof=1)
quartiles = np.percentile(heights, [25, 50, 75])
Descriptive statistics in Julia:
using Statistics
heights = [168,172,165,175,169,170,166,173,171,174,
167,169,170,175,172,168,169,171,170,173,
174,168,169,166,172,170,168,171,175,169]
mean_height = mean(heights)
median_height = median(heights)
sd_height = std(heights)
q1, med, q3 = quantile(heights, [0.25, 0.5, 0.75])
These commands compute measures of central tendency and spread. Histograms and boxplots can be produced using functions such as ‘hist‘ in R, ‘matplotlib.pyplot.hist‘ in Python and ‘StatsPlots‘ in Julia.
Exercises
Practice
For the student heights data above, draw a histogram and boxplot in your preferred language. Comment on the symmetry or skewness.
Create a small dataset of 10 values with a large outlier. Compute the mean and median. Discuss which measure better reflects the central tendency.
Explain why the variance is computed with in the denominator rather than . What effect would using have on the estimate?
Find a dataset online (e.g. from a government statistics portal) and compute descriptive statistics for a quantitative variable. Produce a scatterplot of two variables if available.
References
Tukey JW. Exploratory Data Analysis. Reading, MA: Addison–Wesley; 1977.
Cleveland WS. The Elements of Graphing Data. Monterey, CA: Wadsworth; 1985.
McKinney W. Python for Data Analysis. 2nd ed. O’Reilly; 2018.