How to test data for normality with Pearson’s chi-squared test (in R)
Task
We often want to know whether a set of data is normally distributed, so that we can deduce what inference tests are appropriate to conduct. If we have a set of data and want to figure out if it comes from a population that follows a normal distribution, one tool that can help is Pearson’s $\chi^2$ test. How do we perform it?
Related tasks:
- How to create a QQ-plot
- How to test data for normality with the D’Agostino-Pearson test
- How to test data for normality with the Jarque-Bera test
Solution
We’re going to use some fake restaurant data, but you can replace our fake data with your real data in the code below. The values in our fake data represent the amount of money that customers spent on a Sunday morning at the restaurant.
1
2
3
4
5
6
# Replace your data here
spending <- c(34, 12, 19, 56, 54, 34, 45, 37, 13, 22, 65, 19,
16, 45, 19, 50, 36, 23, 28, 56, 40, 61, 45, 47, 37)
mean(spending)
sd(spending)
1
2
3
4
5
[1] 36.52
[1] 15.77213
We will now conduct a test of the following null hypothesis: The data comes from a population that is normally distributed with mean 36.52 and standard deviation 15.77.
We will use a value $\alpha=0.05$ as our Type I error rate.
The pearson.test()
function in the nortest
package can perform Pearson’s $\chi^2$ test for normality.
1
2
3
# install.packages("nortest") # if you have not already done so
library(nortest)
pearson.test(spending)
1
2
3
4
Pearson chi-square normality test
data: spending
P = 3.48, p-value = 0.6264
The p-value is 0.6264, which is greater than $\alpha=0.05$, so we fail to reject our null hypothesis. We would continue to operate under our original assumption that the data come from a normally distributed population.
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Contributed by Elizabeth Czarniak (CZARNIA_ELIZ@bentley.edu)