Quantitative Analysis/ Correlation
Measuring association

How to measure how strongly two variables are related

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.

14 min read Correlation Beginner to Intermediate

01What is correlation?

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.

02How correlation is calculated

Pearson's r

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.

r = Σ (x - x-bar) × (y - y-bar) / √( Σ (x - x-bar)² × Σ (y - y-bar)² )

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

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:

rho = 1 - 6 × Σ d² / ( n × (n² - 1) )

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.

Testing whether a correlation is different from zero

A correlation in a sample could be a product of chance. The usual test converts r into a t statistic:

t = r × √(n - 2) / √(1 - r²) with n - 2 degrees of freedom

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.

A worked example

Eight people report their years of education and monthly income. One earns far more than the rest.

Eight people: years of education and monthly income, with ranks
PersonYears of education (x)Monthly income (y)Rank of xRank of y
Person 181,80011
Person 2102,1002.53
Person 3101,9002.52
Person 4122,6004.55
Person 5122,4004.54
Person 6143,10066
Person 7163,30077
Person 8189,00088

Pearson.

  1. Averages
    x-bar = 12.5 years and y-bar = 3,275.
  2. Sums of products and squares
    Σ(x - x-bar)(y - y-bar) = 45,100, Σ(x - x-bar)² = 78, and Σ(y - y-bar)² = 39,475,000.
  3. The coefficient
    r = 45,100 ÷ √(78 × 39,475,000) = 45,100 ÷ 55,489 = 0.813.
  4. Significance
    t = 0.813 × √6 ÷ √(1 - 0.661) = 3.42 with 6 degrees of freedom, and the p-value is 0.0142, significant at the 5% level.

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.

03Pearson or Spearman?

Pearson compared with Spearman
FeaturePearson's rSpearman's rho
Works withThe actual valuesThe ranks of the values
DetectsStraight-line relationshipsAny steadily rising or falling relationship, whether straight or curved
VariablesNumeric, such as income, age, or a scale totalNumeric, or ordinal such as Likert items and income groups
OutliersStrongly affectedMuch less affected
Typical useTwo measured quantities that relate in a roughly straight lineRatings, 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.

04Zero correlation does not mean no relationship

A coefficient near zero does not mean the variables are unrelated. It means there is no straight-line pattern, for Pearson, or no steadily rising or falling pattern, for Spearman. A strong relationship that curves, rises then falls, or differs between subgroups can produce a correlation of about zero.
Figure 1. A strong curved relationship with a correlation of about zeroScatter plot of points forming a U shape. A flat line shows the best straight-line fit, and the correlation coefficients are near zero.0369-3-2-10123Best straight line is flatTrue pattern: y rises with x squaredPearson r = -0.01, Spearman rho = -0.01Variable XVariable Y
Figure 1. A strong curved relationship with a correlation of about zero

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.

05Reading the coefficient

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%.

06How to run it in AnalyZ Solutions

Open Inferential Analysis, choose Correlation, then choose Pearson Correlation or Spearman Correlation.

  1. Select the variables
    Pick two or more variables. With more than two, you get a full correlation matrix in one run. Pearson needs numeric variables. Spearman also accepts ordinal and coded categorical variables, so it is the right choice for Likert items.
  2. Choose display options
    Tick significance stars to mark significant pairs, lower triangle to show each pair once, and colour heatmap to shade cells by strength. The heatmap runs from orange for negative coefficients through white at zero to green for positive ones, and deeper colour means a stronger relationship.
  3. Apply a subsample filter if needed
    For example, to check whether relationships hold within one region.
  4. Click Run
    The output shows the matrix and a plain-language interpretation that counts how many pairs are significant and names the strongest ones. You can download the matrix as an image, export it, or add it to a Data Canvas.

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.

Start with fewer variables. A matrix of 20 variables has 190 pairs, and around 10 of them will look significant at the 5% level by chance alone. Choose variables that your research question makes relevant, and give the strong relationships more attention than the borderline ones.

07Interpreting the result

The figures below are invented to show the steps. Stars mark significance: * below 0.05, below 0.01, * below 0.001.

Example 1: Pearson correlation of five numeric variables

Suppose you have years of education, monthly income, age, weekly hours worked, and a job satisfaction score for 250 adults.

Pearson correlation matrix (lower triangle, n = 250)
EducationIncomeAgeHours workedJob satisfaction
Education1
Income0.56***1
Age0.120.26***1
Hours worked-0.020.12-0.38***1
Job satisfaction0.42***0.44***0.11-0.20**1
Figure 2. Pearson correlation heatmap (n = 250)Lower-triangle correlation matrix drawn as a heatmap. Green cells are positive correlations, orange cells are negative, and deeper colour means a stronger correlation.EducationIncomeAgeHoursworkedJobsatisfactionEducation1Income0.56***1Age0.120.26***1Hours worked-0.020.12-0.38***1Job satisfaction0.42***0.44***0.11-0.20**1-1-0.500.51Correlation coefficient
Figure 2. Pearson correlation heatmap (n = 250)

Reading it step by step

  1. Look for the darkest cells
    Education and income have r = 0.56 with three stars, a strong positive relationship. Income and job satisfaction (r = 0.44) and education and job satisfaction (r = 0.42) are moderate and positive.
  2. Look for orange cells
    Age and hours worked have r = -0.38, a moderate negative relationship, so older people in this sample work fewer hours. Hours worked and job satisfaction have r = -0.20, a weak negative relationship with two stars.
  3. Notice the pale and unstarred cells
    Education and hours worked have r = -0.02, essentially nothing. Education and age (r = 0.12) and age and job satisfaction (r = 0.11) carry no stars, so they could easily be chance. Plot any of these before concluding that nothing is going on.
  4. Check the sign against the coding
    A negative coefficient for hours worked is a statement about those two variables as scored, so read each against how it is coded.

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.

Example 2: Spearman correlation of five survey ratings

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.

Spearman correlation matrix (lower triangle, n = 300)
Income groupService qualityTrustEase of useWould recommend
Income group1
Service quality0.40***1
Trust0.37***0.41***1
Ease of use0.18**0.21***0.30***1
Would recommend0.15*0.15**0.19**0.21***1
Figure 3. Spearman correlation heatmap (n = 300)Lower-triangle Spearman correlation matrix drawn as a heatmap.IncomegroupServicequalityTrustEase of useWouldrecommendIncome group1Service quality0.40***1Trust0.37***0.41***1Ease of use0.18**0.21***0.30***1Would recommend0.15*0.15**0.19**0.21***1-1-0.500.51Correlation coefficient
Figure 3. Spearman correlation heatmap (n = 300)

Reading it step by step

  1. Check the coding
    Every variable runs from low to high, so a positive coefficient means higher goes with higher.
  2. Find the strongest pairs
    Service quality and trust (rho = 0.41), income group and service quality (rho = 0.40), and income group and trust (rho = 0.37) are moderate and positive, all at the 0.1% level.
  3. Read the weak ones as weak
    Would recommend correlates only weakly with the other four (rho between 0.15 and 0.21). With 300 respondents even these are significant, but they describe small patterns.
  4. Remember what rho means
    It reflects how well the ordering of one rating matches the ordering of another. It does not say that a one-step rise in income group raises trust by a fixed amount.

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.

08Common mistakes

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.

Frequently Asked Questions
Should I use Pearson or Spearman?
If both variables are numeric, roughly bell-shaped, and the relationship looks straight, Pearson is fine. 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 points to outliers or a curved relationship.
What is a good correlation?
There is no universal answer. In social research, values around 0.1 are weak, around 0.3 moderate, and around 0.5 strong. What counts as meaningful depends on your field and on what the relationship is being used for.
Why is my correlation not significant even though it looks sizable?
In small samples, even moderate correlations can fail to reach significance because the estimate is imprecise. Look at the sample size, and report the coefficient together with the fact that the evidence is inconclusive.
Can I use Pearson correlation with a Likert item?
A single Likert item is ordinal, so Spearman is more appropriate. For a scale total built from several items, Pearson is generally acceptable.
What if the relationship is curved?
Pearson only detects straight-line patterns. Spearman can capture a curve if it rises or falls consistently. A pattern that rises and then falls, such as a U shape, defeats both, so plot the data and consider a regression with a squared term or a different summary.
Does a correlation matrix correct for the number of pairs?
No. Each pair is tested separately at the 5% level, so with many variables some pairs will look significant by chance. Prioritise strong correlations and those that fit a prior expectation.
Can I compare correlations across groups?
Yes. Use the subsample filter to run the same matrix for each group and compare the coefficients. Differences between groups need care, since small subsamples produce unstable coefficients.

Explore relationships in your data

Open Correlation in AnalyZ Solutions. Free to sign up, free to analyze.

Get started
Related Guides