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

convert_oddsratio_to_riskratio() / convert_oddsratio_to_riskdiff() and vice versa #568

Open
bwiernik opened this issue Mar 6, 2023 · 7 comments · May be fixed by #575
Open

convert_oddsratio_to_riskratio() / convert_oddsratio_to_riskdiff() and vice versa #568

bwiernik opened this issue Mar 6, 2023 · 7 comments · May be fixed by #575

Comments

@bwiernik
Copy link
Contributor

bwiernik commented Mar 6, 2023

convert_oddsratio_to_odds <- function(OR, log = FALSE, base_rate = NULL, base_odds = NULL) {
  if (is.null(base_odds)) {
    if (is.null(base_rate)) {
      insight::format_error("Either `base_rate` or `base_odds` must be supplied.")
    }
    base_odds <- convert_probs_to_odds(base_rate, log = log)
  }
  compare_odds <- ifelse(isTRUE(log), OR + base_odds, OR * base_odds)
  return(compare_odds)
}

convert_oddsratio_to_probs <- function(OR, log = FALSE, base_rate = NULL, base_odds = NULL) {
  compare_odds <- convert_oddsratio_to_odds(OR = OR, log = log, base_rate = base_rate, base_odds = base_odds)
  compare_rate <- convert_odds_to_probs(compare_odds, log = log)
  return(compare_rate)
}

convert_oddsratio_to_riskratio <- function(OR, log = FALSE, base_rate = NULL, base_odds = NULL) {
  compare_rate <- convert_oddsratio_to_probs(OR = OR, log = log, base_rate = base_rate, base_odds = base_odds)
  if (is.null(base_rate)) {
    base_rate <- convert_odds_to_probs(base_odds, log = log)
  }
  riskratio <- compare_rate / base_rate
}

convert_oddsratio_to_riskdiff <- function(OR, log = FALSE, base_rate = NULL, base_odds = NULL) {
  compare_rate <- convert_oddsratio_to_probs(OR = OR, log = log, base_rate = base_rate, base_odds = base_odds)
  if (is.null(base_rate)) {
    base_rate <- convert_odds_to_probs(base_odds, log = log)
  }
  riskratio <- compare_rate - base_rate
}
@bwiernik bwiernik changed the title convert_oddsratio_to_riskratio() / convert_oddsratio_to_riskdifference() and vice versa convert_oddsratio_to_riskratio() / convert_oddsratio_to_riskdiff() and vice versa Mar 6, 2023
@mattansb
Copy link
Member

mattansb commented Mar 6, 2023

We have the OR to RR one here https://easystats.github.io/effectsize/reference/oddsratio_to_riskratio.html

Should we have all possible pairings?

@bwiernik
Copy link
Contributor Author

bwiernik commented Mar 6, 2023

Oh, then I guess the issue is that some of our functions start with convert and some don't. That's confusing and we should consider standardizing

@mattansb
Copy link
Member

mattansb commented Mar 6, 2023

I think the verbosity can be reduced (:

@strengejacke
Copy link
Member

Do any functions start with convert_*?

@strengejacke
Copy link
Member

Just saw, that seem to be aliases, right? Maybe we can deprecate those?

@strengejacke
Copy link
Member

But for convenience reasons, we could probably add those conversion functions, too? And also add log-odds functions that call the oddsratio-functions with log = TRUE? Some colleagues were using the effectsize package and "complaining" that you can only convert to/from odds ratio, but not log-odds. They missed the log argument, which also isn't clearly documented (people need "keywords" like "log-odds" or similar).

@mattansb
Copy link
Member

mattansb commented Mar 9, 2023

Okay, so I think we need two sets of functions:

1. Between prob-change metrics

  • OR to RR (oddsratio_to_riskratio)
  • OR to ARR (oddsratio_to_arr)
  • OR to NNT
  • logOR to RR
  • logOR to ARR
  • logOR to NNT
  • RR to OR (riskratio_to_oddsratio)
  • RR to logOR
  • RR to ARR (riskratio_to_arr)
  • RR to NNT
  • ARR to OR (arr_to_oddsratio)
  • ARR to logOR
  • ARR to RR (arr_to_riskratio)
  • ARR to NNT (arr_to_nnt)
  • NNT to OR
  • NNT to logOR
  • NNT to RR
  • NNT to ARR (nnt_to_arr)

Do we need??

  • OR to logOR
  • logOR to OR

2. Change to Probs

  • OR to prob
  • logOR to prob
  • RR to prob
  • ARR to prob
  • NNT to prob

@strengejacke @bwiernik

  • Do we also want the inverse of these? (e.g., prob to OR)
  • Do we also want conversion to odds? (e.g., NNT to odds)

Also

@strengejacke started on some of these in #569

@mattansb mattansb linked a pull request Mar 10, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants