A curved relationship with zero correlation

Start with five pairs lying on y = x. Every increase in x is matched by an increase in y, so Pearson's r is 1.

Replace y with x². The relationship is still exact, but upward and downward contributions cancel. Follow the centred products below to see why r becomes zero.

Follow the maths
Pearson correlation r...
Observations...

Look for the direction and closeness of a straight-line pattern

Each dot is one observation with an x value and a y value. An upward linear pattern gives positive r. A downward linear pattern gives negative r. Points closer to a straight line give r closer to +1 or −1.

Worked comparison

Follow the calculation

−1≤r≤1
What the symbols mean

r measures the direction and strength of a straight-line association. It has no units. It is undefined if either variable has no variation.

Assumptions and full calculation

The slider constructs points with the selected sample correlation. It does not draw a random sample from a population with that correlation. New pattern changes the points while keeping r fixed. Manual input calculates r from your paired observations. A value of zero means no linear association. A curved relationship may still exist. Outliers can change r substantially. Correlation alone cannot establish causation.

How is r calculated? Follow the vectors and their angle

This walkthrough follows the observations in the scatterplot. Start with a small example to see every number, then use the same steps with any data.

These buttons change the actual paired observations above. Reset restores the original example.

1 · Read each column as one vector

Each dot in the scatterplot has an x value and a y value. Read down the x column to make one ordered list, then do the same for y. Each list is a vector. We can represent it as an arrow with one component per observation. Keep the observations in the same order in both lists.

x=(x1,x2,…,xn),y=(y1,y2,…,yn)

Multiply matching components and add the products to get the dot product. The dot product depends on both vector lengths and the angle between them. The next steps remove the effects of the means and lengths to calculate Pearson's r.

The diagram below represents the two whole lists as arrows. Each arrow has one component per observation. Two arrows from the same origin fit in a shared plane. Drawing them in that plane preserves their angle, even when they have many components.

The two vectors in their shared plane

We turn the view so the first vector points right. This preserves lengths and the angle between the vectors. The axes here describe vector directions. The scatterplot axes describe measurements. We resize each view to fit, so use the printed lengths to compare steps.

Angle between the current vectors No angle is defined.
Step 1 of 4

This explanation was inspired by Brendan O'Connor's 2012 article, "Cosine similarity, Pearson correlation, and OLS coefficients".