Learn R Programming

oddsratio (version 2.0.1)

or_gam: Calculate Odds Ratios of Generalized Additive (Mixed) Models

Description

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.

Usage

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

Arguments

data

The data used for model fitting.

model

A fitted GAM(M).

pred

Predictor name for which to calculate the odds ratio.

values

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

Percentage number to split the predictor distribution into. A value of 10 would split the predictor distribution by 10\ Only needed if slice = TRUE.

slice

Whether to calculate odds ratios for fixed increment steps over the whole predictor distribution. See percentage for setting the increment values.

ci

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

See Also

or_glm() plot_gam() insert_or()

Examples

Run this code
# NOT RUN {
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)
)

## Calculate OR for change of indicator variable
or_gam(
  data = data_gam, model = fit_gam, pred = "x4",
  values = c("B", "D")
)

## Calculate ORs for percentage increments of predictor distribution
## (here: 20%)
or_gam(
  data = data_gam, model = fit_gam, pred = "x2",
  percentage = 20, slice = TRUE
)
# }

Run the code above in your browser using DataLab