liveBook · Manning

Contingency table

As explained in Statistics Slam Dunk

A contingency table is a tabular arrangement of counts for combinations of categorical variables, with one variable represented by rows and another by columns.

A contingency table summarizes counts for combinations of categorical variables. Rows show one distribution, columns show another, and each cell records a frequency. section 9.0 section 9.6.1

A practical R workflow uses the table to:

  • Arrange categories such as rest advantage in rows and outcomes such as home wins or losses in columns. section 9.6.1
  • Visualize cell frequencies with a balloon plot or mosaic plot. section 9.1 section 9.6.1
  • Pass the table to chisq.test() for a chi-square test of independence, then use Cramer's V to quantify association strength. section 9.6.2 section 9.7

NBA rest and home results

Create a 3 × 2 table with rows More Rest, Same Rest, and Less Rest, and columns Home Wins and Home Losses. The resulting counts are 1,552/545, 1,955/1,432, and 717/990. A balloon plot makes larger counts visually prominent; the chi-square test reports a significant relationship, while Cramer's V of about 0.236 indicates a small effect. section 9.6.1 section 9.6.2 section 9.7

chisq_table <- matrix(c(1552, 545, 1955, 1432, 717, 990), 
                     ncol = 2, byrow = TRUE)
rownames(chisq_table) <- c("More Rest", "Same Rest", "Less Rest")
colnames(chisq_table) <- c("Home Wins", "Home Losses")
print(chisq_table)
##           Home Wins Home Losses
## More Rest      1552         545
## Same Rest      1955        1432
## Less Rest       717         990

Inspect executable R code that constructs and labels the contingency table. section 9.6.1

How Statistics Slam Dunk covers it

How deep it goes
Defines the structure, constructs it in R, visualizes counts, and connects it to chi-square and effect-size tests.
Examples
Uses NBA rest categories crossed with home wins and losses, including a labeled 3 × 2 count table and balloon plot.
What it assumes
Assumes categorical variables and frequency counts, while defining rows, columns, matrices, and crosstabs through an applied example.
What you can do after
Evaluate/understand categorical associations by constructing, visualizing, and testing contingency tables in R.
How it connects
Connects contingency tables to matrices, balloon plots, mosaic plots, chi-square tests, and Cramer's V.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.