Learn R Programming

quanteda (version 0.99.12)

keyness: compute keyness (internal functions)

Description

Internal function used in textstat_keyness. Computes \(chi^2\) with Yates' continuity correction for 2x2 tables.

Usage

keyness_chi2_dt(x, correction = c("default", "yates", "williams", "none"))

keyness_chi2_stats(x)

keyness_exact(x)

keyness_lr(x, correction = c("default", "yates", "williams", "none"))

keyness_pmi(x)

Arguments

x

a dfm object

correction

implement the Yates correction for 2x2 tables

Value

a data.frame of chi2 and p-values with rows named for each feature

Details

keyness_chi2_dt uses vectorized computation from data.table objects.

keyness_chi2_stats uses element-by-element application of chisq.test.

keyness_exact computes Fisher's exact using element-by-element application of fisher.test, returning the odds ratio.

keyness_lr computes the \(G^2\) likelihood ratio statistic using vectorized computation

keyness_pmi computes the Pointwise Mutual Information statistic using vectorized computation

References

https://en.wikipedia.org/wiki/Yates's_correction_for_continuity

http://influentialpoints.com/Training/g-likelihood_ratio_test.htm

Examples

Run this code
# NOT RUN {
mydfm <- dfm(c(d1 = "a a a b b c c c c c c d e f g h h",
               d2 = "a a b c c d d d d e f h"))
quanteda:::keyness_chi2_dt(mydfm)
quanteda:::keyness_chi2_stats(mydfm)
quanteda:::keyness_exact(mydfm)
quanteda:::keyness_lr(mydfm)
quanteda:::keyness_pmi(mydfm)
# }

Run the code above in your browser using DataLab