Descriptive Statistics
Centre
Mean
Median: the middle value of the sorted data. With an even number of values it is the average of the middle two.
Mode: the most common value (or values).
Spread
Range: the largest value minus the smallest. Simple, but set entirely by the two most extreme points.
Variance: roughly the average squared deviation from the mean. For a sample we divide by rather than :
Why ? We measure deviations from the sample mean , not the true mean , and is by construction the point that minimises the sum of squared deviations for this sample. So the sum is systematically too small. Dividing by (Bessel's correction) makes an unbiased estimate of the population variance. The 1 is there because one quantity, , was estimated from the same data: once is fixed, only of the deviations are free to vary (they must sum to zero).
If you really do have the whole population, you know , and dividing by is correct. NumPy's np.var divides by by default (ddof=0); pandas' .var() divides by (ddof=1).
Standard deviation: the square root of the variance, which puts it back in the units of the data.
Interquartile range: the 75th percentile minus the 25th. Unlike the range and the standard deviation, it is barely affected by outliers.
Covariance
Variance measures how one variable deviates from its mean; covariance measures how two variables deviate from their means together:
A large positive covariance means tends to be large when is large and small when is small. A large negative covariance means the opposite. A covariance near zero means no such linear relationship.
Covariance is hard to interpret on its own:
- Its units are the product of the two variables' units.
- Doubling every doubles the covariance, though the two variables are just as related as before. So it is hard to say what counts as "large".
Correlation
Pearson's correlation coefficient divides the covariance by both standard deviations, which removes the units and bounds it between −1 and 1:
Things to remember about it:
- It only picks up linear relationships, where knowing how compares with the mean of tells you how compares with the mean of . A perfect relationship on symmetric data has a correlation of zero.
- It says nothing about how large the effect is. A correlation of 0.9 is compatible with rising by a tiny amount per unit of ; the slope comes from linear regression.
- A correlation in the whole population can reverse inside every subgroup when a confounding variable is ignored (Simpson's paradox).
For a rank-based alternative that handles any monotonic relationship, see Spearman's correlation in Feature Importance.
Adapted in part from Joel Grus, Data Science from Scratch (2nd edition), chapter 5.
Revision log
- Migrated from data-science-notes
Tags: Statistics