The test below is for a single categorical variable. The null hypothesis and alternative hypothesis for the goodness of fit test are
The π1,0,π2,0,…,πk,0 represent the hypothesized probabilities of each category. The Chi-Squared test statistic is:
where Oi is the observed frequency and Ei = nπi,0 is the expected frequency. The test
statistic follows, approximately, a Chi-squared distribution with k - 1 degrees of
freedom.
For example, imagine that it is believed that for mobile phones black is chosen 70% of the time, then pink at 20% and others at 10%. This would be the null hypothesis.
The researcher decides to reject the null hypothesis at an alpha level of 0.05. A random sample of 100 people that have mobile phones are asked the color of their phone. From the survey, 75 people have black phones, 10 people pink, and 15 another color. Thus
which has approximately a Chi-squared distribution with (3-1) degrees of freedom. Thus since 7.857 > 5.991 the researcher decides to reject the null hypothesis and believes that the percent of black, pink and other phones are not the percent previously believed.