diff --git a/NAMESPACE b/NAMESPACE index e3911363..30a76c8a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -185,6 +185,8 @@ export(oddsratio) export(oddsratio_to_arr) export(oddsratio_to_d) export(oddsratio_to_nnt) +export(oddsratio_to_odds) +export(oddsratio_to_probs) export(oddsratio_to_r) export(oddsratio_to_riskratio) export(omega_squared) diff --git a/R/convert_between_riskchange_ro_probs.R b/R/convert_between_riskchange_ro_probs.R new file mode 100644 index 00000000..bcbc8250 --- /dev/null +++ b/R/convert_between_riskchange_ro_probs.R @@ -0,0 +1,47 @@ +#' Convert Between Metrics of Change in Probabilities and Probabilities +#' +#' +#' @param OR Odds ratio `odds(p1)/odds(p0)` +#' @param p0,Odds0 Base rate or odds. Exactly one must be specified. +#' @param log If `TRUE`, inputs `OR` and `Odds0` are taken to be `logOR` and +#' `logOdds0`, and outputted odds are `logOdds1`. +#' @param ... Ignored +#' +#' @export +oddsratio_to_odds <- function(OR, p0, Odds0, log = FALSE, ...) { + if ((missing(p0) && missing(Odds0)) || (!missing(p0) && !missing(Odds0))) { + insight::format_error("Exactly one of `p0` or `Odds0` must be supplied.") + } + + if (missing(Odds0)) { + Odds0 <- probs_to_odds(Odds0, log = TRUE) + } else if (!log) { + Odds0 <- log(Odds0) + } + + Odds1 <- OR + Odds0 + + if (!log) Odds1 <- exp(Odds1) + + return(Odds1) +} + +#' @export +#' @rdname oddsratio_to_odds +oddsratio_to_probs <- function(OR, p0, Odds0, log = FALSE, ...) { + Odds1 <- oddsratio_to_odds(OR, p0, Odds0, log = log) + if (log) Odds1 <- exp(Odds1) + odds_to_probs(Odds1) +} + + +# LogOR ------------------------------------------------------------------- + + +# RR ---------------------------------------------------------------------- + + +# ARR --------------------------------------------------------------------- + + +# NNT --------------------------------------------------------------------- diff --git a/_pkgdown.yml b/_pkgdown.yml index ce36fdfc..839f1cbd 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -69,6 +69,7 @@ reference: - oddsratio_to_riskratio - d_to_u3 - eta2_to_f2 + - oddsratio_to_odds - odds_to_probs - title: "Interpretation" diff --git a/man/oddsratio_to_odds.Rd b/man/oddsratio_to_odds.Rd new file mode 100644 index 00000000..19641405 --- /dev/null +++ b/man/oddsratio_to_odds.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/convert_between_riskchange_ro_probs.R +\name{oddsratio_to_odds} +\alias{oddsratio_to_odds} +\alias{oddsratio_to_probs} +\title{Convert Between Metrics of Change in Probabilities and Probabilities} +\usage{ +oddsratio_to_odds(OR, p0, Odds0, log = FALSE, ...) + +oddsratio_to_probs(OR, p0, Odds0, log = FALSE, ...) +} +\arguments{ +\item{OR}{Odds ratio \code{odds(p1)/odds(p0)}} + +\item{p0, Odds0}{Base rate or odds. Exactly one must be specified.} + +\item{log}{If \code{TRUE}, inputs \code{OR} and \code{Odds0} are taken to be \code{logOR} and +\code{logOdds0}, and outputted odds are \code{logOdds1}.} + +\item{...}{Ignored} +} +\description{ +Convert Between Metrics of Change in Probabilities and Probabilities +}