Post Reply 
[HP-12C] Angular coefficent from linear regression off by 1
05-01-2016, 11:23 AM (This post was last modified: 05-02-2016 12:08 AM by Marcio.)
Post: #1
[HP-12C] Angular coefficent from linear regression off by 1
While doing linear regression on the 12C, I noticed the last digit of the angular coefficient is usually off by 1. Does anyone know why? I thought the 12C used the same algorithm as the 15C.

Example:
Code:

x       y
0.00    1.0
0.15    2.1
0.45    3.9
0.83    8.1
1.12    14

The 15C will return y=0.159340862+11.09933164. The 12C gives ...165 instead.

Thank you.
Find all posts by this user
Quote this message in a reply
05-01-2016, 07:12 PM
Post: #2
RE: HP-15C and 12C give different results to the same data set
My HP-38C, predecessor to the HP-12C (12C is modeled after the 38C) also gives 11.09933165. However my iPhone emulator of the 38C, which carries 15 or 16 digit accuracy yields 11.09933164.


Regards,
Bob
Find all posts by this user
Quote this message in a reply
05-01-2016, 11:37 PM
Post: #3
RE: [HP-12C] 9-digit angular coefficent from linear regression off by 1
(05-01-2016 07:12 PM)bshoring Wrote:  My HP-38C, predecessor to the HP-12C (12C is modeled after the 38C) also gives 11.09933165. However my iPhone emulator of the 38C, which carries 15 or 16 digit accuracy yields 11.09933164.

Hmm... in this case all variables of the equation for calculating the regression slope (i.e. the various sums accumulated by Σ+) have at most five significant digits. So the result can be calculated exactly even with merely 10 digits, while both the 38C and the 12C should use 13 digits internally.

Using the formulas in the 15C manual, the exact result for the slope of the given data is 48,16 : 4,339 which any HP should be able to calculate exactly. ;-) So something else must be going on here.

Dieter
Find all posts by this user
Quote this message in a reply
05-02-2016, 11:16 AM
Post: #4
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-01-2016 11:37 PM)Dieter Wrote:  Using the formulas in the 15C manual, the exact result for the slope of the given data is 48,16 : 4,339 which any HP should be able to calculate exactly. ;-) So something else must be going on here.

Dieter
Can't say it's a bug in the new firmware because the 38C also has it.
HP powered this machine on an air-plane engine. The thing is faster than speed of light. I wonder what the battery (2x CR2032) consumption is like, though.
It still has the double-registering problem but that seems to be fading as I use it.

Marcio
Find all posts by this user
Quote this message in a reply
05-02-2016, 11:48 AM
Post: #5
RE: [HP-12C] Angular coefficent from linear regression off by 1
I don't know either the 12C or the 15C very well but I have emulators on my phone ;-)

So, correct me if I'm wrong, but the 12C doesn't have linear regression as a function, just x-intercept and y-intercept. So you calculate the slope in two steps:
y | x=1 minus y | x=0

or

1 g(y,r) (11.25867251)
0 g(y,r) (0.15934086.19)
X<>Y
RDN
-

If you do the same on a 15C, you get the same result. But a 15C has a f(L.R.)
function delivering the result without 10-digit intermediate calculations. Hence the difference.

Cheers, Werner
Find all posts by this user
Quote this message in a reply
05-02-2016, 12:09 PM
Post: #6
RE: [HP-12C] Angular coefficent from linear regression off by 1
You nailed it.

Thank you.
Find all posts by this user
Quote this message in a reply
05-02-2016, 12:30 PM
Post: #7
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-02-2016 12:09 PM)Marcio Wrote:  You nailed it.

OK – so you did a manual calculation to obtain slope and intercept. This was not clear to me reading your first post where you said that "the 12C used the same algorithm as the 15C". That's why I expected the 12C to offer a built-in L.R. function, like the 15C. In fact the 12C manual suggests a manual method similar to Werner's to obtain the two coefficients. This of course explains why the result may be off by a ULP or two. #-)

Now, what about a short program that calculates slope and intercept directly from the sums in R1...R6 ?-)

Dieter
Find all posts by this user
Quote this message in a reply
05-02-2016, 02:50 PM (This post was last modified: 05-02-2016 06:29 PM by Werner.)
Post: #8
RE: [HP-12C] Angular coefficent from linear regression off by 1
Something like this?

Code:
 RCL 6
 RCL 1
 x
 RCL 2
 RCL 4
 x
 -
 RCL 3
 RCL 1
 x
 RCL 2
 ENTER
 x
 -
 STO 0
 /
 RCL 4
 RCL 3
 x
 RCL 6
 RCL 2
 x 
 -
 RCL 0
 /
 R/S

Cheers, Werner
Find all posts by this user
Quote this message in a reply
05-03-2016, 11:56 AM
Post: #9
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-02-2016 02:50 PM)Werner Wrote:  Something like this?

Sort of, yes. ;-)

After you posted your code I wanted to add an improved version, but you were faster. Personally, I would prefer the slope returned in X and the y-intercept in Y, but this can be changed easily.

On the other hand your code returns the results the same way as my good old 34C (and maybe other HPs as well). BTW the 34C shows the correct slope: 11,09933164. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
05-03-2016, 12:14 PM
Post: #10
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-02-2016 11:16 AM)Marcio Wrote:  HP powered this machine on an air-plane engine. The thing is faster than speed of light. I wonder what the battery (2x CR2032) consumption is like, though.

I guess you mean the new ARM powered version? I have a 3 battery 12C from the 1980s and the batteries last about 10 years...

It ain't OVER 'till it's 2 PICK
Find all posts by this user
Quote this message in a reply
05-03-2016, 12:37 PM
Post: #11
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-03-2016 12:14 PM)HP67 Wrote:  
(05-02-2016 11:16 AM)Marcio Wrote:  HP powered this machine on an air-plane engine. The thing is faster than speed of light. I wonder what the battery (2x CR2032) consumption is like, though.

I guess you mean the new ARM powered version? I have a 3 battery 12C from the 1980s and the batteries last about 10 years...

I think so. The 12C I have is one of the most recent, guessing from 2009. I bought it to save wear on my near-mint 15C.
The keys will double-register sometimes and the labels are painted on. The display is not very good quality either, read somewhere that life expectancy is about 3-4 years if used daily. Replacing batteries once a year is fine with me.
We'll see.
Find all posts by this user
Quote this message in a reply
05-03-2016, 01:01 PM
Post: #12
RE: [HP-12C] Angular coefficent from linear regression off by 1
I haven't heard of the new 12Cs key bouncing. That's unfortunate. I wonder if there is a key delay function like on some other ARM powered HP calcs.

It ain't OVER 'till it's 2 PICK
Find all posts by this user
Quote this message in a reply
05-03-2016, 01:20 PM
Post: #13
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-03-2016 01:01 PM)HP67 Wrote:  I haven't heard of the new 12Cs key bouncing. That's unfortunate. I wonder if there is a key delay function like on some other ARM powered HP calcs.

No, there is no such function on the voyagers.
Unfortunate indeed, and yes, it is common. I also heard that 12-15% of 15C LE units produced suffer from the same double-registering problem.
Guess youd have to be lucky. Still, very nice little calc with a good amount of scientific functions. L.R. is the one I use the most.
Find all posts by this user
Quote this message in a reply
05-03-2016, 01:33 PM
Post: #14
RE: [HP-12C] Angular coefficent from linear regression off by 1
I knew that Voyagers don't have it. I meant the newer ARM versions running emulation. Since they added a few other tricks I thought maybe it was supported. If it bothers you maybe you can pick up a pre ARM 12C. They're just wonderful, wonderful calculators. Mine paid for itself the day I bought it. I have no idea how available/expensive they are on the used market. One one hand I can't imagine anyone parting with one. On the other hand many people want the latest and greatest model and don't like old stuff.

It ain't OVER 'till it's 2 PICK
Find all posts by this user
Quote this message in a reply
05-03-2016, 01:49 PM
Post: #15
RE: [HP-12C] Angular coefficent from linear regression off by 1
The old ones are the best. Smile

I missed the opportunity to buy a 11C in good condition for the equivalent to US$60 (shipping included) from the same auction site I bought the ARM powered 12C I have now.

I've been kicking myself since then.
Find all posts by this user
Quote this message in a reply
05-03-2016, 01:59 PM
Post: #16
RE: [HP-12C] Angular coefficent from linear regression off by 1
Well, hang in there and you'll probably get lucky.

I'm kicking myself for not buying a 41CX back in the day. I didn't have the money for both at the time so I bought an HP 67 and never regretted the choice. Still, I would love to have a 41 and it looks unlikely now. But we never know.

It ain't OVER 'till it's 2 PICK
Find all posts by this user
Quote this message in a reply
05-05-2016, 07:07 AM
Post: #17
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-03-2016 11:56 AM)Dieter Wrote:  
(05-02-2016 02:50 PM)Werner Wrote:  Something like this?
... an improved version...

Something like this? Smile


01: 0
02: g y,r
03: x<>y
04: g s
05: ÷
06: ×
07: R/S


Csaba
Find all posts by this user
Quote this message in a reply
05-06-2016, 07:50 AM
Post: #18
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-05-2016 07:07 AM)Csaba Tizedes Wrote:  
(05-03-2016 11:56 AM)Dieter Wrote:  ... an improved version...

Something like this? Smile


01: 0
02: g y,r
03: x<>y
04: g s
05: ÷
06: ×
07: R/S


Csaba

Hey, guys, what's the problem? This is the greatest improvement since the sliced bread. Far better than muck about those registers and better than the "classic" solution from the Owner's Handbook. 6 steps only.

OK, I have a big face, but I'm groved up here (MoHPC), and I can remember the discussions at the 2000's. And yes, I'm not really clever, just googled the simple linear regression on Wikipedia - but really missing those clever discussions like 15 years before...

BTW: the result is 11.09933164 and 0.1593408619. I don't know it is good for you or not...

Csaba

PS.: and yes, I know you're will reflect only my words, not my 6 steps solution... Sad That is exactly what I want to say...
Find all posts by this user
Quote this message in a reply
05-06-2016, 01:11 PM
Post: #19
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-06-2016 07:50 AM)Csaba Tizedes Wrote:  [ 6-step solution using r and s ]
BTW: the result is 11.09933164 and 0.1593408619. I don't know it is good for you or not...

In this particular case it's good enough of course, as this is the exact 10-digit result. ;-)

The method you suggested is short and elegant. However, it uses the regression coefficient and the two standard deviations, where all three are internally calculated using square roots. That's why this method is prone to slight errors in the last digit, just as the method suggested in the manual.

And that's why the suggested direct solution using the six registers is inherently more exact. As long as these data do not have too many significant digits (which usually is the case with empirical data) the results are exact. Even in the last digit. ;-)

So you can choose between a shorter and a potentially more exact solution.

Dieter
Find all posts by this user
Quote this message in a reply
05-06-2016, 01:55 PM
Post: #20
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-03-2016 01:20 PM)Marcio Wrote:  I also heard that 12-15% of 15C LE units produced suffer from the same double-registering problem.
My bet would be 100%. The de-bouncing algorithm just doesn't work, and it's the same in all 15C LEs. If it repeats an entry, which is rare but happens, you immediately see e.g. the two numbers in the display. It appears to me the emulation executes the original 15C de-bouncing code, disregarding the higher speed of the ARM-hardware.

Tim?
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)