Skip to content
11 min read

Understanding Correlation and Regression: A Practical Guide

Correlation and regression are two of the most widely used statistical techniques. Correlation measures the strength and direction of the linear relationship between two variables, while regression finds the best-fitting line to predict one variable from another. Together, they form the backbone of data analysis in science, business, economics, and social research.

This guide covers the Pearson correlation coefficient, interpreting correlation values, simple linear regression, the least squares method, coefficient of determination, and common pitfalls. We work through full numerical examples so you can apply these techniques with confidence.

What Is Correlation?

Correlation quantifies how closely two variables move together. The most common measure is the Pearson correlation coefficient rr, which ranges from −1-1 to +1+1.

  • r=+1r = +1: Perfect positive linear relationship (as one variable increases, so does the other)
  • r=−1r = -1: Perfect negative linear relationship (as one increases, the other decreases)
  • r=0r = 0: No linear relationship

The Pearson Correlation Formula

For paired data (x1,y1),(x2,y2),…,(xn,yn)(x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n):

r=n∑xiyi−∑xi∑yi[n∑xi2−(∑xi)2][n∑yi2−(∑yi)2]r = \frac{n\sum x_i y_i - \sum x_i \sum y_i}{\sqrt{[n\sum x_i^2 - (\sum x_i)^2][n\sum y_i^2 - (\sum y_i)^2]}}

This can also be written as:

r=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2∑(yi−yˉ)2r = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum (x_i - \bar{x})^2 \sum (y_i - \bar{y})^2}}

Example 1: Computing the Correlation Coefficient

Consider the following data on hours studied (xx) and exam score (yy):

Hours (xx)Score (yy)
255
462
570
778
1090

First, compute the needed sums (n=5n = 5):

∑x=28,∑y=355,∑xy=2,136,∑x2=194,∑y2=26,093\sum x = 28, \quad \sum y = 355, \quad \sum xy = 2{,}136, \quad \sum x^2 = 194, \quad \sum y^2 = 26{,}093

Now apply the formula:

r=5(2136)−(28)(355)[5(194)−784][5(26093)−126025]r = \frac{5(2136) - (28)(355)}{\sqrt{[5(194) - 784][5(26093) - 126025]}}
=10680−9940(970−784)(130465−126025)=740186×4440= \frac{10680 - 9940}{\sqrt{(970 - 784)(130465 - 126025)}} = \frac{740}{\sqrt{186 \times 4440}}
=740825,840=740908.76≈0.9814= \frac{740}{\sqrt{825{,}840}} = \frac{740}{908.76} \approx 0.9814

An rr value of 0.98 indicates a very strong positive linear relationship between hours studied and exam score.

Interpreting Correlation Values

While the exact thresholds vary by field, a common guideline is:

  • ∣r∣<0.3|r| < 0.3: Weak correlation
  • 0.3≤∣r∣<0.70.3 \leq |r| < 0.7: Moderate correlation
  • ∣r∣≥0.7|r| \geq 0.7: Strong correlation

Always remember: correlation does not imply causation. Two variables can be strongly correlated without one causing the other. A third variable (a confounding variable) might drive both, or the relationship might be coincidental.

Simple Linear Regression

While correlation measures the strength of a relationship, regression finds the equation of the line that best fits the data. The simple linear regression model is:

y^=a+bx\hat{y} = a + bx

where bb is the slope (how much yy changes per unit increase in xx) and aa is the y-intercept (the predicted value of yy when x=0x = 0).

The Least Squares Method

The “best fit” is defined as the line that minimises the sum of squared residuals (the vertical distances between data points and the line). The formulas for the slope and intercept are:

b=n∑xiyi−∑xi∑yin∑xi2−(∑xi)2b = \frac{n\sum x_i y_i - \sum x_i \sum y_i}{n\sum x_i^2 - (\sum x_i)^2}
a=yˉ−bxˉa = \bar{y} - b\bar{x}

Example 2: Finding the Regression Line

Using the same data from Example 1, find the regression equation.

The slope:

b=5(2136)−(28)(355)5(194)−(28)2=10680−9940970−784=740186≈3.978b = \frac{5(2136) - (28)(355)}{5(194) - (28)^2} = \frac{10680 - 9940}{970 - 784} = \frac{740}{186} \approx 3.978

The means: xˉ=285=5.6\bar{x} = \frac{28}{5} = 5.6 and yˉ=3555=71\bar{y} = \frac{355}{5} = 71.

The intercept:

a=71−3.978(5.6)=71−22.277=48.723a = 71 - 3.978(5.6) = 71 - 22.277 = 48.723

The regression equation is:

y^=48.72+3.98x\hat{y} = 48.72 + 3.98x

Interpretation: for each additional hour of study, the predicted exam score increases by about 3.98 points.

Example 3: Making Predictions

Using our regression equation, predict the exam score for a student who studies 6 hours.

y^=48.72+3.98(6)=48.72+23.88=72.6\hat{y} = 48.72 + 3.98(6) = 48.72 + 23.88 = 72.6

The predicted score is approximately 73. This is interpolation (within the range of our data), which is generally reliable. Extrapolating far beyond the data range (e.g. predicting for 50 hours) would be unreliable.

Coefficient of Determination (R-Squared)

The coefficient of determination, R2R^2, tells you what proportion of the variation in yy is explained by the linear relationship with xx.

R2=r2R^2 = r^2

For our example, R2=(0.9814)2=0.963R^2 = (0.9814)^2 = 0.963. This means about 96.3% of the variation in exam scores is explained by the number of hours studied. Only 3.7% is due to other factors.

An R2R^2 close to 1 indicates an excellent fit; close to 0 indicates the model explains very little of the variation.

Spearman Rank Correlation

The Pearson coefficient assumes a linear relationship. When the relationship is monotonic but not necessarily linear, or when the data contains outliers, the Spearman rank correlation rsr_s is more appropriate. It applies the Pearson formula to the ranked data:

rs=1−6∑di2n(n2−1)r_s = 1 - \frac{6\sum d_i^2}{n(n^2 - 1)}

where did_i is the difference between the ranks of each pair of observations. This formula assumes no tied ranks; when ties exist, use the general Pearson formula on the ranks.

Residual Analysis

A residual is the difference between the observed value and the predicted value: ei=yi−y^ie_i = y_i - \hat{y}_i. Examining residuals helps validate the regression model:

  • Residuals should be randomly scattered around zero.
  • If residuals show a pattern (e.g. a curve), the linear model may be inappropriate.
  • If residuals fan out (increase in spread), heteroscedasticity is present.
  • Large individual residuals may indicate outliers.

Common Mistakes

  • Assuming causation from correlation. A strong correlation between ice cream sales and drowning rates does not mean ice cream causes drowning. Both increase in summer.
  • Ignoring outliers. A single extreme point can dramatically change the correlation coefficient and regression line. Always plot your data.
  • Extrapolating beyond the data range. The regression line is only reliable within the range of observed xx values.
  • Using R2R^2 alone. A high R2R^2 does not guarantee the model is appropriate. Always check residual plots.
  • Confusing rr and R2R^2. An rr of 0.7 sounds strong, but R2=0.49R^2 = 0.49 means only 49% of the variation is explained.

Multiple Regression

Simple linear regression uses one predictor variable. In practice, outcomes are influenced by many factors. Multiple regression extends the model:

y^=a+b1x1+b2x2+⋯+bkxk\hat{y} = a + b_1 x_1 + b_2 x_2 + \cdots + b_k x_k

Each coefficient bib_i represents the effect of xix_i on yy, holding all other predictors constant. While the calculations become more complex (requiring matrix algebra), the underlying principle is the same: minimise the sum of squared residuals.

Try It Yourself

Compute correlation coefficients and explore relationships in your data with our free Correlation Calculator. Enter paired data values and get the Pearson correlation, regression equation, and R2R^2 value instantly. For related statistical analysis, explore our Standard Deviation Calculator and Probability Calculator.

Related Articles