Learn R Programming

questionr (version 0.7.7)

odds.ratio: Odds Ratio

Description

S3 method for odds ratio

Usage

odds.ratio(x, ...)

# S3 method for glm odds.ratio(x, level = 0.95, ...)

# S3 method for multinom odds.ratio(x, level = 0.95, ...)

# S3 method for factor odds.ratio(x, fac, level = 0.95, ...)

# S3 method for table odds.ratio(x, level = 0.95, ...)

# S3 method for matrix odds.ratio(x, level = 0.95, ...)

# S3 method for numeric odds.ratio(x, y, level = 0.95, ...)

# S3 method for odds.ratio print(x, signif.stars = TRUE, ...)

Value

Returns a data.frame of class odds.ratio with odds ratios, their confidence interval and p-values.

If x and y are proportions, odds.ratio simply returns the value of the odds ratio, with no confidence interval.

Arguments

x

object from whom odds ratio will be computed

...

further arguments passed to or from other methods

level

the confidence level required

fac

a second factor object

y

a second numeric object

signif.stars

logical; if TRUE, p-values are encoded visually as 'significance stars'

Author

Joseph Larmarange <joseph@larmarange.net>

Details

For models calculated with glm, x should have been calculated with family=binomial. p-value are the same as summary(x)$coefficients[,4]. Odds ratio could also be obtained with exp(coef(x)) and confidence intervals with exp(confint(x)).

For models calculated with multinom (nnet), p-value are calculated according to https://stats.oarc.ucla.edu/r/dae/multinomial-logistic-regression/.

For 2x2 table, factor or matrix, odds.ratio uses fisher.test to compute the odds ratio.

See Also

glm in the stats package.

multinom in the nnet package.

fisher.test in the stats package.

printCoefmat in the stats package.

Examples

Run this code
data(hdv2003)
reg <- glm(cinema ~ sexe + age, data=hdv2003, family=binomial)
odds.ratio(reg)
odds.ratio(hdv2003$sport, hdv2003$cuisine)
odds.ratio(table(hdv2003$sport, hdv2003$cuisine))
M <- matrix(c(759, 360, 518, 363), ncol = 2)
odds.ratio(M)
odds.ratio(0.26, 0.42)

Run the code above in your browser using DataLab