6.2 C
London
Thursday, December 19, 2024
HomeRProbability Distributions in RHow to Calculate the P-Value of a Chi-Square Statistic in R

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

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

Whenever you conduct a Chi-Square test, you will end up with a Chi-Square test statistic. You can then find the p-value that corresponds to this test statistic to determine whether or not the test results are statistically significant. 

To find the p-value that corresponds to a Chi-Square test statistic in R, you can use the pchisq() function, which uses the following syntax:

pchisq(q, df, lower.tail = TRUE)

where:

  • q: The Chi-Square test statistic
  • df: The degrees of freedom
  • lower.tail: If TRUE, the probability to the left of in the Chi-Square distribution is returned. If FALSE, the probability to the right of in the Chi-Square distribution is returned. Default is TRUE.

The following examples show how to use this function in practice.

Example 1: Chi-Square Goodness of Fit Test

A shop owner claims that an equal number of customers come into his shop each weekday. To test this hypothesis, an independent researcher records the number of customers that come into the shop on a given week and finds the following:

  • Monday: 50 customers
  • Tuesday: 60 customers
  • Wednesday: 40 customers
  • Thursday: 47 customers
  • Friday: 53 customers

After performing a Chi-Square Goodness of Fit test, the researcher finds the following:

Chi-Square Test Statistic (X2): 4.36

Degrees of freedom: (df): 4

To find the p-value associated with this Chi-Square test statistic and degrees of freedom, we can use the following code in R:

#find p-value for the Chi-Square test statistic
pchisq(q=4.36, df=4, lower.tail=FALSE)

[1] 0.3594721

The p-value turns out to be 0.359. Since this p-value is not less than 0.05, we fail to reject the null hypothesis. This means we do not have sufficient evidence to say that the true distribution of customers is different from the distribution that the shop owner claimed.

Example 2: Chi-Square Test of Independence

Researchers want to know whether or not gender is associated with political party preference. They take a simple random sample of 500 voters and survey them on their political party preference. After performing a Chi-Square Test of Independence, they find the following:

Chi-Square Test Statistic (X2): 0.8642

Degrees of freedom: (df): 2

To find the p-value associated with this Chi-Square test statistic and degrees of freedom, we can use the following code in R:

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

[1] 0.6491445

The p-value turns out to be 0.649. Since this p-value is not less than 0.05, we fail to reject the null hypothesis. This means we do not have sufficient evidence to say that there is an association between gender and political party preference.

Related: How to Perform a Chi-Square Test of Independence in R

Find the complete documentation for the pchisq() function here.

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories