Skip to content
We use only essential cookies to keep you signed in and remember your preferences. See our Cookie Policy.
TestStop
MocksPracticeResourcesIndiaBlogPricing
Sign in
Resources › Basic statistics › 7. Regression
Basic statistics · Lesson 7 of 10

A first look at regression: the line of best fit

Correlation tells you how closely two variables move together. Regression goes one step further and answers a question economists ask all the time: if x is this much higher, how much higher do we expect y to be? This lesson builds the least-squares line from scratch, shows how it connects to r and to R², and ends with what a fitted line can and cannot tell you. It is a primer; the detailed treatment comes in the econometrics module.

← Basic statistics moduleLesson 7 of 10 · about 50 minutes
1Data2Averages3GM and HM4Spread5Shape6Correlation7Regression8Index numbers9Growth rates10Hard problems
A question to hold on to
The two regression lines are 3X + 2Y = 26 and 6X + Y = 31. What is the correlation coefficient r?
CUET 2021Solved at the end ↓
New here?What is Ashanagar?The invented district behind this page's examples: 60 households, with incomes you can inspect.

Ashanagar is an invented district. The statistics lessons use it for every worked example, so you meet the same households again as the ideas build: first as a list of numbers, then as a spread, then as a population to sample from.

It has 60 households, each with a monthly income in rupees. Unless a page says otherwise, those 60 are the whole population, and a “sample” means a few of them drawn at random. Where a page needs two variables, it uses a smaller set of 12 households with the head’s years of schooling beside income.

The figures are illustrative, made up once and fixed. They are not official statistics.

Households
60
Mean income
₹28,783 a month
Median income
₹25,000 a month
Standard deviation
₹13,366
Lowest and highest
₹10,500 and ₹72,000

Meet the full data set →

In this guide
Lesson · about 60 minutes
  1. From moving together to predicting
  2. The line of best fit
  3. The slope and the intercept
  4. What happens when the units change
  5. Two regression lines
  6. How much the line explains: R²
  7. What a fitted line does not show
  8. The opening question, solved
  9. The lesson on one screen
  10. Check yourself
  11. Past papers, by level
01
The idea

From moving together to predicting

Lesson 6 left a question open. The twelve Ashanagar households showed a correlation of 0.87 between years of schooling and monthly income. That says the two rise together. It does not say how much extra income one more year of schooling goes with, and that is usually what we want to know. A regression line answers it: it is the straight line that comes closest to the points, written as

y^​=a+bx

Here x is the variable we start from (the independent or explanatory variable), y is the one we want to explain (the dependent variable), b is the slope and a is the intercept, the predicted y when x is zero. The hat over y means a predicted value, as opposed to an observed one.

This is a different job from correlation. Correlation treats the two variables alike. Regression picks a side: it predicts y from x, and the line you get changes if you swap them, as the fourth section shows.

In economics

The consumption function is the classic example. Write consumption as C = a + bY. The slope b is the marginal propensity to consume: the extra consumption that goes with one extra rupee of income. The intercept a is consumption when income is zero. Fitting that line to data is simple linear regression.

02
Interactive

The line of best fit

Any line leaves a gap between what it predicts and what actually happened. That gap is the residual: actual minus estimated, ê = y − ŷ (CUET 2020, CUET 2023). If the fitted line is Ŷ = −15 + 0.75X, then at X = 30 the line predicts −15 + 22.5 = 7.5. A household with Y = 50 there has a residual of 50 − 7.5 = 42.5 (CUET 2018): the line badly underestimates it.

Which line is the best? Residuals above and below the line would cancel if you just added them, so we square them first, exactly as we did for the variance. The least-squares line is the one that makes the sum of the squared residuals as small as possible. It is the only line that does.

Least squares
choose a and b to minimise i=1∑n​(yi​−a−bxi​)2
Σe² is called the residual sum of squares, or SSE.

Try it yourself. The two sliders set a line through the twelve households. The red segments are the residuals, and the box on the left adds up their squares. Slide until you think you have the smallest total, then snap to the real least-squares line to see how close you came.

Your sum of squared residuals373
The smallest any line can reach167.6
R² of your line0.455
Least-squares line2.47 + 1.97x
0510152001020304050years of schooling of the household headmonthly income (₹ thousand)

Your line leaves 205.4 more squared miss than the best line. Tilt it and move it up or down until the red segments are as short as you can make them together. A bad line can even give a negative R², because it fits worse than a flat line at the mean income.

Why squares

Squaring does three jobs. It stops positive and negative misses cancelling, it punishes one big miss more than several small ones, and it gives formulas for the best a and b that can be written down exactly, with no trial and error. It is the same square that built the variance.

03
The result

The slope and the intercept

Minimising the squared residuals gives two clean formulas:

The least-squares line
b=σX2​Cov(X,Y)​=rσX​σY​​,a=yˉ​−bxˉ
The slope is also written b_yx, the regression coefficient of y on x.

Three things follow, and each appears in the exams:

  • The slope is the covariance over the variance of x. With a covariance of 100 and standard deviations of 5 and 20, the regression of Y on X has slope 100 ÷ 5² = 4 (CUET 2023). The standard deviation of Y is not used at all.
  • The line passes through the point of means (x̄, ȳ). That is where the intercept formula comes from. With X̄ = 2, Ȳ = 4.67 and a slope of 1.5, the intercept is 4.67 − 1.5 × 2 = 1.67 (CUET 2023).
  • The slope has the sign of r. It is positive when the correlation is positive and negative when it is negative, since the covariance sets both.

For the twelve households, the covariance is 21.83 and the variance of schooling is 3.33² = 11.08, so b = 1.97 and a = 23 − 1.97 × 10.42 = 2.47. The line is income ≈ 2.47 + 1.97 × schooling, in ₹ thousand. Read it as: households whose head has one more year of schooling have, on average in this sample, about ₹1,970 a month more.

Derive it

Where the slope and the intercept come from

We want to show
The line ŷ = a + bx that makes the squared misses smallest has b=Sxx​Sxy​​ and a=yˉ​−bxˉ, where Sxx​=∑(xi​−xˉ)2 and Sxy​=∑(xi​−xˉ)(yi​−yˉ​).
  1. 1
    Say what is being minimised.

    Take any line ŷ = a + bx. Household i misses by yi​−a−bxi​. Misses above and below would cancel, so square them and add:

    S(a,b)=i=1∑n​(yi​−a−bxi​)2

    S depends on two numbers, a and b. Drawn against both it is a bowl, and the lowest point is where the bowl stops sloping in either direction. So we look for the place where both slopes are zero.

  2. 2
    Slope in the a direction: the line goes through the means.
    ∂a∂S​⟹∑yi​−na−b∑xi​​=−2∑(yi​−a−bxi​)=0=0⟹yˉ​=a+bxˉ​

    Dividing by n says the average miss is zero, which is the same as saying the line passes through the point of means (x̄, ȳ). Whatever slope we end up with, the intercept is a = ȳ − b x̄. For the twelve households, x̄ = 125 ÷ 12 = 10.42 and ȳ = 23.

  3. 3
    Put that intercept back and one unknown is left.

    Write ui = xi − x̄ and vi = yi − ȳ. With a = ȳ − b x̄ the miss at household i is vi − b ui, so

    S(b)​=∑(vi​−bui​)2=Syy​∑vi2​​​−2bSxy​∑ui​vi​​​+b2Sxx​∑ui2​​​​

    For the twelve households Sxx = 132.92, Sxy = 262 and Syy = 684, so S(b) = 684 − 524b + 132.92b². Slide b along the bowl and watch the line it stands for.

  4. 4
    Find the bottom of the bowl.
    dbdS​=−2Sxy​+2bSxx​=0⟹b=Sxx​Sxy​​

    It is a minimum, not a maximum, because the second derivative 2Sxx is positive. There is also a way to see it without calculus. Complete the square:

    S(b)=Sxx​(b−Sxx​Sxy​​)2+(Syy​−Sxx​Sxy2​​)

    The first term is never negative and is zero at exactly one slope. The second term does not involve b at all, so nothing can beat it.

  5. 5
    Read the result.

    b = Sxy ÷ Sxx = 262 ÷ 132.92 = 1.971 and a = 23 − 1.971 × 10.42 = 2.47. Divide the top and bottom by n and the slope becomes covariance over variance, 21.83 ÷ 11.08, the form the lesson uses. Since Sxy = r √(SxxSyy), it is also rσY​/σX​.

    The smallest possible total miss is the second bracket: 684 − 262² ÷ 132.92 = 167.56, which is Syy(1 − r²). That small fact is where R² comes from, in the last derivation of this lesson.

Step 1 of 5
So
Setting both slopes of the bowl to zero gives the intercept a = ȳ − b x̄ and the slope b = Sxy ÷ Sxx. Nothing was assumed about the data except that the x values are not all equal, which would make Sxx zero.
IIT JAM 2026 · hard
n = 100, ΣX² = 460,000, ΣY² = 320,000, ΣX = 6,000, ΣY = 500 and ΣXY = 40,000. Find the estimated intercept α.
  1. 1
    Means.
    X̄ = 6,000 ÷ 100 = 60 and Ȳ = 500 ÷ 100 = 5.
  2. 2
    Sums of squares and products about the means.
    Sₓₓ = ΣX² − nX̄² = 460,000 − 100 × 3,600 = 100,000. Sₓᵧ = ΣXY − nX̄Ȳ = 40,000 − 100 × 60 × 5 = 10,000.
  3. 3
    Slope.
    b = Sₓᵧ ÷ Sₓₓ = 10,000 ÷ 100,000 = 0.1.
  4. 4
    Intercept.
    a = Ȳ − bX̄ = 5 − 0.1 × 60 = −1.
Answer
α = −1. The sum ΣY² is not needed for the line. It would be needed for R². Questions often give more than you need.
Pause and predict
A fitted line is ŷ = 60 + 5x. A student says 'multiply the slope 5 by x and you get the predicted y'. Is that right?
04
Rescaling

What happens when the units change

Regression slopes carry units, so they respond to changes of units in a pattern worth learning once. Suppose the fitted line is y = 10 + 3x.

  • Add a constant to x or y. The slope does not change, because the line is only shifted. If the slope of Y on X is 15, the slope of Y + 10 on X − 5 is still 15 (CUET 2023). Only the intercept moves.
  • Multiply y by a number. Everything about y scales, so both the intercept and the slope are multiplied by it. Multiply y by 0.9 and y = 10 + 3x becomes y = 9 + 2.7x (DSE 2018).
  • Multiply x by a number c. The slope is divided by c, since a unit of the new x is c old units. The intercept does not change, because x = 0 is still x = 0.
  • R² and r do not change when either variable is shifted or rescaled by a positive number, for the same reason as in Lesson 6.

Models that are linear in the parameters are linear regressions even when they are not linear in the variables: y = a + b ln x, or y = a + bx + cx² (CUET 2023, CUET 2025). A model such as y = a·xb is not, until you take logarithms to turn it into ln y = ln a + b ln x.

Logs and growth rates

A regression of ln Y on time t, ln Yt = a + bt, says Y grows by a roughly constant percentage each year. The slope is the growth rate in logs, so the compound annual rate is eb − 1. With b = 0.1512 that is e0.1512 − 1 = 16.32% (JAM 2026). The slope read as a percentage, 15.12%, is only an approximation, and it gets worse as b grows. This is the same continuous-versus-compound point as in Lesson 9.

05
Interactive

Two regression lines

You can regress y on x, minimising vertical misses, or x on y, minimising horizontal misses. These are different lines. Their slopes are

The two regression coefficients
byx​=rσX​σY​​,bxy​=rσY​σX​​,byx​bxy​=r2

Multiply them and the standard deviations cancel, leaving r². So r = ±√(byx bxy), with the sign taken from the slopes, and byx and bxy always have the same sign. If byx = 1.6 and bxy = 0.4, then r = √0.64 = 0.8, positive because both are (CUET 2021). Use the sliders to see how the two lines behave as r changes.

Slope of y on x0.6
Slope of x on y0.6
Product of the two slopes0.36 = r²
Angle between the lines (as drawn)28°
−3−2−10123−3−2−10123x (distance from its mean, in SDs)y
y on x: minimises vertical missesx on y: minimises horizontal misses

The weaker the correlation, the further apart the lines swing. Both slopes carry the sign of r, and both lines pass through the point of means. Change the spread of y and both slopes change, since they depend on units, while the picture and the product of the slopes do not.

The facts the exams ask, all visible in the picture:

  • Both lines pass through the point of means (x̄, ȳ), so that is where they cross (Hyderabad 2011, JNU 2021).
  • If one coefficient is greater than 1, the other is less than 1. Their product is r², which cannot exceed 1 (CUET 2022, JNU 2014, JNU 2021).
  • The lines are at right angles exactly when r = 0 (CUET 2022). Then both slopes are zero, so byx + bxy = 0 (JNU 2020), and the lines are horizontal and vertical.
  • The lines coincide exactly when r = ±1, so the correlation is perfect (Hyderabad 2019).

Why two lines? Because the predictions differ. Take very tall parents: their children tend to be tall, but on average not as tall as the parents. Predicting child from parent pulls the prediction back toward the average. That pull, called regression to the mean, is what the weaker slope shows. Francis Galton noticed it in heights in the 1880s, and the word “regression” comes from it.

A question that hands you the two lines and asks for r needs one decision first: which line is y on x, and which is x on y? Try an assignment and multiply the two slopes. If the product exceeds 1 the assignment was wrong, because r² cannot. The opening question works through exactly this, at the end of the lesson.

06
Goodness of fit

How much the line explains: R²

A line can be the best possible and still fit badly. The coefficient of determination, R², measures how well it fits. The total variation in y is SST, the sum of squared deviations of y from its mean. The line explains part of it, SSR, and leaves the rest as residual, SSE:

R-squared
R2=total variationexplained variation​=1−SSTSSE​=r2
With an intercept, R² in simple regression equals r², the square of the correlation.
  • If the correlation is 0.6, then 36% of the variation in Y is explained by X (CUET 2023). If r = 0.8, then 64% (UGC NET 2024). The 8% and 80% options forget to square.
  • The coefficient of non-determination is the unexplained share, 1 − R² (CUET 2022).
  • R² is a number from 0 to 1. It is 0 when the slope is zero, so the line is flat at ȳ and explains nothing (DSE 2013). It is 1 when every point is on the line. Coefficient of determination is therefore both the explained-over-total share and a measure of how well the sample regression fits the data (CUET 2025).

A small worked case: the line Y = −2.5 + 2X is fitted to Y = 2, 5, 9, 14 and X = 2, 4, 6, 8. It predicts 1.5, 5.5, 9.5, 13.5, so the residuals are 0.5, −0.5, −0.5, 0.5 and SSE = 1. The mean of Y is 7.5, so SST = 30.25 + 6.25 + 2.25 + 42.25 = 81. Then R² = 1 − 1 ÷ 81 = 0.988 (JAM 2024).

For the schooling data R² = 0.87² = 0.755: about three-quarters of the variation in income among these households is accounted for by schooling in a straight-line fit. It does not say the other quarter is noise; it says schooling alone does not account for it.

Swapping the variables

If you regress x on y instead, the slope changes (it is bxy, not 1 ÷ byx) and so does the sum of squared errors, since it now measures horizontal misses in different units. But r and R² do not change, and the slope keeps its sign (UGC NET 2024).

Derive it

Why R² is the share of variation the line explains, and why it equals r²

We want to show
For the least-squares line, SST = SSR + SSE, and the explained share SSR ÷ SST equals r².
  1. 1
    Split each household's distance from the mean.

    The line predicts ŷi. The distance of the actual income from the mean income splits into a part the line accounts for and a part it misses:

    yi​−yˉ​=(y^​i​−yˉ​)+(yi​−y^​i​)

    Explained plus left over, drawn as the blue and red strokes in the picture below.

  2. 2
    Square and add.
    SST∑(yi​−yˉ​)2​​​=SSR∑(y^​i​−yˉ​)2​​+SSE∑(yi​−y^​i​)2​​+2∑(y^​i​−yˉ​)(yi​−y^​i​)​

    The last term has to go if the pieces are to add up. Does it?

  3. 3
    For the least-squares line the cross term is zero.

    With a = ȳ − b x̄ we have ŷi − ȳ = b ui, and the miss is ei = vi − b ui (u and v as in the slope derivation). So

    ∑(y^​i​−yˉ​)ei​=b∑ui​(vi​−bui​)=b(Sxy​−bSxx​)=0

    because b = Sxy ÷ Sxx. Try it in the picture. At the least-squares slope SSR + SSE equals SST exactly. Tilt the line and the pieces stop adding up, by the amount 2b(bSxx − Sxy).

  4. 4
    The explained share is r².
    SSR=∑b2ui2​=b2Sxx​=Sxx​Sxy2​​⟹SSTSSR​=Sxx​Syy​Sxy2​​=r2

    It also follows that SSE = SST − SSR = SST(1 − r²), the smallest total miss found in the slope derivation.

  5. 5
    Check with the twelve households.

    SST = 684, SSR = 262² ÷ 132.92 = 516.4 and SSE = 167.6, and 516.4 + 167.6 = 684. The explained share is 516.4 ÷ 684 = 0.755, which is 0.869². About three quarters of the variation in income across these households goes with differences in schooling.

Step 1 of 5
So
R² is defined as 1 − SSE ÷ SST for any fitted line. For the least-squares line with an intercept it also equals SSR ÷ SST and r², which is why the three are used interchangeably in simple regression.
07
Reading it carefully

What a fitted line does not show

A regression line is a summary of how y moves with x in the data. It does not, on its own, say that x causes y. Regression analysis does not necessarily imply causation (Hyderabad 2015), and the line represents a quantitative relationship between variables, not causality and not an economic identity (Hyderabad 2011). It is the tool used when we have a reason to treat one variable as depending on another, which is why CUET 2019 names regression as the method for analysing a dependence between two variables. Whether the dependence is causal is a question about the data and the design of the study, which the line cannot answer.

Some cautions that apply every time you read a fitted line:

  • Do not predict far outside the data. The twelve Ashanagar households have 5 to 16 years of schooling. The line says nothing reliable about 25 years, or about 0.
  • One point can tilt the line. Drag a household far from the rest in the first lab and watch the fitted line follow, as r did in Lesson 6.
  • A line can be fitted to anything. Check the scatter plot first. The four sets in Anscombe’s quartet all have the same line.
  • Is the slope really different from zero? With a sample, even a useless variable produces some slope. Testing whether the slope is real uses its standard error and a p-value. A low p-value is evidence that the slope is not zero in the population. JNU 2013 asks which statement about the slope is incorrect, and it is the one that says a slope may be treated as zero when its p-value is below 0.01, which is the wrong way round. That belongs to the next module; the residual sum of squares has n − 2 degrees of freedom in a simple regression, so 98 with 100 observations (CUET 2023).
Watch out for

The mistakes examiners are fishing for

  • Regression is not symmetric. The line of y on x is not the line of x on y, and you cannot invert one slope to get the other.
  • r² needs squaring. A correlation of 0.8 explains 64% of the variation, not 80%.
  • Slope times x is not ŷ. Add the intercept.
  • Rescaling. Adding to x or y leaves the slope alone. Multiplying y multiplies slope and intercept. Multiplying x divides the slope.
  • High R² is not causation, and a low R² does not mean the slope is unimportant.
08
Solving the opening question

The opening question, solved

CUET 2021 · hard
The regression lines are 3X + 2Y = 26 and 6X + Y = 31. Find r.
  1. 1
    Slopes of the two lines.
    Line 1 as Y on X: slope −1.5. Line 2 as X on Y: slope −1/6.
  2. 2
    r².
    (−1.5)(−1/6) = 0.25.
  3. 3
    Sign.
    Both slopes are negative, so r is negative: r = −0.5.
Answer
−0.5, which is option B. The other options fail the check: ±0.4, 0.6 and 0.7 do not square to 0.25. The two lines also give you the means, since they cross there: substituting Y = 31 − 6X into the first line gives 3X + 62 − 12X = 26, so X̄ = 4 and Ȳ = 7. Check: 3 × 4 + 2 × 7 = 26 and 6 × 4 + 7 = 31.
09
Revise

The lesson on one screen

The lesson on one screen
The line
ŷ = a + bx, with a and b chosen to minimise Σ(y − a − bx)². Residual = actual − estimated.
Slope and intercept
b = Cov(X, Y) ÷ σₓ² = r σᵧ ÷ σₓ. a = ȳ − b x̄. The line passes through (x̄, ȳ).
Two lines
b_yx = r σᵧ/σₓ, b_xy = r σₓ/σᵧ. b_yx × b_xy = r². Same sign. One above 1 means the other below 1. Cross at the means. r = 0: perpendicular. r = ±1: coincide.
R²
Explained ÷ total = 1 − SSE ÷ SST = r². 1 − R² is the coefficient of non-determination. Same for y on x and x on y.
Units
Shift x or y: slope unchanged. Multiply y by c: a and b × c. Multiply x by c: b ÷ c. R² unchanged.
Logs
ln Y on t: growth rate e^b − 1. Linear regression means linear in parameters.
Limits
Not causation. Not outside the data. One outlier can tilt it. Plot first.
10
Practice

Check yourself

0 of 14 correct so far

Compute

The intercept
x̄ = 6, ȳ = 20 and the slope of y on x is 1.5. Find the intercept.
Slope from r
r = 0.6, σY = 10 and σX = 5. Find the slope of the regression of Y on X.
r from the two slopes
byx = 0.9 and bxy = 0.4. Find r.
Negative slopes
byx = −1.2 and bxy = −0.3. Find r.
R² from r
The correlation between x and y is −0.7. What proportion of the variation in y does the regression of y on x explain?
A residual
The fitted line is Ŷ = 5 + 2X. A household has X = 4 and Y = 10. Find its residual.
From the sums
n = 10, ΣX = 50, ΣY = 80, ΣX² = 290 and ΣXY = 480. Find the slope of the regression of Y on X.
Two lines, one point
The regression lines are 4X − 5Y + 33 = 0 and 20X − 9Y = 107. Find the mean of X.
Log growth rate
A regression of ln Y on the year t has slope 0.07. Find the compound annual growth rate, in percent, to two decimal places.

Quick questions

1A constant is added to every value of x. The slope of the regression of y on x
2You swap the dependent and independent variables and refit. Which of these is unchanged?
3The two regression lines coincide. Then
4One regression coefficient is 1.4. The other must be
5A regression of y on x finds a strong fit. This shows that
11
Real questions

Past papers, by level

Foundation

Definitions, one-step arithmetic and which-measure questions. Most CUET and Hyderabad questions sit here.

15 questionsPractise →

Standard

Grouped data, combined means, effects of shifting and scaling, and statement questions, up to JNU level.

20 questionsPractise →

Delhi School level

This topic’s hardest questions, from the DSE entrance, are worked through in Lesson 10: Regression.

17 questionsLesson 10 →
All 35 past-paper questions for this lesson, easiest first: practise the full set →

✦These are questions from the TestStop bank. A free account answers 10 a day, each with its worked solution; All-Access opens every set with no daily limit.

← Lesson 6Correlation: covariance, r and causationLesson 8 →Index numbers: Laspeyres, Paasche and Fisher

Read next

All resources →
StatisticsStatistics 8: index numbers, Laspeyres, Paasche and FisherPrice relatives and simple indices, Laspeyres, Paasche, Fisher and Marshall-Edgeworth, why Laspeyres overstates, the time and factor reversal tests, base shifting, real wages, the CPI and WPI, and the components of a time series.Complete guide · 50 minStatisticsStatistics 6: covariance, correlation and rank correlationScatter plots, covariance as an average of products, Pearson's r and what leaves it unchanged, the variance of sums, Anscombe's quartet, why zero correlation is not independence, Spearman's rank correlation and the probable error.Complete guide · 50 minStatisticsHypothesis testing in one placeThe 2×2 of Type I and Type II errors, power and p-values, with a lab that shows the α–β trade-off as areas.Complete guide · 30 min