I used the package questionr to calculate the odds ratios for a logistic regression model with two variables, var1 and var2. I used the code:
odds.ratio(mymodel, level=0.95)
This returned odds ratios with 95% CIs; however, I would like to report odds ratios for a 10-unit increase versus a 1-unit increase. Is there a package in r capable of doing this?
CodePudding user response:
If anyone else is searching for this in the future...just discovered the oddsratio package, which has the incr (increment) argument.
CodePudding user response:
The odds ratio (as reported in questionr
) shows you the odds of a positive outcome when the independent variable is 1, divided by the odds of a positive outcome when the independent variable is 0. However, by extension, when the independent variable is two, we can square the odds ratio to find the odds ratio of a two-point increase, and so on.
This means that you can raise the odds ratio (and its confidence intervals) to the power of 10 to get the odds ratio for a 10-point increase.
Let's demonstrate with a simple logistic regression:
set.seed(1)
iv <- sample(100)
dv <- rbinom(100, 1, iv/100)
df <- data.frame(dv, iv)
model <- glm(dv ~ iv, data = df, family = binomial)
model
#>
#> Call: glm(formula = dv ~ iv, family = binomial, data = df)
#>
#> Coefficients:
#> (Intercept) iv
#> -2.46465 0.04997
#>
#> Degrees of Freedom: 99 Total (i.e. Null); 98 Residual
#> Null Deviance: 138.6
#> Residual Deviance: 102.9 AIC: 106.9
Now we can see the odds ratio easily using questionr
:
questionr_or <- questionr::odds.ratio(model)
#> Waiting for profiling to be done...
questionr_or
#> OR 2.5 % 97.5 % p
#> (Intercept) 0.085039 0.025954 0.2354 9.833e-06 ***
#> iv 1.051241 1.032145 1.0741 7.070e-07 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
This shows us the odds ratio for a 1-point increase. If we want a 10-point increase, we just raise these coefficients by a power of 10:
questionr_or[2, 1:3]^10
#> OR 2.5 % 97.5 %
#> iv 1.648257 1.372168 2.043965
You will see that this gives the same result as the incr
argument being set to 10 in the or_glm
function from oddsratio
:
oddsratio::or_glm(df, model, incr = list(iv = 10))
#> predictor oddsratio ci_low (2.5) ci_high (97.5) increment
#> 1 iv 1.648 1.372 2.044 10
Created on 2021-10-21 by the reprex package (v2.0.0)