Learn R Programming

REdaS (version 0.9.1)

Odds-Ratios: Compute (Log) Odds Ratios

Description

This function computes the (log-)odds ratio (OR) for a $2\times{}2$ table (x must be an object of class 'table' either by using table or as.table). For a data frame of $k$ variables with 2 categories each, all $k(k-1)/2$ pairwise (log-)odds-ratios are computed.

Usage

odds_ratios(x)

## S3 method for class 'REdaS_ORs': print(x, ...)

## S3 method for class 'REdaS_ORs': summary(object, ...)

Arguments

x
either a $2\times{}2$ table object or a data frame where each variable has two categories.
object
an object of class 'REdaS_ORs'.
...
further arguments.

Value

  • odds_ratios() returns a list of class 'REdaS_ORs':
  • callthe issued function call.
  • xthe original data.
  • tablesa list of one or more tables.
  • compsa list of the compared variables' names.
  • ORsa list with (log-)odds-ratios, standard errors, $z$- and $p$-values.
  • print.REdaS_ORs() invisibly returns a matrix containing all statistics shown by the print-method.

encoding

UTF-8

Details

Note that tables where one or more cells are 0 are not processed and a warning is issued in such cases.

Examples

Run this code
# create a table from a 2 x 2 matrix of frequencies using as.table()
tab <- as.table( matrix(c(49, 1, 5, 45), 2) )
dimnames(tab) <- list("LED on?" = c("no", "yes"),
                      "PC running?" = c("no", "yes"))
tab

odds_ratios(tab)

# generate a matrix with 3 variables and 100 observations
# note that each variable must have exactly two categories
set.seed(5)
x <- data.frame("A" = as.factor(sample(1:2, 100, TRUE)),
                "B" = as.factor(sample(3:4, 100, TRUE)),
                "C" = as.factor(sample(5:6, 100, TRUE)))
head(x)

res <- odds_ratios(x)

# print the results and save the summarized information in a matrix
resmat <- print(res)
resmat

# the summary method gives a rather lengthy output with all tables etc.
summary(res)

Run the code above in your browser using DataLab