Showing posts with label Logistic regression. Show all posts
Showing posts with label Logistic regression. Show all posts

Wednesday, September 6, 2017

Fun with the TI-80

Fun with the TI-80


TI-80 Program D2DMS - Decimal to Degrees-Minutes-Seconds

Variables:

Decimal Format:
D = decimal

DMS Format:
H = degrees/hours, M = minute, S = seconds

INPUT “DEC:”,D
IPART D→H
IPART (60*FPART D)→M
60 * FPART (60 * FPART D)→S
DISP “H,M,S:”,H,M,S

TI-80 Program DMS2D - Degrees-Minutes-Seconds to Decimal

Variables:

Decimal Format:
D = decimal

DMS Format:
H = degrees/hours, M = minute, S = seconds

INPUT “H:”,H
INPUT “M:”,M
INPUT “S:”,S
H + M/60 + S/3600 → D
DISP “DEC:”,D

TI-80 Program QUADRAT - Quadratic Equation

Variables:

A, B, C are coefficients of the equation Ax^2 + Bx + C, where the discriminant D:

D = B^2 – 4*A*C
If D≥0, then the roots are real and stored in X and Y.

If D<0, then the roots are complex and are in the form of conjugates X ± Yi.  X is the real part, Y is the imaginary part.



DISP “AX^2+BX+C=0”
INPUT “A:”,A
INPUT “B:”,B
INPUT “C:”,C
B^2 – 4AC → D
DISP D 
-B / (2A) → E
IF D≥0
THEN
E + √D/(2A) → X
E - √D/(2A) → Y
DISP “R1:”,X
DIPS “R2:”,Y
ELSE
E → X
√-D / (2A) → Y
DISP “RE:”,X
DISP “IM :”,Y
END

Annuity Factors

Variables:
I = periodic interest rate
N = number of payments/periods/deposits

TI-80 Program USFV – Annuity Future Value Factor

INPUT “I:”,I
INPUT “N:”,N
( (1+.01)^N – 1)/(.01I) → F
DISP F

TI-80 Program USPV – Annuity Present Value Factor

INPUT “I:”,I
INPUT “N:”,N
(1 – (1 + .01I)^-N)/(.01I) → P
DISP P

Two Dimensional Vector Operations

Let two vectors be defined as V1 = [A, B] an V2 = [C, D].  The program calculates the dot product, stored in E, norm of V1, stored in F, norm of V2, stored in G, and the angle between V1 and V2 in degrees, stored in H.

TI-80 Program VECTOR2

DEGREE
DISP “V1:”
INPUT A
INPUT B
DISP “V2:”
INPUT C
INPUT D
AC + BD → E
√(A^2 + B^2) → F
√(C^2 + D^2) → G
COS^-1 (E /(F*G)) → H
DISP “NORM V1:”, F
DISP “NORM V2:”, G
PAUSE
DISP “DOT:”, E
DISP “ANGLE:”, H

Simplistic Logistic Regression

Fit data (x,y) to the equation:

Y = 1 / (A + B*e^(-X))


TI-80 Program SIMPLOG

INPUT “L1:”, L1
INPUT “L2:”, L2
e^-L1 → L1
1/L2 → L2
LINREG(aX+b) L1, L2
a→A: b→B
DISP “1/(B+Ae^X)”,A,B
PAUSE
DISP “CORR^2”,r^2





Eddie


This blog is property of Edward Shore, 2017

Saturday, June 3, 2017

HP 20S and HP 21S: Simple Logistic Regression

HP 20S and HP 21S:  Simple Logistic Regression

For the HP Prime and TI-84 Plus CE versions, please click here:  http://edspi31415.blogspot.com/2017/04/hp-prime-and-ti-84-plus-ce-simple.html

This program attempts to fit a simple logistic curve of data (X, Y) to the equation:

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

By the following transformations:

X’ = e^(-X)  
Y’ = 1/Y

And performing linear regression analysis on X’ and Y’.   Note that the data point which includes Y = 0 is not allowed. 

The keystrokes for the HP 20S and HP 21S are slightly different.  Each program will be shown separately.

Input:
Initialize the data:  XEQ A
For each data point:  x, [INPUT], y, XEQ B
Calculate the parameters:  XEQ C.  B is shown first, then A.

HP 20S Program: Simple Logistic Regression

STEP
CODE
KEY
01
61, 41, A
LBL A
02
61, 75
CLRΣ
03
61, 26
RTN
04
61, 41, B
LBL B
05
15
1/X
06
51, 31
SWAP
07
32
+/-
08
12
e^x
09
51, 31
SWAP
10
16
Σ+
11
61, 26
RTN
12
61, 41, C
LBL C
13
61, 16
m, b
14
26
R/S
15
51, 31
SWAP
16
61, 26
RTN

HP 21S Program: Simple Logistic Regression


STEP
CODE
KEY
01
61, 41, A
LBL A
02
61, 75
CLRΣ
03
61, 26
RTN
04
61, 41, B
LBL B
05
15
1/X
06
51, 31
SWAP
07
32
+/-
08
12
e^x
09
51, 31
SWAP
10
16
Σ+
11
61, 26
RTN
12
61, 41, C
LBL C
13
51, 14
m, b
14
26
R/S
15
51, 31
SWAP
16
61, 26
RTN

Like the last post (minimum and maximum), this is one of my favorite programs I have done this year.  I think the Wheatstone circuit would also make the list.

Eddie


This blog is property of Edward Shore, 2017

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

Earth's Radius by Latitude

Earth's Radius by Latitude Introduction: Calculating the Earth’s Radius In quick, general calculations, we assume that the...