indepTests: Tests for Independence in Contingency Tables

View source: R/indepTests.R

indepTestsR Documentation

Tests for Independence in Contingency Tables

Description

The Pearson's Chi-Squared test, likelihood ratio (G test) of independence, Fisher's Exact test, and linear-by-linear association test are performed on the data matrix.

Usage

indepTests(x, digits = 3)

Arguments

x

an object of class CrossTable containing the contingency table

digits

number of digits to round to

Details

A Pearson's Chi-Squared test Yate's Continuity Correction is applied in the case of 2 by 2 tables.

Value

A table with method name, test statistic, degrees of freedom, and p-value reported for each Chi-squared test.

Author(s)

Derek Chiu

See Also

descr::CrossTable()

Examples

# Example from documentation of CrossTable
library(descr)
data(esoph, package = "datasets")
ct <- CrossTable(esoph$alcgp, esoph$agegp, expected = TRUE,
                 chisq = FALSE, prop.chisq = FALSE,
                 dnn = c("Alcohol consumption", "Tobacco consumption"))
indepTests(ct)

# Better example
set.seed(1108)
A <- rbinom(100, 3, 0.2)
B <- rbinom(100, 4, 0.8)
ct <- CrossTable(A, B)
indepTests(ct)

TalhoukLab/biostatUtil documentation built on April 14, 2025, 4:15 a.m.