The Museum of HP Calculators

HP Forum Archive 09

 hp41 howto do simple linear regression?Message #1 Posted by David E on 17 Dec 2002, 7:17 p.m. HI. I have the stat pac for hp41, and neither of the linear regressions sets seems to do what I need. I need something that I can input my data (x and y) and from that get R, slope, and y (y=mx+b). Thanks for any guidance .

 Re: hp41 howto do simple linear regression?Message #2 Posted by Dave Shaffer on 17 Dec 2002, 8:02 p.m.,in response to message #1 by David E Well, David, you can always do it the semi-hard way - with just the '41 itself. If you use the sigma+ button (top left on the keypad)(after clearing the summation registers using the CLSigma button - shift x<>y key, just below the sigma+ key), you can accumulate the sums of x, x^2, y, y^2, and xy in memory registers 11 through 15 respectively, while register 16 will get the value of n (the number of x,y pairs). To put in your numbers, enter y first, then "ENTER", and then enter your x value - then hit the sigma+ key. After you have entered all you pairs of values, you need to remember (or be told - or, left as an exercise for the student, derive!) the least-squares fitting expressions for slope, intercept, and correlation coefficient. In case you are rusty: the slope is (n*SUMxy - SUMx*Sumy)/(n*SUMx^2 - (Sumx)^2) the intercept has the numerator SUMy*SUMx^2 - SUMxy*SUMx (with the same denominator as for the slope) r is (n*SUMXY - SUMx*SUMy) / ( SQRT(n*SUMx^2 - (SUMx)^2) * SQRT(n*SUMy^2 - (SUMy)^2) ) I hope my notation is clear. SUMx means the summation of x, and (SUMx)^2 means to square this sum (whereas SUMx^2 means the summation of x-squared). Have fun.

 Re: hp41 howto do simple linear regression?Message #3 Posted by David on 17 Dec 2002, 9:45 p.m.,in response to message #2 by Dave Shaffer Boy, that scares me just looking at it. lol. maybe i will try to write a prog for that. thanks

 Re: hp41 howto do simple linear regression?Message #4 Posted by Mike (Stgt) on 18 Dec 2002, 10:07 a.m.,in response to message #3 by David Citation from Dave's append: "After you have entered all you pairs of values, you need to remember (or be told - or, left as an exercise for the student, derive!) the least-squares fitting expressions for slope, intercept, and correlation coefficient." To ease the exercise for the student just take the values of X as free of error. My little (basic) routine is based on this assumption. Next step in students exercise would be to take Y values for true and the fault is in X :-) And if you have some time and piles of paper left, just take X as faulty as Y ;-) Ciao.....Mike

 Re: hp41 howto do simple linear regression?Message #5 Posted by Vieira, Luiz C. (Brazil) on 17 Dec 2002, 9:40 p.m.,in response to message #1 by David E Hi; Dave Shaffer's post contains ALL information you need, but you can do it in the "easy way" by using the STAT pack programs. Get your Stat Pack manual and open it on page 32, under "Curve Fitting". On page 33, top left, you'll see your Y = a + bX expression. Now go to page 34 and you'll see that you should [XEQ] [SIGMA]LIN program for a straight line sample (or any of the other three: LOG, EXP or POW), being [SIGMA] the summation symbol. You should enter each pair in the REVERSED orther (why do some applications are against Y and X registers?), say:` X [ENTER^] Y [A]` for each pair; to correct any mistakes:` X [ENTER^] Y [C]` After the last (x,y) pair, simply press [E] and you'll have:``` R2 = (corr. coef.) [R/S] a = (intercept) [R/S] b = (slope)``` Hope this is waht you want. BUT if you really want to know the mechanics, read D. Shaffer's post. It is complete reference. Success.

 Re: hp42s how to operate it, do simple mathMessage #6 Posted by Kenneth on 17 Dec 2002, 11:10 p.m.,in response to message #5 by Vieira, Luiz C. (Brazil) hi i'm trying to operate my 42s rpn scietific and i can't do a simple problem with it, i don't have a manual or instructions on how to operate it can you help me?

 Re: hp42s how to operate it, do simple mathMessage #7 Posted by Richard Garner on 18 Dec 2002, 1:32 p.m.,in response to message #6 by Kenneth Here is a quick primer 4+5=9 4 Enter 5 + (4+5)x10=90 4 Enter 5 + 10 x (4+5)/3=3 4 Enter 5 + 3 / I hope this helps. Depending on how the numbers are set in the stack, you can load the stack with you numbers and the perform the operations all at once. As in (4x5)+7=27 7 Enter 5 Enter 4 x + Have fun.

 Re: hp42s how to operate it, do simple math - a light hearted responseMessage #8 Posted by Tom (UK) on 19 Dec 2002, 1:02 p.m.,in response to message #6 by Kenneth The HP42S is a tricky beast to master, and much harder without the manual. Best thing to do is pop it in the post to me and I'll return a much easier to use calculator in exchange... how about a Casio FX580? But seriously: The HP42S is a nice tool, once you have mastered it (doesn't take long) you will wonder how you got along without it. To start using it this site has a brief introduction on RPN. To get a manual buy the DVD/CD's from this web site, it will be well worth it in the long run.

 Re: hp41 howto do simple linear regression?Message #9 Posted by Mike (Stgt) on 18 Dec 2002, 7:34 a.m.,in response to message #1 by David E I just did an 'edit/copy-edit/paste' from my emulator on the IBM-host, so the § stands for Sigma: ```01·LBL "§" 02 §REG 10 03 CL§ 04 MEAN 05 X<>Y 06 RCL 10 07 ST* Z 08 * 09 RCL 14 10 - 11 X<>Y 12 RCL 11 13 - 14 / 15 STO 04 16 MEAN 17 LASTX 18 * 19 - 20 STO 05 21 RCL 04 22 STOP 23 SDEV 24 RCL 04 25 * 26 X<>Y 27 / 28 END ``` That's the minimum code, to make life easier just use the Alpha capabilities of the HP-41 and add some literals and prompts. Ciao.....Mike

 Re: hp41 howto do simple linear regression?Message #10 Posted by Vieira, Luiz C. (Brazil) on 18 Dec 2002, 9:02 a.m.,in response to message #9 by Mike (Stgt) Hi; I did not load the program and run it, but I am curious about one sequence: CL§ and MEAN. How can you compute MEAN if CL§ clears all statistic data? As you change the §REGS to R10 instead of original R16 and you execute CL§, I thought you created a buffer to compute partial data and return to §REG 16 before using MEAN. But right after that you clear statistic data and execute MEAN with all registers down to zero. Is that what you want? Did I miss something? If I am wrong, sorry. I just want to understand. Cheers.

 Re: hp41 howto do simple linear regression?Message #11 Posted by Mike (Stgt) on 18 Dec 2002, 9:44 a.m.,in response to message #10 by Vieira, Luiz C. (Brazil) No, you did not miss something. I gave no clear explanation. This is my LinReg prgm that fits in every HP-41, independent what other BIG routines use up all memory. There are no literals and no prompts to ease the user input and result output. After line 03 you may add the two lines "Y enter X §+" PROMPT. Without it you just see DATA ERROR and must know that this is the point to enter data. Ciao.....Mike

Go back to the main exhibit hall