-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
|
||
#' @title | ||
#' Calculate an odds ratio (OR) from a risk ratio (RR) | ||
#' | ||
#' @description | ||
#' Calculate an odds ratio (OR) from a risk ratio (RR) and the outcome prevalence | ||
#' in the unexposed (referent) group. | ||
#' | ||
#' | ||
#' @param .riskratio | ||
#' numeric: risk ratio. | ||
#' | ||
#' @param .baseline | ||
#' numeric: outcome prevalence in unexposed (referent) group. | ||
#' | ||
#' @return | ||
#' An odds ratio. | ||
#' | ||
#' @export | ||
|
||
|
||
risk_ratio_to_odds_ratio <- function(.riskratio = NULL, .baseline = NULL) { | ||
|
||
if ( !hasArg(.riskratio) | !is.numeric(.riskratio) ) { | ||
cli::cli_abort(c( | ||
"{.var .riskratio} must be a numeric vector.", | ||
"x" = "You have supplied a {.cls {class(.riskratio)}} vector." | ||
)) | ||
} | ||
|
||
if ( !hasArg(.baseline) | !is.numeric(.baseline) ) { | ||
cli::cli_abort(c( | ||
"{.var .baseline} must be a numeric vector.", | ||
"x" = "You have supplied a {.cls {class(.baseline)}} vector." | ||
)) | ||
} | ||
|
||
if ( .baseline < 0 | .baseline > 1) { | ||
cli::cli_abort(c( | ||
"{.var .baseline} must be probability between [0, 1].", | ||
"x" = "You have supplied a value less than 0 or greater than 1." | ||
)) | ||
} | ||
|
||
if ( .baseline == 0 | .baseline == 1 ) { | ||
cli::cli_warn(c( | ||
"{.var .baseline} should not be 0 or 1, with rare exception.", | ||
"i" = "You have supplied a {.var .baseline} value of 0 or 1.", | ||
"i" = "Run {.run help(risk_ratio_to_odds_ratio)} for more details." | ||
|
||
)) | ||
} | ||
|
||
.oddsratio <- .riskratio * ( 1 - .baseline ) / ( 1 - .riskratio * .baseline) | ||
|
||
return(.oddsratio) | ||
|
||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6fa0bdf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial fix for #17