Skip to content

Commit

Permalink
Add adjust_sodium_for_glucose. Update some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
LS31 committed Nov 11, 2020
1 parent df7a78e commit 7c451d8
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 25 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export("%>%")
export(adjust_calcium_for_albumin)
export(adjust_sodium_for_glucose)
export(calculate_bmi)
export(calculate_pulse_pressure)
export(calculate_qtc)
Expand Down
2 changes: 1 addition & 1 deletion R/bmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ calculate_bmi <- function(weight, height) {
#' @export
#' @seealso [units::set_units()], [units::drop_units()]
estimate_ibw <- function(height, is_female) {
assertthat::assert_that(assertthat::is.number(height) | is.na(height))
assertthat::assert_that(assertthat::is.flag(is_female))
assertthat::assert_that(assertthat::is.number(height))

if(is_female) {
(45.5 + 0.9 * (height - 152)) %>%
Expand Down
12 changes: 8 additions & 4 deletions R/bsa.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ estimate_bsa <- function(weight, height, method = "Monsteller") {
#' @describeIn estimate_bsa Estimate the body surface area (BSA) according to Monsteller.
#' @noRd
estimate_bsa_monsteller <- function(weight, height) {
assertthat::assert_that(assertthat::is.number(weight))
assertthat::assert_that(assertthat::is.number(height))
assertthat::assert_that(assertthat::is.number(weight) |
is.na(weight))
assertthat::assert_that(assertthat::is.number(height) |
is.na(height))
((weight * height / 3600) ^ (0.5)) %>%
units::set_units("m-2", mode = "standard")
}

#' @describeIn estimate_bsa Estimate the body surface area (BSA) according to Du Bois
#' @noRd
estimate_bsa_du_bois <- function(weight, height) {
assertthat::assert_that(assertthat::is.number(weight))
assertthat::assert_that(assertthat::is.number(height))
assertthat::assert_that(assertthat::is.number(weight) |
is.na(weight))
assertthat::assert_that(assertthat::is.number(height) |
is.na(height))
(0.007184 * (weight ^ 0.425) * (height ^ 0.725)) %>%
units::set_units("m-2", mode = "standard")
}
45 changes: 45 additions & 0 deletions R/electrolytes.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,48 @@ adjust_calcium_for_albumin <-
(calcium + 0.025 * (normal_albumin - albumin)) %>%
units::set_units("mmol1 l-1", mode = "standard")
}


#' Adjust sodium for hyperglycaemia
#'
#' Hyperglycaemia can lead to hypertonic hyponatriemia. Using observational
#' data, the following formula predicts sodium levels after correction of
#' glucose: \eqn{\text{Na}_{predicted} = \text{Na}_\text{measured} + \kappa
#' \times \frac{\text{glucose} - 5.6}{5.6}}, where \eqn{\kappa} is 1.6 when
#' derived from the publication by Katz and 2.4 when derived from more recent
#' work by Hillier (default).
#'
#' @references [Katz, M. A. Hyperglycemia-Induced Hyponatremia — Calculation of
#' Expected Serum Sodium Depression. N Engl J Med 289, 843–844
#' (1973).](https://doi.org/10.1056/NEJM197310182891607) and [Hillier, T. A.,
#' Abbott, R. D. & Barrett, E. J. Hyponatremia: evaluating the correction
#' factor for hyperglycemia. The American Journal of Medicine 106, 399–403
#' (1999).](https://doi.org/10.1016/s0002-9343(99)00055-8).
#'
#' @section Caveats: It's just a prediction, and the choice between both
#' formulae may result in quite different predictions.
#'
#' @param sodium Measured sodium level (mmol/l).
#' @param glucose Measured glucose level (mmol/l).
#' @param method Formula. Options are: "Hillier" (default), "Katz".
#' @return Glucose-adjusted sodium level (mmol/l).
#' @export
#' @seealso [units::set_units()], [units::drop_units()]
adjust_sodium_for_glucose <-
function(sodium, glucose, method = "Hillier") {
assertthat::assert_that(assertthat::is.number(sodium) |
is.na(sodium))
assertthat::assert_that(assertthat::is.number(glucose) |
is.na(glucose))
assertthat::assert_that(assertthat::is.string(method))

xkappa <- switch(
method,
"Hillier" = 2.4,
"Katz" = 1.6,
stop("Illegal value for argument method in adjust_sodium_for_glucose().")
)

(sodium + xkappa * ((glucose-5.6)/5.6)) %>%
units::set_units("mmol1 l-1", mode = "standard")
}
21 changes: 12 additions & 9 deletions R/renal_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
#' @export
#' @seealso [units::set_units()], [units::drop_units()]
estimate_gfr_cockcroft <- function(creatinine, age, is_female, weight) {
assertthat::assert_that(assertthat::is.number(creatinine))
assertthat::assert_that(assertthat::is.number(age))
assertthat::assert_that(assertthat::is.number(creatinine) |
is.na(creatinine))
assertthat::assert_that(assertthat::is.number(age) |
is.na(age))
assertthat::assert_that(assertthat::is.flag(is_female))
assertthat::assert_that(assertthat::is.number(weight))
assertthat::assert_that(assertthat::is.number(weight) |
is.na(weight))

egfr <- ((140 - age) * weight) / (0.81 * creatinine)

Expand Down Expand Up @@ -49,8 +52,8 @@ estimate_gfr_cockcroft <- function(creatinine, age, is_female, weight) {
#' @export
#' @seealso [units::set_units()], [units::drop_units()]
estimate_gfr_mdrd <- function(creatinine, age, is_female, is_african_american) {
assertthat::assert_that(assertthat::is.number(creatinine))
assertthat::assert_that(assertthat::is.number(age))
assertthat::assert_that(assertthat::is.number(creatinine) | is.na(creatinine))
assertthat::assert_that(assertthat::is.number(age) | is.na(age))
assertthat::assert_that(assertthat::is.flag(is_female))
assertthat::assert_that(assertthat::is.flag(is_african_american))

Expand Down Expand Up @@ -83,8 +86,8 @@ estimate_gfr_mdrd <- function(creatinine, age, is_female, is_african_american) {
#' @export
#' @seealso [units::set_units()], [units::drop_units()]
estimate_gfr_schwartz <- function(creatinine, height) {
assertthat::assert_that(assertthat::is.number(creatinine))
assertthat::assert_that(assertthat::is.number(height))
assertthat::assert_that(assertthat::is.number(creatinine) | is.na(creatinine))
assertthat::assert_that(assertthat::is.number(height) | is.na(height))
(36.2 * height) / creatinine %>%
units::set_units("ml1 min-1", mode = "standard")
}
Expand Down Expand Up @@ -121,8 +124,8 @@ estimate_gfr_schwartz <- function(creatinine, height) {
#' @export
#' @seealso [units::set_units()], [units::drop_units()]
estimate_gfr_ckdepi <- function(creatinine, age, is_female, is_african_american) {
assertthat::assert_that(assertthat::is.number(creatinine))
assertthat::assert_that(assertthat::is.number(age))
assertthat::assert_that(assertthat::is.number(creatinine) | is.na(creatinine))
assertthat::assert_that(assertthat::is.number(age) | is.na(age))
assertthat::assert_that(assertthat::is.flag(is_female))
assertthat::assert_that(assertthat::is.flag(is_african_american))

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ Help and pull requests are more than welcome.
- *Anthropometry*
- Body mass index (BMI, Quetelet index).
- Body surface area (BSA).
- Ideal body weight (IBW).
- Mean arterial blood pressure (MAP).
- Pulse pressure.
- *Cardiology*
- Corrected QT interval (QTc).
- *Electrolytes*
- Albumin-corrected calcium.
- Albumin-adjusted calcium.
- Glucose-adjusted sodium.
- *Infectiology*
- CURB-65 community-acquired pneumonia severity score.
- qSOFA score for sepsis.
Expand Down Expand Up @@ -66,7 +68,6 @@ remotes::install_github("lc31/clinicalr")

# To do
* effective osmolality?
* glucose corrected sodium?
* anion gap?
* total body water?
* fractional excretion of sodium?
Expand All @@ -75,3 +76,4 @@ remotes::install_github("lc31/clinicalr")
* A-a gradient?
* creatinine clearance (using urine)?
* Framingham?
* assertion tests
16 changes: 9 additions & 7 deletions docs/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pandoc: 2.7.3
pkgdown: 1.6.1
pkgdown_sha: ~
articles: {}
last_built: 2020-11-04T11:39Z
last_built: 2020-11-04T21:04Z
urls:
reference: https://ls31.github.io/clinicalr//reference
article: https://ls31.github.io/clinicalr//articles
Expand Down
Loading

0 comments on commit 7c451d8

Please sign in to comment.