# ============================================================
# Chi-square & Fisher's Test
# Biostatistics in R — Rverse Analytics
# https://rverseanalytics.com/learn-biostatistics/chisq
# ============================================================

# 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)
