Chi-Square Test of Independence

KULDEEP PATEL
3 min readOct 1, 2018

--

Explanation with an Example:-

The chi-square test is one of the most common ways to examine relationships between two or more categorical variables. Not surprisingly, It involves calculating a number, called the chi-square statistic - χ2. Which follows a chi-square distribution. The chi-square test relies on the difference between observed and expected values.

Our hypotheses will be:

Let’s understand a chi-square test by taking an example :

2 Categorical Variables
Contingency Table
The chi-square statistic
Need to know a degree of freedom to interpret a chi-square statistic

We can find p-value by online distribution calculator. We can also calculate both chi-square statistic and p-value with the help of an online calculator.

At Significance Level:0.05, The chi-square statistic is 0.09 and the p-value is .764177. If we look at the Chi-square Distribution Table at the degree of freedom 1 and at Significance Level (Alpha) 0.05, The critical value is 3.84

Chi-square Distribution Table

Reject H0 if χ2 ≥ 3.84 and retain H0 if χ2 < 3.84. Finally, We will check p-value= value of chi-square>0.09. If p≤0.05, we reject the null hypothesis at level 0.05.

As per our test results, χ2 is 0.09 and the p-value is .764177. So, We will retain the null hypothesis i.e.There is no relationship between 2 categorical variables. ‘Gender’ and ‘Like Shopping?’ both variables are independent.

Python Code:-

Please, find the code here: Kaggle or Github

Thanks a lot for reading! Feedback is always greatly appreciated…

Connect with me:- Linkedin

--

--