3.4 Test of Independence and Goodness of Fit Test

The \(\chi ^2\) test is used to determine whether there is a significant difference between the observed and expected frequencies in one or more categories.

Do the number of individuals or objects that fall in each category differ significantly from the number you would expect? Is the difference merely sampling error, or is it real? That is what the test decides.

\(\chi ^2\) Test

1.
Quantitative data
2.
One or more categories
3.
Independent observations
4.
Enough sample size (at least 10)
5.
Simple random sampling
6.
Data frequencies

\[\text {Test statistic}\hspace {0.4cm} \chi ^2=\sum \frac {(O-E)^2}{E}\] Where:

\(O-\) the observed frequency in a category
\(E-\) the expected frequency in that category, if \(H_0\) were true
\(\chi ^2-\) the test statistic.

The differences are squared, so that shortfalls and excesses both count against \(H_0\) rather than cancelling, and each is divided by \(E\) so that a discrepancy is judged against the size of the category it occurs in – being 10 out on an expected 20 matters far more than being 10 out on an expected 2000.

Degrees of freedom. These are not \(n-1\), where \(n\) is the sample size. They count the categories, not the observations:

  • Goodness of fit: \(\text {df} = k-1-m\), where \(k\) is the number of categories and \(m\) the number of parameters estimated from the data. The \(-1\) appears because the expected frequencies are constrained to the same total as the observed ones, so once \(k-1\) of them are fixed the last is determined.
  • Test of independence: \(\text {df} = (r-1)(c-1)\) for an \(r\times c\) contingency table, since the row and column totals are fixed.

The \(\chi ^2\) - test should be used when the sampling distribution \(\chi ^2\approx \chi ^2_c\) distribution.

The conditions for these are:

1.
The total frequencies is not less than 50.
2.
The expected class frequencies are not less than 5.

If the second condition is not met it can be improved where \(v=1\) by making an adjustment known as YATES correction which involves reducing value of \(|O-e|\) by 1/2.

Example 3.10. Four coins where tossed 160 times , the results are given below showing the number of heads is this evidence that this coin is balanced.

number of heads 0 1 2 3 4
\(O\) 15 46 54 35 10

Solution.

1.
Set up the hypothesis

\(H_0: P=1/2\) vs \(H_1:P>1/2\)
2.
Set \(\alpha =0.05\)
3.
Test statistic: \(\displaystyle {\chi ^2=\frac {\sum (O-e)^2}{e}}\)

No of Heads \(O\) \(e\) \((O-e)^2\) \(\frac {(O-e)^2}{e}\)
0 15 \(160\times P(0)=10\) 25 2.500
1 46 \(160\times P(1)=40\) 36 0.900
2 54 \(160\times P(2)=60\) 36 0.600
3 35 \(160\times P(3)=40\) 25 0.625
4 10 \(160\times P(4)=10\) 0 0.000
Total 160 160 4.625

\begin {align*} P(x) &=\binom {n}{x}P^x(1-P)^{n-x}\\\\ e(0)=160\times P(0) &=160\times \binom {4}{0} \Big (\frac {1}{2}\Big )^0\Big (\frac {1}{2}\Big )^4=160\times \frac {1}{16}=10\\ \end {align*}

Our statistic is \(\chi ^2=4.625\)

4.
Critical Region
CAχrc2icteicpatla= Rnec9ge.i R4oe8ng8ion
  4,0.05
Figure 28: Goodness-of-fit test: the statistic against \(\chi ^2_{4,0.05}\).

Interpretation: Our statistic \(\chi ^2=4.625\) lies in the acceptance region.

We accept \(H_0\) and reject \(H_1\). That is the distribution follows a Binomial with \(P=1/2\), \(n=4\).
\(\therefore \) The coin is balanced, P-value is 0.075

Since the P-value is greater than 0.05 \(\implies \) Accept \(H_0\) and reject \(H_1\).

Example 3.11. On a national bases the success rate for the people taking the driving test for the first time is \(40\%\). A driving instructors records show that for the 50 pupils of his who took the test for the first time last year 25 passed.
Does his success rate differ from the national success rate?

Solution.

1.
Set up the hypothesis
\(H_0: P=0.40\)
\(H_1: P\neq 0.40\)
2.
Set up level of significance \(\alpha =0.05\)
3.
Test statistic \(\displaystyle {\chi ^2=\frac {\sum (O-e)^2}{e}}\)

\(O\) \(e\) \(|O-e|\) \(|O-e|-\frac {1}{2}\) \((|O-e|-1/2)^2\)
Passed 25 20 5 4.5 1.0015
fail 25 30
1.6875
4.
Critical Region
0χχχA.222c01,1,c20=0e5.0.0p25125t.6a=8=n7c550e.0.0 R20e41gion
Figure 29: Test of independence on a \(2\times 2\) table: \(\chi ^2=1.6875\) falls in the acceptance region.

P-value is 0.975
Since P -value is greater than 0.025 \(\implies \) We accept \(H_0\) and reject \(H_1\).

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.