New: 6 free SQL practice datasets with 300+ questions — try the SQL Compiler →
Statistics

Correlation and Simple Linear Regression

Correlation and simple linear regression explained: Pearson versus Spearman, the least squares line, R-squared, and why correlation never proves causation.

Upskly AI Team October 5, 2026 7 min read
Correlation and Simple Linear Regression

Correlation and regression are two different questions that get asked about the same scatter of points: how strongly do two variables move together, and if one predicts the other, what does that relationship actually look like. This works through both, with one real eight-point dataset carried through correlation, the regression line, and R-squared.

In this guide

The Pearson correlation coefficient

A Pearson correlation coefficient measures the strength and direction of a linear relationship between two numeric variables, ranging from -1 to 1. A value of 1 means a perfect positive linear relationship, -1 a perfect negative one, and 0 means no linear relationship at all, though a non-linear one could still exist underneath it.

Worked example

For the pairs (1,2), (2,4), (3,5), (4,4), (5,5), (6,7), (7,8), (8,9), the Pearson correlation is 0.9512, a strong positive linear relationship.

Strength depends on distance from zero, not sign. Of -0.85, 0.3 and 0.6, the strongest relationship is -0.85, its distance from zero is the largest of the three, even though it is negative.

Spearman correlation

Spearman’s rank correlation measures a monotonic relationship, based on the ranks of the values rather than the raw values, so it can detect a consistently rising or falling pattern even when the relationship curves rather than forming a straight line. For the same eight pairs above, Spearman comes out to 0.9398, close to the Pearson value here since the relationship is already fairly linear.

Spearman is generally preferred over Pearson when the relationship is monotonic but not clearly linear, or when outliers might distort a Pearson calculation, since it works on ranks rather than raw values.

Correlation does not imply causation

A strong correlation never proves one variable causes the other. A strong statistical association can arise from genuine causation, a shared underlying cause, pure coincidence, or even reversed causation, and correlation alone cannot distinguish between them.

A shared underlying cause

Ice cream sales and shark attacks both rise in summer, producing a strong positive correlation between them. Neither causes the other, warmer weather independently drives more swimming (and so more shark encounters) and more ice cream sales.

Correlation is symmetric; regression is not

Correlation is symmetric: the formula treats both variables identically, so swapping which one is x and which is y never changes the result. A regression line is different, because it treats one variable as the one being predicted and the other as the predictor, regressing y on x and regressing x on y generally produce two different lines.

The regression line: slope, intercept and prediction

A regression line is the straight line that best fits the data, chosen by the least squares criterion: minimising the sum of the squared vertical distances between the data points and the line. Squaring the gaps keeps larger errors from cancelling out smaller ones in the opposite direction.

Fitting and using the regression line
TermMeaningValue (same 8-point dataset)
SlopeAverage change in y for every one-unit increase in x0.9048
InterceptPredicted y when x = 0 (may not be meaningful if x never reaches 0)1.4286
Prediction at x = 10slope x 10 + intercept10.48

Residuals

A residual is the difference between an actual observed y value and the value the regression line predicts for it. At x = 5, the line predicts about 5.95, but the actual y value is 5, giving a residual of -0.95, the actual point falls just below the line.

R-squared

R-squared is the proportion of the variation in y that is explained by its linear relationship with x. In a simple linear regression, R-squared is simply the Pearson correlation squared: 0.9512 squared gives an R-squared of 0.9048, meaning about 90 percent of y’s variation is explained by x.

A high R-squared does not guarantee the true relationship is linear. It only measures how well a straight line fits, not whether a straight line was the right model to begin with, which is why checking a scatter plot still matters.

Pitfalls: curves, outliers and extrapolation

Three ways correlation and regression can mislead
PitfallWhat happens
A U-shaped relationshipPearson correlation can come out close to 0 even though a clear, strong pattern exists, since the shape rises then falls, cancelling out in a measure built for one consistent direction
A single extreme outlier (small sample)Can shift correlation substantially, making a weak relationship look artificially strong, or vice versa
Extrapolating far beyond the data's x rangeThe relationship observed within the data's range is not guaranteed to continue holding outside of it

Common mistakes

  • Treating correlation as proof of causation. A strong correlation can arise from a shared cause, coincidence, or reversed causation just as easily.
  • Assuming a correlation near 0 means no relationship at all. It only rules out a straight-line relationship; a curved one could still be strong.
  • Judging correlation strength by sign instead of distance from zero. -0.85 is a stronger relationship than 0.6.
  • Assuming the regression line predicting y from x is the same as the one predicting x from y. They are generally different lines.
  • Extrapolating a fitted line far outside the range of the original data. The pattern inside the data’s range is not guaranteed to continue outside it.

Cheat sheet

Quick answers
QuestionAnswer
What does a Pearson correlation measure?Strength and direction of a linear relationship
What is the valid range for Pearson correlation?-1 to 1
What does Spearman correlation measure?A monotonic relationship, based on ranks
Does correlation prove causation?No, never on its own
Is correlation symmetric?Yes; regression generally is not
What does the least squares line minimise?Sum of squared vertical distances to the data
What does the regression slope represent?Average change in y per one-unit increase in x
What is a residual?Actual y minus the line's predicted y
What is R-squared, in simple linear regression?The Pearson correlation squared
Does a high R-squared prove the relationship is linear?No, it only measures straight-line fit

Try it yourself

Quick check

A dataset has pairs (10,21), (20,39), (30,62), (40,78), (50,101). Fitting a regression line gives a slope of 1.99 and an intercept of 0.50. What value does the line predict at x = 60 (1 dp)?

Show answer

119.9. Plugging x = 60 into the fitted line, 1.99 times 60 plus 0.50, gives a predicted y of 119.9.

Frequently asked questions

What does a correlation coefficient measure?

A correlation coefficient measures the strength and direction of a linear relationship between two numeric variables, ranging from -1 (perfect negative) to 1 (perfect positive).

What is the difference between Pearson and Spearman correlation?

Pearson measures a straight-line relationship using raw values. Spearman measures a monotonic relationship using ranks, which makes it better suited to curved-but-consistent patterns or data with outliers.

Does a strong correlation prove that one variable causes the other?

No. A strong correlation can arise from genuine causation, a shared underlying cause, pure coincidence, or reversed causation, and correlation alone cannot tell these apart.

What does the slope of a regression line represent?

The slope represents the average change in y for every one-unit increase in x, the core of what the regression line communicates.

What is R-squared?

R-squared is the proportion of the variation in y explained by its linear relationship with x. In a simple linear regression, it equals the Pearson correlation squared.

Why can a correlation near zero still hide a real relationship?

Correlation only detects straight-line patterns. A curved relationship, such as a U-shape, can produce a correlation close to zero even though a strong, real pattern exists.

Test yourself

Timed questions on Correlation and Simple Linear Regression, with an explanation for every answer.

Take the Quiz
Upskly AI Team
Learning made simple
Scroll to Top