-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
oddsratio_to_riskratio
could accept glm
objects
#368
Comments
How do you extract |
I would say set the other predictors to the model to their typical values, ala emmeans |
See https://github.com/strengejacke/sjstats/blob/82c055cbf87340832d92c56abfb4768c4bbf1503/R/odds_to_rr.R |
Looking at my code, P0 is the mean of the dependent variable (when converted to 0/1) |
@bwiernik Would it make sense to allow users to pass a (single) |
Yeah, that’s makes sense. |
m <- glm(am ~ factor(cyl), data = mtcars,
family = binomial())
parameters::model_parameters(m, exponentiate = TRUE)
#> Parameter | Odds Ratio | SE | 95% CI | z | p
#> ---------------------------------------------------------------
#> (Intercept) | 2.67 | 1.81 | [0.77, 12.17] | 1.45 | 0.147
#> cyl [6] | 0.28 | 0.29 | [0.03, 1.99] | -1.24 | 0.214
#> cyl [8] | 0.06 | 0.06 | [0.01, 0.39] | -2.72 | 0.007
#>
#> Showing profiled confidence intervals.
effectsize::oddsratio_to_riskratio(m)
#> Warning in oddsratio_to_riskratio.glm(m): 'p0' not provided.RR is relative to
#> the intercept (p0 = 0.73) - make sure your intercept is meaningful.
#> Parameter | Risk Ratio | 95% CI
#> ---------------------------------------
#> (Intercept) | 0.73 |
#> cyl [6] | 0.59 | [0.11, 1.16]
#> cyl [8] | 0.20 | [0.02, 0.70]
#>
#> Showing profiled confidence intervals.
effectsize::oddsratio_to_riskratio(m, p0 = 0.05)
#> Parameter | Risk Ratio | 95% CI
#> -------------------------------------
#> (p0) | 0.05 |
#> cyl [6] | 0.29 | [0.03, 1.90]
#> cyl [8] | 0.07 | [0.01, 0.41]
#>
#> Showing profiled confidence intervals. Created on 2021-08-19 by the reprex package (v2.0.1) |
I just noticed that you pushed a pull-request on this 19 days ago pull369. I updated my
My last very minor concern is that how could we generate the p-value on this RR estimate? Could someone give me a quick hint? Many thanks! |
The p value for the original coefficient applies. Edit: to clarify, what I mean is my recommendation is that you should perform inference on the model coefficients and use the RR descriptively to interpret the result (similar to using standardized regression coefficients) |
Thank you very much! I suppose it means that p-values from: I will go ahead and do more literature. |
Both the risk ratio and odds ratio are just transformations of the model coefficient. You should focus your null-or-not inference for a predictor on the model coefficient. For interpreting the magnitude of the risk ratio, you should focus on its confidence interval. But note also that you should ensure that you are making appropriate comparisons for the risk ratio. This current function fixes all predictors other than the focal one to zero. Is that appropriate or meaningful? |
Also, if you only have categorical predictors, you can consider using a log-link (instead of the logit-link), as this will produce the log of the RR: m1 <- glm(am ~ factor(cyl), data = mtcars,
family = binomial("logit"))
m2 <- glm(am ~ factor(cyl), data = mtcars,
family = binomial("log"))
effectsize::oddsratio_to_riskratio(m1)
#> Warning in oddsratio_to_riskratio.glm(m1): 'p0' not provided.RR is relative to
#> the intercept (p0 = 0.73) - make sure your intercept is meaningful.
#> Warning in oddsratio_to_riskratio.glm(m1): CIs are back-transformed from the
#> logit scale.
#> Parameter | Risk Ratio | 95% CI
#> ---------------------------------------
#> (Intercept) | 0.73 |
#> cyl [6] | 0.59 | [0.11, 1.16]
#> cyl [8] | 0.20 | [0.02, 0.70]
#>
#> Showing profiled confidence intervals.
parameters::model_parameters(m2, exponentiate = TRUE)
#> Parameter | Risk Ratio | SE | 95% CI | z | p
#> --------------------------------------------------------------
#> (Intercept) | 0.73 | 0.13 | [0.44, 0.92] | -1.72 | 0.085
#> cyl [6] | 0.59 | 0.28 | [0.17, 1.31] | -1.12 | 0.264
#> cyl [8] | 0.20 | 0.13 | [0.03, 0.59] | -2.39 | 0.017
#>
#> Showing profiled confidence intervals. Created on 2021-09-08 by the reprex package (v2.0.1) |
Thank you so much for all the help! Sorry I have been forgetting to express my appreciation until I finish running all logistic regression models. This is really an inspiring R package. |
See strengejacke/sjstats#106
Could we add glm-support in a way that it automatically pulls the coefficients from a model object and returns the risk ratios?
The text was updated successfully, but these errors were encountered: