Description Usage Arguments Value See Also Examples
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
.
1 2 3 4 5 6 7 8 9 |
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 |
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 |
or_glm()
plot_gam()
insert_or()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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
)
|
Loading required package: nlme
This is mgcv 1.8-28. For overview type 'help("mgcv-package")'.
predictor value1 value2 oddsratio CI_low (2.5%) CI_high (97.5%)
1 x2 0.099 0.198 23.32353 23.30424 23.34283
predictor value1 value2 oddsratio CI_low (2.5%) CI_high (97.5%)
1 x4 B D 0.4744264 0.4976375 0.452298
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.