CHI²Test of independence of two variables
Posted: 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 Xregister)
Output: Zregister: Degrees of freedom for CHI² distributuion
Yregister: CHI² value
Xregister: 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
Input: Matrix of absolute frequencies (has to be in Xregister)
Output: Zregister: Degrees of freedom for CHI² distributuion
Yregister: CHI² value
Xregister: 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[