Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

chisq.test

Apply stats::chisq.test to a two-way tabyl


Description

This generic function overrides stats::chisq.test. If the passed table is a two-way tabyl, it runs it through janitor::chisq.test.tabyl, otherwise it just calls stats::chisq.test.

Usage

chisq.test(x, ...)

## Default S3 method:
chisq.test(x, y = NULL, ...)

## S3 method for class 'tabyl'
chisq.test(x, tabyl_results = TRUE, ...)

Arguments

x

a two-way tabyl, a numeric vector or a factor

...

other parameters passed to stats::chisq.test

y

if x is a vector, must be another vector or factor of the same length

tabyl_results

if TRUE and x is a tabyl object, also return 'observed', 'expected', 'residuals' and 'stdres' as tabyl

Value

The result is the same as the one of stats::chisq.test. If 'tabyl_results' is TRUE, the returned tables 'observed', 'expected', 'residuals' and 'stdres' are converted to tabyls.

Examples

tab <- tabyl(mtcars, gear, cyl)
chisq.test(tab)
chisq.test(tab)$residuals

janitor

Simple Tools for Examining and Cleaning Dirty Data

v2.1.0
MIT + file LICENSE
Authors
Sam Firke [aut, cre], Bill Denney [ctb], Chris Haid [ctb], Ryan Knight [ctb], Malte Grosser [ctb], Jonathan Zadra [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.