The chi-square goodness-of-fit test examines the null hypothesis that the probabilities of the k possible outcomes for a categorical variable are equal to a particular set of values, p1,p2,…,pk. The data for the test are the observed counts in the k cells, n1,n2,…,nk.
Expected cell counts under the null hypothesis are
expected count=npi
where n is the total number of observations.
The chi-square statistic measures how much the observed cell counts differ from the expected cell counts. The formula for the statistic is
The degrees of freedom are k−1, and P-values are computed from the chi-square distribution. Use this procedure when the expected counts are all 5 or more.