diff --git a/NAMESPACE b/NAMESPACE index ecd66ec..42d8279 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/bmi.R b/R/bmi.R index 94fb559..43d4c07 100644 --- a/R/bmi.R +++ b/R/bmi.R @@ -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)) %>% diff --git a/R/bsa.R b/R/bsa.R index 5fb8776..27726ce 100644 --- a/R/bsa.R +++ b/R/bsa.R @@ -25,8 +25,10 @@ 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") } @@ -34,8 +36,10 @@ estimate_bsa_monsteller <- function(weight, height) { #' @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") } diff --git a/R/electrolytes.R b/R/electrolytes.R index fc8a363..04eaeab 100644 --- a/R/electrolytes.R +++ b/R/electrolytes.R @@ -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") +} diff --git a/R/renal_function.R b/R/renal_function.R index e57fb57..8e865de 100644 --- a/R/renal_function.R +++ b/R/renal_function.R @@ -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) @@ -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)) @@ -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") } @@ -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)) diff --git a/README.md b/README.md index 39442b9..7a1e93b 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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? @@ -75,3 +76,4 @@ remotes::install_github("lc31/clinicalr") * A-a gradient? * creatinine clearance (using urine)? * Framingham? +* assertion tests diff --git a/docs/index.html b/docs/index.html index 8cd8163..70f4853 100644 --- a/docs/index.html +++ b/docs/index.html @@ -87,6 +87,7 @@
Clinicalr is not (yet) available on CRAN. Install devtools. Then use devtools to install clinicalr directly from GitHub using the remotes package.
--install.packages("remotes") -remotes::install_github("ls31/clinicalr")
+install.packages("remotes")
+remotes::install_github("ls31/clinicalr")
-remotes::install_github("lc31/clinicalr")
+remotes::install_github("lc31/clinicalr")
Hyperglycaemia can lead to hypertonic hyponatriemia. Using observational +data, the following formula predicts sodium levels after correction of +glucose: \(\text{Na}_{predicted} = \text{Na}_\text{measured} + \kappa +\times \frac{\text{glucose} - 5.6}{5.6}\), where \(\kappa\) is 1.6 when +derived from the publication by Katz and 2.4 when derived from more recent +work by Hillier (default).
+adjust_sodium_for_glucose(sodium, glucose, method = "Hillier")+ +
sodium | +Measured sodium level (mmol/l). |
+
---|---|
glucose | +Measured glucose level (mmol/l). |
+
method | +Formula. Options are: "Hillier" (default), "Katz". |
+
Glucose-adjusted sodium level (mmol/l).
+It's just a prediction, and the choice between both +formulae may result in quite different predictions.
+Katz, M. A. Hyperglycemia-Induced Hyponatremia — Calculation of Expected Serum Sodium Depression. N Engl J Med 289, 843–844 (1973). 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)..
+Adjust sodium for hyperglycaemia