or_glm: Calculate Odds Ratios of Generalized Linear (Mixed) Models

Description Usage Arguments Details Value See Also Examples

View source: R/or_glm.R

Description

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

Usage

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

Arguments

data

The data used for model fitting.

model

A fitted GLM(M).

incr

Increment values of each predictor given in a named list.

ci

Which confidence interval to calculate. Must be between 0 and 1. Default to 0.95

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

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)

See Also

or_gam()

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
25
26
27
28
29
30
## 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))

# Calculate OR and change the confidence interval level
or_glm(
  data = data_glm, model = fit_glm,
  incr = list(gre = 380, gpa = 5), ci = .70
)

## Example with MASS:glmmPQL()
# load data
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))

Example output

  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
  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
  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
Warning message:
No confident interval calculation possible for 'glmmPQL' models. 

oddsratio documentation built on July 1, 2020, 10:22 p.m.