Skip to content

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

Closed
@bwiernik

Description

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
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions