Skip to content
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

Closed
strengejacke opened this issue Aug 19, 2021 · 13 comments · Fixed by #369
Closed

oddsratio_to_riskratio could accept glm objects #368

strengejacke opened this issue Aug 19, 2021 · 13 comments · Fixed by #369
Labels
enhancement 🔥 New feature or request

Comments

@strengejacke
Copy link
Member

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?

@strengejacke strengejacke added the enhancement 🔥 New feature or request label Aug 19, 2021
@mattansb
Copy link
Member

How do you extract p0? From the intercept?

@bwiernik
Copy link
Contributor

I would say set the other predictors to the model to their typical values, ala emmeans

@strengejacke
Copy link
Member Author

@strengejacke
Copy link
Member Author

strengejacke commented Aug 19, 2021

Looking at my code, P0 is the mean of the dependent variable (when converted to 0/1)
(not sure if this is correct, or if it's better using the intercept, or if this is always the same)

@mattansb
Copy link
Member

@bwiernik Would it make sense to allow users to pass a (single) p0?
If not provided, we can compare to the intercept with a warning "RR is relative to the intercept - make sure your intercept is meaningful".

@bwiernik
Copy link
Contributor

Yeah, that’s makes sense.

@mattansb
Copy link
Member

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)

@AndyWangSFU
Copy link

I just noticed that you pushed a pull-request on this 19 days ago pull369. I updated my effectsize package and it works! Thank you very much!

> effectsize::oddsratio_to_riskratio(h_glm)

> Parameter          | Risk Ratio |       95% CI
> ----------------------------------------------
> (Intercept)        |       0.39 |             
> group x            |       1.80 | [1.21, 2.24]

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!

@bwiernik
Copy link
Contributor

bwiernik commented Sep 7, 2021

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)

@AndyWangSFU
Copy link

The p value for the original coefficient applies.

Thank you very much! I suppose it means that p-values from: logistic regression coefficient estimation = odds ratio =? relative risk. The first equal sign makes sense but the second one seems a little counter-intuitive (sorry I am new to this).

I will go ahead and do more literature.

@bwiernik
Copy link
Contributor

bwiernik commented Sep 7, 2021

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?

@mattansb
Copy link
Member

mattansb commented Sep 8, 2021

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)

@AndyWangSFU
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🔥 New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants