print_chi2: Print the results of a chi-square test

View source: R/print_chi2.R

print_chi2R Documentation

Print the results of a chi-square test

Description

Print the results of a chi-square test

Usage

print_chi2(
  x,
  es = TRUE,
  correct = FALSE,
  decimals = 2,
  decimals_p = 3,
  italic_greek = TRUE
)

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)

italic_greek

Should the greek letters (for chi and possily phi) be printed in italic font. Defaults to TRUE. According to APA style this should be FALSE.

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


# 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))

# Use non italic chi symbol
print_chi2(tab, italic_greek = FALSE)


m-Py/prmisc documentation built on Aug. 23, 2023, 1:20 a.m.