S3 method for odds ratio
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, ...)
object from whom odds ratio will be computed
further arguments passed to or from other methods
the confidence level required
a second factor object
a second numeric object
logical; if TRUE
, p-values are encoded visually as 'significance stars'
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.
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.
fisher.test
in the stats package.
printCoefmat
in the stats package.
data(hdv2003)
reg <- glm(cinema ~ sexe + age, data=hdv2003, family=binomial)
odds.ratio(reg)
#> Waiting for profiling to be done...
#> OR 2.5 % 97.5 % p
#> (Intercept) 10.41153 7.46408 14.6374 <2e-16 ***
#> sexeFemme 1.14333 0.93852 1.3934 0.1838
#> age 0.94233 0.93591 0.9486 <2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
odds.ratio(hdv2003$sport, hdv2003$cuisine)
#> OR 2.5 % 97.5 % p
#> Fisher's test 1.4771 1.2242 1.7829 3.646e-05 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
odds.ratio(table(hdv2003$sport, hdv2003$cuisine))
#> OR 2.5 % 97.5 % p
#> Fisher's test 1.4771 1.2242 1.7829 3.646e-05 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
M <- matrix(c(759, 360, 518, 363), ncol = 2)
odds.ratio(M)
#> OR 2.5 % 97.5 % p
#> Fisher's test 1.4771 1.2242 1.7829 3.646e-05 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
odds.ratio(0.26, 0.42)
#> [1] 0.4851995