Quantiles for the HP-41
Overview
-This program calculates the median, quartiles, or any other quantile,
by linear interpolation.
-The data are supposed to be grouped like this:
xi | frequencies |
[ x1 ; x2 [ | n1 |
[ x2 ; x3 [ | n2 |
.......... | ....... |
[ xp; xp+1] | np |
Program Listing
Data Registers: • R00: p ( All these registers are to be initialized before executing "QTLE" )
• R01: x1
• R02: x2 ..........
• Rpp: xp • Rpp+1:
xp+1
• Rpp+2: n1 • Rpp+3:
n2 ........ • R2p+2:
np
Flags: /
Subroutines: /
01 LBL "QTLE"
02 STO M 03 RCL 00 04 ENTER^ 05 ST+ X 06 1 07 + 08 0 09 LBL 00 |
10 RCL IND Y
11 + 12 DSE Y 13 DSE Z 14 GTO 00 15 RCL M 16 * 17 0 18 LBL 01 |
19 ISG Z
20 CL X 21 RCL IND Z 22 + 23 X<Y? 24 GTO 01 25 ST- Y 26 X<> L 27 / |
28 X<>Y
29 RCL 00 30 - 31 ENTER^ 32 DSE X 33 X<> Z 34 RCL IND Y 35 RCL IND T 36 - |
37 *
38 RCL IND Y 39 + 40 0 41 X<> M 42 SIGN 43 X<>Y 44 END |
( 71 bytes / SIZE 2p+2 )
STACK | INPUTS | OUTPUTS |
Y | / | 1 |
X | r ( 0 < r < 1 ) | quantile |
L | / | r |
Example:
-Find the median Me , the first and last quartile Q1 and
Q3 , the first decile d1 and the third centile
c3 of the following data:
x | n |
[ 10 ; 12 [ | 1 |
[ 12 ; 15 [ | 3 |
[ 15 ; 20 [ | 7 |
[ 20 ; 24 [ | 4 |
[ 24 ; 30 [ | 2 |
-There are 5 classes: 5
STO 00
-Then, we store
10 ; 12 ; 15 ; 20 ; 24 ; 30 ; 1 ; 3 ; 7 ; 4 ; 2
into registers R01 thru R11 respectively and
.5 XEQ "QTLE"
yields Q2 = 18.2143 = Me
.25 R/S
yields Q1 = 15.1786
.75 R/S
yields Q3 = 21.75
.1
R/S
yields d1 = 12.7
.03 R/S
yields c3 = 11.02