HP Forums
hp41 howto do simple linear regression? - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: hp41 howto do simple linear regression? (/thread-25206.html)



hp41 howto do simple linear regression? - David E - 12-17-2002

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? - Dave Shaffer (Arizona) - 12-17-2002

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? - Vieira, Luiz C. (Brazil) - 12-17-2002

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: hp41 howto do simple linear regression? - David - 12-17-2002

Boy, that scares me just looking at it. lol. maybe i will try to write a prog for that.

thanks


Re: hp42s how to operate it, do simple math - Kenneth - 12-17-2002

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: hp41 howto do simple linear regression? - Mike (Stgt) - 12-18-2002

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? - Vieira, Luiz C. (Brazil) - 12-18-2002

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? - Mike (Stgt) - 12-18-2002

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


Re: hp41 howto do simple linear regression? - Mike (Stgt) - 12-18-2002

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: hp42s how to operate it, do simple math - Richard Garner - 12-18-2002

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 response - Tom (UK) - 12-19-2002

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.