Post Reply 
(35S) Linearized S-Curve (Logistic Curve) Regression
03-12-2018, 04:08 AM (This post was last modified: 03-13-2018 05:05 AM by gerry_in_polo.)
Post: #1
(35S) Linearized S-Curve (Logistic Curve) Regression
HP-35s Program - Linearized S-Curve (Logistic Curve) Regression (Gerardo V. Lozada, M.S., P.E.E., HP-35s, 2018-03-10)

Linearizes the Logistic Function (S-Curve) so that linear regression may be performed on historical data.

S = F/(1+b*e^(-c*T))

Program S accepts and stores into F the projected ultimate value or upper limit of the variable to be forecasted and then the given pairs of historical data in the sequence of S (dependent) and then T (independent, i.e. Time), storing them into statistical pair memory via the Σ+ key.

Program F then displays F, calculates and displays the values of r, r^2, ln(b), b and c using the 35s' built-in linear regression variables and then uses these values to compute S from given values of T. The program listings below have been cleansed of typographical errors noticed by Dieter (thanks) that resulted from my long-hand transcription of the program listing on my 35s (no USB on the 35s to automatically transfer a program). This program has been tested several times on my 35s before I uploaded the listing here.

Historical Data Input Routine
S001 LBL S
S002 CLΣ
S003 INPUT F
S004 INPUT S
S005 RCL F
S006 x<>y
S007 ÷
S008 1
S009 -
S010 LN
S011 INPUT T
S012 Σ+
S013 STOP
S014 GTO S004

Regression and Forecasting Routine
F001 LBL F
F002 VIEW F
F003 r
F004 STO R
F005 VIEW R
F006 x^2
F007 STO R
F008 VIEW R
F009 m
F010 +/-
F011 STO C
F012 VIEW C
F013 b
F014 STO B
F015 VIEW B
F016 e^x
F017 STO B
F018 VIEW B
F019 INPUT T
F020 RCL C
F021 x
F022 +/-
F023 e^x
F024 RCL B
F025 x
F026 1
F027 +
F028 RCL F
F029 x<>y
F030 ÷
F031 STO S
F032 VIEW S
GTO F019
Find all posts by this user
Quote this message in a reply
03-12-2018, 09:55 AM (This post was last modified: 03-12-2018 12:26 PM by Dieter.)
Post: #2
RE: (35S) Linearized S-Curve (Logistic Curve) Regression
(03-12-2018 04:08 AM)gerry_in_polo Wrote:  HP-35s Program - Linearized S-Curve (Logistic Curve) Regression (Gerardo V. Lozada, M.S., P.E.E., HP-35s, 2018-03-10)

First of all: thank you very much for a useful program.
I hope you do not mind a few remarks and corrections that will make the program work as intended. ;-)

(03-12-2018 04:08 AM)gerry_in_polo Wrote:  Linearizes the Logistic Function (S-Curve) so that linear regression may be performed on historical data.

S = F/(1+b*e^(-b*T))

This probably should read

S = F / (1+b*e^(–c*T))

(03-12-2018 04:08 AM)gerry_in_polo Wrote:  Historical Data Input Routine
S001 LBL S
S002 CLΣ
S003 INPUT F
S005 INPUT S
S006 RCL F
S007 ÷
S008 1
S009 -
S010 LN
S011 INPUT T
S012 Σ+
S013 STOP
S014 GTO S004

There is no line S004 where the last step could jump to. Also the variable transformation (linearization) seems to be wrong. I think there is only an X<>Y missing which would explain both problems:

S = F / (1+b*e^(–c*T))
<=>
ln(F/S – 1) = ln b + (–c)*T

So it has to be F/S instead of S/F:

Code:
S001 LBL S
S002 INPUT F
S003 CLΣ
S004 INPUT S
S005 RCL F
S006 X<>Y    <= missing line
S007 ÷
S008 1
S009 -
S010 LN
S011 INPUT T
S012 Σ+
S013 GTO S004

Notes: The STOP after the Σ+ was removed as it is not required – the program directly jumps back to the S prompt. And the CLΣ was placed after the INPUT to avoid clearing the Σ registers if the program is inadvertedly run.

I finally tried another version that adds a Σ– function for removing erroneous data and has the user enter the data pairs via T [ENTER] S which is faster than separate prompts for both values.

Dieter
Find all posts by this user
Quote this message in a reply
03-12-2018, 11:36 AM
Post: #3
RE: (35S) Linearized S-Curve (Logistic Curve) Regression
(03-12-2018 09:55 AM)Dieter Wrote:  
(03-12-2018 04:08 AM)gerry_in_polo Wrote:  HP-35s Program - Linearized S-Curve (Logistic Curve) Regression (Gerardo V. Lozada, M.S., P.E.E., HP-35s, 2018-03-10)

First of all: thank you very much for a useful program.
I also think this is a usseful program, at least for biology and many other subjects
After Dieter´s corrections I would like to test with a numerical example; could you please post some example to illustrate.

Thank you in advance,

Pedro
Find all posts by this user
Quote this message in a reply
03-12-2018, 01:20 PM (This post was last modified: 03-12-2018 06:43 PM by Dieter.)
Post: #4
RE: (35S) Linearized S-Curve (Logistic Curve) Regression
(03-12-2018 11:36 AM)PedroLeiva Wrote:  After Dieter´s corrections I would like to test with a numerical example; could you please post some example to illustrate.

For F=100 assume the following data:

Code:
T   1   2   3   4   5
S  20  40  70  80  95

Start program:

Code:
[XEQ] S [ENTER]
F?  100 [R/S]

Enter data pairs:

Code:
S?  20 [R/S]
T?   1 [R/S]

S?  40 [R/S]
T?   2 [R/S]

S?  70 [R/S]
T?   3 [R/S]

S?  80 [R/S]
T?   4 [R/S]

S?  95 [R/S]
T?   5 [R/S]

Calculate regression:

Code:
XEQ F [ENTER]
              R=-0,9921
   [R/S]      R= 0,9842   // this is r²
   [R/S]      B= 2,4587   // this is ln b (!)
   [R/S]      B= 11,6898
   [R/S]      C= 1,0453

Forecast T => S:

Code:
   [R/S]      T? 
 2 [R/S]      S= 40,9008
   [R/S]      T?
 6 [R/S]      S= 97,8400

BTW, I would remove the output of ln b (line F014 and F015) since this can be misleading. The value is ln b but the display says it's b. The same is true for the regression coefficient. I'd simply display r here ("R=") and have r² in X so that it may be displayed by pressing the [<=] key, if required.

Dieter
Find all posts by this user
Quote this message in a reply
03-12-2018, 02:37 PM (This post was last modified: 03-12-2018 02:45 PM by gerry_in_polo.)
Post: #5
RE: (35S) Linearized S-Curve (Logistic Curve) Regression
I know but I want to see all the variables. The HP-35s allows only one letter per variable. They can be easily removed from the program if you want to. The STOP was added so you can see the data counter progress. Again you can remove it. e^(-b*T) is a typographical error, it is e^(-c*T) in the program. The program listing itself is correct, I have run it several times on various data. Thank you for pointing out the typographical error.
Find all posts by this user
Quote this message in a reply
03-12-2018, 05:57 PM (This post was last modified: 03-12-2018 06:20 PM by Dieter.)
Post: #6
RE: (35S) Linearized S-Curve (Logistic Curve) Regression
(03-12-2018 02:37 PM)gerry_in_polo Wrote:  I know but I want to see all the variables. The HP-35s allows only one letter per variable. They can be easily removed from the program if you want to. The STOP was added so you can see the data counter progress. Again you can remove it.

Fine.

(03-12-2018 02:37 PM)gerry_in_polo Wrote:  e^(-b*T) is a typographical error, it is e^(-c*T) in the program. The program listing itself is correct, I have run it several times on various data.

Gerardo, the S program cannot be correct as it has a jump to line S004 at the end. But such a line does not exist: in the listing line S003 is directly followed by S005.
So could you please check again and compare the listing in your post with the original program?

I still think that there is a line missing. Please take a look at this part of the code:

S005 INPUT S
S006 RCL F
S007 ÷
S008 1
S009 -
S010 LN

Since S is less than F the quotient S/F is < 1, and this minus 1 is negative. So the program tries to calculate the logarithm of a negative number – which cannot be correct.

Dieter
Find all posts by this user
Quote this message in a reply
03-12-2018, 06:54 PM (This post was last modified: 03-12-2018 08:11 PM by SlideRule.)
Post: #7
RE: (35S) Linearized S-Curve (Logistic Curve) Regression
(03-12-2018 11:36 AM)PedroLeiva Wrote:  … I would like to test with a numerical example; could you please post some example to illustrate …
Pedro

Equations(s) w Example(s) for the Gompertz Curve from pages 48-49 of the HP-41 User Library Solutions Business Stat-Marketing-Sales booklet…

[attachment=5748] [attachment=5749]

… as well as the HP-12 Solutions Manual

[attachment=5750] [attachment=5751]

… and a PPX-59 approach …

[attachment=5752]

BEST!
SlideRule
Find all posts by this user
Quote this message in a reply
03-12-2018, 09:34 PM
Post: #8
RE: (35S) Linearized S-Curve (Logistic Curve) Regression
(03-12-2018 06:54 PM)SlideRule Wrote:  
(03-12-2018 11:36 AM)PedroLeiva Wrote:  … I would like to test with a numerical example; could you please post some example to illustrate …
Pedro

Equations(s) w Example(s) for the Gompertz Curve from pages 48-49 of the HP-41 User Library Solutions Business Stat-Marketing-Sales booklet…

BEST!
SlideRule
Thank you, I will try these examples
Pedro
Find all posts by this user
Quote this message in a reply
03-12-2018, 10:24 PM (This post was last modified: 03-12-2018 10:31 PM by gerry_in_polo.)
Post: #9
RE: (35S) Linearized S-Curve (Logistic Curve) Regression
Another typographical error, the problem when I have to transcribe the program listing by hand from the 35s manually (no USB). Thanks for catching it. S005 should be S004, inserted the missing x<>y after RCL F. Will update the listing. But the original program on my 35s runs fine, it is the hand transcription which had errors. Corrected the typos now ☺.
Find all posts by this user
Quote this message in a reply
Post Reply 




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