keyness: Compute keyness (internal functions)

Description Usage Arguments Details Value References Examples

View source: R/textstat_keyness.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
keyness_chi2_dt(x, correction = c("default", "yates", "williams", "none"))

keyness_chi2_stats(x)

keyness(t, f, sum_t, sum_f)

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

t

(scalar) frequency of target

f

(scalar) frequency of reference

sum_t

total of all target words

sum_f

total of all reference words

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 stat using vectorized computation

Value

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

References

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

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

Examples

1
2
3
4
5
6
7
dfmat <- 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.core:::keyness_chi2_dt(dfmat)
quanteda.core:::keyness_chi2_stats(dfmat)
quanteda.core:::keyness_exact(dfmat)
quanteda.core:::keyness_lr(dfmat)
quanteda.core:::keyness_pmi(dfmat)

koheiw/quanteda.core documentation built on Sept. 21, 2020, 3:44 p.m.