10.3 Test for Independence
Use the chi-square test for independence to test the independence of two categorical variables. Remember, qualitative data is collected on individuals that are categories or names. Then you would count how many of the individuals had particular qualities. An example is that there is a theory that there is a relationship between breastfeeding and having autism spectrum disorder (ASD). To determine if there is a relationship, researchers could collect the time-period that a mother breastfed her child and if that child was diagnosed with ASD. Then you would have a table containing this information. Now you want to know if each cell is independent of each other cell. Remember, independence says that one event does not affect another event. Here it means that having ASD is independent of being breastfed. What you really want is to see if they are dependent (not independent). In other words, does one affect the other? If you were to do a hypothesis test, this is your alternative hypothesis and the null hypothesis is that they are independent. There is a hypothesis test for this and it is called the chi-square test for independence.
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 expected frequencies and the observed frequencies should be the same.
The test statistic here will involve looking at the difference between the expected frequency and the observed frequency for each cell. Then you want to find the “total difference” of all of these differences. The larger the total, the smaller the chances that you could find that test statistic given that the assumption of independence is true. That means that the assumption of independence is not true.
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 process finds the variance, and we use a chi-square 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; leave the other rows alone: Store Expected to: statvars\e; Store CompMat to: statvars\c. 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), hosted on LibreTexts (stats.libretexts.org) and licensed under CC BY-SA 4.0. Changes were made. License: CC-BY-SA-4.0.