A sorting device is advertised to send objects to four channels equally often, and a run of 80 objects gives counts of 28, 22, 18 and 12. Even a device that works perfectly rarely splits 80 objects evenly, so uneven counts alone do not settle anything. The real question is whether this much imbalance is unusual for a device that works as advertised. This lesson measures the gap between observed counts and the counts a probability model predicts, turns it into a p-value, and shows how the reference distribution changes when the model is fitted to the same data.
Key terms
Multinomial model
Definition A multinomial model describes observations, each falling into exactly one of categories. The observations are independent, and each one falls into category with the same probability , where every and . The category counts then add to and have the multinomial distribution
for whole numbers with . Each count on its own is binomial with trials and success probability , so .
In plain words The model is a die with faces of possibly unequal weights, rolled times. The categories must not overlap and must cover every possible outcome, or the probabilities could not add to 1. Observations that arrive in correlated batches, or probabilities that drift during the collection period, break the model, and a test built on it can then mislead.
Example If the 80 objects are routed independently and each one goes to any given channel with probability , the four channel counts follow a multinomial model with and . Under this model the chance of exactly 20 objects in every channel is only about 0.0014, so unequal counts are the usual result even for a perfect device.
Goodness-of-fit test
Definition For counts from a multinomial model with categories, a goodness-of-fit test of a specified model tests
against the alternative that for at least one . The specified probabilities are positive, add to 1 and are fixed before the data are seen. The test measures how far the observed counts are from the counts the model predicts. A small p-value is evidence against the specified model. A large p-value means the data are compatible with the model, not that the model is true.
In plain words There is one categorical variable and one proposed distribution, and the question is whether the counts sit farther from the proposal than chance usually puts them. A test of independence asks a different question, whether two categorical variables measured on the same units are related, and it builds its expected counts from the margins of a two-way table rather than from probabilities given in advance.
Example For the sorting device, the null hypothesis says each channel has probability , and says at least one channel probability differs from . The data are the counts 28, 22, 18 and 12 from 80 objects. If the test does not reject , it has not shown that the four probabilities are exactly equal.
Expected frequency
Definition Under a specified model the expected frequency of category is
the mean of the count when holds. The expected frequencies add to , and they need not be whole numbers.
In plain words An expected frequency is the average count the model predicts over many samples of the same size, not a count that any single sample is supposed to hit. Comparing each count with its expected frequency, rather than the counts with each other, is what brings the model into the test.
Example For the device, every channel has . For three categories with probabilities , and and a sample of 60, the expected frequencies are 15, 30 and 15. With a sample of 50 and a probability of , the expected frequency is , and it is used without rounding.
Chi-square statistic
Definition Pearson’s chi-square statistic for observed counts and expected frequencies is
It equals exactly when every count equals its expected frequency, and larger values mean a larger discrepancy. If holds, the specified probabilities are all positive and the expected frequencies are large, then has approximately the chi-square distribution with degrees of freedom. The p-value is at the observed value , the approximate probability, computed assuming , of a statistic at least as large as the one observed. The number reflects the constraint that the counts add to , so once of them are known the last one is determined. The approximation can be poor when expected frequencies are small. A common guideline asks for all of them to be at least 5, but that is a rule of thumb, not a theorem. For sparse counts the exact multinomial distribution of can be used instead, or a simulation that draws many samples from the specified model and recomputes the same statistic. Merging categories changes the hypothesis being tested, so a merge should follow from the question, be decided before looking at the counts and be reported.
In plain words Squaring makes excesses and shortages count alike, and dividing by measures each gap against the size of its expectation, so a gap of 8 matters more when 20 are expected than when 200 are. For fixed proportions the statistic grows in proportion to the sample size, so a small p-value is not the same thing as a large or important discrepancy. Report the observed proportions next to the test.
Example For the counts 28, 22, 18 and 12, the differences from 20 are , , and , and
The first and last channels give most of it. With 3 degrees of freedom the p-value is . The exact multinomial probability of a statistic at least this large is about 0.078, close to the approximation because every expected frequency is 20. At a significance level of 0.05 chosen in advance, the test does not reject the model. Doubling every count to 56, 44, 36 and 24 keeps the proportions 0.35, 0.275, 0.225 and 0.15 but doubles the statistic to 13.6, with a p-value of about 0.0035.
Degrees of freedom for estimated parameters
Definition Sometimes says only that the probabilities belong to a family with unknown parameters, such as a binomial or Poisson family. The parameters are then estimated from the same data, and the expected frequencies become . If is the maximum likelihood estimate computed from the category counts and regularity conditions hold, then under the statistic has approximately the chi-square distribution with
degrees of freedom, which must be at least 1. The conditions include identifiable parameters, meaning that different parameter values give different category probabilities, a true parameter value inside the parameter range rather than on its boundary, positive category probabilities, and categories fixed before the data are seen. If the parameters are estimated from the raw, ungrouped observations instead, the large-sample distribution of lies between the chi-square distributions with and degrees of freedom, and in general neither one is exact.
In plain words Fitting the parameters moves the expected frequencies toward the observed counts, so tends to be smaller than it would be against a model fixed in advance. Each estimated parameter uses up one degree of freedom. Keeping would make the p-value too large and the test too reluctant to reject a poor model. The rule counts the parameters actually estimated from these counts, and it relies on a valid fitting method, not on counting the symbols in a formula.
Example Each of 80 observations records how many of two independent trials succeed, where every trial has the same unknown success probability, so the categories are 0, 1 and 2 successes. The counts are 25, 30 and 25. There are successes in 160 trials, so the estimate is . The fitted binomial probabilities , and give expected frequencies 20, 40 and 20, and
With categories and estimated parameter, and the p-value is . Using degrees of freedom by mistake would give about 0.082.
Check yourself
- A process is supposed to assign items to three categories with probabilities , and . In 60 independent assignments the counts are 18, 27 and 15. Find the expected frequencies, the chi-square statistic, the degrees of freedom and the approximate p-value.
Show the answer
The expected frequencies are , and 15. The differences are 3, and 0, so
No probability was estimated from the data, so there are degrees of freedom. For 2 degrees of freedom the upper tail beyond is exactly , so the p-value is . The sample gives little evidence against the specified probabilities, which is not the same as showing that they are correct.
- A spinner is advertised to land on red, blue and green with probabilities 0.5, 0.3 and 0.2. In 40 spins it lands on red 26 times, on blue 6 times and on green 8 times. A classmate converts the counts to the percentages 65, 15 and 20, compares them with 50, 30 and 20, and gets a statistic of 12. Find the correct statistic and p-value, and explain the mistake.
Show the answer
The expected frequencies are , and , so
with 2 degrees of freedom and a p-value of . At the 0.05 level the data are compatible with the advertised probabilities. All three expected frequencies are at least 8, so the chi-square approximation is reasonable here.
The statistic needs counts. Percentages treat the data as if there had been 100 spins, and since the statistic grows in proportion to the sample size for fixed proportions, the classmate’s value is times too large. Its p-value of about 0.0025 would wrongly suggest strong evidence against the spinner.
- Fifty pairs of seeds are planted, and for each pair the number of seeds that germinate is recorded. The numbers of pairs with 0, 1 and 2 germinated seeds are 12, 16 and 22. Test whether a binomial model with two trials and a common germination probability fits, with the probability estimated from these counts. How many degrees of freedom does the test have, and what pattern do the counts show?
Show the answer
There are germinated seeds out of 100, so the estimate is . The fitted probabilities are , and , so the expected frequencies are 8, 24 and 18, and
One parameter was estimated by maximum likelihood from the category counts, so , and the p-value is . Every expected frequency is at least 8, so the approximation is reasonable, and at the 0.05 level the test rejects the binomial model. Using 2 degrees of freedom by mistake would give about 0.062, and the test would not reject at that level.
More pairs than expected have no germinated seed or two germinated seeds, and fewer have exactly one, the category with the largest contribution, . That pattern fits seeds in the same pair sharing growing conditions, or a germination probability that varies from pair to pair. Either would break the assumption of independent trials with a common probability, and the test alone cannot say which one is happening.