In the chi square Goodness of fit test, we are determining how well the distribution
of experimental or observed data fits the population or expectation.
It is employed when dealing with counts or frequencies for a categorical variable with
2 or more categories or what is called a multinomial experiment.
In this first example, a car manufacturer expects customers will order colours of their
model J according to this distribution:
They selected a random sample of 140 orders as shown in this second table.
We want to test at the 5% significance level if there is a statistically significant difference
between the observed and expected frequencies.
The expected proportions in the first table will be the null hypothesized proportions.
In essence, we can write the null hypothesis as
p1 = 0.28, p2 = 0.25, p3 = 0.16 and p4 = 0.31.
The alternative will be that the null hypothesis is not true or not correct.
That is, at least one of the proportions is not as
specified in the null hypothesis.
In other words, the observed values are not consistent with
the expected distribution.
The goodness of fit test is a Chi square test.
Chi-square distributions are a family of distributions with each defined by its degrees of freedom.
They are typically skewed to the right and take on only positive values.
The degrees of freedom for the goodness of fit test are defined as k – 1,
where k is the number of categories in the independent variable.
Since we have 4 categories here, the degrees of freedom will be 3.
At alpha = 0.05, with degrees of freedom = 3, the critical value from the table or software
is 7.815.
So the rejection region is where the observed chi-square is greater than 7.815.
The formula for calculating the chi square statistic is shown here.
Or, sometimes in this format.
Where O represents observed frequency and E represents expected frequency.
The test statistic is a measure how far the observed frequencies are from expected
and it is easy to compute using a table set up like this one.
Here are the observed frequencies, which add up to 140.
The expected frequencies for the Goodness of Fit test are calculated by n times p_i.
where n is the total of the observed frequencies (that is, 140 in this case)
and the p_i’s are the expected proportions that we have in the null hypothesis here.
Therefore, for White, the expected frequency is 140 times 0.28
which gives 39.2.
For Black, 140 times 0.25 gives 35.
For Silver, we have 22.4 and for Other we have 43.4.
Adding these up we get a total Expected of 140 as well.
This is not a coincidence.
The expected frequencies must add up to the same total as the observed frequencies
since the expected proportions add up to 1.
Note that the Goodness of Fit test requires each expected cell frequency
to be at least 5.
If the expected cell for a category has a frequency less than 5,
we should combine that category with another category to satisfy that requirement.
Since all the expected values are greater than 5 here, that requirement is satisfied.
Another requirement is that of randomization.
Since we assumed we have a random sample at the beginning,
then that requirement is also satisfied.
Next, we take we compute the difference between the Observed and Expected here.
Then square the differences.
And finally, divide the squared differences by the expected.
The sum of this last column is 1.6315.
And it is the value of the chi square statistic for this test.
Since this test statistic is not greater than the critical value,
we fail to reject the null hypothesis.
The result is not statistically significant, or we don’t have enough evidence to conclude
that the distribution of the observed colours differs significantly from the expectation.
We can also estimate the p-value by checking on the df = 3 row,
where 1.63 will fall.
We see that it will fall between 0.584 and 6.251 here.
Therefore, the p-value is somewhere between alphas of 0.1 and 0.9.
Using software, we can obtain the exact P-value to be 0.6523.
Recall that the rule is: if the P-value < α, we reject the null hypothesis.
Since this p-value is much larger than our alpha of 0.05,
it confirms our decision to not reject the null hypothesis.
Now, suppose we simply want to test if there are preferences for any of the 4 categories.
That is, customer orders are different between the colour categories.
In other words, we want to determine if the frequencies differ significantly from a uniform
distribution.
Then the expected percentage in each category will be 100% divided by the number of categories,
which is 4 in this case.
So, we will expect 25% in each category if there is no preference.
The null hypothesis will thus be that all the proportions are equal to 0.25.
For the alternative hypothesis, we can still state that at least one pi is not as specified
in H0. or we can simply say that
at least one of the proportions is not equal to 0.25.
The degrees of freedom are still 3 and the rejection region is the same.
In calculating the test statistic, expected values can be obtained by n times
pi as before.
Or we can simply divide the sample size 140 by the number of categories 4,
to obtain 35 each for the expected cells.
Next, we take the differences, Square them.
Divide by expected and sum them to obtain the chi square statistic
of 9.7714.
Since this statistic is greater than the critical value,
we reject the null hypothesis.
From the chi square table, for df = 3, we also see that the test statistic falls
between the critical values for alpha = 0.025 and alpha = 0.01,
indicating that the p-value is less than 0.05.
Using software, the p-value is 0.0206 which is less than 0.05.
So, we reject the null hypothesis.
The result is statistically significant.
That is, we have enough evidence to conclude that the colours are not equally preferred.
Or that the colour categories are not equally distributed among the customer orders.
And that’s it for this video.
Thanks for watching.