easystats / effectsize

:dragon: Compute and work with indices of effect size and standardized parameters
https://easystats.github.io/effectsize/
Other
331 stars 22 forks source link

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

Open bwiernik opened 1 year ago

bwiernik commented 1 year ago
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
}
mattansb commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

I think the verbosity can be reduced (:

strengejacke commented 1 year ago

Do any functions start with convert_*?

strengejacke commented 1 year ago

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

strengejacke commented 1 year ago

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 commented 1 year ago

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

1. Between prob-change metrics

Do we need??

2. Change to Probs

@strengejacke @bwiernik

Also

@strengejacke started on some of these in #569