Skip to main content
Statistics LibreTexts

11.3: Tests Using Contingency tables

  • Page ID
    13835
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\dsum}{\displaystyle\sum\limits} \)

    \( \newcommand{\dint}{\displaystyle\int\limits} \)

    \( \newcommand{\dlim}{\displaystyle\lim\limits} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \(\newcommand{\longvect}{\overrightarrow}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\ket}[1]{\left| #1 \right>}\)
    \(\newcommand{\bra}[1]{\left< #1 \right|}\)
    \(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
    \(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
    \(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
    \(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
    \(\newcommand{\expect}[1]{\langle #1 \rangle}\)
    \(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    Introduction

    We will review two additional tests that use the chi-squared distribution. The test for independence and the test for homogeneity. Both tests help us look for relationships between two data set by comparing what we observe with what we expect much like the goodness of fit test did for a single set of categorized data. For both tests, we will follow the same five steps as earlier chapters:

    1. Setup the Hypotheses
    2. Find the test statistic
    3. Find the Critical Value or the p-value
      • Note: Even though the table for the Chi-Squared Distribution exist, we will focus on the technology use and p-value method in these examples. 
    4. Make a Decision about \(H_0\)
    5. State the Conclusion.

    Test of Independence

    A test of independence determines whether two factors are independent or not. Like with correlation, the presence of a dependency does not indicate cause and effect, just a relationship between te categories.

    In a test of independence, we state the null and alternative hypotheses in words.

    Since the contingency table consists of two factors, the null hypothesis states that the factors are independent and the alternative hypothesis states that they are not independent (dependent).

    For example:

    \(H_0\): Population 1 is Independent of Population 2

    \(H_1\): Population 1 is Dependent on Population 2

    Even though these hypotheses are stated in words, they still follow our guidelines of the null involving equality and the alternate involving inequality. If values are independent of each other, then we can think of this as having "no preference" between the categories much like we did with goodness-of-fit. There is a sameness amongst the categories. 

    Tests of independence involve using a contingency table of observed (data) values.

    The test statistic for a test of independence is similar to that of a goodness-of-fit test:

    \[\chi^2=\sum_{(i \cdot j)} \frac{(O-E)^{2}}{E}\]

    where:

    • \(O =\) observed values
    • \(E =\) expected values
    • \(i =\) the number of rows in the table
    • \(j =\) the number of columns in the table

    There are \(i \cdot j\) terms of the form \(\frac{(O-E)^{2}}{E}\).

    The test of independence is always right-tailed because of the calculation of the test statistic. If the expected and observed values are not close together, then the test statistic is very large and way out in the right tail of the chi-square curve, as it is in a goodness-of-fit.

    The number of degrees of freedom for the test of independence is:

    \[df = (\text{number of columns} - 1)(\text{number of rows} - 1) \nonumber\]

    The following formula calculates the expected number (\(E\)):

    \[E = \frac{\text{(row total)(column total)}}{\text{total number surveyed}} \nonumber\]

    The expected value for each cell needs to be at least five in order for you to use this test.

    You first encountered the term independence in Probability Topics. As a review, consider the following example.

    Example \(\PageIndex{1}\)

    Suppose \(A =\) a speeding violation in the last year and \(B =\) a cell phone user while driving. \(A \text{ AND } B\) is the event that a driver received a speeding violation last year and also used a cell phone while driving.

    Suppose, in a study of drivers who received speeding violations in the last year, and who used cell phone while driving, that 755 people were surveyed. Out of the 755, 70 had a speeding violation and 685 did not; 305 used cell phones while driving and 450 did not.

    Assuming that \(A\) and \(B\) are independent, find the value of \(A \text{ AND } B\)

    Solution

    Using the provided information, we could set up the following table: 

        Speeding Violation  
    Using Cellphone   YES NO Row Totals
    YES ? ? 305
    NO ? ? 450
    Column Totals 70 685 755

    We don't know what any of the individual cell values are, but if the events are independent, then we can use the the formula for independent events to determine the values that should be there.

    Recall: If \(A\) and \(B\) are independent, then \(P(A \text{ AND } B) = P(A)P(B)\).

    Let \(y =\) expected number of drivers who used a cell phone while driving and received speeding violations.

    By substitution,

    \[\frac{y}{755} = \left(\frac{70}{755}\right)\left(\frac{305}{755}\right) \nonumber\]

    Solve for \(y\):

    \[y = \frac{(70)(305)}{755} = 28.3 \nonumber\]

    About 28 people from the sample are expected to use cell phones while driving and to receive speeding violations. This lets us fill in the first cell in the table.

        Speeding Violation  
    Using Cellphone   YES NO Row Totals
    YES 28.3 ? 305
    NO ? ? 450
    Column Totals 70 685 755

    If we were to do a test of independence using the example, then the hypotheses are:

    \(H_{0}\): Being a cell phone user while driving and receiving a speeding violation are independent events.

    \(H_{1}\): Being a cell phone user while driving and receiving a speeding violation are dependent events.

    If the null hypothesis were true, we would expect about 28 people to use cell phones while driving and to receive a speeding violation.

    Notice that \(P(A \text{ AND } B) = P(A)P(B)\) and the formula for expected number in each cell \(E = \frac{\text{(row total)(column total)}}{\text{total number surveyed}}\) result in the same expected value. 

     \[P(A \text{ AND } B) = P(A)P(B)\nonumber\] \[\dfrac{y}{n} = \dfrac{A}{n}\cdot \dfrac{B}{n} \nonumber\]  \[n \cdot \dfrac{y}{n} = (\dfrac{A}{n}\cdot \dfrac{B}{n} ) \cdot n\nonumber\]  \[y = \dfrac{A\cdot B}{n} \nonumber\] 

    Since A gives us the row total and B gives us the column total, we arrive at the same formula

    \[E = \frac{\text{(row total)(column total)}}{\text{total number surveyed}}\nonumber\]

    Exercise \(\PageIndex{1}\)

    A sample of 300 students is taken. Of the students surveyed, 50 were music students, while 250 were not. 97 were on the honor roll, while 203 were not. If we assume being a music student and being on the honor roll are independent events, what is the expected number of music students who are also on the honor roll?

    Answer

    \[E = \frac{\text{(row total)(column total)}}{\text{total number surveyed}}\nonumber\]

    \[E = \frac{(50)(97)}{300} \nonumber\]

    \[E = 16.1666...\nonumber\]

    About 16 students are expected to be music students and on the honor roll.

    Example \(\PageIndex{2}\)

    De Anza College is interested in the relationship between anxiety level and the need to succeed in school. A random sample of 400 students took a test that measured anxiety level and need to succeed in school. Table \(\PageIndex{1}\) shows the results. De Anza College wants to know if anxiety level and need to succeed in school are independent events.

    Table \(\PageIndex{1}\) Need to Succeed in School vs. Anxiety Level
    Need to Succeed in School High
    Anxiety
    Med-high
    Anxiety
    Medium
    Anxiety
    Med-low
    Anxiety
    Low
    Anxiety
    Row Total
    High Need 35 42 53 15 10 155
    Medium Need 18 48 63 33 31 193
    Low Need 4 5 11 15 17 52
    Column Total 57 95 127 63 58 400
    1. How many high anxiety level students are expected to have a high need to succeed in school?
    2. If the two variables are independent, how many students do you expect to have a low need to succeed in school and a med-low level of anxiety?
    3. \(E = \frac{(\text{row total})(\text{column total})}{\text{total surveyed}} =\) ________
    4. The expected number of students who have a med-low anxiety level and a low need to succeed in school is about ________.
    Solution

    a. The column total for a high anxiety level is 57. The row total for high need to succeed in school is 155. The sample size or total surveyed is 400.

    \[E = \frac{(\text{row total})(\text{column total})}{\text{total surveyed}} = \frac{155 \cdot 57}{400} = 22.09\]

    The expected number of students who have a high anxiety level and a high need to succeed in school is about 22.

    b. The column total for a med-low anxiety level is 63. The row total for a low need to succeed in school is 52. The sample size or total surveyed is 400.

    c. \(E = \frac{(\text{row total})(\text{column total})}{\text{total surveyed}} = 8.19\)

    d. 8

    Exercise \(\PageIndex{2}\)

    The Bureau of Labor Statistics gathers data about employment in the United States. A sample is taken to calculate the number of U.S. citizens working in one of several industry sectors over time. Table \(\PageIndex{2}\) shows the results:

    Table \(\PageIndex{2}\)
    Industry Sector 2000 2010 2020 Total
    Non-agriculture wage and salary 13,243 13,044 15,018 41,305
    Goods-producing, excluding agriculture 2,457 1,771 1,950 6,178
    Services-providing 10,786 11,273 13,068 35,127
    Agriculture, forestry, fishing, and hunting 240 214 201 655
    Non-agriculture self-employed and unpaid family worker 931 894 972 2,797
    Secondary wage and salary jobs in agriculture and private household industries 14 11 11 36
    Secondary jobs as a self-employed or unpaid family worker 196 144 152 492
    Total 27,867 27,351 31,372 86,590

    How many service providing jobs are there expected to be in 2020? How many non-agriculture wage and salary jobs are there expected to be in 2020?

    Answer

    12,727, 14,965

    Example \(\PageIndex{3}\)

    In a volunteer group, adults 21 and older volunteer from one to nine hours each week to spend time with a disabled senior citizen. The program recruits among community college students, four-year college students, and non-students. In Table \(\PageIndex{3}\) is a sample of the adult volunteers and the number of hours they volunteer per week.

    Table \(\PageIndex{3}\): Number of Hours Worked Per Week by Volunteer Type (Observed). The table contains observed (O) values (data).
    Type of Volunteer 1–3 Hours 4–6 Hours 7–9 Hours Row Total
    Community College Students 111 96 48 255
    Four-Year College Students 96 133 61 290
    Non-students 91 150 53 294
    Column Total 298 379 162 839

    Is the number of hours volunteered independent of the type of volunteer?

    Solution

    The observed table and the question at the end of the problem, "Is the number of hours volunteered independent of the type of volunteer?" tell you this is a test of independence. The two factors are "number of hours volunteered" and "type of volunteer." Reminder: This test is always right-tailed.

    Step 1:

    • \(H_{0}\): The number of hours volunteered is independent of the type of volunteer. (claim)
    • \(H_{1}\): The number of hours volunteered is dependent on the type of volunteer.

    Step 2:

    To find the test statistic, we need the expected number for each cell.  

    The expected results are in Table \(\PageIndex{4}\).

    Table \(\PageIndex{4}\): Number of Hours Worked Per Week by Volunteer Type (Expected). The table contains expected(\(E\)) values (data).
    Type of Volunteer 1-3 Hours 4-6 Hours 7-9 Hours
    Community College Students 90.57 115.19 49.24
    Four-Year College Students 103.00 131.00 56.00
    Non-students 104.42 132.81 56.77

    For example, the calculation for the expected frequency for the top left cell is

    \[E = \frac{(\text{row total})(\text{column total})}{\text{total number surveyed}} = \frac{(255)(298)}{839} = 90.57 \nonumber\]

    Calculate the test statistic:

    \(\chi^2=\sum_{(i \cdot j)} \frac{(O-E)^{2}}{E}\)

    Use a similar process to goodness-of-fit to find the sum of each \(\frac{(O-E)^{2}}{E}\) term.

    \(\chi^{2} = 12.99\) 

    Step 3: Calculate p-value or Critical value. As with goodness-of-fit, since we typically rely on technology for these tests, p-value is the preferred comparison method.

    Distribution for the test: \(\chi^{2}_{4}\)

    \[df = (3 \text{ columns} – 1)(3 \text{ rows} – 1) = (2)(2) = 4 \nonumber\]

    \(p\text{-value} = \chi^{2}cdf(12.99,E99,4) = 0.0113\)

    Step 4:Compare \(\alpha\) and the \(p\text{-value}\)

    Since no \(\alpha\) is given, assume \(\alpha = 0.05\).

    \(0.0113 \leq 0.05\) so reject \(H_{0}\). 

    Step 5:

    Conclusion: At a 5% level of significance, from the data, there is sufficient evidence to reject that the number of hours volunteered and the type of volunteer are independent on one another.

    USING THE TI-83, 83+, 84, 84+ CALCULATOR

    Press the MATRX key and arrow over to EDIT. Press 1:[A]. Press 3 ENTER 3 ENTER. Enter the table values by row from Table. Press ENTER after each. Press 2nd QUIT. Press STAT and arrow over to TESTS. Arrow down to C:χ2-TEST. Press ENTER. You should see Observed:[A] and Expected:[B]. If necessary, use the arrow keys to move the cursor after Observed: and press 2nd MATRX. Press 1:[A] to select matrix A. It is not necessary to enter expected values. The matrix listed after Expected: can be blank. Arrow down to Calculate. Press ENTER. The test statistic is 12.9909 and the p-value = 0.0113. Do the procedure a second time, but arrow down to Draw instead of calculate.

    Exercise \(\PageIndex{3}\)

    The Bureau of Labor Statistics gathers data about employment in the United States. A sample is taken to calculate the number of U.S. citizens working in one of several industry sectors over time. Table \(\PageIndex{2}\) shows the results:

    Table \(\PageIndex{2}\)
    Industry Sector 2000 2010 2020 Total
    Non-agriculture wage and salary 13,243 13,044 15,018 41,305
    Goods-producing, excluding agriculture 2,457 1,771 1,950 6,178
    Services-providing 10,786 11,273 13,068 35,127
    Agriculture, forestry, fishing, and hunting 240 214 201 655
    Non-agriculture self-employed and unpaid family worker 931 894 972 2,797
    Secondary wage and salary jobs in agriculture and private household industries 14 11 11 36
    Secondary jobs as a self-employed or unpaid family worker 196 144 152 492
    Total 27,867 27,351 31,372 86,590

    We want to know if the change in the number of jobs is independent of the change in years. State the null and alternative hypotheses and the degrees of freedom.

    Answer
    • \(H_{0}\): The number of jobs is independent of the year. (claim)
    • \(H_{1}\): The number of jobs is dependent on the year.

    \(df = 12\)

    Press the MATRX key and arrow over to EDIT. Press 1:[A]. Press 3 ENTER 3 ENTER. Enter the table values by row. Press ENTER after each. Press 2nd QUIT. Press STAT and arrow over to TESTS. Arrow down to c:\(\chi^{2}\)-TEST. Press ENTER. You should see Observed:[A] and Expected:[B]. Arrow down to Calculate. Press ENTER. The test statistic is 227.73 and the \(p\text{-value} = 5.90E - 42 \approx 0\). 

    Since no \(\alpha\) is given, assume \(\alpha = 0.05\).

    \(\approx 0 \leq 0.05\) so reject \(H_{0}\). 

    Conclusion: At a 5% level of significance, from the data, there is sufficient evidence to reject that the number of jobs is independent of the change in years. 

     Test for Homogeneity

    The goodness–of–fit test can be used to decide whether a population fits a given distribution, but it will not suffice to decide whether two populations follow the same unknown distribution. A different test, called the test for homogeneity, can be used to draw a conclusion about whether two populations have the same distribution. To calculate the test statistic for a test for homogeneity, follow a similar procedure as with the test of independence. The main difference is how the degrees of freedom are calculated. 

    Hypotheses

    • \(H_{0}\): The distributions of the two populations are the same.
    • \(H_{a}\): The distributions of the two populations are not the same.

    Test Statistic

    • Use a \(\chi^{2}\) test statistic. It is computed in the same way as the test for independence.

    Degrees of Freedom (\(df\))

    • \(df = \text{number of columns} - 1\)

    Requirements

    • All values in the table must be greater than or equal to five.

    Common Uses

    Comparing two populations. For example: men vs. women, before vs. after, east vs. west. The variable is categorical with more than two possible response values.

    Example \(\PageIndex{4}\)

    Do male and female college students have the same distribution of living arrangements? Use a level of significance of 0.05. Suppose that 250 randomly selected male college students and 300 randomly selected female college students were asked about their living arrangements: dormitory, apartment, with parents, other. The results are shown in Table \(\PageIndex{5}\). Do male and female college students have the same distribution of living arrangements?

    Table \(\PageIndex{5}\): Distribution of Living Arrangements for College Males and College Females
      Dormitory Apartment With Parents Other
    Males 72 84 49 45
    Females 91 86 88 35

    Solution

    Step 1:

    • \(H_{0}\): The distribution of living arrangements for male college students is the same as the distribution of living arrangements for female college students. (Claim)
    • \(H_{1}\): The distribution of living arrangements for male college students is not the same as the distribution of living arrangements for female college students.

    Step 2:

    Calculate the test statistic: \(\chi^{2} = 10.1287\) (Same as Test for Independence)

    Step 3: 

    Degrees of Freedom (\(df\)):

    \(df = \text{number of columns} - 1 = 4 - 1 = 3\)

    Distribution for the test: \(\chi^{2}_{3}\)

    \(p\text{-value} = \chi^{2}cdf(10.1287,999,3) = 0.0175\)

    Step 4: 

    Compare α and the p-value. Since no \(\alpha\) is given, assume \(\alpha = 0.05\). 

    \(0.0175 \leq 0.05\) so reject \(H_{0}\). 

    Step 5:

    Conclusion: At a 5% level of significance, from the data, there is sufficient evidence to reject that the distributions of living arrangements for male and female college students are the same.

    Notice that the conclusion is only that the distributions are not the same. We cannot use the test for homogeneity to draw any conclusions about how they differ.

    Exercise \(\PageIndex{4}\)

    Do families and singles have the same distribution of cars? Use a level of significance of 0.05. Suppose that 100 randomly selected families and 200 randomly selected singles were asked what type of car they drove: sport, sedan, hatchback, truck, van/SUV. The results are shown in Table \(\PageIndex{6}\). Do families and singles have the same distribution of cars? Test at a level of significance of 0.05.

    Table \(\PageIndex{6}\)
      Sport Sedan Hatchback Truck Van/SUV
    Family 5 15 35 17 28
    Single 45 65 37 46 7
    Answer
    • \(H_{0}\): The distribution of families' cars is the same as the distribution for singles' cars. (claim)
    • \(H_{1}\): The distribution of families' cars is the different from the distribution for singles' cars.

    \(df = 4\)

    Press the MATRX key and arrow over to EDIT. Press 1:[A]. Press 2 ENTER 5 ENTER. Enter the table values by row. Press ENTER after each. Press 2nd QUIT. Press STAT and arrow over to TESTS. Arrow down to c:\(\chi^{2}\)-TEST. Press ENTER. You should see Observed:[A] and Expected:[B]. Arrow down to Calculate. Press ENTER. The test statistic is 62.91 and the \(p\text{-value} = 7.083E- 13 \approx 0\). 

    Since no \(\alpha\) is given, assume \(\alpha = 0.05\).

    \(\approx 0 \leq 0.05\) so reject \(H_{0}\). 

    Conclusion: At a 5% level of significance, from the data, there is sufficient evidence to reject that the distribution of families' cars is the same as the distribution of singles' cars. 

    Example \(\PageIndex{5}\)

    Both before and after a recent earthquake, surveys were conducted asking voters which of the three candidates they planned on voting for in the upcoming city council election. Has there been a change since the earthquake? Use a level of significance of 0.05. Table \(\PageIndex{7}\) shows the results of the survey. Has there been a change in the distribution of voter preferences since the earthquake?

    Table \(\PageIndex{7}\)
      Perez Chung Stevens
    Before 167 128 135
    After 214 197 225

    Solutions

    Step 1:

    \(H_{0}\): The distribution of voter preferences was the same before and after the earthquake.

    \(H_{1}\): The distribution of voter preferences was not the same before and after the earthquake. (Claim)

    Step 2:

    Calculate the test statistic: \(\chi^{2} = 3.2603\) (calculator or computer)

    Step 3:
    Degrees of Freedom (df):

    \(df = \text{number of columns} - 1 = 3 - 1 = 2\)

    Distribution for the test: \(\chi^{2}_{2}\)

    \(p\text{-value} = \chi^{2}cdf(3.2603,999,2) = 0.1959\)

    Press the MATRX key and arrow over to EDIT. Press 1:[A]. Press 2 ENTER 3 ENTER. Enter the table values by row. Press ENTER after each. Press 2nd QUIT. Press STAT and arrow over to TESTS. Arrow down to C:χ2-TEST. Press ENTER. You should see Observed:[A] and Expected:[B]. Arrow down to Calculate. Press ENTER. The test statistic is 3.2603 and the p-value = 0.1959. Do the procedure a second time but arrow down to Draw instead of calculate.

    Step 4:

    Compare \(\alpha\) and the \(p\text{-value}\). \(\alpha = 0.05\) and the \(p\text{-value} = 0.1959\).

    \(0.1959 > 0.05\). So, do not reject \(H_{0}\).

    Step 5:

    Conclusion: At a 5% level of significance, from the data, there is insufficient evidence to support that the distribution of voter preferences was not the same before and after the earthquake.

    Exercise \(\PageIndex{5}\)

    Ivy League schools receive many applications, but only some can be accepted. At the schools listed in Table \(\PageIndex{8}\), two types of applications are accepted: regular and early decision.

    Table \(\PageIndex{8}\)
    Application Type Accepted Brown Columbia Cornell Dartmouth Penn Yale
    Regular 2,115 1,792 5,306 1,734 2,685 1,245
    Early Decision 577 627 1,228 444 1,195 761

    We want to know if the number of regular applications accepted follows the same distribution as the number of early applications accepted. State the null and alternative hypotheses, the degrees of freedom and the test statistic, and draw a conclusion about the test of homogeneity.

    Answer

    \(H_{0}\): The distribution of regular applications accepted is the same as the distribution of early applications accepted. (Claim)

    \(H_{1}\): The distribution of regular applications accepted is not the same as the distribution of early applications accepted.

    \(df = 5\)

    \(\chi^{2} \text{test statistic} = 430.06\)

    Press the MATRX key and arrow over to EDIT. Press 1:[A]. Press 3 ENTER 3 ENTER. Enter the table values by row. Press ENTER after each. Press 2nd QUIT. Press STAT and arrow over to TESTS. Arrow down toC:χ2-TEST. Press ENTER. You should see Observed:[A] and Expected:[B]. Arrow down to Calculate. Press ENTER. The test statistic is 430.06 and the \(p\text{-value} = 9.80E-91\). Do the procedure a second time but arrow down to Draw instead of calculate.

    Since no \(\alpha\) is given, assume \(\alpha = 0.05\).

    \(\approx 0 \leq 0.05\) so reject \(H_{0}\). 

    Conclusion: At a 5% level of significance, from the data, there is sufficient evidence to reject that the distribution of regular applications accepted is the same as the distribution of early applications accepted.

    Comparison of Chi-Squared Tests

    You have seen the \(\chi^{2}\) test statistic used in three different circumstances. The following bulleted list is a summary that will help you decide which \(\chi^{2}\) test is the appropriate one to use.

    • Goodness-of-Fit: Use the goodness-of-fit test to decide whether a population with an unknown distribution "fits" a known distribution. In this case there will be a single qualitative survey question or a single outcome of an experiment from a single population. Goodness-of-Fit is typically used to see if the population is uniform (all outcomes occur with equal frequency), the population is normal, or the population is the same as another population with a known distribution. The null and alternative hypotheses are:
      • \(H_{0}\): The population fits the given distribution.
      • \(H_{a}\): The population does not fit the given distribution.
    • Independence: Use the test for independence to decide whether two variables (factors) are independent or dependent. In this case there will be two qualitative survey questions or experiments and a contingency table will be constructed. The goal is to see if the two variables are unrelated (independent) or related (dependent). The null and alternative hypotheses are:
      • \(H_{0}\): The two variables (factors) are independent.
      • \(H_{a}\): The two variables (factors) are dependent.
    • Homogeneity: Use the test for homogeneity to decide if two populations with unknown distributions have the same distribution as each other. In this case there will be a single qualitative survey question or experiment given to two different populations. The null and alternative hypotheses are:
      • \(H_{0}\): The two populations follow the same distribution.
      • \(H_{a}\): The two populations have different distributions.

    Review

    To assess whether two factors are independent or not, you can apply the test of independence that uses the chi-square distribution. The null hypothesis for this test states that the two factors are independent. The test compares observed values to expected values. The test is right-tailed. Each observation or cell category must have an expected value of at least 5.

    To assess whether two data sets are derived from the same distribution—which need not be known, you can apply the test for homogeneity that uses the chi-square distribution. The null hypothesis for this test states that the populations of the two data sets come from the same distribution. The test compares the observed values against the expected values if the two populations followed the same distribution. The test is right-tailed. Each observation or cell category must have an expected value of at least five.

    The goodness-of-fit test is typically used to determine if data fits a particular distribution. The test of independence makes use of a contingency table to determine the independence of two factors. The test for homogeneity determines whether two populations come from the same distribution, even if this distribution is unknown.

    Formula Review

    Test of Independence

    • The number of degrees of freedom is equal to \((\text{number of columns - 1})(\text{number of rows - 1})\).
    • The test statistic is \(\sum_{(i \cdot j)} \frac{(O-E)^{2}}{E}\) where \(O =\) observed values, \(E =\) expected values, \(i =\) the number of rows in the table, and \(j =\) the number of columns in the table.
    • If the null hypothesis is true, the expected number \(E = \frac{(\text{row total})(\text{column total})}{\text{total surveyed}}\).

    Test of Homogeneity 

    \(\sum_{i \cdot j} \frac{(O-E)^{2}}{E}\) Homogeneity test statistic where: \(O =\) observed values

    \(E =\) expected values

    \(i =\) number of rows in data contingency table

    \(j =\) number of columns in data contingency table

    \(df = (i −1)(j −1)\) Degrees of freedom

     

    References

    1. DiCamilo, Mark, Mervin Field, “Most Californians See a Direct Linkage between Obesity and Sugary Sodas. Two in Three Voters Support Taxing Sugar-Sweetened Beverages If Proceeds are Tied to Improving School Nutrition and Physical Activity Programs.” The Field Poll, released Feb. 14, 2013. Available online at field.com/fieldpollonline/sub...rs/Rls2436.pdf (accessed May 24, 2013).
    2. Harris Interactive, “Favorite Flavor of Ice Cream.” Available online at http://www.statisticbrain.com/favori...r-of-ice-cream (accessed May 24, 2013)
    3. “Youngest Online Entrepreneurs List.” Available online at http://www.statisticbrain.com/younge...repreneur-list (accessed May 24, 2013).
    4. Data from the Insurance Institute for Highway Safety, 2013. Available online at www.iihs.org/iihs/ratings (accessed May 24, 2013).
    5. “Energy use (kg of oil equivalent per capita).” The World Bank, 2013. Available online at http://data.worldbank.org/indicator/...G.OE/countries (accessed May 24, 2013).
    6. “Parent and Family Involvement Survey of 2007 National Household Education Survey Program (NHES),” U.S. Department of Education, National Center for Education Statistics. Available online at http://nces.ed.gov/pubsearch/pubsinf...?pubid=2009030 (accessed May 24, 2013).
    7. “Parent and Family Involvement Survey of 2007 National Household Education Survey Program (NHES),” U.S. Department of Education, National Center for Education Statistics. Available online at http://nces.ed.gov/pubs2009/2009030_sup.pdf (accessed May 24, 2013).

     


    11.3: Tests Using Contingency tables is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?