mini-module ~20 min no-code try-without-ai statistics

Lies, Damned Lies, and Statistics

"There are three kinds of lies: lies, damned lies, and statistics.", Mark Twain

Mean

Take a set of numbers. Add them up. Divide by how many there are. That is the mean. It is the balancing point of the data, the value where everything would sit in equilibrium if placed on a seesaw.

Mean
$$\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i$$
Values (n)
,
Sum
,
Mean (μ)
,

A shop with daily revenues of 200, 400, 300, 500, 100 has a mean of 300. That number hides a lot. It says nothing about how irregular the days were. That is what variance is for.


Variance

Variance measures how spread out the data is around the mean. For each value, compute how far it sits from the mean, square that distance, and average the result. Squaring does two things: it makes all distances positive, and it punishes large deviations more than small ones.

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

Standard deviation \(\sigma\) is just the square root of variance. It brings the number back to the original unit, so you can read it as a typical distance from the mean.

Standard deviation
$$\sigma = \sqrt{\,\frac{1}{n} \sum_{i=1}^{n} (x_i - \bar{x})^2\,}$$
xi xi − μ (xi − μ)²
,
Mean (μ)
,
Variance (σ²)
,
Std dev (σ)
,

Two datasets can share the same mean and look nothing alike. Variance tells you whether the data clusters tightly or sprawls. Still, both mean and variance describe a single variable in isolation. When you have two variables, a third question appears.


Correlation

When one variable changes, does another tend to change with it? A lemonade stand that sells more on warm days has something going on between temperature and sales. A car that loses value as mileage increases has something going on between kilometres and price. The question is whether that something is consistent, and in what direction.

Start with covariance. For each observation, take the deviation of x from its mean and the deviation of y from its mean, multiply them together, and average the result.

Covariance
$$\text{Cov}(x, y) = \frac{1}{n} \sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})$$

When x and y are both above their means, the product is positive. When one is above and the other below, it is negative. Average those products: a positive result means they tend to move together, a negative result means they tend to move in opposite directions.

The problem with covariance is the unit. Multiply euros by kilograms and the number is hard to read. So divide by both standard deviations to normalise everything onto a fixed scale. That gives Pearson's r.

Pearson correlation
$$r = \frac{\text{Cov}(x, y)}{\sigma_x \cdot \sigma_y} = \frac{\displaystyle\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\displaystyle\sum_{i=1}^{n}(x_i - \bar{x})^2 \cdot \sum_{i=1}^{n}(y_i - \bar{y})^2}}$$

The result always sits between -1 and 1. At 1, a perfect positive linear relationship. At -1, a perfect negative one. At 0, no linear relationship. The word linear is doing real work in that sentence. A curved relationship, a cluster with one extreme outlier, a vertical spike of points: all of these can produce the same r while looking completely different from each other.

The numerator of r is the sum of products \((x_i - \bar{x})(y_i - \bar{y})\). If x tends to be above its mean when y is also above its mean, what sign will this sum have?

Anscombe's Quartet

In 1973, statistician Francis Anscombe built a trap. He constructed four datasets.

Calculate the following for each dataset below. Mean of x. Mean of y. Variance of x. Variance of y. Correlation r between x and y. Compare your results across all four.

For each dataset: compute mean(x), mean(y), var(x), var(y), and r(x, y). You should find that all four sets of results are nearly identical.
Dataset I
ixy
1108.04
286.95
3137.58
498.81
5118.33
6149.96
767.24
844.26
91210.84
1074.82
1155.68
Dataset II
ixy
1109.14
288.14
3138.74
498.77
5119.26
6148.10
766.13
843.10
9129.13
1077.26
1154.74
Dataset III
ixy
1107.46
286.77
31312.74
497.11
5117.81
6148.84
766.08
845.39
9128.15
1076.42
1155.73
Dataset IV
ixy
186.58
285.76
387.71
488.84
588.47
687.04
785.25
81912.50
985.56
1087.91
1186.89
You compute r for all four datasets and get approximately 0.816 each time. What does this tell you?

Now Look at Them

You have done the calculation. The four datasets produce the same numbers. Enter the password to see what the numbers are hiding.

🔒

Enter the password to reveal the plots.

His point was not subtle: a number is not a description. Before you report a statistic, you need to see what you are summarising. A correlation of 0.816 can describe a clean linear trend, a perfect curve, a linear relationship with one rogue point, or a vertical stack of values with a single outlier pulling the line. All four look nothing alike. All four produce r = 0.816.

Four datasets. The dashed line is the same regression line on every chart. The points are not.

Dataset I
Dataset II
Dataset III
Dataset IV

Before You Go

Think of a report, a presentation, or a dashboard you have seen. A number was shown. A correlation, a mean, a trend line. Was the raw data shown alongside it? What might a plot have revealed that the number did not?