Raw File
Tip revision: be291479202d9ca826914b9bf0fe0b8efa26e6c3 authored by Martin Lysy on 22 August 2022, 08:20:12 UTC
version 1.1.4
Tip revision: be29147
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/LRT.stat.R
\title{Likelihood ratio test statistic for contingency tables}
\item{tab}{A \code{K x C} matrix (contingency table) of counts. See details.}
The calculated value of the LRT statistic.
Calculate the likelihood ratio test statistic for general two-way contingency tables.
Suppose that \code{tab} consists of counts from \eqn{K} populations (rows) in \eqn{C} categories.  The likelihood ratio test statistic is computed as
  2 \sum_{i=1}^K \sum_{j=1}^N O_{ij} \log(p^A_{ij}/p^0_{j}),
  2 \sum_ij O_ij log(p_ij/p_0j),
where \eqn{O_{ij}}{O_ij} is the observed number of counts in the \eqn{i}th row and \eqn{j}th column of \code{tab}, \eqn{p^A_{ij} = O_{ij}/\sum_{j=1}^C O_{ij}}{p_ij = O_ij/(\sum_j O_ij)} is the unconstrained estimate of the proportion of category \eqn{j} in population \eqn{i}, and \eqn{p^0_j = \sum_{i=1}^K O_{ij} / \sum_{i=1}^K\sum_{j=1}^C O_{ij}}{p_0j = \sum_i O_ij / \sum_ij O_ij} is the estimate of this proportion under \eqn{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.
# simple contingency table
ctab <- rbind(pop1 = c(5, 3, 0, 3),
                pop2 = c(4, 10, 2, 5))
colnames(ctab) <- LETTERS[1:4]
LRT.stat(ctab) # likelihood ratio statistic
back to top