diff --git a/NEWS.md b/NEWS.md index f6102996c4..6b68c49c1b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -53,6 +53,8 @@ are not unique. (#2563) `derive_extreme_event()`, and `filter_joined()` were updated to reduce their memory consumption. (#2590) +- The function `compute_egfr()` updated to allow missing values for sex which result in missing values for output. (#2612) + ## Breaking Changes - The following function arguments are entering the next phase of the deprecation process: (#2487) diff --git a/R/compute_kidney.R b/R/compute_kidney.R index 423ba58c07..3ce8e5e026 100644 --- a/R/compute_kidney.R +++ b/R/compute_kidney.R @@ -139,7 +139,7 @@ compute_egfr <- function(creat, creatu = "SI", age, weight, sex, race = NULL, me optional = TRUE )) assert_numeric_vector(age) - assert_character_vector(sex, values = c("M", "F")) + assert_character_vector(sex, values = c("M", "F", NA_character_)) assert_character_vector(race, optional = TRUE) assert_character_scalar( method, @@ -159,9 +159,10 @@ compute_egfr <- function(creat, creatu = "SI", age, weight, sex, race = NULL, me egfr <- case_when( race == "BLACK OR AFRICAN AMERICAN" & sex == "F" ~ 175 * (scr^-1.154) * (age^-0.203) * 0.742 * 1.212, - race == "BLACK OR AFRICAN AMERICAN" ~ 175 * (scr^-1.154) * (age^-0.203) * 1.212, + race == "BLACK OR AFRICAN AMERICAN" & sex == "M" ~ 175 * (scr^-1.154) * (age^-0.203) * 1.212, sex == "F" ~ 175 * (scr^-1.154) * (age^-0.203) * 0.742, - sex == "M" ~ 175 * (scr^-1.154) * (age^-0.203) + sex == "M" ~ 175 * (scr^-1.154) * (age^-0.203), + TRUE ~ NA_real_ ) } else if (method == "CRCL") { assert_numeric_vector(weight) @@ -172,7 +173,8 @@ compute_egfr <- function(creat, creatu = "SI", age, weight, sex, race = NULL, me tolower(creatu) %in% c("cv", "mg/dl") & sex == "M" ~ ((140 - age) * weight) / (creat * 72), sex == "F" ~ ((140 - age) * weight * 1.04) / creat, - sex == "M" ~ ((140 - age) * weight * 1.23) / creat + sex == "M" ~ ((140 - age) * weight * 1.23) / creat, + TRUE ~ NA_real_ ) } else if (method == "CKD-EPI") { kappa <- case_when( @@ -189,7 +191,8 @@ compute_egfr <- function(creat, creatu = "SI", age, weight, sex, race = NULL, me gender_coefficent <- case_when( sex == "F" ~ 1.012, - TRUE ~ 1 + sex == "M" ~ 1, + TRUE ~ NA_real_ ) egfr <- 142 * pmin(scr / kappa, 1)^(alpha) * diff --git a/tests/testthat/test-compute_kidney.R b/tests/testthat/test-compute_kidney.R index 87b28f2df9..800e32e5fb 100644 --- a/tests/testthat/test-compute_kidney.R +++ b/tests/testthat/test-compute_kidney.R @@ -73,7 +73,9 @@ test_that("compute_egfr Test 7: CKD-EPI calculated on input data", { "P01", "P01-1001", 55, "M", "WHITE", 90.7, 96.3, "umol/L", "P01", "P01-1002", 52, "F", "BLACK OR AFRICAN AMERICAN", 68, 70, "umol/L", "P01", "P01-1003", 67, "M", "BLACK OR AFRICAN AMERICAN", 85, 77, "umol/L", - "P01", "P01-1004", 76, "F", "ASIAN", 60, 65, "umol/L" + "P01", "P01-1004", 76, "F", "ASIAN", 60, 65, "umol/L", + "P01", "P01-1005", 54, NA_character_, "AMERICAN INDIAN OR ALASKA NATIVE", 65, 68, + "umol/L", ) expected_output <- tibble::tribble( @@ -82,6 +84,8 @@ test_that("compute_egfr Test 7: CKD-EPI calculated on input data", { "P01", "P01-1002", 52, "F", "BLACK OR AFRICAN AMERICAN", 68, 70, "umol/L", 89.7175, "P01", "P01-1003", 67, "M", "BLACK OR AFRICAN AMERICAN", 85, 77, "umol/L", 94.5453, "P01", "P01-1004", 76, "F", "ASIAN", 60, 65, "umol/L", 84.4646, + "P01", "P01-1005", 54, NA_character_, "AMERICAN INDIAN OR ALASKA NATIVE", 65, 68, + "umol/L", NA_real_, ) egfr <- input %>%