Statistics refresher: correlation, variance, and standard deviation

Overview

Why this post

A personal reference for the statistics concepts I keep forgetting.


Correlation

The correlation coefficient r is a single number ranging from -1 to +1. It quantifies the linear relationship between two variables.

Value Meaning
r = 1 Perfect positive correlation
r = 0 No correlation
r = -1 Perfect negative correlation

Example

1r = 0.8  → correlation between grade and study time
2
3r² = 0.8² = 0.64
4
564% of the variation in grade is explained by study time.

The square of r (called R-squared) tells you how much of the variation in one variable is explained by the other.


Variance

Variance measures how far the values in a data set deviate from their mean. It is the average of the squared deviations.

Population variance (all data points are known):

$$\sigma^{2} = \frac{1}{N} \sum_{i=1}^{N} (x_i - \mu)^{2}$$

Sample variance (working with a sample, not the full population):

$$s^{2} = \frac{1}{n-1} \sum_{i=1}^{n} (x_i - \bar{x})^{2}$$

The sample formula divides by n - 1 instead of n. This corrects for the bias that comes from estimating the mean from the sample itself.

Worked example

$$ \begin{aligned} \text{Mean:} \quad & \bar{x} = \frac{18 + 12 + 15 + 15}{4} = 15 \\ \text{Squared deviations:} \quad & (18-15)^2 = 9 \\ & (12-15)^2 = 9 \\ & (15-15)^2 = 0 \\ & (15-15)^2 = 0 \\ \text{Sum:} \quad & 9 + 9 + 0 + 0 = 18 \\ \text{Population variance:} \quad & \sigma^2 = \frac{18}{4} = 4.5 \\ \text{Sample variance:} \quad & s^2 = \frac{18}{3} = 6 \end{aligned} $$

Why we square the deviations

Deviations can be positive or negative. Without squaring, they would cancel each other out and the sum would always be zero.

Squaring achieves three things:

  • Signs do not cancel.
  • Larger deviations count disproportionately more.
  • The resulting formula is mathematically smooth and works well with the normal distribution and many statistical estimators.

If you need a measure that is less sensitive to outliers, consider mean absolute deviation instead.


Standard deviation

The standard deviation is the square root of the variance. It brings the measure back to the same unit as the original data.

Population standard deviation:

$$\sigma = \sqrt{\frac{1}{N} \sum_{i=1}^{N} (x_i - \mu)^{2}}$$

Sample standard deviation:

$$s = \sqrt{s^{2}}$$

Worked example (continued from above)

$$ \begin{aligned} \text{Population standard deviation:} \quad & \sigma = \sqrt{4.5} \approx 2.12 \\ \text{Sample standard deviation:} \quad & s = \sqrt{6} \approx 2.45 \end{aligned} $$

Why a square is never negative

Any real number multiplied by itself gives a non-negative result.

Case Example Result
Positive $5 \times 5$ 25
Zero $0 \times 0$ 0
Negative $(-3) \times (-3)$ 9

The two minus signs cancel for negative numbers:

$$(-8) \times (-8) = 64$$

Geometric intuition: the area of a square with side length $|a|$ is always non-negative, regardless of the sign of a.

$$\text{Area} = |a| \times |a| = a^{2} \ge 0$$

Absolute value notation

The absolute value $|a|$ is the distance from zero. It is always non-negative.

$$|a| = \begin{cases} a & \text{if } a \ge 0 \\ -a & \text{if } a < 0 \end{cases}$$

The distance between two numbers x and y:

$$\text{dist}(x, y) = |x - y|$$

This is why absolute value appears in mean absolute deviation: it removes the sign without squaring.


Quick reference

  • Correlation: $r \in [-1, 1]$
  • R-squared: $r^2$ = fraction of variance explained
  • Population variance: $\sigma^2 = \frac{1}{N}\sum_{i=1}^{N}(x_i-\mu)^2$
  • Sample variance: $s^2 = \frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar{x})^2$
  • Population std dev: $\sigma = \sqrt{\sigma^2}$
  • Sample std dev: $s = \sqrt{s^2}$
  • Absolute value: $|a| = a$ if $a \ge 0$, else $-a$