10.3 Test for Independence
Use the chi-square test for independence to assess association between two categorical variables. Count each sampled individual in a contingency-table cell. For example, a table may cross-classify a child’s ASD diagnosis and reported duration of breastfeeding. The null hypothesis states that the variables are independent; the alternative states that they are associated. Association concerns their joint distribution. This observational test alone does not establish that one variable causes the other.
Finding the test statistic involves several steps. First, the data is collected, counted, and then organized into a contingency table. These values are known as the observed frequencies, and the symbol for an observed frequency is . Total each row and column.
The null hypothesis is that the two variables are independent. If two events are independent then and we can use the multiplication rule for independent events, to calculate the probability that variable and as the . Remember in a hypothesis test, you assume that is true, the two variables are assumed to be independent.

Now you want to find out how many individuals you expect to be in a certain cell. To find the expected frequencies, you just need to multiply the probability of that cell times the total number of individuals. Do not round the expected frequencies.
If the variables are independent, the observed frequencies should be reasonably close to the expected frequencies, allowing for random sampling variation.
The statistic sums over the cells. Larger values indicate stronger departures from the fitted counts under independence. The right-tail p-value measures how unusual this statistic or a larger one would be under the null model. A small p-value is evidence against independence; it does not prove dependence with certainty or establish causation.
How do you find the test statistic? First, compute the differences between the observed and expected frequencies. Because some of these differences will be positive and some will be negative, you need to square these differences. These squares could be large just because the frequencies are large, so you need to divide by the expected frequencies to scale them. Then finally add up all of these fractional values. This sum is Pearson’s chi-square statistic, rather than a sample variance. Under the null model and the count assumptions, use a chi-square reference distribution to find the critical value or p-value. Hence, sometimes this test is called a chi-square test.
It will be helpful to make a table for the expected counts and another one for each of the values to aid in computing the test statistic.

The test statistic is the sum of all eight values: .
The critical value for a right-tailed -test with degrees of freedom is found using a -distribution right-tail area. The critical value is = CHISQ.INV.RT(0.01,3) = 11.3449. See Figure 10-5.

Alternatively, use the online calculator: https://homepage.divms.uiowa.edu/~mbognar/applets/chisq.html.

Since the test statistic is not in the rejection area, our decision is to fail to reject .
There is not enough evidence to show a relationship between autism spectrum disorder and breastfeeding.

If we were asked to find the p-value, you would just find the area to right of the test statistic (always a right-tailed test) using your calculator or Excel. This gives a p-value = 0.0106, which is more than ; therefore, we do not reject H0.
You can also use the -Test shortcut keys on your calculator to get a p-value, see directions below.
TI-84: Press the [2nd] then [MATRX] key. Arrow over to the EDIT menu and 1:[A] should be highlighted, press the [ENTER] key. For a contingency table, type in the number of rows and the number of columns at the top of the screen so that it looks like this: MATRIX[A] . For a contingency table, the top of the screen would look like this: MATRIX[A] . As you hit [ENTER], the table will automatically widen to the size you put in. Now enter all of the observed values in their proper positions. Then press the [STAT] key, arrow over to the [TESTS] menu, arrow down to the option [C: -Test] and press the [ENTER] key. Leave the default as Observed:[A] and Expected:[B], arrow down to [Calculate] and press the [ENTER] key.
The calculator returns the -test statistic and the p-value.
If you go back to the matrix menu [2nd] then [MATRX] key, arrow over to EDIT and choose 2:[B], you will see all of the expected values.
![Five TI-84 screens for the matrix χ²-Test: the matrix EDIT menu, matrix [A] entered as a 2 by 4 table of observed counts ending with cell 2,4 = 44, the TESTS menu with C:χ²-Test selected, the inputs Observed:[A] and Expected:[B], and the output χ²=11.21668801, p=.0106100514, df=3.](photos/17070_clipboard_ef2b107930424500e6b9f219631f5c2f8.jpg)
TI-89: First you need to create the matrix for the observed values: Press [Home] to return to the Home screen, press [Apps] and select Data/Matrix Editor. A menu is displayed, select 3:New. The New dialog box is displayed. Press the right arrow key to highlight 2:Matrix, and press [ENTER] to choose Matrix type. Press the down arrow key to highlight 1:Main, and press [ENTER], to choose main folder. Press the down arrow key, and then enter the letter for the name in the Variable field. Enter 2 for Row dimension and 4 for Column dimension. Press [ENTER] to display the matrix editor. Enter the observed value (do not include total row or column). Important: Next time you use this test instead of option 3:New, choose 2: Open. The open dialog box is displayed. Press the right arrow key to highlight 2:Matrix, and press [ENTER] to choose Matrix type. Press the down arrow key to make sure you are in the Main folder and that your variable says . Press [Apps], and then select Stats/List Editor. To display the Chi-square 2-Way dialog box, press 2nd then F6 [Tests], then select 8: Chi-2 2-way. Enter in in the Observed Mat: o; set Store Expected to: statvars\expmat; Store CompMat to: statvars\compmat. This will store the expected values in the matrix folder statvars with the name expmat, and the values in the matrix compmat. Press the [ENTER] key to calculate. The calculator returns the -test statistic and the p-value. If you go back to the matrix menu, you will see some of the expected and values.

To see all the expected values, select [APPS] and select Data/Matrix Editor. Select 2:Open, change the Type to Matrix, change the Folder to statvars, and change the Variable to expmat.

To see all the values, select [APPS] and select Data/Matrix Editor. Select 2:Open, change the Type to Matrix, change the Folder to statvars, and change the Variable to compmat.

If you need to delete a row or column, move the cursor to the row or column that you want to delete, then select F6 Util, then 2:Delete, then choose row or column, then enter. To add a row or column, just arrow over to the new row or column and type in the observed values.

Example 2
The sample data below show the number of companies providing dental insurance for small, medium and large companies. Test to see if there is a relationship between dental insurance coverage and company size. Use .
Try it in XYZ Crunch
Turn χ² = 9.9073 into the p-value
This 2 × 3 table has df = (2 - 1)(3 - 1) = 2, and the link opens the chi-square curve with the area right of the test statistic already shaded: p = 0.0071, well under α = 0.05, so reject. The contingency table itself still has to be typed into the Chi-Square panel's Test for Independence grid - a link cannot preload a matrix yet - but every independence test ends at this same one-number read.

Show solution
State the hypotheses.
Dental insurance coverage and company size are independent.
Dental insurance coverage and company size are dependent.
Compute the expected values by taking each row total times column total, divided by grand total.

For the small companies with dental insurance: ,
small companies without dental insurance: ,
medium companies with dental insurance: , etc. See table below.

Compute the test statistic.

Test statistic is .
Use technology to find the p-value using the chi-square cdf with .

Using the TI-Calculator, we find the p-value = 0.0071.
The p-value is less than ; therefore, reject .
There is enough evidence to support the claim that there is a relationship between dental insurance coverage and company size.
Adapted from Mostly Harmless Statistics by Rachel Webb (Portland State University, https://mostlyharmlessstat.wixsite.com/webpage), © Rachel Webb, licensed under CC BY-SA 4.0. Changes were made. License: CC-BY-SA-4.0.