CHI²-Test of independence of two variables

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: http://www.swissmicros.com/dm42/decoder/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
rawi
Posts: 14
Joined: Sat Dec 28, 2019 4:50 am

CHI²-Test of independence of two variables

Post by rawi » Sun Feb 09, 2020 3:57 pm

Program CHIT (uses program “CHIX” for integration of CHI²-distribution).
Input: Matrix of absolute frequencies (has to be in X-register)
Output: Z-register: Degrees of freedom for CHI² distributuion
Y-register: CHI² value
X-register: Confidence level of test
Matrix of absolute frequencies: FTR
Matrix of absolute frequencies in case of independence: FTI

Example: (Werner Voß (editor): Taschenbuch der Statistik, Leipzig 2000, p. 449f):
1000 people were asked what party they would vote for. The absolute frequencies were as follows:
Party female male
SPD 200 170
CDU/CSU 200 200
Grüne 45 35
FDP 25 35
PDS 20 30
Other 30 10

Result:
Z: 5 (degrees of freedom)
Y: 15.7743 (CHI²-value)
X: 0.9925 (The hypothesis of the independence of party an gender can be rejected with a confidence
level of 99,25%)
Matrix FTI:
192.4 177.6
208 192
41.6 38,4
31.2 28,8
26 24
20.8 19.2

Example: If party and gender were fully independent there would be 192.4 men preferring SPD.
Note: All elements of the matrix FTI should be > 5. Otherwise the approximative use of the CHI² distribution is not valid.

Enjoy
Raimund Wildner

Code: Select all

{  109 - Byte Prgm  }
LBL “CHIT”
STO “FTR”
RSUM
RCL “FTR”
TRANS
RSUM
TRANS
ENTER
RSUM
DET
STO 03
R↓
*
RCL 03
./.
ENTER
ENTER
STO “FTI”
RCL”FTR”
-
X↑2
X<>Y
1/X
DOT
STO 01
RCL “FTR”
DIM?
1
-
X<>Y
1
-
*
STO 03
PGMINT “CHIX”
0
STO “LLIM”
RCL 01
STO “ULIM”
.0001
STO “ACC”
INTEG “X”
STO 02
RCL 03
RCL  01
RCL 02
END

Code: Select all

{   47 - Byte Prgm  }
LBL “CHIX”
MVAR “X”
RCL ”X”
RCL 03
2
./.
1
-
Y↑X
RCL “X”
+/-
2
./.
E↑X
*
2
RCL 03
2 
./.
Y↑X
./.
RCL 03
2
./.
GAMMA
./.
RTN
END[/code[

Post Reply