Skip to content

Commit

Permalink
Add logoddsratio-functions (#569)
Browse files Browse the repository at this point in the history
* Add logoddsratio-functions

* news, version bump

* fix lints

* Apply automatic changes

* kill convert_ aliases

* add missing prob-change functions

* fix

* lint and spell check

[skip ci]

---------

Co-authored-by: strengejacke <[email protected]>
Co-authored-by: Mattan S. Ben-Shachar <[email protected]>
Co-authored-by: Mattan S. Ben-Shachar <[email protected]>
  • Loading branch information
4 people authored Mar 10, 2023
1 parent 585f7c1 commit 66341ee
Show file tree
Hide file tree
Showing 13 changed files with 369 additions and 173 deletions.
14 changes: 12 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export(F_to_f2)
export(F_to_omega2)
export(F_to_r)
export(arr)
export(arr_to_logoddsratio)
export(arr_to_nnt)
export(arr_to_oddsratio)
export(arr_to_riskratio)
Expand All @@ -88,8 +89,6 @@ export(common_language)
export(convert_d_to_common_language)
export(convert_d_to_oddsratio)
export(convert_d_to_r)
export(convert_logoddsratio_to_d)
export(convert_logoddsratio_to_r)
export(convert_odds_to_probs)
export(convert_oddsratio_to_d)
export(convert_oddsratio_to_r)
Expand All @@ -101,6 +100,7 @@ export(cov_pooled)
export(cramers_v)
export(d_to_cles)
export(d_to_common_language)
export(d_to_logoddsratio)
export(d_to_oddsratio)
export(d_to_overlap)
export(d_to_p_superiority)
Expand Down Expand Up @@ -165,18 +165,25 @@ export(interpret_vif)
export(is.rules)
export(is_effectsize_name)
export(kendalls_w)
export(logoddsratio_to_arr)
export(logoddsratio_to_d)
export(logoddsratio_to_nnt)
export(logoddsratio_to_r)
export(logoddsratio_to_riskratio)
export(mad_pooled)
export(mahalanobis_d)
export(means_ratio)
export(nnt)
export(nnt_to_arr)
export(nnt_to_logoddsratio)
export(nnt_to_oddsratio)
export(nnt_to_riskratio)
export(normalized_chi)
export(odds_to_probs)
export(oddsratio)
export(oddsratio_to_arr)
export(oddsratio_to_d)
export(oddsratio_to_nnt)
export(oddsratio_to_r)
export(oddsratio_to_riskratio)
export(omega_squared)
Expand All @@ -190,6 +197,7 @@ export(print_md)
export(probs_to_odds)
export(r2_semipartial)
export(r_to_d)
export(r_to_logoddsratio)
export(r_to_oddsratio)
export(rank_biserial)
export(rank_epsilon_squared)
Expand All @@ -201,6 +209,8 @@ export(rb_to_vda)
export(rb_to_wmw_odds)
export(riskratio)
export(riskratio_to_arr)
export(riskratio_to_logoddsratio)
export(riskratio_to_nnt)
export(riskratio_to_oddsratio)
export(rules)
export(sd_pooled)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

- `arr()` and `nnt()` for Absolute Risk Reduction or Number Needed to Treat.
- `oddsratio_to_arr()`, `riskratio_to_arr()`, `nnt_to_arr()` and their inverses.
- `logoddsratio_to_*()` and `*_to_logoddsratio()` have been added as convenient shortcuts for `oddsratio_to_*(log = TRUE)` and `*_to_oddsratio(log = TRUE)`.
- Added all missing functions to convert between (log) OR, RR, ARR, and NNT.

## Changes

- `fei()` gives a more informative error method for invalid table inputs (#566).
- `convert_*()` aliases are deprecated.

## Breaking Changes

- `*_to_riskratio()` and `riskratio_to_*()` argument `log` not longer converts RR to/from log(RR).

## Bug fixes

Expand Down
64 changes: 16 additions & 48 deletions R/convert_between_d_to_r.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#' Enables a conversion between different indices of effect size, such as
#' standardized difference (Cohen's d), (point-biserial) correlation r or (log) odds ratios.
#'
#' @param d Standardized difference value (Cohen's d).
#' @param r Correlation coefficient r.
#' @param d,r,OR,logOR Standardized difference value (Cohen's d), correlation
#' coefficient (r), Odds ratio, or logged Odds ratio.
#' @param n1,n2 Group sample sizes. If either is missing, groups are assumed to be of equal size.
#' @param OR *Odds ratio* values in vector or data frame.
#' @param log Take in or output the log of the ratio (such as in logistic models).
#' @param log Take in or output the log of the ratio (such as in logistic models),
#' e.g. when the desired input or output are log odds ratios instead odds ratios.
#' @param ... Arguments passed to or from other methods.
#'
#' @family convert between effect sizes
Expand Down Expand Up @@ -54,37 +54,21 @@
#' methods, 8(4), 448.
#'
#' @export
#' @aliases convert_d_to_r
d_to_r <- function(d, n1, n2, ...) {
h <- .get_rd_h(n1, n2)
d / (sqrt(d^2 + h))
}

#' @export
convert_d_to_r <- d_to_r






#' @rdname d_to_r
#' @aliases convert_r_to_d
#' @export
r_to_d <- function(r, n1, n2, ...) {
h <- .get_rd_h(n1, n2)
sqrt(h) * r / sqrt(1 - r^2)
}

#' @export
convert_r_to_d <- r_to_d



# OR - d ----------------------------------------------------------------

#' @rdname d_to_r
#' @aliases convert_oddsratio_to_d
#' @export
oddsratio_to_d <- function(OR, log = FALSE, ...) {
if (log) {
Expand All @@ -96,25 +80,13 @@ oddsratio_to_d <- function(OR, log = FALSE, ...) {
log_OR * (sqrt(3) / pi)
}

#' @export
convert_oddsratio_to_d <- oddsratio_to_d



#' @rdname d_to_r
#' @aliases convert_logoddsratio_to_d
#' @export
logoddsratio_to_d <- function(OR, log = TRUE, ...) {
oddsratio_to_d(OR, log = log, ...)
logoddsratio_to_d <- function(logOR, log = TRUE, ...) {
oddsratio_to_d(logOR, log = log, ...)
}

#' @export
convert_logoddsratio_to_d <- logoddsratio_to_d



#' @rdname d_to_r
#' @aliases convert_d_to_oddsratio
#' @export
d_to_oddsratio <- function(d, log = FALSE, ...) {
log_OR <- d * pi / sqrt(3)
Expand All @@ -126,45 +98,41 @@ d_to_oddsratio <- function(d, log = FALSE, ...) {
}
}

#' @rdname d_to_r
#' @export
convert_d_to_oddsratio <- d_to_oddsratio
d_to_logoddsratio <- function(d, log = TRUE, ...) {
d_to_oddsratio(d, log = log, ...)
}




# OR - r ----------------------------------------------------------------

#' @rdname d_to_r
#' @aliases convert_oddsratio_to_r
#' @export
oddsratio_to_r <- function(OR, n1, n2, log = FALSE, ...) {
d_to_r(oddsratio_to_d(OR, log = log), n1, n2)
}

#' @export
convert_oddsratio_to_r <- oddsratio_to_r

#' @rdname d_to_r
#' @aliases convert_logoddsratio_to_r
#' @export
logoddsratio_to_r <- function(OR, log = TRUE, ...) {
oddsratio_to_r(OR, log = log, ...)
logoddsratio_to_r <- function(logOR, log = TRUE, ...) {
oddsratio_to_r(logOR, log = log, ...)
}

#' @export
convert_logoddsratio_to_r <- logoddsratio_to_r



#' @rdname d_to_r
#' @aliases convert_r_to_oddsratio
#' @export
r_to_oddsratio <- function(r, n1, n2, log = FALSE, ...) {
d_to_oddsratio(r_to_d(r), log = log, n1, n2)
}

#' @rdname d_to_r
#' @export
convert_r_to_oddsratio <- r_to_oddsratio
r_to_logoddsratio <- function(r, n1, n2, log = TRUE, ...) {
r_to_oddsratio(r, n1, n2, log = log)
}


# Utils -------------------------------------------------------------------
Expand Down
9 changes: 0 additions & 9 deletions R/convert_between_odds_to_probs.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@
#' probs_to_odds(0.95)
#' probs_to_odds(0.95, log = TRUE)
#' @export
#' @aliases convert_odds_to_probs
odds_to_probs <- function(odds, log = FALSE, ...) {
UseMethod("odds_to_probs")
}

#' @export
convert_odds_to_probs <- odds_to_probs


#' @export
odds_to_probs.numeric <- function(odds, log = FALSE, ...) {
if (log) {
Expand All @@ -48,15 +43,11 @@ odds_to_probs.data.frame <- function(odds, log = FALSE, select = NULL, exclude =


#' @rdname odds_to_probs
#' @aliases convert_probs_to_odds
#' @export
probs_to_odds <- function(probs, log = FALSE, ...) {
UseMethod("probs_to_odds")
}

#' @export
convert_probs_to_odds <- probs_to_odds

#' @export
probs_to_odds.numeric <- function(probs, log = FALSE, ...) {
if (log) {
Expand Down
Loading

0 comments on commit 66341ee

Please sign in to comment.