The basic test statisic which we shall employ is

X^2 = (*sum*((o(i)-e(i))^2/e(i))

Which is approximately distributed as chi-square. o(i) is the observed number of items in the ith category, and e(i) is the expected (hypothesized) number. Although we cannot fully comprehend this expression, we note that it is always non-negative, it is zero if and only if all the observed values are equal to the corresponding expected values, and the magnitude of X^2 increases with the discrepancy of the observed values from the expected values.

Degrees of freedom

The distribution of chi-square depends on the number of degrees of freedom.
The number of degrees of freedom is the number of data you are free to
specify, i.e., the number of data minus the number of constraints. This will
be illustrated below.

Goodness of fit

You are told that 50% of people eat vanilla ice cream, 25% eat chocolate, and
25% eat strawberry. If you see 35 people eating vanilla ice cream, 20 eating
chocolate ice cream, and 31 eating strawberry ice cream, do you question that
hypothesis?

There are N=35+20+31=86 people. Therefore you expect .5 × 86 = 43
vanillas, .25 × 86 = 21.5 chocolates, and .25 × 86 = 21.5
strawberries.

X^2 = (((35-43)^2)/43) + (((20-21.5)^2)/21.5) +
(((31-21.5)^2)/21.5) = 5.7907.

There are three pieces of data, the number of people eating vanilla, chocolate,
and strawberry ice cream (n=3). But those numbers must sum to 86, there is one
constraint. The number of degrees of freedom is 3-1=2. In general, for
goodness of fit, the number of degrees of freedom will be n-1. (Note that n
is the number of categories (3), not the number of people (86).

In our chi-square table we see that for two degrees of freedom, 4.61 is
associated with a tail area of .1, and 5.99 is associated with a tail area of
.05. 4.61 < 5.79 < 5.99. Therefore, we reject the null hypothesis at
the 10% significance level, but not at the 5% significance level.

Test of independence

Sometimes one wishes to know whether two variables are independent, e.g.,
whether knowing ones sex provides information about what ones grade will be.
For such questions, the expected values have to be calculated from the
observed values based on the assumption of independence. The table structure
employed in the page on Bayes and other problems may
be useful.

A professor assigns 5 A's to men, 11 A's to women, 6 B's to men, 18 B's to
women, 21 C's to men, and 16 C's to women. Are sex and grades independent?

5+11+6+18+21+19=80; (5+6+21)/80=.4 of the students are men, (11+18+19)/80=.6
of the students are women; (5+11)/80=.2 of the students received A's,
(6+18)/80=.3 of the students received B's, and (21+19)/80=.5 of the students
received C's. This is the information which we use to calculate the expected
values. The expected proportions, assuming independence, are:

A B C ____________________________ | | | | Male | .08 | .12 | .20 | .4 | | | | ---------------------------- | | | | Female | .12 | .18 | .30 | .6 |________|________|________| .20 .30 .50Multiplying the above entries by 80 converts from proportions to actual counts:

A B C ____________________________ | | | | Male | 6.4 | 9.6 | 16 | 32 | | | | ---------------------------- | | | | Female | 9.6 | 14.4 | 24 | 48 |________|________|________| 16 24 40Note that the values in the margins (numbers per grade and per sex) are the original observed values. This table has count values which can be be used with the original observations in the X^2 formula.

X^2 = ((5-6.4)^2)/6.4 + ((6-9.6)^2)/9.6 + ((21-16)^2)/16 + ((11-9.6)^2)/9.6 + ((18-14.4)^2)/14.4 + ((19-24)^2)/24 = 5.3646

There are 6 numbers specifying the numbers of men and women receiving A's, B's, and C's. The total number of A's, B's, C's, men and women are specified. However, since the total sum is 80, one of those constraints is redundant. Therefore, the number of degrees of freedom is 6-4=2 (in general, for tests of independence the number of degrees of freedom in (r-1)(c-1) where r is the number of rows and c is the number of columns in the tabular display of the information).

Looking at our chi-square table for two degrees of freedom, we see that 4.61 <: 5.36 < 5.99, hence we reject the hypothesis of independence at the 10%, but not at the 5% significance level.

Note that in testing for independence, we are not testing for bias; whether or not women are favored with higher grades is another question. An application of test of independence to diet and health is linked here.

The other tail

Random choice causes deviation around the expected values. Sometimes it is of
interest to ask whether there is too little deviation. This might occur if a
student faked his data rather than perform an experiment, if an employer
hired based on quotas rather than without regard to race. This would result in
an X^2 value which is very small. Some chi-square tables include large tail areas (near one, e.g., .99) as well as small tail areas (near
zero, e.g., .01) in order to serve the above questions, such as the example which follows:

The local population in a community is 6% Hispanic, 11% African-American, and
83% Caucasion. If an employer had 13 Hispanics, 23 African-Americans, and
164 Caucasian employees, would you accuse him of using quotas?

The total number of employees is 200, which means that 12 Hispanic, 22
African-American, and 166 Caucasian are the expected values. The value
of X^2 is .1529. Looking at the chi-square table for two degrees of freedom,
We see that .10 < .15 < .21. the former value corresponds to a tail area
of .95, and the latter to a tail area of .90. Since we are interested in X^2
being 'too small' we would accuse him of using quotas at the 10%, but not
the 5%, significance level.

**Competencies:** If in 50 rolls of a die, you got 9 1's, 4 2's, 12 3's, 3 4's, 13 5's, and 9 6's, would you question that the die was fair (at the 10% significance level?, the 5% significance level? the 1% significance level?)