Log-likelihood ratio (G) test of independence in a contingency table, or of goodness of fit of counts to given
probabilities. Equivalent to DescTools::GTest() in R.
For a table (an array of rows), G = 2 sum x log(x / E) / q with E the products of the margins over the total and
(r - 1)(c - 1) degrees of freedom, counting empty rows and columns as DescTools; for a vector (or a table with one
row or column), E = n p and k - 1 degrees of freedom. correct: "williams" divides by Williams' q
(1 + (n sum 1/R_i - 1)(n sum 1/C_j - 1) / (6 n (r - 1)(c - 1)) for a table, which is not defined with an empty
row or column: an error, where DescTools gives G = 0 and p = 1; and 1 + (k + 1) / (6n) for a vector). correct: "yates" moves the counts of a 2 x 2 table by 0.5 toward
independence as DescTools does: the off-diagonal cells up and the diagonal down when x11 x22 - x12 x21 > 0, and
the other way otherwise, also when it is 0 (so that a table of exact independence gets a positive G), and without
stopping at 0 (a cell that becomes negative makes G NaN, with the warning "NaNs produced"). For two counts it moves
them by 0.5 toward E when they differ from it by more than 0.25.
The p-value is the upper tail of chi-squared (DescTools computes 1 - pchisq for a table, which is 0 below about
1e-16). G is summed as a deviance, without the cancellation of the plain sum. The result also has the Freeman-Tukey
deviates ftResiduals.
The test result, with statisticName"G"; see GTestResult.
Throws
RangeError for negative or non-finite counts, a total of 0, fewer than 2 counts, p of the wrong length,
negative or not summing to 1, "yates" for anything but a 2 x 2 table or two counts, and "williams" for a
table with an empty row or column.
Log-likelihood ratio (G) test of independence in a contingency table, or of goodness of fit of counts to given probabilities. Equivalent to
DescTools::GTest()in R.For a table (an array of rows),
G = 2 sum x log(x / E) / qwithEthe products of the margins over the total and(r - 1)(c - 1)degrees of freedom, counting empty rows and columns as DescTools; for a vector (or a table with one row or column),E = n pandk - 1degrees of freedom.correct: "williams"divides by Williams' q (1 + (n sum 1/R_i - 1)(n sum 1/C_j - 1) / (6 n (r - 1)(c - 1))for a table, which is not defined with an empty row or column: an error, where DescTools gives G = 0 and p = 1; and1 + (k + 1) / (6n)for a vector).correct: "yates"moves the counts of a 2 x 2 table by 0.5 toward independence as DescTools does: the off-diagonal cells up and the diagonal down whenx11 x22 - x12 x21 > 0, and the other way otherwise, also when it is 0 (so that a table of exact independence gets a positive G), and without stopping at 0 (a cell that becomes negative makes G NaN, with the warning "NaNs produced"). For two counts it moves them by 0.5 towardEwhen they differ from it by more than 0.25.The p-value is the upper tail of chi-squared (DescTools computes
1 - pchisqfor a table, which is 0 below about 1e-16). G is summed as a deviance, without the cancellation of the plain sum. The result also has the Freeman-Tukey deviatesftResiduals.