hp-41c regression program generator

19
HP-41C Regression Program Generator Presented by Namir Shammas 1

Upload: emery

Post on 08-Jan-2016

25 views

Category:

Documents


3 download

DESCRIPTION

HP-41C Regression Program Generator. Presented by Namir Shammas. William Kolb’s Book. Kolb published a book in 1982 titled Curve Fitting for Programmable Calculators. Aimed at HP-41C programmers. Presented a wide and comprehensive set of regression models. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: HP-41C Regression Program Generator

1

HP-41C Regression Program Generator

Presented by

Namir Shammas

Page 2: HP-41C Regression Program Generator

2

William Kolb’s Book• Kolb published a book in 1982 titled Curve Fitting for

Programmable Calculators.• Aimed at HP-41C programmers.• Presented a wide and comprehensive set of regression models.• Used a special register-numbering scheme to store statistical

summations for different variables and different transformations.

• Scheme allowed to select best curve fit without re-entering or reprocessing input data.

Page 3: HP-41C Regression Program Generator

3

William Kolb’s Book (cont.)

• Presented equations to calculate regression coefficients in terms of memory registers.

• I was interested in the programs that did basic multiple regression for two and three independent variables.

• Did not want to adhere by Kolb’s register numbering scheme.• Decide to write an Excel application and have the VBA code write

documented HP-41C programs for multiple regression.• The Excel application would support user-defined register indices

for the statistical summations.• Also supports linear and polynomial curve fitting models.

Page 4: HP-41C Regression Program Generator

4

Typical WorksheetSum X 1 Model Z^zp = a + b X^xp + c Y^ypSum X^2 2 Output Filename MLR22.Out.txtSum Y 3 Include Comments? YesSum Y^2 4Sum X*Y 5N 6Sum Z 7Sum Z^2 8Sum X*Z 9Sum Y*Z 10Sxx 11Syz 12Sxy 13Sxz 14Syy 15a 16b 17c 18R-sqr 19R-sqr adj 20X 16Y 17Z 18Xtemp 19Ytemp 20Ztemp 21Xpower 22Ypower 23Zpower 24

Page 5: HP-41C Regression Program Generator

5

App Worksheets• App that generates HP-41C regression programs uses a

consistent and simple interface for the different regression models.

• Column A lists the names of statistical summations, variables used to store intermediate results, coefficients of determination (R2), adjusted R2, input values, and transformed input values.

• Column B contains the new register indices for the names in column A

Page 6: HP-41C Regression Program Generator

6

App Worksheets (cont.)

• Cell D1 contains the regression model supported by that worksheet.

• Cell D2 store the name of the output file. You are welcome to change that filename as you see fit.

• Cell D3 allows you to specify whether or not to include comments in the HP-41C listing. Excluding comments makes it easier to compile the listing’s text to create a .raw file that run on certain HP-41C emulators.

Page 7: HP-41C Regression Program Generator

7

App Worksheets (cont.)

• Linear regression set:• LR worksheet handles general linear regression. Label 00 allows

you to include your own custom transformations for the variables.• LR2 worksheet handles special regression model using the model

Y^yp = a + b*X^xp. The values for the powers can be positive, negative (as long as they do not generate runtime errors), and zero (which is translated as taking the natural logarithm).

• LR3 worksheet handles a power fit.

Page 8: HP-41C Regression Program Generator

8

App Worksheets (cont.)

• Multiple linear regression set for two independent variables:• MLR2 worksheet handles general multiple linear regression. Label

00 allows you to include your own custom transformations for the variables.

• MLR22 worksheet handles special regression model using the model Z^zp = a + b*X^xp + c*Y^yp.

• MLR23 worksheet handles a multiple power fit.

Page 9: HP-41C Regression Program Generator

9

App Worksheets (cont.)

• Multiple linear regression set for three independent variables:• MLR3 worksheet handles general multiple linear regression. Label

00 allows you to include your own custom transformations for the variables.

• MLR32 worksheet handles special regression model using the model T^tp = a + b*X^xp + c*Y^yp + d*Z^zp.

• MLR33 worksheet handles a multiple power fit.

Page 10: HP-41C Regression Program Generator

10

App Worksheets (cont.)

• Polynomial regression set for two variables:• Poly2 worksheet handles quadratic regression. The VBA code for

this worksheet is based on that of MLR2.• Poly3 worksheet handles cubic regression. The VBA code for this

worksheet is based on that of MLR3.

Page 11: HP-41C Regression Program Generator

11

Notes of the VBA Code

• The various Make41Prgm_xxx subroutines contain HP-41C meta-code programs stored as strings of comma-delimited commands.

• The subroutines use multiple statements to build the meta-code before translating it into readable HP-41C statements.

• The subroutines builds an array of records, each storing the name of a program variable, its new register index, and the register index that appeared in Kolb’s book. I have added a few records with my own version of the “Kolb indices” since I needed a complete list of variables that appear in the final HP-41C programs

Page 12: HP-41C Regression Program Generator

12

Notes of the VBA Code

• The subroutines use variable Listing to build the HP-41C meta-code.

• The intended HP-41C statements are separated by commas.• The meta-code uses the letters, s, s+, s-, s*, s/, r, and a as

abbreviations for STO, ST+, ST-, ST*, ST/, RCL, and ARCL statements. These abbreviations trigger the register index mapping and shorten the length of the internal HP-41C program listing.

• In many cases, the VBA source code uses the register indices that appear in Kolb’s book. I have added registers when necessary.

Page 13: HP-41C Regression Program Generator

13

Notes of the VBA Code

• If you want to store and recall values using or in a stack register, you must enter their commands as they appear in the generated HP-41C program.

• You can insert a comment that must start with # in a separate string that appears, after the meta-code that you intent to comment. This comment must appear as a separate comma-delimited meta-command.

Page 14: HP-41C Regression Program Generator

14

Notes of the VBA Code

• The alpha strings start with a single quote. A closing single quote is optional. The VBA program will enclose alpha strings in double quote.

• You can use the characters |- followed by a single quote to append text. A closing single quote is optional.

• Labels, GTO, and XEQ statements that use alphanumeric label names must have these names begin with a single quote. A closing single quote is optional.

• All other HP-41C commands must appear as in their normal name and syntax.

Page 15: HP-41C Regression Program Generator

15

User Interface1. Press [f][A] to clear all registers. In the case of programs

generated by subroutines Make41Prgm_LR2, Make41Prgm_MLR22, and Make41Prgm_MLR32, the HP-41C programs prompt you for the powers used to raise the regression variables. The power of zero is interpreted as a request to calculate the natural logarithm.

2. Press [A] to add the values for an observation point. The program will prompt you to enter the values for the observations.

Page 16: HP-41C Regression Program Generator

16

User Interface3. Press [B] to delete the values for an observation point. The

program will prompt you to enter the values for the observations to be deleted. If you want to delete the last observation you entered in step 2, just press [f][B] to perform this task without re-entering data. The HP-41C programs use flag 00 to make sure that pressing the keys [f][B] delete the last input data only once.

Page 17: HP-41C Regression Program Generator

17

User Interface4. Press [C] to perform the statistical calculations and view the

regression coefficients, the coefficient of determination (R2), and its adjusted value.

5. Press [f][C] to review the results in step 4.

Page 18: HP-41C Regression Program Generator

18

Output• Regression model (as it appears in worksheet).• Memory map (as it appears in worksheet).• HP-41C listing.

Page 19: HP-41C Regression Program Generator

19

Thank You!