analyzeTable_Enrichment: Analyze Enrichment in a Contingency Table

View source: R/EnrichmentAnalysis.R

analyzeTable_EnrichmentR Documentation

Analyze Enrichment in a Contingency Table

Description

This function performs a chi-square test on a given contingency table and generates various diagnostic plots to assess the association between the table's dimensions. Optional plots include a balloon plot, mosaic plot, association plot, heatmap of Pearson's residuals, correlation plot of Pearson's residuals, and a plot displaying the relative contribution of Pearson's residuals.

Usage

analyzeTable_Enrichment(
  tempTbl,
  plotBalloon = FALSE,
  plotMosaic = FALSE,
  plotAssoc = FALSE,
  plotResHeatmap = T,
  plotCorrplot = FALSE,
  plotContrib = F,
  plotContrib_dir = T,
  Title = ""
)

Arguments

tempTbl

A contingency table (e.g., produced by table) containing counts.

plotBalloon

Logical; if TRUE, a balloon plot is generated using the gplots package.

plotMosaic

Logical; if TRUE, a mosaic plot is generated.

plotAssoc

Logical; if TRUE, an association plot is generated using the vcd package.

plotResHeatmap

Logical; if TRUE, a heatmap of Pearson's residuals is produced using the pheatmap package. Default is TRUE.

plotCorrplot

Logical; if TRUE, a correlation plot of Pearson's residuals is generated using the corrplot package.

plotContrib

Logical; if TRUE, a plot showing the relative contribution of Pearson's residuals is generated using the corrplot package. Default is TRUE.

plotContrib_dir

Logical; if TRUE, a plot showing the directional contribution of Pearson's residuals is generated using the corrplot package. Default is TRUE. The directional contribution retains the sign of the residuals.

Title

Character; a title string to be used in the generated plots.

Details

This function requires the following packages: gplots, pheatmap, vcd, and corrplot. Ensure these packages are installed prior to using the function.

Value

A list containing:

test

The chi-square test object.

observed

Observed counts from the contingency table.

expected

Expected counts, rounded to two decimal places.

residuals

Pearson's residuals, rounded to three decimal places.

p.value

The p-value of the chi-square test.

contrib

Relative contribution of Pearson's residuals (in percent), rounded to three decimal places.

Examples

## Not run: 
# Create an example contingency table
tempTbl <- table(sample(letters[1:3], 100, replace = TRUE),
                 sample(c("Low", "High"), 100, replace = TRUE))

# Analyze the table with selected plots
result <- analyzeTable_Enrichment(tempTbl,
                                  plotBalloon = TRUE,
                                  plotMosaic = TRUE,
                                  plotResHeatmap = TRUE,
                                  plotContrib = TRUE,
                                  Title = "Example Plot Title")

# Print chi-square test results and associated metrics
print(result)

## End(Not run)


eisascience/scCustFx documentation built on June 2, 2025, 3:59 a.m.