# Expected Counts in Chi-Squared Goodness-of-Fit Tests of Normality

I have a variable with of 200 values that I would like to test for normality using the Chi-square Goodness of Fit test. To do this, I have to calculate, for each value, the expected value in a normal distribution. How would I calculate it?

• 1. The chi-square test is a terrible way to test for normality; the power is really poor. The Chen-Shapiro or failing that the Shapiro-Wilk are better choices in almost any circumsctance you're likely to encounter. 2. The situations in which tests for normality are most commonly conducted, testing normality at all is generally not a good idea - there are several good answers on that subject here: stats.stackexchange.com/questions/2492/… – Glen_b -Reinstate Monica Apr 8 at 7:11

Shapiro-Wilk test of normality. If you have your choice of goodness-of-fit tests, I think you might get better results with the Shapiro-Wilk test. Here is an example with $$n = 200$$ observations from $$\mathsf{Norm}(\mu=100,\sigma=15).$$ This procedure tests whether the data are consistent with some normal distribution.

Using R:

set.seed(2020)           # for reproducibility
x = rnorm(200, 100, 15)  # generate normal data
summary(x);  sd(x)       # data summary
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
54.15   89.03  101.01   99.95  110.91  148.02
[1] 16.938
shapiro.test(x)          # test for normality

Shapiro-Wilk normality test

data:  x
W = 0.99546, p-value = 0.8155


Normal probability plot. A normal probability plot (normal quantile-quantile plot) provides an informal way to judge normality of a dataset. The emirical CDF of the sample is transformed so that points for a normal sample should lie approximately in a straight line. Here is an example, using the same data as above.

qqnorm(x);  qqline(x, col="green")


Kolmogorov-Smirnov Test. If you want to know whether data are consistent with the particular normal distribution $$\mathsf{Norm}(\mu=100,\sigma=15)$$ with the specified population mean and standard deviation, then you might use a Kolmogorov-Smirnov GOF test (as implemented in R) as follows:

ks.test(x, pnorm, 100, 15)  # specified parameters

One-sample Kolmogorov-Smirnov test

data:  x
D = 0.042461, p-value = 0.8636
alternative hypothesis: two-sided


Results for nonnormal data. We show results of the Shapiro-Wilk test for samples from normal and exponential populations.

set.seed(407)
u = runif(200, 0, 10)
summary(u); sd(u)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
0.02289 2.32162 4.74545 4.94375 7.64946 9.96443
[1] 3.02981
shapiro.test(u)

Shapiro-Wilk normality test

data:  u
W = 0.94561, p-value = 7.288e-07

set.seed(408)
v = rexp(200, 1/10)
summary(v); sd(v)
Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
0.03374  2.69530  6.46082  9.81964 13.56134 52.08287
[1] 9.959839
shapiro.test(v)

Shapiro-Wilk normality test

data:  v
W = 0.81954, p-value = 1.773e-14


Chi-squared GOF tests. For a chi-squared test on possibly normal data, there are two cases to consider.

(a) Parameters unspecified. Test whether the data belong to some unspecified normal distribution. (This is what the Shapiro-Wilk test does.) See this page for details.

(b) Parameters specified. Test whether the data are specifically $$\mathsf{Norm}(100, 15).$$ (This is analogous to the Kolmogorov-Smirnov test.)

Then you could sort the data into perhaps $$k = 10$$ bins (categories) with boundaries at the deciles of $$\mathsf{Norm}(100, 15).$$ and determine the count $$X_i$$ in bins $$i = 1, 2, \dots, 10.$$ Using the deciles to make bins, you would expect $$E = 200/10 = 20$$ observations in each bin. Then the chi-squared GOF test statistic is $$Q = \sum_{i=1}^{10} \frac{(X_i - E)^2}{E},$$ which has approximately a chi-squared distribution with degrees of freedom $$\mathrm{df} = k - 1.$$

Note: In general, you should have $$E > 5$$ and you would need to choose the number $$k$$ of bins accordingly. If you choose arbitrary bins (not based on equally spaced percentiles), then you would need to find the probability $$p_i$$ according to the hypothetical normal distribution in each bin to get expected counts $$E_i = np_i.$$

• Your recipe for the chi-squared test with unspecified parameters isn't correct--and sometimes the results can be erroneous. See the middle of my post at stats.stackexchange.com/a/17148/919. The problems are summarized at "Things went wrong ... " – whuber Apr 7 at 20:27
• @whuber: Thanks much for your comment. I edited my answer to deter to your link for the case where mean and SD have to be estimated. I have added a mention of the K-S test. // What I have not discussed is how to choose the number $k$ of bins in the chi-squared test to get reasonable power for detecting nonnormal data. My example uses $k=10$ for $E=20.$ It seems clear $k=4$ and $k=1000$ would both be unsuitable. I vaguely recall we have a discussion on this. If so, do you know the link? – BruceET Apr 7 at 23:14
• I can't remember! If I come across it, I'll let you know. (+1). – whuber Apr 7 at 23:41