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.

Card Labels
Multiple Linear Regression
Shift →R 2 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 + bΣxi + cΣyi
Σxizi = aΣxi + bΣxi2 + cΣxiyi
Σyizi = aΣyi + bΣxiyi + cΣyi2
        (i = 1, 2, ..., n)

c = (A-B)/[nΣxi2 - (Σxi)2][nΣyi2 - (Σyi)2] - [nΣxiyi - (Σxi)(Σyi)]2

where

A = [nΣxi2 - (Σxi)2] [nΣ yizi - (Σyi)(Σxi)]

B = [nΣxiyi - (Σxi)(Σyi)][nΣxizi - (Σxi)(Σzi)]

b = ([nΣxizi - (Σxi) (Σzi)] - c[nΣxiyi - (Σxi)(Σyi)])/(nΣxi2 - (Σxi)2)

a = (Σzi - cΣyi - bΣxi)/n

R2 = [aΣzi + bΣxizi + cΣyizi - (Σ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   R↓
010   STO B
011   R↓
012   STO A
013   GSB 7
014   7
015   STO I
016   R↓        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   ×
031   GSB 2
032   STO + 1
033   RCL A
034   RCL C
035   ×
036   GSB 2
037   STO + 2
038   RCL B
039   RCL C
040   ×
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   R↓
057   X2
058   GSB 2
059   STO + (i)
060   RTN
061  *LBL E
062   RCL 0
063   RCL 4
064   ×
065   RCL 7
066   X2
067   -
068   STO D
069   RCL 0
070   RCL 3
071   ×
072   RCL 8
073   RCL 9
074   ×
075   -
076   ×
077   STO C
078   RCL 0     Calculating a, b, c
079   RCL 1
080   ×
081   RCL 7
082   RCL 8
083   ×
084   -
085   STO A
086   RCL 0
087   RCL 2
088   ×
089   RCL 7
090   RCL 9
091   ×
092   -
093   STO B
094   ×
095   RCL C
096   X⇔Y
097   -
098   RCL D
099   RCL 0
100   RCL 5
101   ×
102   RCL 8
103   X2
104   -
105   ×
106   RCL A
107   X2
108   -
109   ÷
110   STO C
111   RCL B
112   RCL A
113   RCL C
114   ×
115   -
116   RCL D
117   ÷
118   STO B
119   RCL 9
120   RCL C
121   RCL 8
122   ×
123   -
124   RCL B
125   RCL 7
126   ×
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   ×
143   RCL B
144   RCL 2
145   ×
146   +
147   RCL C
148   RCL 3     Calculating R2
149   ×
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
171   RCL C     given x,y.
172   ×
173   X⇔Y
174   RCL B
175   ×
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

Go back to the software library
Go back to the main exhibit hall