50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

reporttools (version 1.1.4)

nominalTest: Compute Chi square or Fisher's exact test

Description

Depending on the value of the smallest expected count compute either a χ2 or Fisher's exact test.

Usage

nominalTest(tab, limit.exp = 5)

Value

A list containing:

p

The computed p-value.

test

A string indicating the test that was used.

Arguments

tab

Frequency table, received by applying table() to two nominal variables.

limit.exp

If the smallest expected count is at most limit.exp the p-value of a Fisher test is returned. Otherwise, a χ2 test is computed.

Examples

Run this code
v1 <- as.factor(round(runif(40, 0, 3)))
v2 <- as.factor(round(runif(40, 2, 3)))
tab <- table(v1, v2)
nominalTest(tab)

Run the code above in your browser using DataLab