Probability & Statistics · Unit 2 · Topic 08

Regression lines: from a relationship to a prediction.

Short answer

The line of \(y\) on \(x\) is \(y - \bar y = b_{yx}(x - \bar x)\) with \(b_{yx} = r\dfrac{\sigma_y}{\sigma_x}\); the line of \(x\) on \(y\) swaps the roles. Both pass through \((\bar x, \bar y)\), and \(r^2 = b_{yx}\, b_{xy}\).

Example: \(b_{yx} = 0.8\), \(b_{xy} = 0.45\) gives \(r = \sqrt{0.36} = 0.6\).

Engineering MathsBScStatistics
01

Two lines of best fit

Before you start: you need correlation, especially Karl Pearson's \(r\).

Correlation tells you how strongly \(x\) and \(y\) are related. Regression goes one step further and gives an equation, so you can predict one variable from the other: the sales you can expect for a given advertising budget, or the physics mark that usually goes with a given maths mark.

The regression line of \(y\) on \(x\) is the straight line that makes the sum of squared vertical distances \(\sum (y - \hat y)^2\) as small as possible. Use it to estimate \(y\) when \(x\) is known. Swap the roles and you get the regression line of \(x\) on \(y\), which minimises horizontal distances and is used to estimate \(x\) from \(y\). Unless the points lie exactly on a line, these are two different lines.

Regression lines

\(y\) on \(x\): \[y - \bar y = b_{yx}(x - \bar x), \qquad b_{yx} = r\,\frac{\sigma_y}{\sigma_x} = \frac{\operatorname{Cov}(x, y)}{\sigma_x^2}\]

\(x\) on \(y\): \[x - \bar x = b_{xy}(y - \bar y), \qquad b_{xy} = r\,\frac{\sigma_x}{\sigma_y} = \frac{\operatorname{Cov}(x, y)}{\sigma_y^2}\]

From raw sums

\[b_{yx} = \frac{n\sum xy - \sum x\sum y}{n\sum x^2 - \left(\sum x\right)^2}, \qquad b_{xy} = \frac{n\sum xy - \sum x\sum y}{n\sum y^2 - \left(\sum y\right)^2}\]

With deviations \(X = x - \bar x\) and \(Y = y - \bar y\), these become \(b_{yx} = \dfrac{\sum XY}{\sum X^2}\) and \(b_{xy} = \dfrac{\sum XY}{\sum Y^2}\).

02

Properties of the regression coefficients

Facts you will use

\(r^2 = b_{yx}\cdot b_{xy}\), so \(r = \pm\sqrt{b_{yx}\, b_{xy}}\).

\(r\), \(b_{yx}\) and \(b_{xy}\) all have the same sign. Take the sign of \(r\) from the coefficients.

\(b_{yx}\cdot b_{xy} \le 1\), so if one coefficient is more than 1 in size, the other must be less than 1.

Both lines pass through \((\bar x, \bar y)\), so solving the two equations gives the means.

  • The coefficients are independent of change of origin but not of scale. If \(u = \dfrac{x - a}{h}\) and \(v = \dfrac{y - b}{k}\), then \(b_{yx} = \dfrac{k}{h}\,b_{vu}\) and \(b_{xy} = \dfrac{h}{k}\,b_{uv}\).
  • If \(r = \pm 1\), the two lines coincide. If \(r = 0\), they are \(y = \bar y\) and \(x = \bar x\), which are perpendicular.

Which given line is which?

  1. Make a guess. Take the first equation as \(y\) on \(x\) (write it as \(y = \dots\)) and the second as \(x\) on \(y\) (write it as \(x = \dots\)).
  2. Read off \(b_{yx}\) and \(b_{xy}\) as the coefficients of \(x\) and \(y\).
  3. Test: if \(b_{yx}\, b_{xy} \le 1\) (and both have the same sign), the guess is right. If the product is more than 1, swap the roles.
03

Solved examples

Example 1: Both lines from data

Easy

For \(x\): 1, 2, 3, 4, 5 and \(y\): 2, 4, 5, 4, 5, find both regression lines and estimate \(y\) when \(x = 6\).

  1. \(\bar x = 3\), \(\bar y = 4\). From the deviations: \(\sum XY = 6\), \(\sum X^2 = 10\), \(\sum Y^2 = 6\).
  2. \(b_{yx} = \dfrac{6}{10} = 0.6\). Line: \(y - 4 = 0.6(x - 3)\), so \(y = 0.6x + 2.2\).
  3. \(b_{xy} = \dfrac{6}{6} = 1\). Line: \(x - 3 = 1(y - 4)\), so \(x = y - 1\).
  4. Estimate with the \(y\) on \(x\) line: \(y = 0.6(6) + 2.2 = 5.8\). Check: \(r^2 = 0.6 \times 1 = 0.6\), so \(r \approx 0.7746\), the same as by Pearson's formula.

Answer\(y = 0.6x + 2.2\), \(x = y - 1\); \(y \approx 5.8\) at \(x = 6\)

Example 2: Raw sums and prediction

Medium

Advertising spend \(x\) and sales \(y\) (both in ₹ lakh) for 5 months: \(x\): 2, 4, 5, 6, 8 and \(y\): 3, 7, 8, 9, 13. Find both lines. Estimate sales when spend is 7, and spend when sales are 10.

  1. \(n = 5\), \(\sum x = 25\), \(\sum y = 40\), \(\sum x^2 = 145\), \(\sum y^2 = 372\), \(\sum xy = 232\). So \(\bar x = 5\), \(\bar y = 8\).
  2. Common numerator: \(5(232) - 25(40) = 160\).
  3. \(b_{yx} = \dfrac{160}{5(145) - 625} = \dfrac{160}{100} = 1.6\). Line: \(y - 8 = 1.6(x - 5)\), so \(y = 1.6x\).
  4. \(b_{xy} = \dfrac{160}{5(372) - 1600} = \dfrac{160}{260} = \dfrac{8}{13} \approx 0.6154\). Line: \(x - 5 = 0.6154(y - 8)\).
  5. At \(x = 7\): \(y = 11.2\). At \(y = 10\): \(x = 5 + \dfrac{8}{13}(2) \approx 6.23\).

AnswerSales \(\approx\) ₹11.2 lakh at spend 7; spend \(\approx\) ₹6.23 lakh for sales of 10

Example 3: From means, SDs and r

Medium

Maths marks \(x\) and physics marks \(y\): \(\bar x = 40\), \(\bar y = 45\), \(\sigma_x = 10\), \(\sigma_y = 8\), \(r = 0.6\). Find both lines. Estimate the physics mark for a maths mark of 50, and the maths mark for a physics mark of 53.

  1. \(b_{yx} = 0.6 \times \dfrac{8}{10} = 0.48\). Line: \(y - 45 = 0.48(x - 40)\), so \(y = 0.48x + 25.8\).
  2. \(b_{xy} = 0.6 \times \dfrac{10}{8} = 0.75\). Line: \(x - 40 = 0.75(y - 45)\), so \(x = 0.75y + 6.25\).
  3. \(x = 50\): \(y = 24 + 25.8 = 49.8\). \(y = 53\): \(x = 39.75 + 6.25 = 46\).

AnswerPhysics \(\approx 49.8\); maths \(= 46\)

Example 4: Means and r from the equations

Exam level

The two regression lines are \(4x - 5y + 16 = 0\) and \(20x - 9y - 48 = 0\). Find \(\bar x\), \(\bar y\), \(r\), and \(\sigma_y\) if \(\operatorname{Var}(x) = 9\).

  1. Both lines pass through the means. Solve \(4x - 5y = -16\) and \(20x - 9y = 48\). Multiply the first by 5: \(20x - 25y = -80\). Subtract from the second: \(16y = 128\), so \(\bar y = 8\), and then \(\bar x = 6\).
  2. Guess: first line is \(y\) on \(x\): \(y = 0.8x + 3.2\), so \(b_{yx} = 0.8\). Second is \(x\) on \(y\): \(x = 0.45y + 2.4\), so \(b_{xy} = 0.45\).
  3. Product \(= 0.36 \le 1\), so the guess is right. (The other way round gives \(1.25 \times \tfrac{20}{9} > 1\), impossible.)
  4. \(r = +\sqrt{0.36} = 0.6\), positive because both coefficients are positive.
  5. \(b_{yx} = r\dfrac{\sigma_y}{\sigma_x}\): \(0.8 = 0.6 \times \dfrac{\sigma_y}{3}\), so \(\sigma_y = 4\).

Answer\(\bar x = 6\), \(\bar y = 8\), \(r = 0.6\), \(\sigma_y = 4\)

Example 5: A negative correlation

Exam level

The regression lines are \(x + 2y = 11\) and \(25x + 8y = 149\). Find the means and \(r\).

  1. From the first, \(x = 11 - 2y\). Substitute: \(25(11 - 2y) + 8y = 149\), so \(42y = 126\), \(\bar y = 3\), \(\bar x = 5\).
  2. Guess: \(x + 2y = 11\) is \(y\) on \(x\): \(y = -0.5x + 5.5\), \(b_{yx} = -0.5\). Then \(25x + 8y = 149\) is \(x\) on \(y\): \(x = -0.32y + 5.96\), \(b_{xy} = -0.32\).
  3. Product \(= 0.16 \le 1\). (The swap gives \(-2\) and \(-\tfrac{25}{8}\), product 6.25, impossible.)
  4. Both coefficients are negative, so \(r = -\sqrt{0.16}\).

Answer\(\bar x = 5\), \(\bar y = 3\), \(r = -0.4\)

Example 6: Spotting impossible coefficients

Easy

Can the regression coefficients be (a) \(b_{yx} = 1.6\), \(b_{xy} = 0.8\)? (b) \(b_{yx} = -0.5\), \(b_{xy} = 0.4\)?

  1. (a) \(b_{yx}\, b_{xy} = 1.28\). That would make \(r^2 > 1\).
  2. (b) The coefficients have opposite signs, but both must have the sign of \(r\).

AnswerNeither pair is possible

Example 7: Coded data

Medium

With \(u = \dfrac{x - 100}{10}\) and \(v = \dfrac{y - 50}{5}\), the coefficients are \(b_{vu} = 0.8\) and \(b_{uv} = 0.45\). Find \(b_{yx}\), \(b_{xy}\) and \(r\).

  1. Here \(h = 10\), \(k = 5\). \(b_{yx} = \dfrac{k}{h}\,b_{vu} = \dfrac{5}{10}(0.8) = 0.4\).
  2. \(b_{xy} = \dfrac{h}{k}\,b_{uv} = \dfrac{10}{5}(0.45) = 0.9\).
  3. \(r^2 = 0.4 \times 0.9 = 0.36\) (the same as \(0.8 \times 0.45\), since \(r\) does not change with scale).

Answer\(b_{yx} = 0.4\), \(b_{xy} = 0.9\), \(r = 0.6\)

Vipul Sir's tip

In "find the means" questions, solve the two equations first and only then worry about which line is which. The means don't depend on that choice. Students who start with the guessing game often run out of time before they get the easy marks.

04

Common mistakes

1. Using the wrong line to predict

To estimate \(x\) from \(y\), use the \(x\) on \(y\) line. In Example 3, rearranging \(y = 0.48x + 25.8\) at \(y = 53\) gives \(x \approx 56.7\), far from the correct 46.

2. Taking r positive when the coefficients are negative

If \(b_{yx} = -0.5\) and \(b_{xy} = -0.32\), then \(r = -\sqrt{0.16} = -0.4\), not \(+0.4\).

3. Reading the coefficient off the wrong form

For \(4x - 5y + 16 = 0\) as \(y\) on \(x\), first write \(y = 0.8x + 3.2\), so \(b_{yx} = 0.8\). The 4 and the \(-5\) are not the coefficient.

05

Practice questions

Try each one on paper before you open the answer.

Q1\(b_{yx} = -0.5\) and \(b_{xy} = -0.72\). Find \(r\).

\(r^2 = 0.36\) and both are negative, so \(r = -0.6\).

Q2\(\bar x = 10\), \(\bar y = 20\), \(\sigma_x = 2\), \(\sigma_y = 3\), \(r = 0.8\). Find the line of \(y\) on \(x\) and estimate \(y\) at \(x = 12\).

\(b_{yx} = 0.8 \times \tfrac{3}{2} = 1.2\). \(y - 20 = 1.2(x - 10)\), so \(y = 1.2x + 8\).

At \(x = 12\): \(y = 22.4\).

Q3The regression lines are \(3x + 5y = 21\) and \(5x + 3y = 19\). Find the means and \(r\).

Adding gives \(x + y = 5\); subtracting gives \(y - x = 1\). So \(\bar x = 2\), \(\bar y = 3\).

First as \(y\) on \(x\): \(b_{yx} = -0.6\); second as \(x\) on \(y\): \(b_{xy} = -0.6\). Product 0.36, fine. So \(r = -0.6\).

Q4Find the line of \(y\) on \(x\) for \(x\): 1, 2, 3, 4, 5 and \(y\): 3, 5, 4, 6, 7, and estimate \(y\) at \(x = 6\).

\(\bar x = 3\), \(\bar y = 5\), \(\sum XY = 9\), \(\sum X^2 = 10\), so \(b_{yx} = 0.9\).

\(y = 0.9x + 2.3\). At \(x = 6\): \(y = 7.7\).

Q5\(b_{yx} = 1.6\), \(b_{xy} = 0.4\) and \(\sigma_x = 3\). Find \(r\) and \(\sigma_y\).

\(r = \sqrt{0.64} = 0.8\).

\(1.6 = 0.8 \times \dfrac{\sigma_y}{3}\), so \(\sigma_y = 6\).

Q6The line of \(y\) on \(x\) is \(y = 0.5x + 3\) and the line of \(x\) on \(y\) is \(x = 0.72y + 0.4\). Find \(\bar x\), \(\bar y\) and \(r\).

Substitute: \(x = 0.36x + 2.56\), so \(\bar x = 4\) and \(\bar y = 5\).

\(r = \sqrt{0.5 \times 0.72} = 0.6\).

Stuck on a question?

Bring it to a free demo class and work through it with Vipul Sir. Book on WhatsApp.

06

Frequently asked questions

Why are there two regression lines?

The line of \(y\) on \(x\) minimises vertical errors and is used to predict \(y\). The line of \(x\) on \(y\) minimises horizontal errors and is used to predict \(x\). They are the same line only when \(r = \pm 1\).

What is the difference between correlation and regression?

Correlation gives one number for the strength of a linear relationship and treats \(x\) and \(y\) alike. Regression gives an equation for predicting one variable from the other, and \(b_{yx}\) is usually different from \(b_{xy}\).

Where do the two regression lines meet?

At the point of means \((\bar x, \bar y)\). That is why solving the two given equations gives the means.

How do I find r from the regression lines?

Find \(b_{yx}\) and \(b_{xy}\) after deciding which line is which, then \(r = \pm\sqrt{b_{yx}\, b_{xy}}\), with the sign of the coefficients.

Related lessons

← All 10 Probability & Statistics topics
Vipul Sir
Written by Vipul Sir

Vipul Sir has taught mathematics for over 15 years to HSC, CBSE, ICSE, IGCSE/IB, Diploma, Engineering and BSc students at VVS Classes in Goregaon and Vile Parle, Mumbai. He teaches every class himself, concepts first and exam technique second.

Probability and Statistics

Get Probability & Statistics right, with Vipul Sir beside you.

Concept-first classes in small batches in Goregaon and Vile Parle, or online. Your first class is free.

WhatsApp↗