Chi-Square Test: Contingency Tables

Chi-Square Test: Contingency Tables

  • Used to determine whether there is an association between two categorical variables.
    • Example: Personality (Introvert, Extrovert) and Colour Preference (Red, Yellow, Green, Blue).

Application

  • The Chi-Square test may be used to investigate the association between personality and colour preference.
  • Note: The Chi-Square test may be used for ordinal data, but the test will treat the ordinal data as categorical. In R, it is possible to modify the Chi-Square test using the linear-by-linear option to ensure the order is taken into account.

Hypotheses

  • Null Hypothesis (H0H_0): There is no association between the variables.
  • Alternative Hypothesis (H1H_1): There is an association between the variables.
  • The method is based on comparing observed frequencies with the frequencies you would expect to get by chance.

Test Statistic

  • For a table with rr rows and cc columns, the Chi-Square statistic is calculated as:
    x2=<em>i=1r</em>j=1c(O<em>ijE</em>ij)2Eijx^2 = \sum<em>{i=1}^{r} \sum</em>{j=1}^{c} \frac{(O<em>{ij} - E</em>{ij})^2}{E_{ij}}
    where:

    • OijO_{ij} represents the observed frequency.
    • EijE_{ij} represents the expected frequency.
  • x2x^2 approximately follows a χ2\chi^2 distribution with (r1)(c1)(r-1)(c-1) degrees of freedom.

Expected Frequencies

  • The expected frequency E<em>ijE<em>{ij} is calculated as: E</em>ij=Y<em>i.×Y</em>.jnE</em>{ij} = \frac{Y<em>{i.} \times Y</em>{.j}}{n} where:
    • Yi.Y_{i.} gives the row totals.
    • Y.jY_{.j} gives the column totals.
    • nn is the total number of observations.

Evaluation

  • We evaluate x2x^2 using tables of χ2\chi^2 distribution with (r1)(c1)(r-1)(c-1) degrees of freedom.

Yates' Continuity Correction

  • For 2x2 frequency tables (where degrees of freedom, df=1=(r1)(c1)df = 1 = (r-1)(c-1)), the Chi-Square test produces overly significant results (rejecting H0H_0 when it is true).
  • In such cases, we apply Yates' Continuity Correction to the test statistic:
    x2<em>corrected=</em>i=1r<em>j=1c(O</em>ijE<em>ij0.5)2E</em>ijx^2<em>{\text{corrected}} = \sum</em>{i=1}^{r} \sum<em>{j=1}^{c} \frac{(|O</em>{ij} - E<em>{ij}| - 0.5)^2}{E</em>{ij}}
  • Yates' continuity correction is also applied to the x2x^2 goodness-of-fit test when df=K1=1df = K-1 = 1.

Effect Size: Strength of Association


  • Chi-Square tests do not tell us how strong an association is; therefore, consider effect size measures.



    • Phi Coefficient (ϕ\phi):

  • Used for 2x2 tables only.
    ϕ=x2n\phi = \sqrt{\frac{x^2}{n}}
  • Guidelines:
    • Small: 0.1
    • Medium: 0.3
    • Large: 0.5


  • Cramer's V:

    • Can be used with 2 categorical variables when each variable has 2 or more categories.
      V=x2n×df<em>vV = \sqrt{\frac{x^2}{n \times df<em>v}} where df</em>v=min(c1,r1)df</em>v = \min(c-1, r-1)


  • 0V10 \leq V \leq 1. When V=0V = 0, there is no association between the variables. V=1V = 1 only when the variables are equal to each other.



    • Guidelines:
  • dfvSmallMediumLarge
    1 (2x2)0.10.30.5
    20.070.210.35
    30.060.170.29
    40.050.150.25
    50.050.130.22
  • Odds Ratio:

    • Consider the following table:

    • Outcome A
      Outcome B
      Totals
      Group 1
      A1A_1
      B1B_1
      N1N_1
      Group 2
      A2A_2
      B2B_2
      N2N_2
      Totals
      NAN_A
      NBN_B
    • The odds ratio (OR) is given by:

    • OR=A<em>1/B</em>1A<em>2/B</em>2=A<em>1B</em>2A<em>2B</em>1OR = \frac{A<em>1 / B</em>1}{A<em>2 / B</em>2} = \frac{A<em>1 B</em>2}{A<em>2 B</em>1}


      Evaluation of Odds Ratio

      • OR = 1: Belonging to Group 1 has not affected the odds of Outcome A.
      • OR > 1: Belonging to Group 1 has increased the odds of Outcome A.
      • OR < 1: Belonging to Group 1 has decreased the odds of Outcome A.

      Post Hoc Tests

      • If x2x^2 is significant ⇒ association between the variables, but it does not provide any specific information about the association.
      • In R, we can use post hoc tests to investigate further. We will use the standardised residuals approach.

      The Likelihood Ratio

      • An alternative to the x2x^2 test uses a Model based on Maximum-likelihood theory.
        L{x^2} = 2 \left{ \sum{i=1}^{r} \sum{j=1}^{c} y{ij} \ln \left( \frac{y{ij}}{E{ij}} \right) \right}

      Evaluation of Likelihood Ratio

      • Evaluate Lx2L_{x^2} in the same way as x2x^2.
      • Example: Following Example 3.6, find Lx2=0.42L_{x^2} = 0.42.
      • Again, χ2<em>0.05,1=3.841>0.42=L</em>x2\chi^2<em>{0.05, 1} = 3.841 > 0.42 = L</em>{x^2}. Do not reject \H_0 ⇒ there does not appear to be an association between Education Levels and Department.

      Violation of the expected frequency assumption

      Fisher's Exact Test