## Wednesday, April 19, 2017

### HP Prime and TI-84 Plus CE: Simple Logistic Regression

HP Prime and TI-84 Plus CE:  Simple Logistic Regression

The program SIMPLOGI attempts to fit two lists of data (X, Y) to the equation:

y = 1 / (A + B*e^(-x))

by using the translation:  X’ = e^-X and Y’ = 1/Y and performing linear regression analysis on X’ and Y’.   This is good for all data except when y = 0.

HP Prime Program SIMPLOGI

EXPORT SIMPLOGI(L1,L2)
BEGIN
// EWS 2017-04-18

LOCAL S:=SIZE(L1);
LOCAL L0:=MAKELIST(1,X,1,S);
L1:=e^(−L1);
L2:=1/L2;

LOCAL M1,M2,M3;
M1:=list2mat(CONCAT(L0,L1),S);
M1:=TRN(M1);
M2:=list2mat(L2,S);
M2:=TRN(M2);
M3:=CAS.LSQ(M1,M2);

RETURN {"Y=1/(A+Be^(−X))",M3};

END;

TI-84 Plus CE Program SIMPLOGI

Disp "LOGISTIC FIT"
Disp "Y=1/(A+B*e^(­X))"
Input "X: ",L
e^(­L)→L
Input "Y: ",L
1/L→L
LinReg(a+bx) L,L
Disp "A=",a
Disp "B=",b

Example

Data:  (X’ and Y’ are provided for reference)

 X Y X’ = e^(-X) Y’ = 1/Y 0.5 0.384 0.6065306597 2.604166667 1.0 0.422 0.3678794412 2.369668246 1.5 0.450 0.2231301601 2.222222222 2.0 0.468 0.1353352832 2.136752137 2.5 0.480 0.0820849986 2.083333333

X = {0.5, 1, 1.5, 2, 2.5}, Y = {0.384, 0.422, 0.45, 0.468, 048}

Results (Matrix [ [ A ]. [B ] ]):

A = 2.00185929
B = 0.9942654005

Hence y = 1 / (2.00185929 + 0.9942654005*e^(-x))

Eddie

This blog is property of Edward Shore, 2017

#### 1 comment:

1. That is really interesting!

123 HP Com

### Retro Review: Texas Instruments BA-55

General Information Company:  Texas Instruments Type:  Programmable Finance Memory:  40 steps, 10 cash flows Battery:  2...