Descriptive Statistics: Mean, Median, Mode
Before making inferences, you first describe what you see. Mean, median, mode, variance, and standard deviation are the vocabulary of data summarization.
The Purpose of Descriptive Statistics
Before you can infer anything from data (before you can test a hypothesis or fit a model) you must first understand what the data actually looks like. Descriptive statistics are the tools for this initial exploration. They summarize large datasets into a handful of numbers that capture the essential features: where is the data centered, how spread out is it, and what shape does it have?
Population vs. Sample
There is an important distinction between a population and a sample.
The population is the entire group you are interested in studying. The S&P 500 companies, all daily returns over the past 20 years, every trade in a particular stock: these are populations. In principle, you could measure every element of a population, but often the population is too large or even infinite.
A sample is a subset of the population that you actually observe and measure. We use sample statistics to estimate population parameters. The formulas for the sample mean and sample variance are slightly different from their population counterparts, and we will be careful about which is which.
The Mean
The arithmetic mean (commonly called “the average”) is the most familiar measure of central tendency. For a sample of observations :
The mean has many attractive mathematical properties. It is the balance point of the distribution: the sum of deviations above the mean equals the sum of deviations below the mean. It is the best unbiased estimator of the population mean under squared error loss. It is additive: the mean of the combined dataset is a weighted average of the individual means.
However, the mean is sensitive to extreme values. A portfolio with an average return of 12% could consist of consistently 12% returns, or it could be a mix of 20% winners and occasional 40% losses. The mean alone cannot distinguish these.
The Median
The median is the middle value when the data is sorted in order: the 50th percentile. If is odd, the median is the single middle value. If is even, it is the average of the two middle values.
The median is robust to outliers. If one trading day had a 30% loss due to a flash crash, the median is barely affected, while the mean drops significantly. This robustness makes the median the preferred measure of central tendency for highly skewed data, like income distributions or asset returns that occasionally have extreme moves.
The Mode
The mode is the most frequently occurring value in the dataset. It is the only measure of central tendency that applies to categorical (non-numerical) data: the most common sector in your portfolio, the most frequent trading pattern.
For continuous data, every value is unique (no repeats), so the mode is less useful in its raw form. Instead, practitioners often look at the mode of a histogram, the peak of the distribution, also called the modal bin.
Variance and Standard Deviation
Central tendency tells you where the data is. Variance and standard deviation tell you how spread out it is.
For a sample of observations with mean :
The sample variance uses in the denominator (not ), making it an unbiased estimator of the population variance. This is Bessel’s correction.
The standard deviation is the square root of variance. Because variance is in squared units, standard deviation returns to the original units of the data, making it more interpretable. For financial returns, standard deviation is called volatility, a concept so central to quantitative finance that it gets its own name.
Range and Interquartile Range
The range is the difference between the maximum and minimum values: . It is simple to compute but heavily influenced by outliers.
The interquartile range (IQR) is the range of the middle 50% of the data:
where is the 25th percentile and is the 75th percentile. The IQR is robust to outliers and tells you how spread out the “typical” portion of the data is. A common rule of thumb is that values outside and are potential outliers.
Skewness and Kurtosis
Skewness measures the asymmetry of a distribution:
- Positive skewness means the right tail is longer: extreme gains are possible but losses are bounded. Asset returns are often positively skewed due to the possibility of large gains.
- Negative skewness means the left tail is longer: crashes are possible but gains are capped. This describes many insurance-type payoffs.
- Zero skewness means symmetry, like a normal distribution.
Kurtosis measures the heaviness of the tails relative to a normal distribution:
A normal distribution has kurtosis of 3. Excess kurtosis is kurtosis minus 3. Positive excess kurtosis (“leptokurtic”) means fatter tails and a sharper peak than normal, exactly what we observe in financial returns. This is why 4-sigma events in markets happen more often than a normal model predicts.
The Five-Number Summary and Box Plots
The five-number summary captures a dataset in five numbers: minimum, , median, , and maximum. A box plot (or box-and-whisker plot) visualizes these five numbers. The box spans to , the line inside the box is the median, and the whiskers extend to the most extreme values within 1.5 times the IQR.
Python: Exploring S&P 500 Returns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
np.random.seed(42)
n = 1_000
daily_returns = np.random.normal(0.0003, 0.01, n) # ~8% annual return, ~16% annual vol
returns_series = pd.Series(daily_returns)
print("Descriptive Statistics:")
print(returns_series.describe())
print(f"\nSkewness: {returns_series.skew():.4f}")
print(f"Excess Kurtosis: {returns_series.kurtosis():.4f}")
print(f"Median: {returns_series.median():.6f}")
print(f"IQR: {returns_series.quantile(0.75) - returns_series.quantile(0.25):.6f}")
fig, axes = plt.subplots(1, 2, figsize=(14, 5))
# Histogram with mean and median marked
axes[0].hist(daily_returns, bins=50, density=True, alpha=0.7)
axes[0].axvline(returns_series.mean(), color='red', linestyle='--', lw=2, label=f'Mean: {returns_series.mean():.4f}')
axes[0].axvline(returns_series.median(), color='green', linestyle=':', lw=2, label=f'Median: {returns_series.median():.4f}')
axes[0].set_xlabel('Daily return')
axes[0].set_ylabel('Density')
axes[0].set_title('Distribution of Simulated Daily Returns')
axes[0].legend()
axes[0].grid(alpha=0.3)
# Box plot
axes[1].boxplot(daily_returns, vert=True)
axes[1].set_ylabel('Daily return')
axes[1].set_title('Box Plot of Daily Returns')
axes[1].grid(alpha=0.3)
plt.tight_layout()
plt.show()
PROMPT
Use numpy, pandas, matplotlib, and scipy.stats to compute descriptive statistics on simulated returns and plot a histogram and box plot.
In real S&P 500 data, you would typically see slight negative skewness and positive excess kurtosis. The normal distribution that is often assumed in models is only an approximation. The actual distribution of returns has fatter tails and a sharper peak than the Gaussian bell curve.
References
Moore, D. S. and McCabe, G. P. Introduction to the Practice of Statistics, Chapter 1. Freeman. Ross, S. M. A First Course in Probability, review of statistics. Pearson.