TI-30Xa Algorithms: Linear Regression
Welcome to the March 2024 installment of TI-30Xa Algorithms.
Linear Regression with a TI-30Xa?
Today’s task is to fit bi-variate data to the line:
y = m * x + b
with the TI-30Xa. What? This calculator does not have a linear regression mode. Yes, with it is possible. We are going to use the technique shown in by the TI-36 Solar Guidebook from 1985 (see Source below). The TI-36 Solar was part of Texas Instruments’ line in the late 1980s and the early 1990s.
You can read my review on the TI-36 Solar from September 26, 2020 here:
https://edspi31415.blogspot.com/2020/09/retro-review-ti-36-solar.html
Where the TI-36 Solar only had one memory register, the TI-30Xa has three memory registers, and they are going to come in handy here.
Procedure
Caution: Be sure the calculator is on the entire time. Turning off the calculator will clear out statistics mode.
1. Enter the y data. Store the mean (y-bar) into memory register 2. Store the population deviation (σy) into memory register 3.
Keystrokes:
Mean of y-data: [ 2^{nd} ] [ x^2 ] {x-bar} [ STO ] [ 2 ]
Population of y-data: [ 2^{nd} ] [ ÷ ] { σxn } [ STO ] [ 3 ]
2. Clear the stat registers and enter the x data. As we are entering the x data, use memory register 1 to calculate Σxy.
Keystrokes:
Clear Stat Registers: [ 2^{nd} ] [ 7 ] {CSR}
1^{st} Point:
x1 [ × ] y1 [ = ] [ STO ] [ 1 ]
x1 [ Σ+ ]
Every point there after:
x_i [ × ] y_i [ = ] [ 2^{nd} ] [ RCL ] {SUM} [ 1 ]
x_i [ Σ+ ]
3. Calculate the slope, and replace Σxy with the slope.
m = ( y-bar * Σx – Σxy) / ( x-bar * Σx - Σx^2)
Keystrokes:
[ ( ] [ RCL ] [ 2 ] [ × ] [ 2^{nd} ] [ ( ] [ - ] [ RCL ] [ 1 ] [ ) ]
[ ÷ ] [ ( ] [ 2^{nd} ] [ x^2 ] [ × ] [ 2^{nd} ] [ ( ] [ - ] [ 2^{nd} ] [ ) ] [ = ] [ STO ] [ 1 ]
4. Calculate the y-intercept, replace y-bar with the y-intercept.
b = -m * x-bar + y-bar
Keystrokes:
[ RCL ] [ 1 ] [ +/- ] [ × ] [ 2^{nd} ] [ x^2 ] [ + ] [ RCL ] [ 2 ] [ = ] [ STO ] [ 2 ]
5. Calculate the correlation. If the correlation is close to -1 or +1, the linear fit will be excellent.
r = m * σx / σy
Keystrokes:
[ RCL ] [ 1 ] [ × ] [ 2^{nd} ] [ ÷ ] [ ÷ ] [ RCL ] [ 3 ] [ = ]
6. Use slope (m) and intercept (b) to predict x and y values:
y’ = m * x0 + b
Keystrokes: [ RCL ] [ 1 ] [ × ] x0 [ + ] [ RCL ] [ 2 ] [ = ]
x’ = (y0 – b) / m
Keystrokes: [ ( ] y0 [ - ] [ RCL ] [ 2 ] [ ) ] [ ÷ ] [ RCL ] [ 1 ] [ = ]
Key Map
[ RCL ] [ 1 ]: first Σxy, then m
[ RCL ] [ 2 ]: first y-bar, then b
[ RCL ] [ 3 ]: σy
[ 2^{nd} ] [ x^2 ]: x-bar
[ 2^{nd} ] [ ÷ ]: σxn
Example
Fit a line to the data:
X |
Y |
12 |
100 |
13 |
98.7 |
14 |
97.1 |
16 |
94.9 |
18 |
92.6 |
20 |
90 |
1. Enter the y data. Store the mean (y-bar) into memory register 2. Store the population deviation (σy) into memory register 3.
100 [ Σ+ ]
98.7 [ Σ+ ]
97.1 [ Σ+ ]
94.9 [ Σ+ ]
92.6 [ Σ+ ]
90 [ Σ+ ] (display n = 6)
Mean of y-data: [ 2^{nd} ] [ x^2 ] [ STO ] [ 2 ] (y-bar = 95.55)
Population of y-data: [ 2^{nd} ] [ ÷ ] [ STO ] [ 3 ] (σy = 3.465424457)
2. Clear the stat registers and enter the x data. As we are entering the x data, use memory register 1 to calculate Σxy.
Keystrokes:
Clear Stat Registers: [ 2^{nd} ] [ 7 ] {CSR}
12 [ × ] 100 [ = ] [ STO ] [ 1 ]
12 [ Σ+ ]
13 [ × ] 98.7 [ = ] [ 2^{nd} ] [ RCL ] [ 1 ] (SUM 1)
13 [ Σ+ ]
14 [ × ] 97.1 [ = ] [ 2^{nd} ] [ RCL ] [ 1 ] (SUM 1)
14 [ Σ+ ]
16 [ × ] 94.9 [ = ] [ 2^{nd} ] [ RCL ] [ 1 ] (SUM 1)
16 [ Σ+ ]
18 [ × ] 92.6 [ = ] [ 2^{nd} ] [ RCL ] [ 1 ] (SUM 1)
18 [ Σ+ ]
20 [ × ] 90 [ = ] [ 2^{nd} ] [ RCL ] [ 1 ] (SUM 1)
20 [ Σ+ ]
RCL 1: Σxy = 8827.7
[ 2^{nd} ] [ x^2 ]: x-bar = 15.5
3. Calculate the slope, and replace Σxy with the slope.
[ ( ] [ RCL ] [ 2 ] [ × ] [ 2^{nd} ] [ ( ] [ - ] [ RCL ] [ 1 ] [ ) ]
[ ÷ ] [ ( ] [ 2^{nd} ] [ x^2 ] [ × ] [ 2^{nd} ] [ ( ] [ - ] [ 2^{nd} ] [ ) ] [ = ] [ STO ] [ 1 ]
Slope: m = -1.230526316
4. Calculate the y-intercept, replace y-bar with the y-intercept.
[ RCL ] [ 1 ] [ +/- ] [ × ] [ 2^{nd} ] [ x^2 ] [ + ] [ RCL ] [ 2 ] [ = ] [ STO ] [ 2 ]
Intercept: b = 114.6231579
5. Calculate the correlation.
[ RCL ] [ 1 ] [ × ] [ 2^{nd} ] [ ÷ ] [ ÷ ] [ RCL ] [ 3 ] [ = ]
Correlation: r = -0.999092386
The line is:
y = -1.230526316 * x + 114.6231579
6. Predict values.
If x = 15, predict the y value (y’):
[ RCL ] [ 1 ] [ × ] x0 [ + ] [ RCL ] [ 2 ] [ = ]
y’ = 96.16526316
If y = 95, predict the x value (x’):
[ ( ] y0 [ - ] [ RCL ] [ 2 ] [ ) ] [ ÷ ] [ RCL ] [ 1 ] [ = ]
x’ = 15.94696322
Source
Alley, Chris M., Brenda M. Cornitius, et al. TI-36 Solar Guidebook Texas Instruments Incorporated. Dallas, TX. 1985, 1986, 1987. pp. 4.6 – 4.13
Eddie
All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.