{
  "name": "Categorical data situations mapped to R and statsmodels functions",
  "description": "Original decision table compiled from the R-devel manual pages for chisq.test and fisher.test and the statsmodels contingency-tables documentation: for six common data situations it lists the documented R function and the documented statsmodels call.",
  "page": "https://casrai.org/guides/categorical-data-analysis",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-16T22:02:45Z",
  "temporalCoverage": null,
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Data situation",
      "unit": "",
      "description": ""
    },
    {
      "name": "R function (base stats)",
      "unit": "",
      "description": ""
    },
    {
      "name": "statsmodels call",
      "unit": "",
      "description": ""
    },
    {
      "name": "Documented note",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Data situation": "One variable against expected proportions",
      "R function (base stats)": "chisq.test(x, p = ...)",
      "statsmodels call": "—",
      "Documented note": "R: p gives the expected probabilities; rescale.p rescales them"
    },
    {
      "Data situation": "Two unordered variables, count table",
      "R function (base stats)": "chisq.test(x)",
      "statsmodels call": "Table(table).test_nominal_association()",
      "Documented note": "R returns expected, residuals, stdres; statsmodels has fittedvalues, resid_pearson, standardized_resids"
    },
    {
      "Data situation": "2 x 2 table, small counts",
      "R function (base stats)": "fisher.test(x)",
      "statsmodels call": "Table2x2 (odds ratios, risk ratios)",
      "Documented note": "R estimate is the conditional MLE of the odds ratio, not the sample odds ratio"
    },
    {
      "Data situation": "Table larger than 2 x 2, sparse",
      "R function (base stats)": "chisq.test or fisher.test with simulate.p.value = TRUE",
      "statsmodels call": "—",
      "Documented note": "R: B = 2000 by default; fisher.test needs strictly positive marginals"
    },
    {
      "Data situation": "Paired binary outcomes",
      "R function (base stats)": "—",
      "statsmodels call": "mcnemar(table, exact, correction)",
      "Documented note": "Tests equal marginal proportions in paired data"
    },
    {
      "Data situation": "Several 2 x 2 tables (strata)",
      "R function (base stats)": "—",
      "statsmodels call": "StratifiedTable(tables, shift_zeros)",
      "Documented note": "Pooled estimates across the 2 x 2 tables"
    },
    {
      "Data situation": "Ordered categories",
      "R function (base stats)": "—",
      "statsmodels call": "Table(table).test_ordinal_association()",
      "Documented note": "Optional row and column scores"
    }
  ],
  "sources": [
    {
      "title": "R stats::chisq.test",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/stats/html/chisq.test.html",
      "accessed": "2026-11-14"
    },
    {
      "title": "R stats::fisher.test",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/stats/html/fisher.test.html",
      "accessed": "2026-11-14"
    },
    {
      "title": "statsmodels contingency tables",
      "url": "https://www.statsmodels.org/stable/contingency_tables.html",
      "accessed": "2026-11-14"
    },
    {
      "title": "statsmodels Table class",
      "url": "https://www.statsmodels.org/stable/generated/statsmodels.stats.contingency_tables.Table.html",
      "accessed": "2026-11-14"
    }
  ]
}