S3 method for odds ratio
odds.ratio(x, ...)
# S3 method for class 'glm'
odds.ratio(x, level = 0.95, ...)
# S3 method for class 'multinom'
odds.ratio(x, level = 0.95, ...)
# S3 method for class 'factor'
odds.ratio(x, fac, level = 0.95, ...)
# S3 method for class 'table'
odds.ratio(x, level = 0.95, ...)
# S3 method for class 'matrix'
odds.ratio(x, level = 0.95, ...)
# S3 method for class 'numeric'
odds.ratio(x, y, level = 0.95, ...)
# S3 method for class 'odds.ratio'
print(x, signif.stars = TRUE, ...)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