Skip to content

Correlation and linear regression

Bivariate data contain two measurements for each individual or object. If xx is a person’s height and yy is their arm span, each person supplies one pair (x,y)(x,y). We use correlation to describe the strength and direction of an association, and regression to model one variable in terms of the other.

These ideas answer different questions:

  • correlation asks how closely the points follow a straight line;
  • regression asks which straight line should be used to estimate one variable from the other.

Neither, by itself, establishes that one variable causes the other.

You should be able to:

  • plot coordinates and interpret the gradient and intercept of y=a+bxy=a+bx;
  • calculate means and standard deviations;
  • use summation notation and calculator statistics modes;
  • distinguish a population from a sample.

Review averages and measures of spread if ar x, variance or standard deviation are unfamiliar.

A scatter diagram plots one point for each paired observation. The variable thought to explain or predict is usually placed on the horizontal axis and called the explanatory variable. The variable being predicted is placed on the vertical axis and called the response variable.

Look for four features:

  1. Direction: positive, negative or no apparent association.
  2. Form: linear, curved, clustered or another pattern.
  3. Strength: how tightly the points follow the form.
  4. Unusual observations: outliers or influential points.

In positive correlation, larger xx values tend to occur with larger yy values. In negative correlation, larger xx values tend to occur with smaller yy values. A strong curved relationship can have weak linear correlation, so always inspect the scatter diagram before relying on one calculated number.

A sample shows a negative association between the age of a used car and its selling price.

A careful conclusion is:

Older cars in this sample tended to have lower selling prices.

This describes association, direction and context. It does not claim that age is the only cause. Mileage, condition and model may also affect price.

If one point represents a very old but unusually expensive classic car, it may be an outlier. Removing it merely to strengthen the pattern would be unjustified. Investigate whether it is an error, a member of a different population, or a genuine observation.

Pearson’s product moment correlation coefficient

Section titled “Pearson’s product moment correlation coefficient”

Pearson’s product moment correlation coefficient, usually written rr, measures the strength and direction of linear association in a sample.

1r1\boxed{-1\leq r\leq 1}

Its interpretation is:

Value of rrLinear association
close to 11strong positive
close to 00weak or no linear association
close to 1-1strong negative
exactly 11 or 1-1perfect linear association

There are no universal boundaries at which correlation suddenly becomes “strong”. Context and sample size matter. An rr of 0.70.7 may be impressive for noisy biological data but disappointing for repeated measurements from calibrated equipment.

Define the corrected sums of squares and products by

Sxx=(xxˉ)2=x2(x)2n,Syy=(yyˉ)2=y2(y)2n,Sxy=(xxˉ)(yyˉ)=xy(x)(y)n.\begin{aligned} S_{xx}&=\sum(x-\bar x)^2 =\sum x^2-\frac{(\sum x)^2}{n},\\ S_{yy}&=\sum(y-\bar y)^2 =\sum y^2-\frac{(\sum y)^2}{n},\\ S_{xy}&=\sum(x-\bar x)(y-\bar y) =\sum xy-\frac{(\sum x)(\sum y)}{n}. \end{aligned}

Then

r=SxySxxSyy.\boxed{r=\frac{S_{xy}}{\sqrt{S_{xx}S_{yy}}}}.

The denominator is positive, so the sign of rr is the sign of SxyS_{xy}. The division standardises the result, making rr dimensionless and unaffected by the units used.

For a point with x>xˉx>\bar x and y>yˉy>\bar y, both deviations are positive, so their product is positive. A point with both values below their means also gives a positive product. These points support positive association.

If one value is above its mean and the other below, the product is negative. Such points support negative association. Adding the products gives SxyS_{xy}; standardising gives a value between 1-1 and 11.

For five students, xx is the number of hours revised and yy is a test score.

xx1122334455
yy52525555616164646868

The required totals are

x=15,y=300,x2=55,\sum x=15,\quad \sum y=300,\quad \sum x^2=55, y2=18130,xy=938,n=5.\sum y^2=18130,\quad \sum xy=938,\quad n=5.

Therefore

Sxx=551525=10,S_{xx}=55-\frac{15^2}{5}=10, Syy=1813030025=130,S_{yy}=18130-\frac{300^2}{5}=130,

and

Sxy=93815(300)5=38.S_{xy}=938-\frac{15(300)}5=38.

Hence

r=3810×130=1.053r=\frac{38}{\sqrt{10\times130}}=1.053\ldots

This is impossible, since rr cannot exceed 11. The contradiction exposes an arithmetic error: the correct value is

xy=1(52)+2(55)+3(61)+4(64)+5(68)=941.\sum xy=1(52)+2(55)+3(61)+4(64)+5(68)=941.

Thus Sxy=41S_{xy}=41 and

r=411300=1.137r=\frac{41}{\sqrt{1300}}=1.137\ldots

That is still impossible, revealing that y2\sum y^2 must also be checked. In fact,

y2=522+552+612+642+682=18170.\sum y^2=52^2+55^2+61^2+64^2+68^2=18170.

Now Syy=170S_{yy}=170, so

r=4110×170=0.994 to 3 s.f.\boxed{r=\frac{41}{\sqrt{10\times170}}=0.994\text{ to 3 s.f.}}

There is a very strong positive linear association between revision time and score in this sample. The deliberate checks illustrate an important safeguard: r>1|r|>1 always signals an input or arithmetic error.

What can you conclude if r=0r=0?

Answer

There is no measured linear association. You cannot conclude that the variables are unrelated. For example, points lying exactly on y=x2y=x^2 and arranged symmetrically about x=0x=0 can have r=0r=0 despite a perfect curved relationship.

The regression line of yy on xx predicts yy from a given value of xx. Write it as

y=a+bx,\boxed{y=a+bx},

where

b=SxySxxanda=yˉbxˉ.\boxed{b=\frac{S_{xy}}{S_{xx}}} \qquad\text{and}\qquad \boxed{a=\bar y-b\bar x}.

The gradient bb is the predicted change in yy for a one unit increase in xx. Its units are “units of yy per unit of xx”. The intercept aa is the predicted yy when x=0x=0, but it may have no practical meaning if x=0x=0 is outside the observed range.

The line always passes through the mean point (xˉ,yˉ)(\bar x,\bar y) because

yˉ=a+bxˉ.\bar y=a+b\bar x.

For an observed point (xi,yi)(x_i,y_i), the fitted value is

y^i=a+bxi.\hat y_i=a+bx_i.

The vertical residual is

ei=yiy^i.e_i=y_i-\hat y_i.

The least squares line chooses aa and bb to minimise

ei2=(yiabxi)2.\sum e_i^2=\sum\left(y_i-a-bx_i\right)^2.

Residuals are squared so that positive and negative errors cannot cancel. A positive residual means the observed value lies above the line; a negative residual means it lies below.

Worked example 3: finding and interpreting a regression line

Section titled “Worked example 3: finding and interpreting a regression line”

Return to the revision data. We found

Sxx=10,Sxy=41,S_{xx}=10,\qquad S_{xy}=41,

and the means are

xˉ=3,qquadyˉ=60.\bar x=3,qquad \bar y=60.

So

b=4110=4.1b=\frac{41}{10}=4.1

and

a=604.1(3)=47.7.a=60-4.1(3)=47.7.

The regression line of score on revision time is

y^=47.7+4.1x.\boxed{\hat y=47.7+4.1x}.

The gradient predicts an increase of 4.14.1 marks for each additional hour of revision. This is an association based on the fitted model, not proof that forcing every student to revise one more hour will raise their score by exactly 4.14.1.

For x=3.5x=3.5 hours,

y^=47.7+4.1(3.5)=62.05.\hat y=47.7+4.1(3.5)=62.05.

The predicted score is about 6262 marks. This is an interpolation because 3.53.5 lies within the observed range 1x51\leq x\leq5.

For the student who revised for 44 hours, the fitted score is

y^=47.7+4.1(4)=64.1.\hat y=47.7+4.1(4)=64.1.

The observed score was 6464, so the residual is

e=6464.1=0.1.e=64-64.1=-0.1.

The model overestimates this score by 0.10.1 marks.

The regression line of yy on xx minimises vertical squared residuals and predicts yy from xx. If the task is instead to predict xx from yy, use the regression line of xx on yy:

x=c+dy,d=SxySyy,c=xˉdyˉ.x=c+dy, \qquad d=\frac{S_{xy}}{S_{yy}}, \qquad c=\bar x-d\bar y.

These are generally different lines. Do not find yy on xx and rearrange it to predict xx. Rearranging preserves the same geometric line, but it does not change which squared residuals were minimised.

Worked example 4: regression in the other direction

Section titled “Worked example 4: regression in the other direction”

For the revision data,

d=SxySyy=41170=0.241176d=\frac{S_{xy}}{S_{yy}}=\frac{41}{170}=0.241176\ldots

and

c=3d(60)=11.4705.c=3-d(60)=-11.4705\ldots.

Thus the regression line of revision time on score is

x^=11.4705+0.241176y.\boxed{\hat x=-11.4705+0.241176y}.

To estimate revision time for a score of 6363,

x^=11.4705+0.241176(63)=3.72 hours.\hat x=-11.4705+0.241176(63)=3.72\text{ hours}.

The yy on xx line would give x=(6347.7)/4.1=3.73x=(63-47.7)/4.1=3.73 hours. The answers happen to be close because the correlation is almost perfect, but only xx on yy is appropriate for predicting xx.

Both regression lines pass through (xˉ,yˉ)(\bar x,\bar y). Their gradients also satisfy

(SxySxx)(SxySyy)=r2.\left(\frac{S_{xy}}{S_{xx}}\right) \left(\frac{S_{xy}}{S_{yy}}\right)=r^2.

For a data set, xˉ=8\bar x=8, yˉ=21\bar y=21, Sxx=40S_{xx}=40 and Sxy=30S_{xy}=-30. Find the regression line of yy on xx and estimate yy when x=10x=10.

Answer b=3040=0.75,b=\frac{-30}{40}=-0.75, a=21(0.75)(8)=27.a=21-(-0.75)(8)=27.

Therefore

y^=270.75x.\hat y=27-0.75x.

When x=10x=10,

y^=270.75(10)=19.5.\hat y=27-0.75(10)=19.5.

Interpolation predicts within the range of observed explanatory values. Extrapolation predicts beyond that range.

Interpolation is usually safer because it uses the model where data have actually been observed. Extrapolation assumes the same linear pattern continues into an unobserved region, which may be unrealistic.

Worked example 5: spotting an unsafe prediction

Section titled “Worked example 5: spotting an unsafe prediction”

Suppose tree height was measured for ages from 22 to 1212 years and the fitted model is

h^=0.8+0.55t,\hat h=0.8+0.55t,

where tt is age in years and hh is height in metres.

At t=8t=8,

h^=0.8+0.55(8)=5.2 m.\hat h=0.8+0.55(8)=5.2\text{ m}.

This is interpolation and may be reasonable if the scatter diagram supports a linear model.

At t=80t=80, the model predicts 44.844.8 m. This is extreme extrapolation. Tree growth does not remain linear for a lifetime, so the numerical calculation is valid but the prediction is not credible.

Even interpolation deserves caution when there is an outlier, a curved pattern, changing variability, or a sample that is not representative of the target population.

Adding a constant to every value, or multiplying every value by a positive constant, does not change rr. Changing centimetres to metres therefore leaves correlation unchanged. Multiplying one variable by a negative constant reverses the sign of rr.

The regression coefficients do change with units. If xx changes from metres to centimetres, a gradient measured per metre must be rescaled to a gradient per centimetre.

A curved relationship can sometimes be transformed into a linear one. For example, if

y=Abx,y=Ab^x,

then

lny=lnA+xlnb.\ln y=\ln A+x\ln b.

Correlation and regression may be applied to (x,lny)(x,\ln y), not blindly to (x,y)(x,y). Learn more in linearising data.

  • “A high rr proves causation.” It shows strong linear association in the data, not a causal mechanism.
  • “An rr near zero means no relationship.” It means little linear association; a curved relationship may remain.
  • “The regression line can be used both ways.” Use yy on xx to predict yy, and xx on yy to predict xx.
  • “A precise calculator answer is an accurate prediction.” Model suitability and data range matter more than displayed decimal places.
  • “An outlier should always be removed.” Remove data only for a defensible reason, such as a confirmed recording error or an explicitly different population.
  • “The intercept must have a real interpretation.” It is algebraically necessary but may correspond to an impossible or unobserved input.

A study of six machines gives xˉ=12\bar x=12, yˉ=38\bar y=38, Sxx=50S_{xx}=50, Syy=200S_{yy}=200 and Sxy=80S_{xy}=-80, where xx is machine age in years and yy is output in units per hour.

  1. Calculate rr and interpret it.
  2. Find the regression line of yy on xx.
  3. Estimate output for a machine aged 1010 years.
  4. Explain one reason why predicting output at age 3030 years may be unreliable if observed ages were between 44 and 1616 years.
Answers
r=8050×200=0.8.r=\frac{-80}{\sqrt{50\times200}}=-0.8.

There is a strong negative linear association between machine age and output in this sample.

  1. The gradient is
b=8050=1.6,b=\frac{-80}{50}=-1.6,

so

a=38(1.6)(12)=57.2.a=38-(-1.6)(12)=57.2.

The line is

y^=57.21.6x.\hat y=57.2-1.6x.
  1. At x=10x=10,
y^=57.21.6(10)=41.2\hat y=57.2-1.6(10)=41.2

units per hour.

  1. An age of 3030 lies far beyond the observed range, so this is extrapolation. The linear trend may not continue that far. The machine might fail, be repaired or be replaced before then.

Before finishing a correlation or regression question, check that you have:

  • used paired observations in the correct rows;
  • confirmed that 1r1-1\leq r\leq1;
  • described association in context without claiming causation;
  • selected the regression direction that matches the variable being predicted;
  • interpreted the gradient with units and context;
  • substituted into the unrounded regression equation;
  • considered the observed range before accepting a prediction.

Correlation strength can be judged formally using a hypothesis test. Continue to hypothesis tests for correlation. For broader issues about samples and conclusions, review populations, samples and sampling. For data quality and influential observations, see outliers and cleaning data.