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.


TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...