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

NEW prob change to prob functions #575

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions R/convert_between_riskchange_ro_probs.R
Original file line number Diff line number Diff line change
@@ -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 ---------------------------------------------------------------------
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ reference:
- oddsratio_to_riskratio
- d_to_u3
- eta2_to_f2
- oddsratio_to_odds
- odds_to_probs

- title: "Interpretation"
Expand Down
24 changes: 24 additions & 0 deletions man/oddsratio_to_odds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.