14 Chapter 14: Chi-Square

We come at last to our final topic: chi-square (chi-squared). This test is a special form of analysis called a nonparametric test, so the structure of it will look a little bit different from what we have done so far. However, the logic of hypothesis testing remains unchanged. The purpose of chi-square is to understand the frequency distribution of a single categorical variable or find a relationship between two categorical variables, which is a frequently very useful way to look at our data.

Categories and Frequency Tables

Our data for the chi-squared test are categorical—specifically nominal—variables. Recall from Unit 1 that nominal variables have no specified order and can only be described by their names and the frequencies with which they occur in the dataset. Thus, unlike the other variables we have tested, we cannot describe our data for the chi-squared test using means and standard deviations. Instead, we will use frequencies tables.

Table 14.1 gives an example of a frequency table used for a chi-squared test. The columns represent the different categories within our single variable, which in this example is pet preference. The chi-squared test can assess as few as two categories, and there is no technical upper limit on how many categories can be included in our variable, although, as with ANOVA, having too many categories makes our computations long and our interpretation difficult. The final column in the table is the total number of observations, or uppercase N. The chi-squared test assumes that each observation comes from only one person and that each person will provide only one observation, so our total observations will always equal our sample size.

Table 14.1. Pet preferences

Cat

Dog

Other

Total

Observed

14

17

5

36

Expected

12

12

12

36

There are two rows in this table. The first row gives the observed frequencies of each category from our dataset; in this example, 14 people reported preferring cats as pets, 17 people reported preferring dogs, and 5 people reported a different animal. The second row gives expected values; expected values are what would be found if each category had equal representation. The calculation for an expected value is:

The formula: E equals N divided by C.

where uppercase N is the total number of people in our sample and C is the number of categories in our variable (also the number of columns in our table). The expected values correspond to the null hypothesis for chi-squared tests: equal representation of categories. Our first of two chi-squared tests, the test for goodness of fit, will assess how well our data lines up with, or deviates from, this assumption.

Test for Goodness of Fit

The test for goodness of fit assesses one categorical variable against a null hypothesis of equally sized frequencies. Equal frequency distributions are what we would expect to get if categorization was completely random. We could, in theory, also test against a specific distribution of category sizes if we have a good reason to. If we have information about how a population is distributed, we could compare our observed sample distribution to the expected values if the sample followed the same distribution as the population. For example, if we know that in the population of a small liberal arts college, 15% of students are international students, while 85% are domestic students, we would then calculate expected values for our sample using these percentages. In that case, we would be testing against the null hypothesis of 15% international students. This is less common, so we will not deal with more examples of this sort in this text.

Hypotheses

All chi-squared tests, including the test for goodness of fit, are nonparametric tests. This means that there is no population parameter we are estimating or testing against; we are working only with our sample data. Because of this, there are no mathematical statements for chi-squared hypotheses. This should make sense because the mathematical hypothesis statements were always about population parameters (e.g., mu symbol), so if we are nonparametric, we have no parameters and therefore no mathematical statements.

We do, however, still state our hypotheses verbally. For chi-squared tests for goodness of fit, our null hypothesis is that there is an equal number of observations in each category. That is, there is no difference between the categories in how prevalent they are. Our alternative hypothesis says that the categories do differ in their frequency. We do not have specific directions or one-tailed tests for chi-squared, matching our lack of mathematical statements.

Degrees of Freedom and the chi-squared Table

Our degrees of freedom for the chi-squared test are based on the number of categories we have in our variable, not on the number of people or observations like it was for our other tests. Luckily, they are still as simple to calculate:

The formula: df equals C minus 1.

So for our pet preference example, we have 3 categories, thus we have 2 degrees of freedom. Our degrees of freedom, along with our significance level (still defaulted to a = .05) are used to find our critical values in the chi-squared table, a portion of which is shown in Table 14.2. (The complete chi-squared table can be found in Appendix E.) Because we do not have directional hypotheses for chi-squared tests, we do not need to differentiate between critical values for one- or two-tailed tests. In fact, just like our tests for regression and ANOVA, all chi-squared tests are one-tailed tests.

Table 14.2. Critical Values for Chi-Square (chi-squared Table)

df

Proportion in Critical Region

.1

.05

.02

.01

.005

1

2.706

3.841

5.024

6.635

7.879

2

4.605

5.991

7.378

9.210

10.597

3

6.251

7.815

9.348

11.345

12.838

4

7.779

9.488

11.143

13.277

14.860

5

9.236

11.070

12.833

15.086

16.750

6

10.645

12.592

14.449

16.812

18.548

7

12.017

14.067

16.013

18.475

20.278

8

13.362

15.507

17.535

20.090

21.955

9

14.684

16.919

19.023

21.666

23.589

10

15.987

18.307

20.483

23.209

25.188

Chi-Squared (bolded) Statistic

The calculations for our test statistic in chi-squared tests combine our information from our observed frequencies (O) and our expected frequencies (E) for each level of our categorical variable. For each cell (category) we find the difference between the observed and expected values, square them, and divide by the expected values. We then sum this value across cells for our test statistic. This is shown in the formula:

The Chi-squared test statistic formula: Chi-squared equals the sum of the quantity (Observed value minus Expected value) squared, divided by the Expected value.

For our pet preference data, we would have:

The chi-squared statistic is calculated as the sum of three terms. Each term is of the form (observed value minus expected value) squared, divided by the expected value. Given observed values of 14, 17, and 5, and an expected value of 12 for all, the calculation is as follows: The first term is (14 minus 12) squared over 12, which simplifies to 0.33. The second term is (17 minus 12) squared over 12, which simplifies to 2.08. The third term is (5 minus 12) squared over 12, which simplifies to 4.08. The total chi-squared value is the sum of these terms: 0.33 plus 2.08 plus 4.08, which equals 6.49.

Notice that, for each cell’s calculation, the expected value in the numerator and the expected value in the denominator are the same value. Let’s now take a look at an example from start to finish.

Example Pineapple on Pizza

There is a very passionate and ongoing debate about whether pineapple should go on pizza. Being the objective, rational data analysts that we are, we will collect empirical data to see if we can settle this debate once and for all. We gather data from a group of adults, asking for a simple yes-or-no answer.

Step 1: State the Hypotheses

We start, as always, with our hypotheses. Our null hypothesis of no difference states that an equal number of people will say they do and do not like pineapple on pizza, and our alternative hypothesis will be that one side wins out over the other:

Null hypothesis, H sub 0: An equal number of people do and do not like pineapple on pizza.

Alternative hypothesis H sub A: A significant majority of people agree one way or the other.

Step 2: Find the Critical Value

To avoid any potential bias in this crucial analysis, we will leave alpha symbol at its typical level. We have two options in our data (Yes or No), which will give us two categories. Based on this, we will have 1 degree of freedom. From our chi-squared table, we find a critical value of 3.84.

Step 3: Calculate the Test Statistic and Effect Size

The results of the data collection are presented in Table 14.3. We had data from 45 people in all and 2 categories, so our expected values are E = 45/2 = 22.50.

Table 14.3. Pineapple-on-pizza preferences

Yes

No

Total

Observed

26

19

45

Expected

22.50

22.50

45

We can use these to calculate our chi-squared statistic:

The chi-squared, equals the sum of two terms. Each term is calculated as the square of the difference between an observed value and an expected value, divided by the expected value. For the first term, the observed value is 26 and the expected value is 22.50. For the second term, the observed value is 19 and the expected value is 22.50. The equation shows: open parenthesis 26 minus 22.50 close parenthesis squared, divided by 22.50; plus open parenthesis 19 minus 22.50 close parenthesis squared, divided by 22.50. This evaluates to 0.54 plus 0.54, which equals 1.08.

Effect Size for Chi-Squared

Like all other significance tests, chi-squared tests—both for goodness of fit and for independence—have effect sizes that can and should be calculated. There are many options for which effect size to use, and the ultimate decision is based on the type of data, the structure of your frequency or contingency table, and the types of conclusions you would like to draw. For the purpose of our introductory course, we will focus only on a single effect size that is simple and flexible: Cramer’s V.

Cramer’s V is a type of correlation coefficient that can be computed on categorical data. Like any other correlation coefficient (e.g., Pearson’s r), the cutoffs for small, medium, and large effect sizes of Cramer’s V are .10, .30, and .50, respectively. The calculation of Cramer’s V is very simple:

The formula for V: V equals the square root of chi squared all over N times the quantity k minus 1.

For this calculation, k is the smaller value of either R (the number of rows) or C (the number of columns). The numerator is simply the test statistic we calculate during Step 3 of the hypothesis-testing procedure. For our example, we had 2 rows and 3 columns, so k = 2:

The formula for V is: V equals the square root of the fraction chi squared divided by N times the quantity k minus 1. This equals the square root of the fraction 1.08 divided by 45 times the quantity 2 minus 1. This simplifies to the square root of the fraction 1.08 divided by 45. This equals the square root of 0.024, which equals 0.15.

So the statistically significant relationship between our variables was moderately strong.

Step 4: Make the Decision

Our observed test statistic had a value of 1.08 and our critical value was 3.84. Our test statistic was smaller than our critical value, so we fail to reject the null hypothesis, and the debate rages on. Figure 14.1 shows the output from JASP for this example.

Figure 14.1. Output from JASP for the chi-squared test for goodness of fit described in the Pineapple on Pizza example. The output provides the chi-squared statistic (1.089), degrees of freedom (1) and the exact p value (.297, which is greater than .05). The output also provides the observed values and expected values (note that both expected values are 22.5, but decimals are not shown). Based on our sample of 45 people, there is no significant difference between the observed and expected values for preferring pineapple on pizza, chi-squared (1, N = 45) = 1.089, p = .297. (“JASP chi-square goodness of fit” by Rupa G. Gordon/Judy Schmitt is licensed under CC BY-NC-SA 4.0.)

A screenshot from the JASP statistical software showing the results of a multinomial test. The output is divided into two tables. The first table, labeled "Multinomial Test," shows the test statistics: (chi ^{2}=1.089), df = 1, and p = 0.297. The second table, labeled "Descriptives," displays the observed and expected frequencies for a variable named "Choice" with two categories: "No" and "Yes." The observed frequencies are 19 for "No" and 26 for "Yes," while the expected frequency for both is 22.

Contingency Tables for Two Variables

The test for goodness of fit is a useful tool for assessing a single categorical variable. However, what is more common is wanting to know if two categorical variables are related to one another. This type of analysis is similar to a correlation, the only difference being that we are working with nominal data, which violates the assumptions of traditional correlation coefficients. This is where the chi-squared test for independence comes in handy.

As noted above, our only description for nominal data is frequency, so we will again present our observations in a frequency table. When we have two categorical variables, our frequency table is crossed. That is, each combination of levels from each categorical variable is presented. This type of frequency table is called a contingency table because it shows the frequency of each category in one variable, contingent upon the specific level of the other variable.

An example contingency table is shown in Table 14.4, which displays whether or not 168 college students watched college sports growing up (Yes/No) and whether the students’ final choice of which college to attend was influenced by the college’s sports teams (Yes, primary; Yes, somewhat; No).

Table 14.4. Contingency table of college sports and decision making

Affected Decision

Primary

Somewhat

No

Total

Watched as a child

Yes

47

26

14

87

No

21

23

37

81

Total

68

49

51

168

In contrast to the frequency table for our test for goodness of fit, our contingency table does not contain expected values, only observed data. Within our table, wherever our rows and columns cross, we have a cell. A cell contains the frequency of observing its corresponding specific levels of each variable at the same time. The top left cell in Table 14.4 shows us that 47 people in our study watched college sports as a child and had college sports as their primary deciding factor in which college to attend.

Cells are numbered based on which row they are in (rows are numbered top to bottom) and which column they are in (columns are numbered left to right). We always name the cell using (R,C), with the row first and the column second. A quick and easy way to remember the order is that the brand RC Cola exists but CR Cola does not. Based on this convention, the top left cell containing our 47 participants who watched college sports as a child and had sports as a primary criteria is cell (1,1). Next to it, which has 26 people who watched college sports as a child but had sports only somewhat affect their decision, is cell (1,2), and so on. We only number the cells where our categories cross. We do not number our total cells, which have their own special name: marginal values.

Marginal values are the total values for a single category of one variable, added up across levels of the other variable. In Table 14.4, these marginal values have been made bold for ease of explanation, though this is not normally the case. We can see that, in total, 87 of our participants (47 + 26 + 14) watched college sports growing up and 81 (21 + 23 + 37) did not. The total of these two marginal values is 168, the total number of people in our study. Likewise, 68 people used sports as a primary criterion for deciding which college to attend, 50 considered it somewhat, and 50 did not consider it at all. The total of these marginal values is also 168, our total number of people. The marginal values for rows and columns will always both add up to the total number of participants, uppercase N, in the study. If they do not, then a calculation error was made and you must go back and check your work.

Expected Values of Contingency Tables

Our expected values for contingency tables are based on the same logic as they were for frequency tables, but now we must incorporate information about how frequently each row and column was observed (the marginal values) and how many people were in the sample overall (uppercase N) to find what random chance would have made the frequencies out to be. Specifically:

The expected value formula: E subscript i j equals R subscript i multiplied by C subscript j, all divided by N. Here, E subscript i j is the expected frequency for the cell in row i and column j, R subscript i is the total for row i, C subscript j is the total for column j, and N is the grand total of all observations.

The subscripts i and j indicate which row and column, respectively, correspond to the cell we are calculating the expected frequency for, and the Ri and Cj are the row and column marginal values, respectively. uppercase N is still the total sample size. Using the data from Table 14.4, we can calculate the expected frequency for cell (1,1), the college sport watchers who used sports at their primary criteria, to be:

The formula E sub one comma one equals the product of 87 and 68, divided by 168, which calculates to 35.21.

We can follow the same math to find all the expected values for this table:

Affected Decision

Primary

Somewhat

No

Total

Watched as a child

Yes

35.21

25.38

26.41

87

No

32.79

23.62

24.59

81

Total

68

49

51

168

Notice that the marginal values still add up to the same totals as before. This is because the expected frequencies are just row and column averages simultaneously. Our total uppercase N will also add up to the same value.

The observed and expected frequencies can be used to calculate the same chi-squared statistic as we calculated for the test for goodness of fit. Before we get there, though, we should look at the hypotheses and degrees of freedom used for contingency tables.

Test for Independence

The chi-squared test performed on contingency tables is known as the test for independence. In this analysis, we are looking to see if the values of each categorical variable (that is, the frequency of their levels) is related to or independent of the values of the other categorical variable. Because we are still doing a chi-squared test, which is nonparametric, we still do not have mathematical versions of our hypotheses. The actual interpretations of the hypotheses are quite simple: the null hypothesis says that the variables are independent or not related, and the alternative hypothesis says that they are not independent or that they are related. Using this setup and the data provided in Table 14.4, let’s formally test for whether watching college sports as a child is related to using sports as a criteria for selecting a college to attend.

Example College Sports

We will follow the same four-step procedure as we have since Chapter 7.

Step 1: State the Hypotheses

Our null hypothesis of no difference will state that there is no relationship between our variables, and our alternative will state that our variables are related.

Null hypothesis H naught: College choice criteria is independent of college sports viewership as a child.

The alternative hypothesis, H subscript A, declares that college choice criteria is related to college sports viewership as a child.

Step 2: Find the Critical Value

Our critical value will come from the same table that we used for the test for goodness of fit, but our degrees of freedom will change. Because we now have rows and columns (instead of just columns) our new degrees of freedom use information from both:

The formula for degrees of freedom: df equals R minus 1, multiplied by C minus 1.

In our example:

The degrees of freedom, df, equals the product of (2 minus 1) and (3 minus 1), which simplifies to the product of 1 and 2, resulting in 2.

Based on our 2 degrees of freedom, our critical value from our table is 5.991.

Step 3: Calculate the Test Statistic and Effect Size

The same formula for chi-squared is used once again:

The Chi-squared test statistic formula: Chi-squared equals the sum of the quantity (Observed value minus Expected value) squared, divided by the Expected value.

"The chi-squared statistic, denoted by the Greek letter chi squared, is shown as the sum of six fractions. Each fraction follows the pattern of an observed count minus an expected count, squared, then divided by the expected count. The first fraction is (47 minus 35.21) squared, divided by 35.21. The second is (26 minus 25.38) squared, divided by 25.38. The third is (14 minus 26.41) squared, divided by 26.41. The fourth is (21 minus 32.79) squared, divided by 32.79. The fifth is (23 minus 23.62) squared, divided by 23.62. The sixth and final fraction is (37 minus 24.59) squared, divided by 24.59."

The formula for chi-squared equals the sum of six decimal values: 3.94 plus 0.02 plus 5.83 plus 4.24 plus 0.02 plus 6.26, which equals 20.31.

Step 4: Make the Decision

The final decision for our test of independence is still based on our observed value (20.31) and our critical value (5.991). Because our observed value is greater than our critical value, we can reject the null hypothesis.

Reject H0. Based on our data from 168 people, we can say that there is a statistically significant relationship between whether someone watches college sports growing up and the influence a college’s sports teams have on that person’s decision on which college to attend, and the effect size was moderate, chi-squared(2, N = 168) = 20.31, p < .05, V < .348.

Figure 14.2 shows the output from JASP for this example.

Figure 14.2. Output from JASP for the chi-squared test for independence described in the College Sports example. The output provides the chi-squared statistic (20.309), degrees of freedom (2), and the p value of less than .001. The output also provides the observed count and expected count in the contingency table and Cramer’s V (.348) in the nominal table. Based on our data from 168 people, we can say that there is a statistically significant relationship between whether someone watches college sports growing up and the influence a college’s sports teams have on that person’s decision on which college to attend, chi-squared (2, N = 168) = 20.31, p < .001, V = .348. (“JASP chi-square independence” by Rupa G. Gordon/Judy Schmitt is licensed under CC BY-NC-SA 4.0.)

A screenshot from the statistical software JASP showing the results of a chi-square test of independence. The output includes a contingency table for the variables "Watched" and "Decision," along with the count and expected count values. Below the table, the chi-square test results show a value of 20.309, 2 degrees of freedom, and a p-value of less than .001. Additionally, a Cramer's V value of 0.348 is listed. The results of a chi-squared test of independence, which is used to determine if there is a statistically significant relationship between two categorical variables. In this case, the variables are "Watched" (Yes/No) and "Decision" (Somewhat, Primary, No). Chi-squared statistic ((chi ^{2})): The calculated value is 20.309. Degrees of freedom (df): The degrees of freedom are 2. p-value (p): The p-value is less than 0.001. Since this value is less than the typical significance level of 0.05, it indicates a statistically significant relationship between the two variables. Cramer's V: This value, 0.348, is a measure of the strength of the association between the variables. It is a correlation coefficient for categorical data. A value of 0.348 suggests a moderate association. Contingency Table: The table shows the observed counts and the expected counts for each combination of the variables. The observed counts are the actual data, while the expected counts are what would be expected if there were no relationship between the variables. The large differences between the observed and expected counts, particularly in the "Primary" and "No" columns, contribute to the significant chi-squared value.

Exercises

  1. What does a frequency table display? What does a contingency table display?
  2. What does a test for goodness of fit assess?
  3. How do expected frequencies relate to the null hypothesis?
  4. What does a test for independence assess?
  5. Compute the expected frequencies for the following contingency table:

    Category A

    Category B

    Category C

    22

    38

    Category D

    16

    14

  6. Test significance and find effect sizes for the following tests:
    1. N = 19, R = 3, C = 2, chi-squared(2) = 7.89, a = .05
    2. N = 12, R = 2, C = 2, chi-squared(1) = 3.12, a = .05
    3. N = 74, R = 3, C = 3, chi-squared(4) = 28.41, a = .01
  7. You hear a lot of people claim that The Empire Strikes Back is the best movie in the original Star Wars trilogy, and you decide to collect some data to demonstrate this empirically (pun intended). You ask 48 people which of the original movies they liked best; 8 said A New Hope was their favorite, 23 said The Empire Strikes Back was their favorite, and 17 said Return of the Jedi was their favorite. Perform a chi-squared test on these data at the .05 level of significance.
  8. A pizza company wants to know if people order the same number of different toppings. They look at how many pepperoni, sausage, and cheese pizzas were ordered in the last week. Fill out the rest of the frequency table and test for a difference.

    Pepperoni

    Sausage

    Cheese

    Total

    Observed

    320

    275

    251

    Expected

  9. A university administrator wants to know if there is a difference in proportions of students who go on to grad school across different majors. Use the data below to test whether there is a relationship between college major and going to grad school.

    Major

    Psychology

    Business

    Math

    Graduate School

    Yes

    32

    8

    36

    No

    15

    41

    12

  10. A company you work for wants to make sure they are not discriminating against anyone in their promotion process. You have been asked to look across gender to see if there are differences in promotion rate (i.e., if gender and promotion rate are independent or not). The following data should be assessed at the normal level of significance:

    Promoted in Last Two Years?

    Yes

    No

    Gender

    Women

    8

    5

    Men

    9

    7

Answers to Odd-Numbered Exercises

1)
Frequency tables display observed category frequencies and (sometimes) expected category frequencies for a single categorical variable. Contingency tables display the frequency of observing people in crossed category levels for two categorical variables, and (sometimes) the marginal totals of each variable level.

3)
Expected values are what we would observe if the proportion of categories was completely random (i.e., no consistent difference other than chance), which is the same was what the null hypothesis predicts to be true.

5)
Observed:

Category A

Category B

Total

Category C

22

38

60

Category D

16

14

30

Total

38

52

90

Expected:

Category A

Category B

Total

Category C

The expression 60 multiplied by 38, divided by 90, equals 25.33.

The calculation shows the product of sixty and fifty-two, divided by ninety, which equals thirty-four point sixty-seven.

60

Category D

The expression 30 multiplied by 38, all divided by 90, equals 12.67.

The equation is: the product of 30 and 52, all divided by 90, equals 17.33.

30

Total

38

52

90

7)

Step 1: H0: “There is no difference in preference for one movie,” HA: “There is a difference in how many people prefer one movie over the others.”
Step 2: Three categories (columns) gives df = 2, The statistical symbol for the chi-square critical value. = 5.991
Step 3: Based on the given frequencies:

New Hope

Empire

Jedi

Total

Observed

8

23

17

48

Expected

16

16

16

chi-squared = 7.13. Since this is a statistically significant result, we should calculate an effect size:Cramer’s V equals the square root of the fraction 7.13 divided by the quantity 48 times the difference 3 minus 1. The entire expression equals 0.27., which is a moderate effect size

Step 4: Our obtained statistic is greater than our critical value, reject H0. Based on our sample of 48 people, there is a statistically significant difference in the proportion of people who prefer one Star Wars movie over the others, chi-squared(2, N = 48) = 7.13, p < .05.

9)
Step 1: H0: “There is no relationship between college major and going to grad school,” HA: “Going to grad school is related to college major.”
Step 2: df = 2, The statistical symbol for the chi-square critical value. = 5.991
Step 3: Based on the expected frequencies:

Major

Psychology

Business

Math

Graduate School

Yes

24.81

25.86

25.33

No

22.19

23.14

22.67

chi-squared = 2.09 + 12.34 + 4.49 + 2.33 + 13.79 + 5.02 = 40.05Step 4: Obtained statistic is greater than the critical value, reject H0. Based on our data, there is a statistically significant relationship between college major and going to grad school, chi-squared(2, N = 144) = 40.05, p < .05, V = .53, which is a large effect.

 

definition

License

Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Introduction to Statistics in the Psychological Sciences Copyright © 2021 by Linda R. Cote Ph.D.; Rupa G. Gordon Ph.D.; Chrislyn E. Randell Ph.D.; Judy Schmitt; and Helena Marvin is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book