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

associationTest

Chi-square test of association / independence


Description

Convenience function that runs a chi-square test of association/independence. This is a wrapper function intended to be used for pedagogical purposes only.

Usage

associationTest( formula, data=NULL )

Arguments

formula

One-sided formula specifying the two variables (required).

data

Optional data frame containing the variables.

Details

The associationTest function runs the chi-square test of association on the variables specified in the formula argument. The formula must be a one-sided formula of the form ~variable1 + variable2, and both variables must be factors.

Value

An object of class 'assocTest'. When printed, the output is organised into six short sections. The first section lists the name of the test and the variables included. The second lists the null and alternative hypotheses for the test. The third shows the observed contingency table, and the fourth shows the expected contingency table under the null. The fifth prints out the test results, and the sixth reports an estimate of effect size.

Warning

This package is under development, and has been released only due to teaching constraints. Until this notice disappears from the help files, you should assume that everything in the package is subject to change. Backwards compatibility is NOT guaranteed. Functions may be deleted in future versions and new syntax may be inconsistent with earlier versions. For the moment at least, this package should be treated with extreme caution.

Author(s)

Daniel Navarro

See Also

Examples

df <- data.frame(     
 gender=factor(c("male","male","male","male","female","female","female")),
 answer=factor(c("heads","heads","heads","heads","tails","tails","heads"))
)

associationTest( ~ gender + answer, df )

lsr

Companion to "Learning Statistics with R"

v0.5
GPL-3
Authors
Daniel Navarro
Initial release
2015-03-01

We don't support your browser anymore

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