Categorical Data Analysis

Biostatistics

The Categorical Data series: analyse counts and contingency tables in R — the chi-square tests of independence and goodness-of-fit, Fisher’s exact test, McNemar and Cochran’s Q for paired data, Cochran-Mantel-Haenszel for stratified data, and the odds ratio & relative risk — with rstatix, base R, and on-plot p-values.

LearnBiostatistics › Categorical Data Analysis

Categorical data are counts — how many observations fall into each category. This series analyses them the way the work happens: build a contingency table, test whether two categorical variables are associated (chi-square, Fisher), handle paired designs (McNemar, Cochran’s Q), control for a third variable (Cochran-Mantel-Haenszel), and quantify risk with the odds ratio & relative risk — with the tidy rstatix helpers, base R shown alongside, and the p-values on the plot.

The chi-square test in one minute

The workhorse: does an outcome depend on a grouping variable? Cross-tabulate, then chisq.test():

xtab <- as.table(rbind(
  Treated   = c(improved = 21, none = 9),
  Untreated = c(improved = 10, none = 20)
))
chisq.test(xtab)

    Pearson's Chi-squared test with Yates' continuity correction

data:  xtab
X-squared = 6.6741, df = 1, p-value = 0.009782

A small p-value says the two variables are associated (here, improvement depends on treatment).

Pick your test

Lessons

🟢 With an AI agent

Ask Prova “which categorical test fits my data?” — it answers with the right test (chi-square, Fisher, McNemar, CMH, odds ratio) and rstatix code you can run on your own counts. The runtime is the judge. Ask Prova →

Was this page helpful?

Prove you can do it. Master the whole Categorical Analysis in R series — track your path, build projects, and earn a certificate.

Start free →

Go Pro — unlimited Prova on your own data and a verifiable certificate that proves the skill.

from $15/mo billed yearly

Go Pro →

✓ You're Pro — keep going. The runtime is the judge.

Get new R & Python lessons by email

Practical, reproducible, no spam. Unsubscribe anytime.

Double opt-in. We never share your email.

Share this pageXLinkedInRedditHN

Citation

BibTeX citation:
@online{untitled,
  author = {},
  title = {Categorical {Data} {Analysis}},
  url = {https://www.datanovia.com/learn/biostatistics/categorical/},
  langid = {en}
}
For attribution, please cite this work as:
“Categorical Data Analysis.” n.d. https://www.datanovia.com/learn/biostatistics/categorical/.