Post Reply 
[HP-12C] Angular coefficent from linear regression off by 1
05-09-2016, 07:33 PM
Post: #21
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

This is amazing! I never knew you could do a linear regression this way. Thanks for enlightening me.


Regards,
Bob
Find all posts by this user
Quote this message in a reply
05-11-2016, 05:58 AM
Post: #22
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-09-2016 07:33 PM)bshoring Wrote:  This is amazing! I never knew you could do a linear regression this way. Thanks for enlightening me.

There are various options. For instance, you could also use  \(m = (\bar y-b)/\bar x\).

Dieter
Find all posts by this user
Quote this message in a reply
05-12-2016, 06:32 PM
Post: #23
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-11-2016 05:58 AM)Dieter Wrote:  
(05-09-2016 07:33 PM)bshoring Wrote:  This is amazing! I never knew you could do a linear regression this way. Thanks for enlightening me.

There are various options. For instance, you could also use  \(m = (\bar y-b)/\bar x\).

Dieter

How would I do that in RPN ?


Regards,
Bob
Find all posts by this user
Quote this message in a reply
05-12-2016, 10:05 PM
Post: #24
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-12-2016 06:32 PM)bshoring Wrote:  
(05-11-2016 05:58 AM)Dieter Wrote:  \(m = (\bar y-b)/\bar x\).
How would I do that in RPN ?

01: 0
02: g y,r
03: RCL 1
04: ×
05: CHS
06: RCL 4
07: +
08: RCL 2
09: ÷
10: R/S


The result is same: 11.09933164

The above equation for the fitted line means that the least squares method fits a line which is goes through the center of "gravity" of the data points. If you know that you'll never forget how simple to calculate slope of that line.

Csaba
Find all posts by this user
Quote this message in a reply
05-12-2016, 10:20 PM
Post: #25
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-06-2016 01:11 PM)Dieter Wrote:  ...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.

May I can spend a short time to check what does it mean in the regression coefficients if each data has a given relative error. Let's say the relative error approx. 1E-3 (=0.1%) in the engineering practice and we have n measuring points (n=5 ... n=9 typical number of data) what is the relative error of slope and intercept.

Csaba
Find all posts by this user
Quote this message in a reply
05-13-2016, 06:24 AM
Post: #26
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-12-2016 06:32 PM)bshoring Wrote:  
(05-11-2016 05:58 AM)Dieter Wrote:  There are various options. For instance, you could also use  \(m = (\bar y-b)/\bar x\).

How would I do that in RPN ?

You could do it the way described by Csaba (which actually is the above expression with nominator and denominator multiplied by n). On the other hand both means are returned by the x_bar key (g 0), so this is a direct translation of the formula:

Code:
01 g x_bar
02 x<>y
02 0
03 g ŷ, r
04 x<>y
05 R↓
06 -
07 x<>y
08 /
09 R/S

Dieter
Find all posts by this user
Quote this message in a reply
05-13-2016, 07:54 PM
Post: #27
RE: [HP-12C] Angular coefficent from linear regression off by 1
Thanks. All very fascinating.


Regards,
Bob
Find all posts by this user
Quote this message in a reply
08-03-2016, 07:38 PM (This post was last modified: 08-03-2016 07:40 PM by Csaba Tizedes.)
Post: #28
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-06-2016 01:11 PM)Dieter Wrote:  ... the suggested direct solution using the six registers is inherently more exact ...

And what is your opinion about that method which is described in the TI-65 Guidebook?!

Csaba

[Image: Q1BcQctoq4MyoTVKA] - The forum motor do not like the Google links Sad(( So try to right click and Open in new tab, or something...
Find all posts by this user
Quote this message in a reply
08-03-2016, 10:10 PM (This post was last modified: 08-03-2016 10:20 PM by Dieter.)
Post: #29
RE: [HP-12C] Angular coefficent from linear regression off by 1
(08-03-2016 07:38 PM)Csaba Tizedes Wrote:  And what is your opinion about that method which is described in the TI-65 Guidebook?!

I'd tell you if ...I could take a look at this book. ;-)

(08-03-2016 07:38 PM)Csaba Tizedes Wrote:  [Image: Q1BcQctoq4MyoTVKA] - The forum motor do not like the Google links Sad(( So try to right click and Open in new tab, or something...

Your link does not work because you used IMG tags for something that is not a picture.
A regular link should be fine: Try this one.
But anyway, this Google thing does not work for me.

But why do you want to link to Google instead of providing a simple link to the picture? You can even insert the picture in your forum post – as a simple JPG or PNG file attachment.

Or what about explaing the method in your own words?

Dieter
Find all posts by this user
Quote this message in a reply
01-19-2019, 05:36 PM
Post: #30
RE: [HP-12C] Angular coefficent from linear regression off by 1
(05-05-2016 07:07 AM)Csaba Tizedes Wrote:  01: 0
02: g y,r
03: x<>y
04: g s
05: ÷
06: ×
07: R/S

This regression slope code is neat !

(05-06-2016 01:11 PM)Dieter Wrote:  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.

Manual suggested method, slope = f(1) - f(0), may lose *many* significant digits, due to subtraction cancellation.
Find all posts by this user
Quote this message in a reply
01-21-2019, 08:10 PM
Post: #31
RE: [HP-12C] Angular coefficent from linear regression off by 1
(01-19-2019 05:36 PM)Albert Chan Wrote:  Manual suggested method, slope = f(1) - f(0), may lose *many* significant digits, due to subtraction cancellation.

OK, then let's combine a manual calculation from the stored sums for the slope and the 0 y^ method for the intercept. The latter should be exact by design as the calculator evaluates 0*slope + intercept. I assume this calculation is even done with the internal extended precision.

Which leads to this program:

Code:
RCL 1
RCL 6
x
RCL 2
RCL 4
x
-
RCL 1
RCL 3
x
RCL 2
ENTER
x
-
÷
0
y^, r
X<>Y
ENTER
R↓
R↓
GTO 00

On exit the stack holds all relevant data:

T: r
Z: r
Y: slope
X: intercept

You may replace the last ENTER with RCL 1 X<>Y, so that T finally holds the number of data points.

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




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