test.chi: Chi-square test

View source: R/Chi_test.R

test.chiR Documentation

Chi-square test

Description

Applies the Pearson chi-square test or Fisher's exact test to assess association between two categorical variables.

Usage

test.chi(
  x,
  y = NULL,
  title = "Chi-square Test",
  xlab = NULL,
  ylab = "Proportion",
  style = c("stacked", "barplot", "mosaic", "pie"),
  show_table = TRUE,
  help = FALSE,
  verbose = TRUE
)

Arguments

x

Categorical vector or data frame with two columns (group 1 and group 2).

y

Categorical vector (group 2). Required if x is a vector.

title

Plot title (string). Default: "Chi-square Test".

xlab

X-axis label in the plot (string). Default: NULL (uses variable name).

ylab

Y-axis label in the plot (string). Default: "Proportion".

style

Plot style generated by the function.

show_table

Logical. If TRUE, prints the contingency table to the console. Default: TRUE.

help

Logical. If TRUE, displays a detailed explanation of the function. Default: FALSE.

verbose

Logical. If TRUE, prints messages about the test and expected frequencies. Default: TRUE.

Value

Test result and contingency table.

Examples


data <- data.frame(
  control = c(rep("healthy", 50), rep("sick", 150)),
  treatment = c(rep("healthy", 100), rep("sick", 100))
)
test.chi(data)

autotestR documentation built on April 29, 2026, 1:09 a.m.