This function calculates odds ratio(s) for specific increment steps of GAM(M) models. Odds ratios can also be calculated for continuous (percentage) increment steps across the whole predictor distribution using slice = TRUE.

or_gam(
data = NULL,
model = NULL,
pred = NULL,
values = NULL,
percentage = NULL,
slice = FALSE,
ci = NULL
)

## Arguments

data The data used for model fitting. A fitted GAM(M). Predictor name for which to calculate the odds ratio. Numeric vector of length two. Predictor values to estimate odds ratio from. Function is written to use the first provided value as the "lower" one, i.e. calculating the odds ratio 'from value1 to value2'. Only used if slice = FALSE. Percentage number to split the predictor distribution into. A value of 10 would split the predictor distribution by 10\ Only needed if slice = TRUE. Whether to calculate odds ratios for fixed increment steps over the whole predictor distribution. See percentage for setting the increment values. Currently fixed to 95\ Currently supported functions: mgcv::gam, mgcv::gamm, gam::gam. For mgcv::gamm, the model input of or_gam needs to be the gam output (e.g. fit_gam\$gam).

## Value

A data.frame with (up to) eight columns. perc1 and perc2 are only returned if slice = TRUE:

predictor

Predictor name

value1

First value of odds ratio calculation

value2

Second value of odds ratio calculation

perc1

Percentage value of value1

perc2

Percentage value of value2

oddsratio

Calculated odds ratio(s)

ci_low

Lower (2.5%) confident interval of odds ratio

ci_high

Higher (97.5%) confident interval of odds ratio

or_glm() plot_gam() insert_or()

## Examples

library(oddsratio)
library(mgcv)
fit_gam <- gam(y ~ s(x0) + s(I(x1^2)) + s(x2) +
offset(x3) + x4, data = data_gam) # fit model

# Calculate OR for specific increment step of continuous variable
or_gam(
data = data_gam, model = fit_gam, pred = "x2",
values = c(0.099, 0.198)
)
#>   predictor value1 value2 oddsratio CI_low (2.5%) CI_high (97.5%)
#> 1        x2  0.099  0.198  23.32353      23.30424        23.34283
## Calculate OR for change of indicator variable
or_gam(
data = data_gam, model = fit_gam, pred = "x4",
values = c("B", "D")
)
#>   predictor value1 value2 oddsratio CI_low (2.5%) CI_high (97.5%)
#> 1        x4      B      D 0.4744264     0.4976375        0.452298
## Calculate ORs for percentage increments of predictor distribution
## (here: 20%)
or_gam(
data = data_gam, model = fit_gam, pred = "x2",
percentage = 20, slice = TRUE
)
#>   predictor value1 value2 perc1 perc2 oddsratio CI_low (2.5%) CI_high (97.5%)
#> 1        x2  0.001  0.200     0    20   2510.77       1091.68         5774.53
#> 2        x2  0.200  0.400    20    40      0.03          0.03            0.03
#> 3        x2  0.400  0.599    40    60      0.58          0.56            0.60
#> 4        x2  0.599  0.799    60    80      0.06          0.06            0.06
#> 5        x2  0.799  0.998    80   100      0.41          0.75            0.22