## What is a Chi-Square Test?

The chi-square test is a statistical test that can be used when we want to determine whether some observed frequencies deviate from the frequencies we would expect under a certain hypothesis. With this test, we examine whether there is an association between two variables, and it shows the probability of association. The Chi-square test is used when we have two categorical variables with two or more groups.

**When Should a Chi-Square be Used?**

You can use a chi-square test of independence **when you have two categorical variables**. It allows you to test whether the two variables are related to each other. If two variables are independent (unrelated), the probability of belonging to a certain group of one variable isn’t affected by the other variable

### An Example Of a **Chi-Square Test **

For example, a researcher wants to check if there is a relationship between gender and math exam results. In that case, we have two categorical variables: gender (male, female) and math exam result (passed the exam or not).

**What are the use of null and alternative hypothesis for the Chi-Square Test?**

Therefore, we test the following hypotheses:

* Null hypothesis: *There is no association between gender and math exam scores.

* Alternative hypothesis*: There is an association between gender and math exam scores.

## R function to Compute Chi-Square Test

The code to run a Chi-Square Test using R is as follows:

chisq.test(V1, V2, data = dataframe)

For this, the `chisq.test()`

the function is used.