or_gam {oddsratio} | R Documentation |
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 |
percentage |
Percentage number to split the predictor distribution into.
A value of 10 would split the predictor distribution by 10\
Only needed if |
slice |
Whether to calculate odds ratios for fixed increment steps over
the whole predictor distribution. See |
ci |
Currently fixed to 95\ Currently supported functions: mgcv::gam, mgcv::gamm,
gam::gam. For mgcv::gamm, the |
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 |
perc2 |
Percentage value of |
oddsratio |
Calculated odds ratio(s) |
ci_low |
Lower |
ci_high |
Higher |
See Also
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)
)
## 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
)