Chi-square independence tests test whether there are two qualitative variables are independent, that is, whether there is a connection between the two categorical variables. In other words, this test is used to determine whether the values ​​of one qualitative variable depend on the values ​​of another qualitative variable.

If the test does not show a relationship between two variables (i.e., the variables are independent), it means that knowing the value of one variable does not provide information about the value of the other variable. Conversely, if the test shows a relationship between variables (i.e., the variables are dependent), it means that knowing the value of one variable provides information about the value of another variable.

This article focuses on how to perform the independence test using the Chi-square by hand and how to interpret the results with a concrete example. If you want to learn how to take this test in R, read the article “Chi-square independence test R.”.

The Chi-square independence test is a hypothesis test so it has zero ( (H_0 )) and the alternative hypothesis ( (H_1 )):

  • (H_0 ) : variables are independent, is No the relationship between two categorical variables. Knowing the value of one variable does not help predict the value of another variable
  • (H_1 ) : variables are dependent, there is a connection between two categorical variables. Knowing the value of one variable helps to predict the value of another variable

The Chi-square independence test works by comparing the observed frequencies (i.e., the frequencies observed in the sample) with the expected frequencies if there was no relationship between the two categorical variables (i.e., the expected frequencies if the null hypothesis was true).

If the difference between the detected frequencies and the expected frequencies is small, we cannot reject the null hypothesis of independence, so we cannot reject the fact that these two the variables are not related. On the other hand, if the difference between the observed frequencies and the expected frequencies is large, we can reject the null hypothesis of independence and thus conclude that these two the variables are related.

The threshold for the small and large difference is the value that comes from the Chi-square distribution (hence the name of the test). This value, called the critical value, depends on the significance level ( alpha ) (usually set at 5%) and degrees of freedom. This critical value can be found in the Chi-square distribution statistical table. More on this critical value and degrees of freedom later in the article.

For example, we want to find out whether there is a statistically significant association between smoking and a professional athlete. Smoking can only be “yes” or “no,” and a professional athlete can only be “yes” or “no”. The two variables of interest are qualitative variables, so we have to use the Chi-square independence test, and the data have been collected from 28 individuals.

Note that we chose binary variables (binary variables = qualitative variables at two levels) for ease, but the Chi-square independence test can also be performed with qualitative variables with more than two levels. For example, if there were three levels of variable smoking: (i) non-smokers, (ii) moderate smokers, and (iii) smokers, the test steps and interpretation are similar to the two levels.

Detected frequencies

Our information is summarized in the contingency table below, which shows the number of people, rows, columns and totals for each subgroup:

Athlete 14 4 18
Non-athlete 0 10 10
Total 14 14 28

Expected frequencies

Keep in mind that for the Chi-square independence test, we need to determine if the readings observed differ significantly from the readings we expect if there is no relationship between the two variables. We have the observed quantities (see table above), so we now have to calculate the expected quantities in case the variables were independent. These expected frequencies are calculated for each subgroup individually using the following formula:

[text{expected frequencies} = frac{text{total # of obs. for the row} cdot text{total # of obs. for the column}}{text{total number of observations}}]

where obs. correspond to the findings. Given the table of observed frequencies above, below is a table of the expected frequencies calculated for each subgroup:

Athlete (18 * 14) / 28 = 9 (18 * 14) / 28 = 9 18
Non-athlete (10 * 14) / 28 = 5 (10 * 14) / 28 = 5 10
Total 14 14 28

Note that the Chi-square independence test should only be done when due the frequencies in all groups are equal to or greater than 5. This assumption is met in our example because the minimum number of expected frequencies is 5. If the condition is not met, Fisher’s exact test is preferred.

Test statistics

We have observed and expected frequencies. We now need to compare these frequencies to see if they differ significantly. The difference between the observed and expected frequencies, called the test statistic (or t-stat), is denoted by ( chi ^ 2 ), is calculated as follows:

[chi^2 = sum_{i, j} frac{big(O_{ij} – E_{ij}big)^2}{E_{ij}}]

where (O ) represents detected frequencies and (E ) expected frequencies. We use the square of the differences in observed and expected frequencies to ensure that negative differences are not offset by positive differences. The formula looks more complex than it actually is, so let’s illustrate it with our example. First, calculate the difference for each subgroup individually according to the formula:

  • in the athlete and non-smoker subgroup: ( frac {(14 – 9) ^ 2} {9} = 2.78 )
  • in the subgroup of non-athletes and non-smokers: ( frac {(0-5) ^ 2} {5} = 5 )
  • in the athlete and smoker subgroup: ( frac {(4-9) ^ 2} {9} = 2.78 )
  • in the non-athlete and smoker subgroup: ( frac {(10 – 5) ^ 2} {5} = 5 )

and then we add them all up to get a test statistic:

[chi^2 = 2.78 + 5 + 2.78 + 5 = 15.56]

Critical value

Test statistics alone are not enough to establish the independence or dependence of two variables. As mentioned earlier, this test statistic (which is in some sense the difference between observed and expected frequencies) must be compared to a critical value to determine if the difference is large or small. It cannot be said that a test statistic is large or small without putting it in perspective with a critical value.

If the test statistic is above the critical value, it means that the probability of detecting such a difference between the detected and expected frequencies is unlikely. On the other hand, if the test statistic is below a critical value, it means that the probability of detecting such a difference is probable. If it is likely to detect this difference, we cannot reject the hypothesis that these two variables are independent, otherwise we can conclude that there is a relationship between the variables.

The critical value can be found in the Chi-square distribution statistical table and depends on the significance level ( alpha )and degrees of freedom (df ). The significance level is usually set to 5%. The degrees of freedom of the Chi-square independence test are as follows:

[df = (text{number of rows} – 1) cdot (text{number of columns} – 1)]

In our example, the degrees of freedom are like this (df = (2-1) cdot (2-1) = 1 ) because the contingency table has two rows and two columns (integers are not counted as a row or column).

We now have all the information we need to find the critical value in the Chi-square table ( ( alpha = 0.05 ) and (df = 1 )). To find the critical value, we need to look at the line (df = 1 ) and column ( chi ^ 2_ {0,050} ) (since ( alpha = 0.05 )) in the figure below. The critical value is (3.84146 ).

Chi-square table – Critical value for alpha = 5% and df = 1

Conclusion and interpretation

Now that we have test statistics and a critical value, we can compare them to check whether the null hypothesis of independence of the variables is rejected. In our example

[text{test statistic} = 15.56 > text{critical value} = 3.84146]

As with any statistical test, when the test statistic is greater than the critical value, we can reject the null hypothesis at the specified significance level.

In our case, therefore, we can reject the two hypotheses of independence between two categorical variables at a significance level of 5%.

( Rightarrow ) This means that there is a significant relationship between smoking habits and being an athlete. Knowing the value of one variable helps to predict the value of another variable.

Thanks for reading. I hope the article has helped you take the Chi-square independence test by hand and interpret its results. If you want to learn how to take this test in R, read the article “Chi-square independence test R.”.

As always, if you have a question or suggestion related to the topic covered in this article, add it as a comment so other readers can benefit from the discussion.

LEAVE A REPLY

Please enter your comment!
Please enter your name here