Chi-square Test

  The \(\chi^{2}\) (chi-square) test is used to assess the dependence between variables in an r × s contingency table.


1 Equation:

\[ \chi^2 = \sum \frac{(Obs - Exp)^2}{Exp} \]

Where:

  • Obs = observed frequency;
  • Exp = expected frequency;
  • df = degrees of freedom = \((r - 1)(s - 1)\).
  In this context, Exp represents the expected frequency for positive and negative outcomes (e.g., disease occurrence, drug effects, etc.).

2 Files:

  1. x2tst program
  2. Program source code

3 Example of use:

  The program performs the test using a significance level of p = 0.05, which can be modified in the source code. To run the program, the data matrix must simply be placed on the stack. The example below refers to the dataset reported in Vieira (2000). In this case, the test aims to verify whether different treatment centers influenced the recurrence of strokes.


  Data input must follow the convention of treatments/types/variations as rows, and binomial responses (Yes/No) as columns.


Table — Distribution of recurrence by treatment center

Center Recurrence (Yes) Recurrence (No)
A 16 179
B 12 70
C 21 78
D 12 54
(a) Insertion of the matrix containing table values.
(b) Results obtained from the x2tst program.
Figure 1: Stack view of the Android version of the HP50G calculator (Go49gp), showing data input and the results of the \(\chi^{2}\) test.


  In agreement with the author’s results, the \(\chi^{2}\) value suggests low dependence of treatment centers on disease recurrence (\(\phi\) = 0.156).

References

  1. Vieira, S. Analysis of Variance: ANOVA. Atlas Publishing, p. 91, 2000.
Back to top