The chi-square goodness-of-fit test
When to use this test:
The \(\chi^2\) goodness-of-fit test (Chi-square goodness-of-fit test), also called the one-sample \(\chi^2\) test, is designed to test the agreement of the values observed for \(r\) (\(r\geq2\)) categories \(X_1, X_2,..., X_r\) of a single feature \(X\) with hypothetical expected values for that feature. The values of all \(n\) measurements should be gathered into a table consisting of \(r\) rows (categories: \(X_1, X_2, ..., X_r\)). For each category \(X_i\), we record the frequency of its occurrence \(O_i\), and either the frequency expected for it \(E_i\), or the probability of its occurrence \(p_i\). The expected frequency is calculated as the product \(E_i=np_i\). The resulting table can take one of the forms below.
Assumptions
- measurement on a nominal scale – any ordering of the categories is not taken into account,
- large expected frequencies, according to the Cochran interpretation (1952)[41],
- the sum of the observed frequencies should equal the sum of the expected frequencies, and the sum of all probabilities \(p_i\) should equal 1.
The table of data can take one of the following forms:
|
|
How to set up the analysis
Statistics \(\to\) Nonparametric tests \(\to\) Chi-square (or via the Wizard).

Performing and interpreting the analysis
Example 1. (dinners.pqs file)
We would like to find out whether the number of dinners served on successive days of the week (Monday to Friday) in a certain school canteen is statistically the same. To do this, a one-week sample was taken, and the number of dinners served was recorded for each day: Monday – 33, Tuesday – 29, Wednesday – 32, Thursday – 36, Friday – 20.
In total, 150 dinners were served over the whole week (5 days). We assume that the probability of a dinner being served is the same on each day, i.e. it equals \(\frac{1}{5}\). The expected number of dinners served for each of the five days of the week is therefore \(E_i=150\cdot\frac{1}{5}=30\).



Hypotheses:
Formulas:
The test statistic is defined by:
This statistic asymptotically (for large expected frequencies) has the \(\chi^2\) distribution with the number of degrees of freedom calculated using the formula \(df=(r-1)\).
The \(p\) value, determined on the basis of the test statistic and the \(\chi^2\) distribution, is compared with the significance level \(\alpha\): if \(p \le \alpha\), we reject \(\mathcal{H}_0\) in favor of \(\mathcal{H}_1\); if \(p > \alpha\), there is no reason to reject \(\mathcal{H}_0\).
PQStat