Compute (Log) Odds Ratios

Share:

Description

This function computes the (log-)odds ratio (OR) for a 2 × 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

1
2
3
4
5
6
7
odds_ratios(x)

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

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

Arguments

x

either a 2 × 2 table object or a data frame where each variable has two categories.

object

an object of class 'REdaS_ORs'.

...

further arguments.

Details

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

Value

odds_ratios() returns a list of class 'REdaS_ORs':

call

the issued function call.

x

the original data.

tables

a list of one or more tables.

comps

a list of the compared variables' names.

ORs

a 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.

Author(s)

Marco J. Maier

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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)