# Calculate chi2 test by hand

Calculate chi2 test by hand  The Chi-square test (or just Chi2) helps you assess whether two categorical variables are significantly correlated with each other. Chi2 can be performed with almost every statistical package, but it is also very easy to do it using a simple calculator. Here is how to do it.

Let’s imagine that we observed 74 people in the store. 30 men and 44 women. Some of them chose Coca-Cola, while others chose Pepsi. We want to know if there is a relationship between gender and soda preference. Take a look at the table.

## Calculate chi2 test by hand  We need to verify the Chi-square assumptions about expected frequency ≥5. To calculate the expected frequency, we need to expand our table and summarize values in rows and in columns.  Now, when we have it summarized, we can calculate the expected frequencies. We do it by multiplying the sum of a row by the sum of a column and dividing this number by the overall sample size (which is 74). Look at the table below.  Now we know that our second assumption is met and expected frequencies in every cell are greater than 5.
Next, we need to use the Chi-square formula to calculate the difference between the observed and expected frequency squared, divided by the expected frequency. And summarize all the results. This gives us the value of the Chi-square. Just like in the table below.  The summarized values gave us Chi-square equal to 6.05. However, we still do not know whether this result is statistically significant. To find out, we need to know the degrees of freedom (df) and look at the Chi-square probabilities table.

Degrees of freedom are calculated with the following formula: (rows – 1)*(columns – 1). In our case this is (2 rows – 1)*(2 columns – 1), which gives us df = 1. We use the default alpha level .05. The table of Chi-square probabilities tells us that the statistically significant Chi-square value for 1 degree of freedom and alpha level =.05 must be 3.84 or higher. For us, it means that there is a significant relationship between gender and soda preference.  