Linear regression (line of best fit) and r
Find the equation of the regression line and the correlation coefficient r from a list of data, with the exact key presses for the TI-84 Plus CE, Casio fx-CG50, Casio fx-CG100 and TI-Nspire CX, plus what to write in the exam.
Enter the x-values in one list and the y-values in another, then run the linear regression command (LinReg(ax+b), the Linear Regression (ax+b) or (mx+b) option). The calculator gives the gradient a, the intercept b and the correlation coefficient r. Write the equation as y = ax + b and use it to predict a value only within the range of the data.
Example
Eight students recorded the number of hours they revised and their test mark .
: 3, 5, 6, 8, 9, 11, 12, 14
: 41, 48, 47, 58, 60, 69, 66, 77
(a) Find the equation of the regression line of on . (b) Find and describe the correlation. (c) Estimate the mark of a student who revised for 10 hours.
Entering the two lists and running linear regression gives (a) , (b) , which is a strong positive correlation, and (c) when . The value lies inside the data range, so the estimate is reliable.
Choose your calculator
How to find a line of best fit and r on a TI-84 Plus CE
Turn on r (once) | |
Press mode, use ▼ to reach STAT DIAGNOSTICS, move to ON with ▶ and press enter. Then press 2nd mode (QUIT). With diagnostics off, the correlation coefficient is not shown. This setting stays on until you reset the calculator. |
|
Enter the data and run LinReg(ax+b) | |
Press stat and choose 1:Edit. Clear any old values: move up to the L1 heading, press clear then enter, and do the same for L2. |
|
Type the -values into L1, pressing enter after each: 3, 5, 6, 8, 9, 11, 12, 14. Press ▶ to move to L2 and type the -values, pressing enter after each: 41, 48, 47, 58, 60, 69, 66, 77. Both lists must have the same number of values. |
L1 = 3, 5, 6, 8, 9, 11, 12, 14 L2 = 41, 48, 47, 58, 60, 69, 66, 77 |
Press stat, move to CALC with ▶, and choose 4:LinReg(ax+b). With the Stat Wizards on, a screen asks for Xlist and Ylist: set Xlist to L1 and Ylist to L2 (press 2nd 1 for L1 and 2nd 2 for L2), then move to Calculate and press enter. If the Stat Wizards are off, type |
LinReg(ax+b) y=ax+b a=3.2346939 b=30.7551020 r²=0.9678131 r=0.9837749 |
Read a (the gradient), b (the -intercept) and r. and , both to 3 significant figures. |
|
Predict a value from the line | |
Before you run LinReg, move to Store RegEQ on the wizard screen, press vars, then ▶ to Y-VARS and choose 1:Function then 1:Y1. The full-accuracy equation is then saved in Y1. On the home screen type when , to 3 significant figures. |
Y1(10) 63.1020408 |
If r does not appear, diagnostics are off: turn STAT DIAGNOSTICS on in the mode screen and run LinReg again. Use the full values of a and b, not rounded ones, when you predict.
How to find a line of best fit and r on a Casio fx-CG50
Enter the data and run the regression | |
Press MENU and choose Statistics. The List Editor opens. |
|
Type the -values into List 1, pressing EXE after each: 3, 5, 6, 8, 9, 11, 12, 14. Move to List 2 with ▶ and ▲ to the top, and type the -values, pressing EXE after each: 41, 48, 47, 58, 60, 69, 66, 77. Both lists must have the same number of values. |
List1 = 3, 5, 6, 8, 9, 11, 12, 14 List2 = 41, 48, 47, 58, 60, 69, 66, 77 |
Press F2 (CALC), then F3 (REG), F1 (X) and F1 (ax+b). The results screen shows a, b, r, r² and MSe. and , both to 3 significant figures. |
Linear Reg(ax+b) a=3.2346939 b=30.7551020 r=0.9837749 r²=0.9678131 MSe=... |
The regression uses the lists named in SET. To check them, press F2 (CALC) then F6 (SET) from the List Editor before the step above: the 2Var XList should be List 1 and the 2Var YList List 2. To draw the line, press F6 (DRAW) on the results screen. |
|
Predict a value from the line | |
Press EXIT until the main menu shows, choose Run-Matrix, and type the equation with the full values of a and b from the results screen: a × 10 + b. when , to 3 significant figures. |
3.2346939×10+30.7551020 63.1020408 |
The results screen gives r for a linear regression. If you want the line drawn over the scatter diagram, use the DRAW key after the calculation.
How to find a line of best fit and r on a Casio fx-CG100
Enter the data and run the regression | |
Press HOME and choose Statistics. The List Editor tab is active. |
|
Type the -values into List 1, pressing EXE after each: 3, 5, 6, 8, 9, 11, 12, 14. Move to List 2 and type the -values, pressing EXE after each: 41, 48, 47, 58, 60, 69, 66, 77. Both lists must have the same number of values. |
List1 = 3, 5, 6, 8, 9, 11, 12, 14 List2 = 41, 48, 47, 58, 60, 69, 66, 77 |
Press the next-tab key to reach the Setup tab. Highlight the first line and press OK, then choose Calculate Summary Statistics and press OK. |
|
Highlight line 2 and press OK, then choose Linear Regression (ax+b). Check that 2Var XList is List 1 and 2Var YList is List 2. |
Calculate Summary Statistics Linear Regression(ax+b) 2Var XList: List1 2Var YList: List2 |
Press the next-tab key, or highlight Execute and press OK. The Results tab shows a, b, r, r² and MSe. and , both to 3 significant figures. |
Linear Regression(ax+b) a=3.2346939 b=30.7551020 r=0.9837749 r²=0.9678131 MSe=... |
Predict a value from the line | |
Press HOME, choose Calculate, and type a × 10 + b using the full values from the Results tab, then press EXE. when , to 3 significant figures. |
3.2346939×10+30.7551020 63.1020408 |
Use the full values of a and b shown on the Results tab, not rounded ones, when you predict.
How to find a line of best fit and r on a TI-Nspire CX
Enter the data and run the regression | |
Press home and choose Lists & Spreadsheet. Move to the top cell of column A, type |
|
Type the -values down column A, pressing enter after each: 3, 5, 6, 8, 9, 11, 12, 14. Then fill column B with the -values: 41, 48, 47, 58, 60, 69, 66, 77. Both columns must have the same number of values. |
x: 3, 5, 6, 8, 9, 11, 12, 14 y: 41, 48, 47, 58, 60, 69, 66, 77 |
Press menu → Statistics → Stat Calculations → Linear Regression (mx+b). In the box, set X List to |
X List: x Y List: y Save RegEqn To: f1 |
Two new columns list the results: m (the gradient), b (the -intercept), r² and r. and , both to 3 significant figures. |
m=3.2346939 b=30.7551020 r²=0.9678131 r=0.9837749 |
Predict a value from the line | |
The results are stored as when , to 3 significant figures. |
stat.m×10+stat.b 63.1020408 |
Give the lists names such as x and y. The results are linked to the data, so if you correct a value in the columns the line and r update.
Sources. Key presses follow the manufacturers' documentation: the TI-84 Plus CE eGuide, the TI-Nspire eGuide, the Casio fx-CG50 Software User's Guide (version 3.30) and the Casio fx-CG100 online manual.
What to write in the exam
- State the regression line and r to 3 significant figures, for example and , and say you used your calculator. Do not write the key presses.
- Name the variables in the equation. If the question uses other letters, such as for mark and for hours, write the line as .
- Describe r in words. The sign gives the direction. As a guide, from 0 to 0.5 is weak, from 0.5 to 0.8 is moderate and from 0.8 to 1 is strong. Say positive or negative as well.
- Predict only inside the data range. An estimate for an -value inside the range is interpolation and is reliable. An estimate outside the range is extrapolation and may not be.
- Check which papers allow a calculator. In AA SL and AA HL, Paper 1 is calculator-free, so regression from data is for Paper 2. In AI SL and AI HL a calculator is allowed on every paper (check your syllabus).
What r and r² tell you
The correlation coefficient lies between and . Its sign is the direction of the relationship and its size is the strength. The calculator also shows , the proportion of the variation in that the line accounts for. A value of close to 0 means a straight line is not a good model. To plot the data first, see making a scatter diagram.
Error messages and what to do
| Calculator | Message | Usual cause | What to try |
|---|---|---|---|
| TI-84 Plus CE | ERR:DIMENSION MISMATCH | L1 and L2 do not have the same number of values. | Open the list editor with STAT then 1:Edit and make both lists the same length. |
| TI-84 Plus CE | ERR:STAT | The lists are not suitable for the calculation, for example fewer than two data points. | Check each list holds all your values. |
| TI-84 Plus CE | ERR:DIVIDE BY 0 | A linear regression was attempted on a vertical line, which happens when every x-value is the same. | Check the x-values were typed correctly into L1. |
| Casio fx-CG50 | Dimension ERROR | The two lists do not have the same number of values. | Make List 1 and List 2 the same length. |
| Casio fx-CG100 | Dimension ERROR | The two lists do not have the same number of values. | Make List 1 and List 2 the same length. |
| TI-Nspire CX | Dimension mismatch | The X List and Y List do not have the same number of values. | Make columns A and B the same length. |
Common mistakes
- Swapping the lists. The regression line of on needs the independent variable in the first list and in the second. Swapping them gives a different line.
- Lists of different lengths. A missing or extra value gives a dimension error. Check both lists have the same number of values.
- No r on the TI-84 Plus CE. r only appears when STAT DIAGNOSTICS is on. Turn it on in the mode screen and run the regression again.
- Predicting from rounded values. Use the full values of a and b, or the stored equation, and round only the final answer.
- Extrapolating. Using the line far outside the range of the data is unreliable, even when r is close to 1.
Try it yourself
Real questions from the IB Maths Help question bank. Type your answer and press Mark it: the worked solution and mark scheme then appear. Use your calculator to run the regression.
Practise with your calculator
Choose your course to see the practice sets that use this skill. You can also try practice mode or browse every GDC guide.
Quick questions
How do I find the equation of the line of best fit on a calculator?
Enter the x-values in one list and the y-values in another, then run linear regression: LinReg(ax+b) on the TI-84 Plus CE, CALC then REG then X then ax+b on the Casio fx-CG50, Calculate Summary Statistics with Linear Regression (ax+b) on the fx-CG100, or Statistics then Stat Calculations then Linear Regression (mx+b) on the TI-Nspire. The calculator gives the gradient and the intercept.
Why does my TI-84 not show r?
The correlation coefficient only appears when STAT DIAGNOSTICS is on. Turn it on in the mode screen, then run LinReg(ax+b) again.
What is the difference between r and r squared?
The correlation coefficient r shows the direction and strength of a linear relationship and lies between -1 and 1. The coefficient of determination r squared is the proportion of the variation in y that the line accounts for, and lies between 0 and 1.
Can I use the line to predict any value?
Only values of x inside the range of your data. A prediction inside the range is interpolation and is reliable. A prediction outside the range is extrapolation and may not be.