Perform Chisquare-Test based on a table with counts
chisquare(.Object) ## S4 method for signature 'features' chisquare(.Object) ## S4 method for signature 'context' chisquare(.Object) ## S4 method for signature 'cooccurrences' chisquare(.Object)
The basis for computing for the chi square test is a contingency table of observationes, which is prepared for every single token in the corpus. It reports counts for a token to inspect and all other tokens in a corpus of interest (coi) and a reference corpus (ref):
Based on the contingency table, expected values are calculated for each cell, as the product of the column and margin sums, divided by the overall number of tokens (see example). The standard formula for calculating the chi-square test is computed as follows.
X2 = (o11 - e11)^2/e11 + (o12 - e12)^2/e12 + (o12 - e12)^2/e12 + (o22 - e22)^2/e22
Results from the chisquare test are only robust for at least 5 observed counts in the corpus of interest. Usually, results need to be filtered accordingly (see examples).
Same class as input object, with enriched table in the
Manning, Christopher D.; Schuetze, Hinrich (1999): Foundations of Statistical Natural Language Processing. MIT Press: Cambridge, Mass., pp. 169-172.
Kilgarriff, A. and Rose, T. (1998): Measures for corpus similarity and homogeneity. Proc. 3rd Conf. on Empirical Methods in Natural Language Processing. Granada, Spain, pp 46-52.
Other statistical methods:
use("polmineR") library(data.table) m <- partition( "GERMAPARLMINI", speaker = "Merkel", interjection = "speech", regex = TRUE, p_attribute = "word" ) f <- features(m, "GERMAPARLMINI", included = TRUE) f_min <- subset(f, count_coi >= 5) summary(f_min) ## Not run: # A sample do-it-yourself calculation for chisquare: # (a) prepare matrix with observed values o <- matrix(data = rep(NA, 4), ncol = 2) o[1,1] <- as.data.table(m)[word == "Weg"][["count"]] o[1,2] <- count("GERMAPARLMINI", query = "Weg")[["count"]] - o[1,1] o[2,1] <- size(f)[["coi"]] - o[1,1] o[2,2] <- size(f)[["ref"]] - o[1,2] # prepare matrix with expected values, calculate margin sums first r <- rowSums(o) c <- colSums(o) N <- sum(o) e <- matrix(data = rep(NA, 4), ncol = 2) e[1,1] <- r * (c / N) e[1,2] <- r * (c / N) e[2,1] <- r * (c / N) e[2,2] <- r * (c / N) # compute chisquare statistic y <- matrix(rep(NA, 4), ncol = 2) for (i in 1:2) for (j in 1:2) y[i,j] <- (o[i,j] - e[i,j])^2 / e[i,j] chisquare_value <- sum(y) as(f, "data.table")[word == "Weg"][["chisquare"]] ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.