Correlation measures how strongly two variables move together. This guide covers Pearson and Spearman correlation: how each is calculated, which to choose, why a coefficient near zero does not mean no relationship, how to read a correlation matrix and heatmap, and how to run it in AnalyZ Solutions.
A correlation coefficient answers a simple question: when one variable goes up, what tends to happen to the other? Do people with more years of education also report higher income? Do shops with more staff have shorter queues? Does satisfaction with a service rise with income group? The coefficient condenses the answer into one number between -1 and +1. To predict one variable from another, see linear regression.
A value near +1 means the two variables rise together almost in lockstep. A value near -1 means one rises as the other falls. A value near 0 means there is no consistent pattern of that kind. The sign gives the direction and the distance from zero gives the strength.
Two coefficients are in common use. Pearson's r measures how closely the points follow a straight line and works with the actual values. Spearman's rho measures how consistently one variable rises or falls with the other, and it works with ranks. Both are available in AnalyZ Solutions, and both can be run for many variables at once to give a correlation matrix.
Pearson's r starts from the distance of each value from its own average. When a person is above average on both variables, or below average on both, the product of the two distances is positive. When they are on opposite sides, the product is negative. Adding the products up and rescaling them gives a number that always falls between -1 and +1.
Here x-bar and y-bar are the averages of x and y, and Σ means add up over all cases. The top of the fraction measures how the two variables vary together. The bottom rescales it by how much each varies alone, which is what keeps r between -1 and +1 and makes it free of the units of measurement.
Spearman's rho replaces each value with its rank, so the smallest value becomes 1, the next 2, and so on, with tied values sharing the average of the ranks they occupy. It then calculates Pearson's r on the ranks. When there are no ties, a shortcut gives the same answer:
where d is the difference between the two ranks of each case and n is the number of cases. Because only the order matters, one extreme value counts as just the highest rank, however large it is.
A correlation in a sample could be a product of chance. The usual test converts r into a t statistic:
The significance level then comes from the t curve. With many cases, even a very small correlation becomes significant, so the size of r matters more than its significance.
Eight people report their years of education and monthly income. One earns far more than the rest.
| Person | Years of education (x) | Monthly income (y) | Rank of x | Rank of y |
|---|---|---|---|---|
| Person 1 | 8 | 1,800 | 1 | 1 |
| Person 2 | 10 | 2,100 | 2.5 | 3 |
| Person 3 | 10 | 1,900 | 2.5 | 2 |
| Person 4 | 12 | 2,600 | 4.5 | 5 |
| Person 5 | 12 | 2,400 | 4.5 | 4 |
| Person 6 | 14 | 3,100 | 6 | 6 |
| Person 7 | 16 | 3,300 | 7 | 7 |
| Person 8 | 18 | 9,000 | 8 | 8 |
Pearson.
Spearman. Using the ranks in the table, with ties given their average rank, the Pearson correlation of the two rank columns is rho = 0.988.
The two answers differ because of one extreme income. The person earning 9,000 pulls the straight-line fit away from the other seven, and Pearson's r falls to 0.81. Without that person it would be 0.97. Spearman's rho stays at 0.99, because that income is simply the highest rank, and the order of the other values hardly changes. When the two coefficients differ a lot, look for outliers or a curved relationship.
| Feature | Pearson's r | Spearman's rho |
|---|---|---|
| Works with | The actual values | The ranks of the values |
| Detects | Straight-line relationships | Any steadily rising or falling relationship, whether straight or curved |
| Variables | Numeric, such as income, age, or a scale total | Numeric, or ordinal such as Likert items and income groups |
| Outliers | Strongly affected | Much less affected |
| Typical use | Two measured quantities that relate in a roughly straight line | Ratings, skewed variables, and small samples |
If both variables are numeric, roughly bell-shaped, and the relationship looks like a straight line, Pearson is slightly more efficient. If either variable is ordinal, skewed, or has outliers, use Spearman. When in doubt, run both. Similar answers give you confidence, and a large gap is a reason to look at the data more closely. Exploring your data first helps you spot outliers and skew, and choosing the right chart type shows how to plot the relationship.
In the figure, Y is almost completely determined by X, yet both coefficients are about zero, because the left half of the pattern falls and the right half rises and the two cancel out. Real examples are common. The chance of an accident is high for young and old drivers and lower in between. Energy use is high in very cold and very hot weather. Performance often rises with anxiety up to a point and then drops.
The remedy is simple: look at the data. Plot the two variables against each other before relying on a coefficient, and treat the coefficient as a summary of one kind of pattern and never as a verdict on whether any relationship exists.
Strength. AnalyZ Solutions describes the absolute value of the coefficient using these bands: under 0.1 negligible, 0.1 to 0.3 weak, 0.3 to 0.5 moderate, 0.5 to 0.7 strong, and above 0.7 very strong. These are guidelines. What counts as meaningful depends on the field.
Direction. A positive sign means the variables move in the same direction, and a negative sign means opposite directions. Check how each variable is scored first. If a satisfaction scale runs from 1 for very satisfied to 5 for very dissatisfied, a positive correlation with income means higher income goes with more dissatisfaction.
Significance. The significance level tells you whether the correlation can be told apart from zero given the sample size. A significant weak correlation is a real but small pattern, so do not describe it as an important relationship.
Shared variation. Squaring r gives the share of variation the two variables have in common. An r of 0.5 means they share 25% of their variation, and an r of 0.3 means they share only 9%.
Open Inferential Analysis, choose Correlation, then choose Pearson Correlation or Spearman Correlation.
Cases with a missing value on any selected variable are left out of the whole matrix, so adding a variable with many missing values shrinks the sample for every pair.
The figures below are invented to show the steps. Stars mark significance: * below 0.05, below 0.01, * below 0.001.
Suppose you have years of education, monthly income, age, weekly hours worked, and a job satisfaction score for 250 adults.
| Education | Income | Age | Hours worked | Job satisfaction | |
|---|---|---|---|---|---|
| Education | 1 | ||||
| Income | 0.56*** | 1 | |||
| Age | 0.12 | 0.26*** | 1 | ||
| Hours worked | -0.02 | 0.12 | -0.38*** | 1 | |
| Job satisfaction | 0.42*** | 0.44*** | 0.11 | -0.20** | 1 |
In plain words. Education, income and job satisfaction go together, and older people tend to work fewer hours. Longer hours are weakly linked to lower satisfaction. Several other pairs show no clear link. These are associations, and they do not show that education raises income or that long hours cause dissatisfaction.
Suppose 300 respondents gave an income group (1 to 5) and ratings from 1 to 5 for service quality, trust, ease of use, and whether they would recommend the service.
| Income group | Service quality | Trust | Ease of use | Would recommend | |
|---|---|---|---|---|---|
| Income group | 1 | ||||
| Service quality | 0.40*** | 1 | |||
| Trust | 0.37*** | 0.41*** | 1 | ||
| Ease of use | 0.18** | 0.21*** | 0.30*** | 1 | |
| Would recommend | 0.15* | 0.15** | 0.19** | 0.21*** | 1 |
In plain words. Every pair of ratings is positively related. People in higher income groups tend to rate the service higher and to trust it more, and perceived quality and trust move together most closely. Intention to recommend is linked to the other measures, but only loosely.
Reading a coefficient of zero as no relationship. It rules out only one kind of pattern. Plot the data.
Correlating coded categories. Region or occupation codes have no numeric order, so a correlation is meaningless.
Ignoring outliers. One extreme case can create or hide a Pearson correlation. Compare it with Spearman.
Restricting the range. Correlations shrink when you study only a narrow slice of a variable, such as only high earners.
Reading a correlation as causation. A third factor, reverse causation, or coincidence can produce the same pattern.
Reading a correlation as agreement. Two raters can be perfectly correlated while one consistently scores higher. Agreement needs a different measure.
Treating a significant weak correlation as important. Check the size, and square it to see how little variation it explains.
Open Correlation in AnalyZ Solutions. Free to sign up, free to analyze.
Get started