Tutorials › AP Statistics › Entering Two-Way Data Into a Matrix on the Calculator

Chi-square tests for categorical data · Tutorial 554 of 1000

Entering Two-Way Data Into a Matrix on the Calculator

Practice entering a two-way table’s observed counts into a calculator matrix and using the chi-square test command to obtain the test results.

Intermediate 10 min read

What You'll Learn

  • Enter only the observed cell counts into a matrix, without row or column totals.
  • Set the matrix dimensions to match the two-way table’s categories.
  • Run the chi-square test command with the observed matrix and identify the expected-count matrix.
  • Check that the calculator’s degrees of freedom and test statistic match the table.
  • Interpret the chi-square test output in context.

From a Two-Way Table to Calculator Input

In “The Chi-Square Statistic Formula,” you learned to compare observed counts with expected counts, cell by cell. In “Chi-Square Distribution Table Versus Calculator Probabilities,” you learned how the test statistic and degrees of freedom lead to an upper-tail probability. A calculator can carry out these calculations, but its output is only useful if the observed counts are entered in the correct order and the test is set up properly.

For a TI-84, the chi-square test command uses a matrix of observed counts. A matrix is a rectangular arrangement of numbers. Its rows and columns should match the categories in the two-way table. The calculator uses those counts to calculate expected counts, the chi-square statistic, degrees of freedom, and the p-value.

Key idea: Enter the table’s interior observed counts into a matrix. Do not include row totals, column totals, percentages, or expected counts as part of the observed matrix.

Entering the Observed Counts

First, decide which table categories will be represented by the matrix rows and which will be represented by its columns. Keep their order consistent with the table. For example, if the table has two row categories and three column categories, the observed-count matrix must have 2 rows and 3 columns.

On a TI-84, press 2nd, then x-1 to open the MATRIX menu. Choose EDIT, then select matrix [A]. Enter the number of rows and columns, then enter the observed counts across the first row, across the second row, and so on. Press ENTER after each value. When the entries are complete, leave the matrix editor.

A matrix contains only the counts inside the table, not the totals printed at its margins. The totals are useful for checking the data entry, but including them as matrix entries would tell the calculator that they are additional categories. That would produce the wrong test.

Entry checklist:
  • Set the matrix dimensions to the number of row categories and column categories—not the table’s dimensions including totals.
  • Enter observed counts in the same row and column order as the table.
  • Enter each interior count once. Leave out row totals, column totals, and the grand total.
  • Before running the test, check that the matrix entries reproduce the table.

Running the Chi-Square Test Command

After entering the observed counts, open the STAT menu, choose TESTS, and select χ²-Test (often listed as choice C on a TI-84). On the test screen, set Observed to [A] and Expected to [B]. Choose Calculate. The calculator uses [A] as the observed counts and fills [B] with the expected counts it calculates under the null hypothesis.

The output includes \(\chi^2\), \(p\), and \(df\). The statistic is the sum of the cell contributions \((O-E)^2/E\). The degrees of freedom for a table with \(r\) row categories and \(c\) column categories are \((r-1)(c-1)\), as covered in “Degrees of Freedom for a Two-Way Table.” The p-value is the upper-tail probability for the statistic and degrees of freedom.

Calculator check: Confirm that Observed names the matrix containing your table’s interior counts, and that its dimensions match the table. The calculator’s expected-count matrix should have the same dimensions. Compare the reported \(df\) with \((r-1)(c-1)\) before interpreting the p-value.

The expected counts are calculated using the table’s row totals, column totals, and grand total. You do not need to type them into the observed matrix or calculate them in advance to run the command. However, examining the expected-count matrix is a useful check and helps you assess the chi-square procedure’s expected-count condition.

Worked Example: A Two-Row, Three-Column Table

Worked Example: A Two-Row, Three-Column Table

A fictional survey asks 120 students which of three study locations they prefer. The table records the observed counts by whether students usually study alone or with others.

LibraryHomeStudy roomTotal
Usually study alone30201060
Usually study with others10203060
Total404040120

Enter the six interior counts into a 2-by-3 matrix [A], reading across each row:

$$ [A]= \begin{bmatrix} 30 & 20 & 10\\ 10 & 20 & 30 \end{bmatrix} $$

On the TI-84, choose matrix [A] in the MATRIX editor, set its dimensions to 2 by 3, and enter those six counts. Then choose STAT, TESTS, χ²-Test. Set Observed to [A], Expected to [B], and select Calculate.

The expected count in each cell is \((\text{row total})(\text{column total})/(\text{grand total})\). Every row total is 60, every column total is 40, and the grand total is 120, so each expected count is \(60(40)/120=20\). The expected-count matrix is therefore:

$$ [B]= \begin{bmatrix} 20 & 20 & 20\\ 20 & 20 & 20 \end{bmatrix} $$

Check the statistic using the formula from “The Chi-Square Statistic Formula.” Four cells differ from their expected count by 10, and two cells match their expected count:

$$ \chi^2= \frac{(30-20)^2}{20}+ \frac{(20-20)^2}{20}+ \frac{(10-20)^2}{20}+ \frac{(10-20)^2}{20}+ \frac{(20-20)^2}{20}+ \frac{(30-20)^2}{20} =5+0+5+5+0+5=20 $$

There are 2 rows and 3 columns, so \(df=(2-1)(3-1)=2\). The calculator should display \(\chi^2=20\), \(df=2\), and \(p\approx0.0000454\), or approximately \(0.0000\) when rounded to four decimal places. Reporting \(p<0.0001\) avoids suggesting that the p-value is exactly zero.

As a condition check, suppose the survey used an appropriate random sample, each student contributed to only one cell, and the population is at least 1,200 students. The observations are independent, the 10% condition is met, and all expected counts are 20, which is at least 5. These checks support using the chi-square test in this example.

Answer: The matrix is 2 by 3, with the six observed counts and no totals. The calculator’s statistic and degrees of freedom agree with the hand checks, and its p-value is the upper-tail area for \(X^2=20\) with 2 degrees of freedom.

Worked Example: A Complete Test With a Two-by-Two Matrix

Worked Example: A Complete Test With a Two-by-Two Matrix

A fictional transportation researcher takes a random sample of 100 city cyclists and records whether each cyclist usually rides on a quiet route or a direct route, and whether the ride is usually on a weekday or weekend. The observed counts are:

Quiet routeDirect routeTotal
Weekday282250
Weekend183250
Total4654100

State. Let the two variables be usual ride day (weekday or weekend) and usual route type (quiet or direct) for city cyclists. The null hypothesis \(H_0\) is that these variables are independent in the population. The alternative hypothesis \(H_a\) is that they are associated.

Plan. Use a chi-square test of independence because one sample of cyclists is classified by two categorical variables. Suppose the sample was selected randomly from a population of more than 1,000 city cyclists. The sample is less than 10% of that population, and each cyclist is counted once in exactly one cell, supporting independence of observations. We will also check that every expected count is at least 5.

Do. Enter the interior counts in a 2-by-2 observed matrix:

$$ [A]= \begin{bmatrix} 28 & 22\\ 18 & 32 \end{bmatrix} $$

Run χ²-Test with Observed [A] and Expected [B]. The row totals are 50 and 50, the column totals are 46 and 54, and the grand total is 100. The expected counts, calculated as row total times column total divided by grand total, are:

$$ E_{11}=\frac{50(46)}{100}=23,\quad E_{12}=\frac{50(54)}{100}=27,\quad E_{21}=\frac{50(46)}{100}=23,\quad E_{22}=\frac{50(54)}{100}=27 $$

All expected counts are at least 5, so the expected-count condition is met. The statistic is:

$$ \chi^2= \frac{(28-23)^2}{23}+ \frac{(22-27)^2}{27}+ \frac{(18-23)^2}{23}+ \frac{(32-27)^2}{27} =\frac{50}{23}+\frac{50}{27} \approx2.1739+1.8519=4.0258 $$

The degrees of freedom are \((2-1)(2-1)=1\). The calculator gives \(\chi^2\approx4.0258\), \(df=1\), and \(p\approx0.04481\). At significance level \(\alpha=0.05\), the p-value is less than \(\alpha\), so we reject \(H_0\).

Conclude. The sample provides convincing evidence of an association between usual ride day and usual route type among city cyclists. This conclusion describes an association; the survey does not establish that ride day causes cyclists to choose a particular route.

Worked Example: Checking a Three-by-Three Matrix

Worked Example: Checking a Three-by-Three Matrix

A fictional community center surveys participants about their preferred activity—crafts, games, or exercise—and records whether they attend in the morning, afternoon, or evening. The observed counts are:

CraftsGamesExerciseTotal
Morning30201060
Afternoon20202060
Evening10203060
Total606060180

Enter [A] as a 3-by-3 matrix, in row order:

$$ [A]= \begin{bmatrix} 30 & 20 & 10\\ 20 & 20 & 20\\ 10 & 20 & 30 \end{bmatrix} $$

Run χ²-Test with Observed [A] and Expected [B]. Every row and column total is 60, so each expected count is \(60(60)/180=20\). All nine expected counts are at least 5. The hand calculation of the statistic is:

$$ \chi^2= \frac{100}{20}+\frac{0}{20}+\frac{100}{20} +\frac{0}{20}+\frac{0}{20}+\frac{0}{20} +\frac{100}{20}+\frac{0}{20}+\frac{100}{20} =5+0+5+0+0+0+5+0+5=20 $$

For 3 rows and 3 columns, \(df=(3-1)(3-1)=4\). The calculator should display \(\chi^2=20\), \(df=4\), and \(p\approx0.0005\). The expected matrix [B] should be a 3-by-3 matrix with 20 in every cell. This second check helps confirm that the observed matrix dimensions and category order were entered as intended.

Answer: The calculator output agrees with the table: \(\chi^2=20\), \(df=4\), and \(p\approx0.0005\). The p-value is small, but a conclusion about evidence in context also depends on the study design and whether the test conditions are met.

Common Mistakes and AP Exam Tip

  • Including totals in the matrix: The calculator treats every matrix entry as an observed cell count. Enter only the interior counts, not the totals along the margins.
  • Using the wrong dimensions: A table with 3 row categories and 2 column categories needs a 3-by-2 matrix. The totals row and totals column do not count as categories.
  • Reversing or rearranging entries: Keep the table’s row and column order. A misordered matrix may still run, but its counts will no longer represent the intended category combinations.
  • Typing expected counts into the observed matrix: Enter observed counts in [A]. The χ²-Test command calculates expected counts and stores them in [B].
  • Trusting the output without checking it: Confirm \(df=(r-1)(c-1)\), inspect [B] for reasonable expected counts, and compare the statistic with a hand calculation when possible.
  • Reading a small p-value as the probability the null is true: The p-value is a probability calculated under the null hypothesis. It is not the probability that the null hypothesis is true.
AP Exam Tip: Describe what the calculator did, not just the keys you pressed. A clear response identifies the observed-count matrix, reports \(\chi^2\), \(df\), and \(p\), and connects the result to the null and alternative hypotheses in context. Check conditions before making a test conclusion.
Key takeaway: Set the matrix dimensions to match the categories, enter only the observed cell counts in table order, and run χ²-Test with that matrix as Observed. Check the expected-count matrix, degrees of freedom, and statistic before interpreting the p-value.

Check Your Understanding

Use the table structure and calculator steps to answer each question.

  1. A table has 2 row categories and 4 column categories. What dimensions should the observed matrix have?
  2. Should row totals and column totals be entered in the observed matrix? Explain.
  3. When running χ²-Test with observed matrix [A], what is the role of matrix [B]?
  4. A table has 3 row categories and 2 column categories. What degrees of freedom should the calculator report?
  5. Why should you compare the calculator’s statistic with the table before interpreting its p-value?