Chi-Square Post-Hoc Tests for Clinicopathological Research
Comprehensive Guide to Pairwise Comparisons in Contingency Tables
ClinicoPath Module
2025-07-13
Source:vignettes/clinicopath-descriptives-12-chisqposttest.Rmd
clinicopath-descriptives-12-chisqposttest.Rmd
Introduction
The Chi-Square Post-Hoc Tests module in ClinicoPath provides comprehensive analysis for identifying specific group differences when an overall chi-square test of independence shows statistical significance. This is particularly valuable in clinicopathological research where researchers need to understand which specific combinations of categorical variables are driving significant associations.
Clinical Motivation
In clinical and pathological research, we often encounter scenarios where:
- Treatment response varies by patient characteristics (e.g., sex, age group, tumor stage)
- Biomarker expression differs across diagnostic categories (e.g., hormone receptor status by tumor grade)
- Complications occur differentially across treatment modalities (e.g., surgical complications by surgeon experience level)
- Survival outcomes vary by multiple pathological features (e.g., lymph node status by tumor size categories)
When an overall chi-square test indicates a significant association, post-hoc testing helps identify which specific group comparisons are driving this significance, while controlling for multiple comparisons.
When to Use Chi-Square Post-Hoc Tests
Chi-square post-hoc tests are appropriate when:
- Overall chi-square test is significant (p < 0.05)
- At least one variable has ≥3 categories (otherwise, no post-hoc testing needed)
- Sample sizes are adequate (expected frequencies ≥5 in most cells)
- Variables are categorical (nominal or ordinal)
- Observations are independent
Package Setup
## Warning: replacing previous import 'dplyr::as_data_frame' by
## 'igraph::as_data_frame' when loading 'ClinicoPath'
## Warning: replacing previous import 'DiagrammeR::count_automorphisms' by
## 'igraph::count_automorphisms' when loading 'ClinicoPath'
## Warning: replacing previous import 'dplyr::groups' by 'igraph::groups' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'DiagrammeR::get_edge_ids' by
## 'igraph::get_edge_ids' when loading 'ClinicoPath'
## Warning: replacing previous import 'dplyr::union' by 'igraph::union' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'igraph::union' by 'lubridate::union' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'igraph::%--%' by 'lubridate::%--%' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::tnr' by 'mlr3measures::tnr' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::precision' by
## 'mlr3measures::precision' when loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::tn' by 'mlr3measures::tn' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::fnr' by 'mlr3measures::fnr' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::tp' by 'mlr3measures::tp' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::npv' by 'mlr3measures::npv' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::ppv' by 'mlr3measures::ppv' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::auc' by 'mlr3measures::auc' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::tpr' by 'mlr3measures::tpr' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::fn' by 'mlr3measures::fn' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::fp' by 'mlr3measures::fp' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::fpr' by 'mlr3measures::fpr' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::recall' by
## 'mlr3measures::recall' when loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::specificity' by
## 'mlr3measures::specificity' when loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::sensitivity' by
## 'mlr3measures::sensitivity' when loading 'ClinicoPath'
## Warning: replacing previous import 'igraph::as_data_frame' by
## 'tibble::as_data_frame' when loading 'ClinicoPath'
## Warning: replacing previous import 'igraph::crossing' by 'tidyr::crossing' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'magrittr::extract' by 'tidyr::extract' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'mlr3measures::sensitivity' by
## 'caret::sensitivity' when loading 'ClinicoPath'
## Warning: replacing previous import 'mlr3measures::specificity' by
## 'caret::specificity' when loading 'ClinicoPath'
## Registered S3 methods overwritten by 'useful':
## method from
## autoplot.acf ggfortify
## fortify.acf ggfortify
## fortify.kmeans ggfortify
## fortify.ts ggfortify
## Warning: replacing previous import 'jmvcore::select' by 'dplyr::select' when
## loading 'ClinicoPath'
## Registered S3 methods overwritten by 'ggpp':
## method from
## heightDetails.titleGrob ggplot2
## widthDetails.titleGrob ggplot2
## Warning: replacing previous import 'DataExplorer::plot_histogram' by
## 'grafify::plot_histogram' when loading 'ClinicoPath'
## Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'mlr3measures::auc' by 'pROC::auc' when
## loading 'ClinicoPath'
## Warning: replacing previous import 'cutpointr::roc' by 'pROC::roc' when loading
## 'ClinicoPath'
## Warning: replacing previous import 'tibble::view' by 'summarytools::view' when
## loading 'ClinicoPath'
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(knitr)
# Load the histopathology dataset
data("histopathology")
# Display dataset structure
str(histopathology[, c("Sex", "Race", "Group", "Grade_Level", "LVI", "PNI", "Mortality5yr")])
## tibble [250 × 7] (S3: tbl_df/tbl/data.frame)
## $ Sex : chr [1:250] "Male" "Female" "Male" "Male" ...
## $ Race : chr [1:250] "White" "White" "White" "White" ...
## $ Group : chr [1:250] "Control" "Treatment" "Control" "Treatment" ...
## $ Grade_Level : chr [1:250] "high" "low" "low" "high" ...
## $ LVI : chr [1:250] "Present" "Absent" "Absent" "Present" ...
## $ PNI : chr [1:250] "Absent" "Absent" "Absent" "Absent" ...
## $ Mortality5yr: chr [1:250] "Alive" "Dead" "Dead" "Alive" ...
Basic Chi-Square Post-Hoc Analysis
Example 1: Treatment Group by Sex
Let’s start with a basic example examining whether treatment group assignment varies by patient sex.
# Basic chi-square post-hoc test
chisqposttest(
data = histopathology,
rows = "Sex",
cols = "Group",
posthoc = "bonferroni",
sig = 0.05,
excl = TRUE,
exp = FALSE,
plot = FALSE
)
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ────────────────────────────────────────────────
## Statistic Value df p-value
## ────────────────────────────────────────────────
## Chi-Square 2.365421e-4 1 0.9877291
## ────────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## <table border='1' style='border-collapse:
## collapse;'>ControlTreatmentFemale5863Male6166
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Control<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Treatment<td style='border: 1px
## solid #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Female<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.015
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.015
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Male<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>0.015
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.015
## As expected
##
## Critical value for significance: ±2.498
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Example 2: Tumor Grade by Lymph Node Status
A more clinically relevant example examining the relationship between tumor grade and lymph node metastasis:
# Chi-square post-hoc test with clinical variables
chisqposttest(
data = histopathology,
rows = "Grade_Level",
cols = "LVI", # Lymphovascular invasion
posthoc = "fdr",
sig = 0.05,
excl = TRUE,
exp = TRUE, # Show expected values
plot = FALSE
)
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ──────────────────────────────────────────────
## Statistic Value df p-value
## ──────────────────────────────────────────────
## Chi-Square 0.6169959 2 0.7345495
## ──────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## Values shown as: Observed
## (Expected)
##
## <table border='1' style='border-collapse:
## collapse;'>AbsentPresenthigh56
## (53)36
## (39)low43
## (44.4)34
## (32.6)moderate44
## (45.6)35
## (33.4)
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Absent<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Present<td style='border: 1px solid
## #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>high<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.785
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.785
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>low<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>-0.389
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.389
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>moderate<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-0.428
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.428
## As expected
##
## Critical value for significance: ±2.638
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Multiple Comparison Adjustments
Understanding Adjustment Methods
When performing multiple pairwise comparisons, we need to adjust p-values to control the family-wise error rate:
Bonferroni Correction
- Most conservative approach
- Multiplies each p-value by the number of comparisons
- Use when: You want strong control of Type I error
chisqposttest(
data = histopathology,
rows = "Race",
cols = "Mortality5yr",
posthoc = "bonferroni",
sig = 0.05,
excl = TRUE,
exp = FALSE,
plot = FALSE
)
## Warning in stats::chisq.test(contTable, correct = FALSE): Chi-squared
## approximation may be incorrect
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ──────────────────────────────────────────────
## Statistic Value df p-value
## ──────────────────────────────────────────────
## Chi-Square 0.8614085 6 0.9903252
## ──────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## <table border='1' style='border-collapse:
## collapse;'>AliveDeadAsian25Bi-Racial13Black1124Hawaiian01Hispanic1527Native12White50106
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Alive<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Dead<td style='border: 1px solid
## #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Asian<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.212
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.212
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Bi-Racial<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-0.313
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.313
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Black<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>-0.113
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.113
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Hawaiian<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-0.691
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.691
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Hispanic<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.526
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.526
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Native<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.04
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.04
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>White<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>-0.091
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.091
## As expected
##
## Critical value for significance: ±2.914
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
False Discovery Rate (FDR)
- Less conservative than Bonferroni
- Controls the expected proportion of false discoveries
- Use when: You want to balance Type I and Type II errors
chisqposttest(
data = histopathology,
rows = "Race",
cols = "Mortality5yr",
posthoc = "fdr",
sig = 0.05,
excl = TRUE,
exp = FALSE,
plot = FALSE
)
## Warning in stats::chisq.test(contTable, correct = FALSE): Chi-squared
## approximation may be incorrect
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ──────────────────────────────────────────────
## Statistic Value df p-value
## ──────────────────────────────────────────────
## Chi-Square 0.8614085 6 0.9903252
## ──────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## <table border='1' style='border-collapse:
## collapse;'>AliveDeadAsian25Bi-Racial13Black1124Hawaiian01Hispanic1527Native12White50106
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Alive<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Dead<td style='border: 1px solid
## #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Asian<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.212
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.212
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Bi-Racial<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-0.313
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.313
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Black<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>-0.113
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.113
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Hawaiian<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-0.691
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.691
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Hispanic<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.526
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.526
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Native<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.04
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.04
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>White<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>-0.091
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.091
## As expected
##
## Critical value for significance: ±2.914
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Holm Method
- Step-down procedure
- More powerful than Bonferroni while maintaining family-wise error control
- Use when: You want more power than Bonferroni but still strong control
chisqposttest(
data = histopathology,
rows = "Race",
cols = "Mortality5yr",
posthoc = "holm",
sig = 0.05,
excl = TRUE,
exp = FALSE,
plot = FALSE
)
## Warning in stats::chisq.test(contTable, correct = FALSE): Chi-squared
## approximation may be incorrect
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ──────────────────────────────────────────────
## Statistic Value df p-value
## ──────────────────────────────────────────────
## Chi-Square 0.8614085 6 0.9903252
## ──────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## <table border='1' style='border-collapse:
## collapse;'>AliveDeadAsian25Bi-Racial13Black1124Hawaiian01Hispanic1527Native12White50106
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Alive<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Dead<td style='border: 1px solid
## #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Asian<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.212
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.212
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Bi-Racial<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-0.313
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.313
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Black<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>-0.113
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.113
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Hawaiian<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-0.691
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.691
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Hispanic<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.526
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.526
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Native<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.04
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.04
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>White<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>-0.091
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.091
## As expected
##
## Critical value for significance: ±2.914
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Comparison of Adjustment Methods
# Create a comparison table of different methods
adjustment_methods <- c("bonferroni", "holm", "fdr", "none")
# Note: In practice, you would run these analyses and compare results
# This is a conceptual example of how different methods affect conclusions
cat("Adjustment Method Comparison:\n")
## Adjustment Method Comparison:
cat("- Bonferroni: Most conservative, lowest power\n")
## - Bonferroni: Most conservative, lowest power
cat("- Holm: Good balance of Type I error control and power\n")
## - Holm: Good balance of Type I error control and power
cat("- FDR: Higher power, controls false discovery rate\n")
## - FDR: Higher power, controls false discovery rate
cat("- None: Highest power, no multiple comparison adjustment\n")
## - None: Highest power, no multiple comparison adjustment
Advanced Features
Including Expected Values
Expected values help assess the magnitude of deviations from independence:
chisqposttest(
data = histopathology,
rows = "PNI", # Perineural invasion
cols = "Grade_Level",
posthoc = "fdr",
sig = 0.05,
excl = TRUE,
exp = TRUE, # Show expected values
plot = FALSE
)
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ─────────────────────────────────────────────
## Statistic Value df p-value
## ─────────────────────────────────────────────
## Chi-Square 1.107106 2 0.5749036
## ─────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## Values shown as: Observed
## (Expected)
##
## <table border='1' style='border-collapse:
## collapse;'>highlowmoderateAbsent61
## (61.9)54
## (50.6)50
## (52.6)Present32
## (31.1)22
## (25.4)29
## (26.4)
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>high<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>low<th style='border: 1px solid
## #666; padding: 8px; text-align: center;'>moderate<td style='border:
## 1px solid #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Absent<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.243
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>1.003
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.74
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Present<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.243
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-1.003
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.74
## As expected
##
## Critical value for significance: ±2.638
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Standardized Residuals Plot
The residuals plot feature is available in the jamovi interface and visualizes patterns of association:
# Plot functionality available in jamovi interface
chisqposttest(
data = histopathology,
rows = "Grade_Level",
cols = "LVI",
posthoc = "fdr",
sig = 0.05,
excl = TRUE,
exp = FALSE,
plot = FALSE # Plot available in jamovi interface # Generate residuals plot
)
Clinical Examples and Case Studies
Case Study 1: Biomarker Expression by Tumor Stage
Investigating whether a biomarker’s expression varies across tumor stages:
# Create a more realistic clinical scenario
# Using Grade and TStage as proxies for biomarker expression levels
# First, let's create meaningful categories
histopathology_clinical <- histopathology %>%
mutate(
TStage_Category = case_when(
TStage <= 1 ~ "Early (T1)",
TStage == 2 ~ "Intermediate (T2)",
TStage >= 3 ~ "Advanced (T3-T4)"
),
Grade_Category = case_when(
Grade == 1 ~ "Well Differentiated",
Grade == 2 ~ "Moderately Differentiated",
Grade == 3 ~ "Poorly Differentiated"
)
)
# Analyze the relationship
chisqposttest(
data = histopathology_clinical,
rows = "TStage_Category",
cols = "Grade_Category",
posthoc = "fdr",
sig = 0.05,
excl = TRUE,
exp = TRUE,
plot = FALSE # Plot available in jamovi interface
)
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ─────────────────────────────────────────────
## Statistic Value df p-value
## ─────────────────────────────────────────────
## Chi-Square 4.023637 4 0.4028164
## ─────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## Values shown as: Observed
## (Expected)
##
## <table border='1' style='border-collapse: collapse;'>Moderately
## DifferentiatedPoorly DifferentiatedWell DifferentiatedAdvanced
## (T3-T4)57
## (53)65
## (68.4)51
## (51.6)Early (T1)9
## (7.4)9
## (9.5)6
## (7.2)Intermediate (T2)10
## (15.6)24
## (20.2)17
## (15.2)
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Moderately Differentiated<th style='border:
## 1px solid #666; padding: 8px; text-align: center;'>Poorly
## Differentiated<th style='border: 1px solid #666; padding: 8px;
## text-align: center;'>Well Differentiated<td style='border: 1px solid
## #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Advanced (T3-T4)<td style='border: 1px solid #666; padding:
## 8px; text-align: center; background-color: #f9f9f9;'>1.195
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.951
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.188
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Early (T1)<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.766
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.213
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.545
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Intermediate (T2)<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-1.918
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>1.236
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.612
## As expected
##
## Critical value for significance: ±2.773
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Case Study 2: Treatment Response by Patient Characteristics
Examining treatment efficacy across patient subgroups:
# Analyze treatment response by patient demographics
chisqposttest(
data = histopathology,
rows = "Group", # Treatment vs Control
cols = "Mortality5yr", # 5-year mortality outcome
posthoc = "bonferroni",
sig = 0.05,
excl = TRUE,
exp = TRUE,
plot = FALSE # Plot available in jamovi interface
)
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ───────────────────────────────────────────────
## Statistic Value df p-value
## ───────────────────────────────────────────────
## Chi-Square 0.06125848 1 0.8045178
## ───────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## Values shown as: Observed
## (Expected)
##
## <table border='1' style='border-collapse:
## collapse;'>AliveDeadControl37
## (37.9)82
## (81.1)Treatment42
## (41.1)87
## (87.9)
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Alive<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Dead<td style='border: 1px solid
## #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Control<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.248
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.248
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Treatment<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>0.248
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.248
## As expected
##
## Critical value for significance: ±2.498
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Case Study 3: Pathological Features Association
Investigating relationships between multiple pathological features:
# Multiple pathological features analysis
chisqposttest(
data = histopathology,
rows = "LVI", # Lymphovascular invasion
cols = "PNI", # Perineural invasion
posthoc = "holm",
sig = 0.05,
excl = TRUE,
exp = TRUE,
plot = FALSE # Plot available in jamovi interface
)
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ──────────────────────────────────────────────
## Statistic Value df p-value
## ──────────────────────────────────────────────
## Chi-Square 0.1719012 1 0.6784276
## ──────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## Values shown as: Observed
## (Expected)
##
## <table border='1' style='border-collapse:
## collapse;'>AbsentPresentAbsent96
## (94.5)46
## (47.5)Present69
## (70.5)37
## (35.5)
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Absent<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Present<td style='border: 1px solid
## #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Absent<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.415
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.415
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Present<td
## style='border: 1px solid #666; padding: 8px; text-align: center;
## background-color: #f9f9f9;'>-0.415
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.415
## As expected
##
## Critical value for significance: ±2.498
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Handling Missing Data
Strategies for Missing Data
# Create dataset with missing values for demonstration
demo_data <- histopathology[1:100, ]
demo_data$Sex[sample(1:100, 10)] <- NA
demo_data$Group[sample(1:100, 8)] <- NA
# Analysis excluding missing data
cat("Analysis excluding missing data:\n")
## Analysis excluding missing data:
chisqposttest(
data = demo_data,
rows = "Sex",
cols = "Group",
posthoc = "fdr",
sig = 0.05,
excl = TRUE, # Exclude missing values
exp = FALSE,
plot = FALSE
)
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ──────────────────────────────────────────────
## Statistic Value df p-value
## ──────────────────────────────────────────────
## Chi-Square 0.3454337 1 0.5567094
## ──────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## <table border='1' style='border-collapse:
## collapse;'>ControlTreatmentFemale1826Male1820
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Control<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Treatment<td style='border: 1px
## solid #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Female<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.588
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.588
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Male<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>0.588
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.588
## As expected
##
## Critical value for significance: ±2.498
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
# Analysis including missing data as category
cat("\nAnalysis including missing data:\n")
##
## Analysis including missing data:
chisqposttest(
data = demo_data,
rows = "Sex",
cols = "Group",
posthoc = "fdr",
sig = 0.05,
excl = FALSE, # Include missing values
exp = FALSE,
plot = FALSE
)
## Warning in stats::chisq.test(contTable, correct = FALSE): Chi-squared
## approximation may be incorrect
##
## CHI-SQUARE POST-HOC TESTS
##
## character(0)
##
## Chi-Square Test Results
## ─────────────────────────────────────────────
## Statistic Value df p-value
## ─────────────────────────────────────────────
## Chi-Square 2.051978 4 0.7261991
## ─────────────────────────────────────────────
##
##
## <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px
## solid #1976d2; margin: 10px 0;">
## <h4 style="color: #1976d2; margin-top: 0;">Chi-Square Post-Hoc
## Analysis Guide
##
## Three-Step Comprehensive Analysis:
##
##
##
## 1.
## Overall Chi-Square Test:
## Tests if there's any association between variables
## <br/>
## 2.
## Residuals Analysis:
## Identifies which specific cells contribute to significance
## <br/>
## 3.
## Pairwise Comparisons:
## Formal hypothesis testing between group pairs
##
##
##
## *Recommended approach: Start with residuals analysis for pattern
## identification, then use pairwise tests for formal hypothesis
## testing.*
##
##
## <table border='1' style='border-collapse:
## collapse;'>ControlTreatmentNAFemale18264Male18203NA542
##
## <div style='margin: 15px 0;'><div style="padding: 15px;
## background-color: #e8f5e8; border-left: 4px solid #4caf50; margin:
## 10px 0;">
## <h4 style="color: #2e7d32; margin-top: 0;">Standardized Residuals
## Interpretation
##
## What are standardized residuals?
##
##
## Standardized residuals measure how much each cell deviates from what
## we'd expect if there was no association. They're calculated as
## (Observed - Expected) / √Expected, then adjusted for multiple
## comparisons.
##
## <div style="background-color: #f1f8e9; padding: 10px; border-radius:
## 3px;">
## Interpretation Guidelines:
## <br/>
## • |Residual| > 2.0: Suggests meaningful deviation
## <br/>
## • |Residual| > 3.0: Strong evidence of deviation
## <br/>
## • Positive values: Over-represented (more than expected)
## <br/>
## • Negative values: Under-represented (fewer than expected)
##
## <table style='border-collapse: collapse; width: 100%; margin: 15px
## 0;'><tr style='background-color: #e8f5e8;'><th style='border: 1px
## solid #666; padding: 8px;'><th style='border: 1px solid #666; padding:
## 8px; text-align: center;'>Control<th style='border: 1px solid #666;
## padding: 8px; text-align: center;'>Treatment<th style='border: 1px
## solid #666; padding: 8px; text-align: center;'>NA<td style='border:
## 1px solid #666; padding: 8px; font-weight: bold; background-color:
## #f5f5f5;'>Female<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.684
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>0.801
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.224
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>Male<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>0.492
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.203
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.49
## As expected<td style='border: 1px solid #666; padding: 8px;
## font-weight: bold; background-color: #f5f5f5;'>NA<td style='border:
## 1px solid #666; padding: 8px; text-align: center; background-color:
## #f9f9f9;'>0.318
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>-0.959
## As expected<td style='border: 1px solid #666; padding: 8px;
## text-align: center; background-color: #f9f9f9;'>1.128
## As expected
##
## Critical value for significance: ±2.773
##
## <div style='padding: 15px; background-color: #d4edda; border: 1px
## solid #c3e6cb;'>Note: Overall chi-square test is not significant (p ≥
## 0.05). Post-hoc pairwise comparisons are not recommended when the
## overall test is non-significant.
##
## Pairwise Comparison Results
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Comparison Test Method Chi-Square p-value Adj. p-value Effect Size (Phi) Significant
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
## ────────────────────────────────────────────────────────────────────────────────────────────────────────────
##
##
## character(0)
Best Practices and Guidelines
Statistical Considerations
Clinical Reporting Guidelines
Essential Elements to Report
- Overall chi-square results: χ², df, p-value
- Sample sizes: For each group and overall
- Adjustment method: Justification for choice
- Significant comparisons: With adjusted p-values
- Effect sizes: Clinical meaningfulness
- Missing data handling: Exclusions and rationale
Example Results Section
cat("Sample Results Reporting:\n\n")
## Sample Results Reporting:
cat("The overall chi-square test revealed a significant association between\n")
## The overall chi-square test revealed a significant association between
cat("tumor grade and lymphovascular invasion (χ² = X.XX, df = X, p < 0.05).\n")
## tumor grade and lymphovascular invasion (χ² = X.XX, df = X, p < 0.05).
cat("Post-hoc pairwise comparisons using FDR adjustment showed that\n")
## Post-hoc pairwise comparisons using FDR adjustment showed that
cat("poorly differentiated tumors had significantly higher rates of\n")
## poorly differentiated tumors had significantly higher rates of
cat("lymphovascular invasion compared to well differentiated tumors\n")
## lymphovascular invasion compared to well differentiated tumors
cat("(adjusted p = 0.XXX). No other pairwise comparisons reached statistical\n")
## (adjusted p = 0.XXX). No other pairwise comparisons reached statistical
cat("significance after multiple comparison adjustment.\n")
## significance after multiple comparison adjustment.
Advanced Applications
Integration with Other Analyses
Combining with Survival Analysis
# Chi-square post-hoc can inform survival analysis stratification
cat("Use chi-square post-hoc results to:\n")
## Use chi-square post-hoc results to:
cat("1. Identify meaningful subgroups for survival analysis\n")
## 1. Identify meaningful subgroups for survival analysis
cat("2. Determine appropriate stratification variables\n")
## 2. Determine appropriate stratification variables
cat("3. Guide covariate selection in Cox models\n")
## 3. Guide covariate selection in Cox models
Biomarker Research Applications
cat("Common biomarker research applications:\n")
## Common biomarker research applications:
cat("• Expression levels by tumor characteristics\n")
## • Expression levels by tumor characteristics
cat("• Mutation status by histological features\n")
## • Mutation status by histological features
cat("• Treatment response by biomarker profiles\n")
## • Treatment response by biomarker profiles
cat("• Progression patterns by molecular subtypes\n")
## • Progression patterns by molecular subtypes
Quality Control and Validation
Assumption Checking
cat("Key assumptions to verify:\n")
## Key assumptions to verify:
cat("1. Independence of observations\n")
## 1. Independence of observations
cat("2. Adequate expected frequencies\n")
## 2. Adequate expected frequencies
cat("3. Appropriate variable coding\n")
## 3. Appropriate variable coding
cat("4. Random sampling from population\n")
## 4. Random sampling from population
Sensitivity Analyses
cat("Consider sensitivity analyses:\n")
## Consider sensitivity analyses:
cat("• Different significance thresholds\n")
## • Different significance thresholds
cat("• Alternative adjustment methods\n")
## • Alternative adjustment methods
cat("• Missing data handling approaches\n")
## • Missing data handling approaches
cat("• Subgroup analyses by key variables\n")
## • Subgroup analyses by key variables
Conclusion
Chi-square post-hoc testing is a powerful tool for identifying specific patterns of association in categorical data. Key takeaways for clinicopathological research:
- Use post-hoc tests only when overall chi-square is significant
- Choose adjustment methods based on your research priorities
- Report effect sizes alongside statistical significance
- Consider clinical context when interpreting results
- Validate findings in independent datasets when possible
The ClinicoPath chi-square post-hoc module provides comprehensive functionality for these analyses, supporting rigorous statistical practices in clinical and pathological research.
References
- Agresti, A. (2018). An Introduction to Categorical Data Analysis. 3rd Edition.
- Benjamini, Y., & Hochberg, Y. (1995). Controlling the false discovery rate. Journal of the Royal Statistical Society, 57(1), 289-300.
- Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, 6(2), 65-70.
- Cramér, H. (1946). Mathematical Methods of Statistics. Princeton University Press.
This vignette was created for the ClinicoPath jamovi module. For more information and updates, visit https://github.com/sbalci/ClinicoPathJamoviModule.