Are two categorical variables associated? Test it with a contingency table.
Your browser does not support embedded video. Download the video (MP4).
:::
Everything in the video, ready to copy:
# Chi-square & Fisher's exact test # A 2x2 table: treatment (rows) by outcome (columns) tbl <- matrix(c(90, 60, 30, 120), nrow = 2, byrow = TRUE) tbl # Chi-square test of independence chisq.test(tbl) # Expected counts under independence chisq.test(tbl)$expected # Fisher's exact test - exact, good for small samples fisher.test(tbl)
Download this R script · ▶ Practice in the playground
When to use it. Use chi-square for large samples; check the expected counts and switch to Fisher’s exact test when any expected count is small (below ~5).
Try the chi-square calculator · read chi-square in R.
Next: Odds Ratio, Relative Risk & NNT →