Showing posts with label program library. Show all posts
Showing posts with label program library. Show all posts

Sunday, March 3, 2024

Casio FX-702P and Swiss Micros DM42: Spearman’s Coefficient of Rank Correlation

Casio FX-702P and Swiss Micros DM42: Spearman’s Coefficient of Rank Correlation


Introduction: Correlation of Rankings Between Two Events



The Spearman’s coefficient rank correlation tests the relationship between two variables according to the rank of the two variables. Ranks are assumed to be positive integers; 1 for 1st, 2 for 2nd, 3 for 3rd, etc. The Spearman’s correlation is said to be non-parametric, eliminating the requirement that the data is normally distributed.


The correlation has a range between -1 and +1. Two variables have a strong statistical relationship if the correlation is close to -1 or +1. Conversely, these variables have no relationship if the correlation is equal to 0.


Let the variables A and B be the two variables. Again, A and B are ranks.



Assuming that there are no ties in ranking in either A or B, the correlation is calculated as:


r = 1 - ( 6 × C)^2 ) ÷ (n^3 – n)


where:

C = Σ( (A_i – B_i)^2, k = 1 to n)

n = number of ranks


Casio FX-702P Code

This is a port of the Spearman’s Coefficient of Rank Correlation program set from Casio for the fx-702P. The original BASIC programs are listed here (Casio, pg. 89, Program Library FX-702P, see sources):



P0 (rank input):

10 C=0:N=1

20 PRT “A”;N;:INP A

30 PRT “B”;N;:INP B

40 C=C+(A-B)↑2

50 N=N+1:GOTO 20



P1 (calculate the correlation):

10 N=N-1

20 R=1-6*C/(N↑3-N)

30 PRT “R=”;R

40 END



Note: PRT and INP are shortcut commands for PRINT and INPUT, respectively. The three letter shortcuts are allowed (and encouraged) on the fx-702P.


Swiss Micros DM 42 Code: SPEAR


00 { 119-Byte Prgm }
01▸LBL "SPEAR"
02 "SPEARMAN CORR"
03 AVIEW
04 PSE
05 0
06 STO 03
07 1
08 STO 04
09 "ENTER RANK #S"
10 AVIEW
11 PSE
12▸LBL 00
13 "DONE? XEQ 01"
14 AVIEW
15 PSE
16 "A"
17 ARCL 04
18 ├"?"
19 PROMPT
20 "B"
21 ARCL 04
22 ├"?"
23 PROMPT
24 -
25 X↑2
26 STO+ 03
27 1
28 STO+ 04
29 GTO 00
30▸LBL 01
31 1
32 STO- 04
33 RCL 04
34 3
35 Y↑X
36 RCL- 04
37 1/X
38 RCL× 03
39 6
40 ×
41 +/-
42 1
43 +
44 STO 05
45 "R="
46 ARCL 05
47 AVIEW
48 .END.



Note: ├ is the append string character, call it up by pressing [ (shift) ] { ALPHA } [ ENTER ].


Instructions

1. Sort event A and B to their relative rankings. We are not analyzing data point by their values, but their rankings.

2. Press [ XEQ ] {SPEAR}

3. For each rank of event A, type the rank and press [ R/S ]. For each rank of event B, type the rank and press [ R/S ]. There are prompts to guide rank entry.

4. When done, execute label 01 by pressing [ XEQ ] 01.


Example

Two algorithms A and B are analyzed. The time between run time with algorithms A and B are:

A: 48 seconds, B: 63 seconds

A: 50 seconds, B: 64 seconds

A: 53 seconds, B: 61 seconds

A: 55 seconds, B: 66 seconds

A: 57 seconds, B: 69 seconds


Ranking the times relative to algorithm A are:

A: 48 seconds (rank 1), B: 63 seconds (rank 2)

A: 50 seconds (rank 2), B: 64 seconds (rank 3)

A: 53 seconds (rank 3), B: 61 seconds (rank 1)

A: 55 seconds (rank 4), B: 66 seconds (rank 4)

A: 57 seconds (rank 5), B: 69 seconds (rank 5)



Calculate the Spearman correlation:

XEQ SPEAR

A1? 1 R/S

B1? 2 R/S

A2? 2 R/S

B2? 3 R/S

A3? 3 R/S

B3? 1 R/S

A4? 4 R/S

B4? 4 R/S

A5? 5 R/S

B5? 5 R/S

XEQ 01

Result: R = 0.7000



The Spearman correlation is 0.7.




Sources


“Spearman’s rank correlation coefficient” DATAtab Team (2024). DATAtab: Online Statistics Calculator. DATAtab e.U. Graz, Austria. URL: https://datatab.net Retrieved January 17, 2024.


“Spearman’s rank correlation coefficient” Wikipedia. https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient Edited January 17, 2024. Retrieved January 17, 2024.


Casio. Program Library: FX-702P pg. 89 (English)

(The Casio Ledudu web page, https://casio.ledudu.com/pockets.asp?lg=eng&type=53has the library in French).



Eddie



All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


Friday, May 25, 2018

TI-84 Plus CE Programs from Casio FX-702P


TI-84 Plus CE Programs from Casio FX-702P

Notes

Here are several programs from the “Bilbliotheque De Programmes” for the Casio FX-702P translated for the Texas Instruments TI-84 Plus CE.  I understand that there is an English version of the book, but I have yet to find it online.  I am thankful to Google Translate since I am not fluent in French. 

I named each of the programs FX702P##, starting with 02.  Of course, use the program name that fits. 

Basic doesn’t translate directly to the TI-84 Plus programming language.  First of all, there are no line numbers for the TI-84 Plus, separate labels had to be created.  I added more descriptive lines to prompts and results strings because (1) the TI-84 Plus CE has a lot more programming space than the 1,680 bytes the Casio FX-702P offered, and (2) it helped me understand what the programs were. 

The reference page ties to the page in the document, not the PDF page. 

TI-84 Plus CE Program FX702P02  (ref. page 85)
Geometric Mean:  Enter 0 to stop data entry

"GEOMETRIC MEAN (85)"
"2018-05-20"
1→A:1→B
Lbl 20
Disp "X-",A
Input X
If X=0:Goto 60
A+1→A:B*X→B
Goto 20
Lbl 60
Disp "G=",B^(1/(A-1))

TI-84 Plus CE Program FX702P03 (ref. page 117)
Chemistry:  Analysis of an Acid

"ACID PRGM, 2018-05-20"
"(117)"
For(J,1,10)
Input "T= (0:END)",T
If T=0:Stop
37-T→T
Input "P*=",A
Input "PH=",P
Input "H=",H
.019T→B:A*10^(B)→A
Disp "P*=",A
P-.0146T→P:Disp "PH=",P
.0307A→C:C*10^(P-6.11)→D
Disp "(HC03­)=",D:Pause
D-(9.5+1.63H)(7.4-P)-24→C
(1-.0143H)C→B
Disp "BE=",B
(1+10^(P-6.11))→I:.0307AI→I
Disp "I=",I:Pause
End


TI-84 Plus CE Program FX702P04  (ref. page 131)
Accounting:  Calculate Accounts Receivable on outstanding invoices

"BILL REDUCTION (131)"
"2018-05-20 EWS"
1→Z:0→E:0→F
Lbl IN
"AMT: A"+toString(Z)+":"→Str1
Input Str1,A
"PERCENT: B"+toString(Z)+":"→Str1
Input Str1,B
"DAYS: C"+toString(Z)+":"→Str1
Input Str1,C
int(A*B/100*C/365+.5)→D
E+A→E:F+D→F
"AMT: D"+toString(Z)+":"→Str1:Disp Str1,D
Pause
Z+1→Z
Menu("MORE DATA?","YES",IN,"NO",NO)
Lbl NO
ClrHome
Disp "TOTAL INVOICES:",E
Disp "TOTAL INTEREST:",F
Input "COMMISSION:",X
E-F-X→N
Disp "NET RECIEVABLE:",N


TI-84 Plus CE Program FX702P05 (ref. page 73)
Thermal Stress

Disp "THERMAL STRESS"
"2018-05-22 EWS"
Disp "LINEAR EXPANSION","COEFFICIENT"
Input "L1:",L
Input "L2:",M
Disp "ELASTIC","COEFFICIENT"
Input "E1:",E
Input "E2:",F
Disp "CROSS SECTION"
Input "A1:",A
Input "A2:",B
Input "T:",T
EF(L-M)T→C
C/(EA+FB)→C
­(BC)→R:AC→S
ClrHome
Disp "THERMAL STRESS","A:","B:"
Output(2,5,R)
Output(3,5,S)


TI-84 Plus CE Program FX702P06  (ref. page 206)
Construction:  Concentrated Load on a Beam

Disp "BEAM FIXED AT","BOTH ENDS UNDER","CONCENTRATED LOAD"
"(63) 2018-05-22 EWS"
Degree
Input "YOUNG MOD (KG/MM^4):",E
Input "INERTIA (MM^4):",I
Input "LENGTH (MM):",L
Input "SUPPORT-LOAD DIST:",A
Input "LOAD (KG):",P
E*I→B
Input "INTEREST POINT:",X
If X≤A
Then:A→Y:X→Z
Else:L-A→Y:L-X→Z
End
Z(L+2Y)→C:P(L-Y)^2/L^3→D
D*Z*Z/6/B*(C-3*Y*L)→F
tan^-1(D*Z/2/B*(C-2*Y*L))→S
D*(C-Y*L)→M
D*C/Z→W
ClrHome:Fix 4
Disp "FLEXION (MM):"," ANGLE:"," TORQUE:","SHELL LOAD:"
Output(1,14,F)
Output(2,14,S)
Output(3,14,M)
Output(4,14,W)
Float

TI-84 Plus CE Program FX702P07 (ref. page 41)
Electronics:  Active Low-Pass Filter

Disp "ACTIVE LOW-PASS FILTER"
"(41) 2018-05-22 EWS"
Input "FREQ (HZ):",F
Input "AF:",A
Input "C1 (MICRO-F):",C
C/1E6→C
√(2)/(4*A*π*F*C)→R
A*R→S
S/(A+1)→T
2*(A+1)*C*1E6→U
ClrHome
Disp "R1:","R2:","R3:",C2:"
Output(1,5,R)
Output(2,5,S)
Output(3,5,T)
Output(4,5,U)


Source: Casio.  “Bibliotheque De Programmes FX-702P” (French document)  1985

You can find a PDF of the book in French on this page: http://casio.ledudu.com/pockets.asp?type=53&lg=eng .  Scroll down to the bottom of the page.  Also, shout out to the casio.ledudu.com page because it is an excellent site!


Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

HP 20S: Acoustics Programs

HP 20S: Acoustics Programs Program A: Speed of Sound in Dry Air cs = 20.05 × √(273.15 + T°C) Code: 01: 61, 41, A: LBL A 02: ...