Fit a straight line to data
Find the least-squares line y = ax + b that best matches a set of points.
A line of best fit is the straight line that sits as close as possible to all your points. The calculator works out its slope (a) and its y-intercept (b).
The example points are x = 1 to 5 and y = 2, 4, 5, 4, 5. The best-fit line is y = 0.6x + 2.2.
Classic Graphing 84
Start on the main screen: Press 2nd then mode (QUIT) to get back to the home screen. Pressing clear on a menu also backs out of it.
Type x into L1 and y into L2.
stat11enter2enter3enter4enter5enter▶2enter4enter5enter4enter5enterOpen STAT, move to CALC and choose LinReg(ax+b).
stat▶4Leave the lists as L1 and L2. Move down to Calculate and press enter.
▼▼▼▼enter
You should seeSlope a = 0.6, intercept b = 2.2. The r values tell you how well the line fits.
If r does not show, turn on diagnostics in the mode settings.
Classic Scientific 30
Start on the main screen: Press 2nd then mode (QUIT) to leave any menu or screen and return to the calculation screen.
Type x into L1 and y into L2.
data1enter2enter3enter4enter5enter▶▲▲▲▲▲2enter4enter5enter4enter5enterOpen the STAT menu (2nd then data) and choose LinReg ax+b. Accept the lists with enter.
2ndstatdata3enterenterenter
You should seey=ax+b 1:a=0.6 2:b=2.2
Natural Scientific 991
Start on the main screen: Press MENU, then 1 (Calculate) to return to the main calculation screen. AC clears the line you are on.
Open Statistics and choose y=a+bx, then type the x column.
MENU621=2=3=4=5=Move right, back up to the top of the table, and type the y column.
▶▲▲▲▲▲2=4=5=4=5=ACPress OPTN and choose Regression Calc.
OPTN3
You should seey=a+bx a=2.2 b=0.6
This model writes the line as a + bx, so a is the intercept and b is the slope.
Natural Color Graphing
Start on the main screen: Press MENU then 1 to open Run-Matrix, the main calculation screen. Press EXIT to back out of a bar or screen, and SHIFT then EXIT (QUIT) to return to the app start.
Type x into List 1 and y into List 2.
MENU21EXE2EXE3EXE4EXE5EXE▲▲▲▲▲▶2EXE4EXE5EXE4EXE5EXEChoose CALC (F2), then REG (F3), then X (F1) and finally ax+b (F1).
F2F3F1F1
You should seePress COPY (F1) to store the line in the graph list, or DRAW (F6) to plot it.
RPN Scientific 15
Start on the main screen: There is no menu to leave. Press the back arrow to clear a number you are typing, or CLx (g then back arrow) to clear the X register.
Clear the statistics memory first, so old data cannot sneak into the answer.
fCLR ΣGSBFor each pair, key in y, press ENTER, key in x, then press Σ+.
2ENTER1Σ+4ENTER2Σ+5ENTER3Σ+4ENTER4Σ+5ENTER5Σ+Press f then Σ+ (L.R.). The intercept appears in X and the slope in Y.
fL.R.Σ+
You should see0.6000 2.2000
RPN Advanced 42
Start on the main screen: Press EXIT (once or twice) to close any menu and return to the plain stack view of Y and X.
For each pair, key in y, press ENTER, key in x, then press the Σ+ key.
2ENTER1Σ+4ENTER2Σ+5ENTER3Σ+4ENTER4Σ+5ENTER5Σ+Open the STAT menu (shift, ÷) then FIT (the last menu key). The menu now offers FCX, FCY, SLP, YIN and r.
⇧STAT÷XEQPress the third key for the slope (SLP).
√x
You should seex: 0.6000
The fourth key (YIN) gives the intercept, 2.2000.
Tips
- To predict y for a new x on RPN models, key in x and use the forecast key (ŷ,r on the Classic RPN 15 / 12, FCY on the Advanced RPN 42).
- A straight line only makes sense if the points look roughly straight. Check with a scatter plot first.
Related guides
- Measure how strongly two lists are relatedFind the correlation coefficient r, which runs from -1 (perfect downhill) to +1 (perfect uphill).
- Draw a scatter plotPlot paired data as dots so you can see whether a pattern is there.
- Fit a parabola to dataFind the curve y = ax² + bx + c that best matches points that bend.