Learn R Programming

SciencesPo (version 1.3.9)

calc.LR: Likelihood Ratio Test (G test) for Tables

Description

Computes the likelihood ratio test (G test) for contingency tables. Currently does not do Williams' and Yates' correction.

Usage

calc.LR(x, y = NULL, ...)

## S3 method for class 'default': calc.LR(x, y = NULL, ...)

Arguments

x
A vector or a matrix.
y
A vector that is ignored if x is a matrix and required if x is a vector.
...
Extra parameters pass to the table function.

References

Agresti, Alan (1996) Introduction to categorical data analysis. NY: John Wiley and Sons

Smithson, M.J. (2003) Confidence Intervals, Quantitative Applications in the Social Sciences Series, No. 140. Thousand Oaks, CA: Sage. pp. 39-41.

Examples

Run this code
# 2000 General Social Survey-Sex and Party affiliation
# Agresti (1996) p. 38:

gss <- data.frame(
   expand.grid(sex=c("female", "male"),
   party=c("dem", "indep", "rep")),
   count=c(762,484,327,239, 468,477))

# expand it:
# GSS <- gss[rep(1:nrow(gss), gss[["count"]]),]
GSS = untable(gss, freq = "count")

calc.LR(GSS$party, GSS$sex)

Run the code above in your browser using DataLab