Skip to content

Commit

Permalink
Closes #2612 improve missing value handling in compute egfr (#2613)
Browse files Browse the repository at this point in the history
* #2612 update to allow missing valeus for sex

* Update NEWS

* #2612 Test: add additional data for testing NA values for sex

* Update R/compute_kidney.R

Co-authored-by: Stefan Bundfuss <[email protected]>

---------

Co-authored-by: Stefan Bundfuss <[email protected]>
  • Loading branch information
jeffreyad and bundfussr authored Dec 23, 2024
1 parent cb8d925 commit 76b83e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions R/compute_kidney.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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) *
Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-compute_kidney.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 %>%
Expand Down

0 comments on commit 76b83e6

Please sign in to comment.