LRT.stat: Likelihood ratio test statistic for contingency tables

Description Usage Arguments Details Value Examples

Description

Calculate the likelihood ratio test statistic for general two-way contingency tables.

Usage

1
LRT.stat(tab)

Arguments

tab

A K x C matrix (contingency table) of counts. See details.

Details

Suppose that tab consists of counts from K populations (rows) in C categories. The likelihood ratio test statistic is computed as

2 ∑_ij O_ij log(p_ij/p_0j),

where O_ij is the observed number of counts in the ith row and jth column of tab, p_ij = O_ij/(∑_j O_ij) is the unconstrained estimate of the proportion of category j in population i, and p_0j = ∑_i O_ij / ∑_ij O_ij is the estimate of this proportion under H_0 that the populations have indentical proportions in each category. If any column has only zeros it is removed before calculating the LRT statistic.

Value

The calculated value of the LRT statistic.

Examples

1
2
3
4
5
6
# simple contingency table
ctab <- rbind(pop1 = c(5, 3, 0, 3),
                pop2 = c(4, 10, 2, 5))
colnames(ctab) <- LETTERS[1:4]
ctab
LRT.stat(ctab) # likelihood ratio statistic

Example output

Loading required package: rstan
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.16.2, packaged: 2017-07-03 09:24:58 UTC, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
     A  B C D
pop1 5  3 0 3
pop2 4 10 2 5
[1] 4.187832

MADPop documentation built on May 1, 2019, 6:47 p.m.