Method  2: Chi-Square Test of Independence

Let us consider an example in which researchers are interested to know whether a particular age group preference is associated with soap products.  Two age groups are present in the population:

  • Below 18 years.
  • Equal to or greater than 18 years.

A random sample of 100 citizens and a survey took place on their soap product preference. Chi-Square Test of Independence was performed and the following information was extracted:

  • Chi-Square Test Statistic (X2): 0.64521
  • Degrees of freedom: (df): 2

Now we will determine the p-value associated with this Chi-Square test statistic and degrees of freedom.

R




# Determine p-value for the Chi-Square 
# test statistic
pchisq(q=0.64521, df=2, lower.tail=FALSE)


Output:

Output

The p-value comes out to be equal to 0.72425. Since the p-value is greater than 0.05, hence we cannot follow the null hypothesis. This implies that we do not have sufficient proof to say that there is a link between age group and soap product preference.



How to Calculate the P-Value of a Chi-Square Statistic in R

Chi-Square Statistic is a method to represent the relationship between two categorical variables. In statistics, variables are categorized into two classes: numerical variables and non-numerical variables (categorical). Chi-square statistic is used to signify how much difference exists between the observed count and the count that is anticipated if there doesn’t exist any relationship in the population. When the Chi-Square test is conducted we get test statistics and with the help of the test statistic, we can find the p-value on the basis of which we can determine whether the test results are statistically significant.  

R provides us the pchisq() function using which we can find the p-value of a Chi-Square Statistic. The syntax of this function is given below:

Syntax:

pchisq(q = “value”, df = “value”, lower.tail = TRUE)

Parameters:

  • q: It represent the Chi-Square test statistic
  • df: It represents the degrees of freedom
  • lower.tail = “TRUE”: The probability in the left of q in the Chi-Square distribution is returned.
  • lower.tail = “FALSE”: The probability in the right of q in the Chi-Square distribution is returned.

Note that by default lower.tail is TRUE.

Similar Reads

Method 1: Chi-Square Goodness of Fit Test

A salon shop owner proposed that an equal number of customers visit his shop on weekends as well as on weekdays. In order to examine this hypothesis, researchers tracked the number of customers visiting his shop during a week. They find the below information:...

Method  2: Chi-Square Test of Independence

...