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