The Museum of HP Calculators

Multiple Linear Regression for the HP-67

This program is Copyright © 1976 by Hewlett-Packard and is used here by permission. This program was originally published in the HP-67 Stat Pac 1.

This program is supplied without representation or warranty of any kind. Hewlett-Packard Company and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

 Multiple Linear Regression Shift ->R2 x^y->est z ->xi... ->xi2... ->xiyi:... Label Start P? xi^...(+) xk^...(-) ->a:b:c Key A B C D E

Overview

For a set of data points {(xi, yi, zi,), i = 1, 2, ..., n} this program fits a linear equation of the form

z = a + bx + cy

by the least squares method. Regression coefficients a, b, c can be found by solving the normal equations:

zi = an + bxi + cyi
xizi = axi + bxi2 + cxiyi
yizi = ayi + bxiyi + cyi2
(i = 1, 2, ..., n)

c = (A-B)/[nxi2 - (xi)2][nyi2 - (yi)2] - [nxiyi - (xi)(yi)]2

where

A = [nxi2 - (xi)2] [nsum yizi - (yi)(xi)]

B = [nxiyi - (xi)(yi)][nxizi - (xi)(zi)]

b = ([nxizi - (xi) (zi)] - c[nxiyi - (xi)(yi)])/(nxi2 - (xi)2)

a = (zi - cyi - bxi)/n

R2 = [azi + bxizi + cyizi - (zi)2/n]/[zi2 -(zi)2/n]

Reference: Introduction to the Theory of Statistics Mood and Graybill McGraw-Hill 1963

Instructions

 Step Instructions Input Data/Units Keys Output Data/Units 1 Load side 1 and side 2. 2 Initialize A 0.00 3 To set print mode* B 1.00 4 Do 5~6 for i = 1,2,...,n 5 Input xi xi ENTER yi yi ENTER zi zi C i 6 If you made a mistake in inputting xk, yk, and zk, then correct by --> xk ENTER yk yk ENTER zk zk D i-1 7 Calculate coefficients: a E a b R/S b c R/S c 8 Calculate the square of multiple correlation coefficient R2 f A R2 9 Calculate estimated z from regression, input: x x ENTER y y f B est. z 10 Repeat step 9 for different (x,y)'s 11 Recall sums: xi f C xi yi R/S yi zi R/S zi 12 Recall sums of squares: xi2 f D xi2 yi R/S yi2 zi R/S zi2 13 Recall sums of cross products: xiyi f E xiyi xizi R/S xizi yizi R/S yizi For a new case, go to 2 *Note: To clear the print mode press --> CLF 0

Example

A set of data points are given as the following

```     1    2     3    4
xi  1.5  0.45  1.8  2.8
yi  0.7  2.3   1.6  4.5
zi  2.1  4.0   4.1  9.4
```

Find the regression line, coefficients a, b, c, R2, est. z, sums, sums of squares, and sums of products.

Keystrokes Outputs

```A                                0.00
B                                1.00
1.5 ENTER 0.7 ENTER 2.1 C        1.50 ***
0.70 ***
2.10 ***
1.00 ***

9 ENTER 9 ENTER 9 C              9.00 ***
9.00 *** (error)
9.00 ***
2.00 ***

9 ENTER 9 ENTER 9 D              9.00 ***
9.00 ***  (correction)
9.00 ***
1.00 ***

0.45 ENTER 2.3 ENTER 4 C         0.45 ***
2.30 ***
4.00 ***
2.00 ***

1.8 ENTER 1.6 ENTER 4.1 C        1.80 ***
1.60 ***
4.10 ***
3.00 ***

2.8 ENTER 4.5 ENTER 9.4 C        2.80 ***
4.50 ***
9.40 ***
4.00 ***

E                               -0.10 *** (a)
R/S                              0.79 *** (b)
R/S                              1.63 *** (c)

f A                              1.00 *** (R2)
DSP 9 PRINTx                     0.998411259 ***
DSP 2 2 ENTER 3 f B              2.00 ***
3.00 ***
6.37 *** (est. z)

f C                              6.55 *** (xi)
R/S                              9.10 *** (yi)
R/S                             19.60 *** (zi)
f D                             13.53 *** (xi2)
R/S                             28.59 *** (yi2)
R/S                            125.58 *** (zi2)
f E                             17.57 *** (xiyi)
R/S                             38.65 *** (xizi)
R/S                             59.53 *** (yizi)

Regression line is
z = -0.10 + 0.79x + 1.63y

For x = 2 and y = 3, est. z = 6.37
```

The Program

```LINE  KEYS
001  *LBL A     Initialize
002   CL REG
003   CF 0
004   CF 1
005   0
006   RTN
007  *LBL C
008   STO C
009   roll dn
010   STO B
011   roll dn
012   STO A
013   GSB 7
014   7
015   STO I
016   roll dn   Input Xi, Yi, Zi.
017   GSB 1
018   8
019   STO I
020   RCL B     Compute Xi, Yi, Zi, Xi2, Yi2
021   GSB 9     Zi2, XiYi, YiZi, ZiXi.
022   GSB 1
023   9
024   STO I
025   RCL C
026   GSB 9
027   GSB 1
028   RCL A
029   RCL B
030   x
031   GSB 2
032   STO + 1
033   RCL A
034   RCL C
035   x
036   GSB 2
037   STO + 2
038   RCL B
039   RCL C
040   x
041   GSB 2
042   STO + 3
043   1
044   GSB 2
045   STO + 0
046   RCL 0
047   GSB 9
048   RTN
049  *LBL 1
050   GSB 2     Subroutine for Xi, Xi2, ...
051   STO + (i)
052   RCL I
053   3
054   -
055   STO I
056   roll dn
057   X2
058   GSB 2
059   STO + (i)
060   RTN
061  *LBL E
062   RCL 0
063   RCL 4
064   x
065   RCL 7
066   X2
067   -
068   STO D
069   RCL 0
070   RCL 3
071   x
072   RCL 8
073   RCL 9
074   x
075   -
076   x
077   STO C
078   RCL 0     Calculating a, b, c
079   RCL 1
080   x
081   RCL 7
082   RCL 8
083   x
084   -
085   STO A
086   RCL 0
087   RCL 2
088   x
089   RCL 7
090   RCL 9
091   x
092   -
093   STO B
094   x
095   RCL C
096   X<>Y
097   -
098   RCL D
099   RCL 0
100   RCL 5
101   x
102   RCL 8
103   X2
104   -
105   x
106   RCL A
107   X2
108   -
109   ÷
110   STO C
111   RCL B
112   RCL A
113   RCL C
114   x
115   -
116   RCL D
117   ÷
118   STO B
119   RCL 9
120   RCL C
121   RCL 8
122   x
123   -
124   RCL B
125   RCL 7
126   x
127   -
128   RCL 0
129   ÷         a
130   STO A
131   GSB 7
132   R/S       b
133   RCL B
134   GSB 9
135   R/S       c
136   RCL C
137   GSB 9
138   R/S
139  *LBL a
140   RCL A
141   RCL 9
142   x
143   RCL B
144   RCL 2
145   x
146   +
147   RCL C
148   RCL 3     Calculating R2
149   x
150   +
151   RCL 9
152   X2
153   RCL 0
154   ÷
155   -
156   RCL 6
157   RCL 9
158   X2
159   RCL 0
160   ÷
161   -
162   ÷
163   GSB 7
164   RTN
165  *LBL b
166   X<>Y
167   GSB 7
168   X<>Y
169   GSB 9
170   ENTER     Calculating approximated z value for given x,y.
171   RCL C
172   x
173   X<>Y
174   RCL B
175   x
176   +
177   RCL A
178   +
179   GSB 9
180   RTN
181  *LBL c
182   F0?
183   PRT SPC   Xi, Yi, Zi.
184   6
185   STO I
186   GTO 8
187   RTN
188  *LBL d     Xi2, Yi2, Zi2.
189   3
190   STO I
191   GSB 8
192   RTN
193  *LBL e     XiYi, XiZi, YiZi
194   0
195   STO I
196   GSB 8
197   RTN
198  *LBL 8
199   ISZ I
200   RCL (i)
201   GSB 9     Print for  LBL a
202   R/S                  LBL b
203   GTO 8                LBL c
204   RTN
205  *LBL D
206   SF 1
207   GSB C
208   CF 1      For correction of Xk,Yk,Zk.
209   RTN
210  *LBL B
211   SF 0
212   1
213   RTN
214  *LBL 7     Set flag 0 for print.
215   F0?
216   PRT SPC
217  *LBL 9
218   F0?       Print Xi, Yi, Zi.
219   PRTX
220   RTN
221  *LBL 2
222   F1?       Change sign for correction.
223   CHS
224   RTN
```

Register Use

```R0  n
R1  XiYi
R2  XiZi
R3  YiZi
R4  Xi2
R5  Yi2
R6  Zi2
R7  Xi
R8  Yi
R9  Zi
A   used, a
B   used, b
C   Zi, B in b, c
D   n*Xj2-(Xj)2
E   n*Xi2 - (ij)2
```