print_association_text: Print the results of a chi-square test

Description Usage Arguments Details Value Author(s) References Examples

View source: R/print_association_text.R

Description

Print the results of a chi-square test

Usage

1
print_association_text(data, x, y, var1_name, var2_name)

Arguments

x

A contingency table (passed as table or matrix) or an object of type "htest" returned by chisq.test. Can also handle objects returned by chisq.unif.test from the spgs package.

es

Boolean. Should the phi coefficient be printed as a measure of effect size. See details.

correct

Boolean. Apply a continuity correction? See chisq.test. Only has an effect if the chi-square-test is computed by this function, i.e., if x is a contingency table. The default value is FALSE.

decimals

How many decimals should be printed

decimals_p

How many decimals should be printed for the p-value (defaults to 3)

Details

The argument es only has an effect if x is passed as a 2x2 contingency table. In this case, the phi coefficient is computed as a measure of effect size (see Cohen, 1988, page 223).

Value

A string describing the results of the chi-square test to be printed in Rmarkdown documents.

Author(s)

Martin Papenberg martin.papenberg@hhu.de

References

Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsale, NJ: Lawrence Erlbaum.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Pass a matrix
x <- matrix(c(12, 5, 7, 7), ncol = 2)
print_chi2(x) # does not use continuity correction by default
print_chi2(x, correct = TRUE) # uses continuity correction

# Pass a table
tab <- table(rbinom(150, 1, 0.5), rbinom(150, 1, 0.1))
print_chi2(tab, correct = FALSE)

# Pass a chi-squared test object
print_chi2(chisq.test(tab, correct = FALSE))

Alaburda/statistician documentation built on Jan. 8, 2021, 4:31 a.m.