This function calculates odds ratio(s) for specific increment steps of GLMs.

or_glm(data, model, incr, ci = 0.95)

## Arguments

data The data used for model fitting. A fitted GLM(M). Increment values of each predictor given in a named list. Which confidence interval to calculate. Must be between 0 and 1. Default to 0.95

## Value

A data frame with five columns:

predictor

Predictor name(s)

oddsratio

Calculated odds ratio(s)

ci_low

Lower confident interval of odds ratio

ci_high

Higher confident interval of odds ratio

increment

Increment of the predictor(s)

## Details

ci_low and ci_high are only calculated for GLM models because MASS::glmmPQL() does not return confident intervals due to its penalizing behavior.

Currently supported functions: stats::glm,MASS::glmmPQL

or_gam()

## Examples

## Example with glm()
library(oddsratio)
# load data (source: http://www.ats.ucla.edu/stat/r/dae/logit.htm) and
# fit model
fit_glm <- glm(admit ~ gre + gpa + rank,
data = data_glm,
family = "binomial"
) # fit model

# Calculate OR for specific increment step of continuous variable
or_glm(data = data_glm, model = fit_glm, incr = list(gre = 380, gpa = 5))
#>   predictor oddsratio ci_low (2.5) ci_high (97.5)          increment
#> 1       gre     2.364        1.054          5.396                380
#> 2       gpa    55.712        2.229       1511.282                  5
#> 3     rank2     0.509        0.272          0.945 Indicator variable
#> 4     rank3     0.262        0.132          0.512 Indicator variable
#> 5     rank4     0.212        0.091          0.471 Indicator variable
# Calculate OR and change the confidence interval level
or_glm(
data = data_glm, model = fit_glm,
incr = list(gre = 380, gpa = 5), ci = .70
)
#>   predictor oddsratio ci_low (15) ci_high (85)          increment
#> 1       gre     2.364       1.540        3.647                380
#> 2       gpa    55.712      10.084      314.933                  5
#> 3     rank2     0.509       0.366        0.706 Indicator variable
#> 4     rank3     0.262       0.183        0.374 Indicator variable
#> 5     rank4     0.212       0.136        0.325 Indicator variable
## Example with MASS:glmmPQL()
library(MASS)
data(bacteria)
fit_glmmPQL <- glmmPQL(y ~ trt + week,
random = ~ 1 | ID,
family = binomial, data = bacteria,
verbose = FALSE
)

# Apply function
or_glm(data = bacteria, model = fit_glmmPQL, incr = list(week = 5))
#> Warning: No confident interval calculation possible for 'glmmPQL' models.#>   predictor oddsratio ci_low ci_high          increment
#> 1   trtdrug     0.296     NA      NA Indicator variable
#> 2  trtdrug+     0.454     NA      NA Indicator variable
#> 3      week     0.485     NA      NA                  5