-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
108 add buncreatinine chart #153
Changes from 10 commits
40cfe12
70b91d6
ad652b2
4d636ff
2fdde86
b452dfb
0df091f
5111d81
9f5545c
cea3ba9
245b1ff
005b925
2178f38
ba28fe5
613a05d
7ef8f93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ | |
^\.lintr$ | ||
^_pkgdown\.yml$ | ||
^pkgdown$ | ||
^nepExplorer\.Rcheck$ | ||
^nepExplorer.*\.tar\.gz$ | ||
^nepExplorer.*\.tgz$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,3 +109,6 @@ dist | |
.Rhistory | ||
.RData | ||
docs | ||
nepExplorer.Rcheck/ | ||
nepExplorer*.tar.gz | ||
nepExplorer*.tgz |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: nepExplorer | ||
Type: Package | ||
Title: Interactive Graphic for Exploring Kidney Function Data in Clinical Trials. | ||
Title: Interactive Graphic for Exploring Kidney Function Data in Clinical Trials | ||
Version: 0.1.0 | ||
Authors@R: c( | ||
person("Preston", "Burns", email = "[email protected]", role = c("cre","aut")), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# test file from | ||
# https://raw.githubusercontent.com/RhoInc/data-library/master/data/clinical-trials/renderer-specific/adbds.csv" | ||
# q: how to convert micro mol/L to mg/dL for creatinine? | ||
|
||
adlb <- read.csv("https://raw.githubusercontent.com/RhoInc/data-library/master/data/clinical-trials/renderer-specific/adbds.csv", | ||
|
||
adlb_ <- read.csv("https://raw.githubusercontent.com/RhoInc/data-library/master/data/clinical-trials/renderer-specific/adbds.csv", | ||
encoding = "UTF-8") %>% | ||
mutate(STRESN = ifelse(TEST == "Creatinine" & STRESU == "μmol/L", STRESN * .0113, STRESN), #Convert μmol/L to mg/dL | ||
STRESU = ifelse(TEST == "Creatinine" & STRESU == "μmol/L", "mg/dL", STRESU), | ||
mutate(STRESN = ifelse(TEST == "Creatinine" & STRESU == "μmol/L", STRESN / 88.4, # 1 mg/dL creatinine = 88.4 µmol/L | ||
ifelse(TEST == "Blood Urea Nitrogen" & STRESU == "mmol/L", STRESN * 2.86, STRESN) # 1 mmol/L BUN = 2.8 mg/dL BUN | ||
), # Convert μmol/L to mg/dL and mmol/L to mg/dL | ||
STRESU = ifelse(TEST %in% c("Creatinine", "Blood Urea Nitrogen", "Albumin"), "mg/dL", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't we need the albumin conversion to mg/dL that you have in the app example code here if we're changing it's unit to mg/dL? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks - it's been updated. To be consistent with the ISG demo app. |
||
ifelse(TEST == "Albumin/Creatinine", "Ratio", STRESU)) | ||
) %>% | ||
mutate(BLFL = ifelse(VISIT == "Screening", TRUE, FALSE)) %>% # add baseline column | ||
ungroup() %>% | ||
|
@@ -14,5 +19,17 @@ adlb <- read.csv("https://raw.githubusercontent.com/RhoInc/data-library/master/d | |
"Systolic Blood Pressure", | ||
"Temperature", ""))) | ||
|
||
# derive BUN/serum creatinine ratio | ||
adlb <- adlb_ %>% | ||
filter(TEST %in% c("Blood Urea Nitrogen", "Creatinine")) %>% | ||
select(-c("STNRLO", "STNRHI")) %>% | ||
tidyr::spread(TEST, STRESN) %>% | ||
mutate(STRESN = `Blood Urea Nitrogen` / Creatinine, | ||
TEST = "Blood Urea Nitrogen/Creatinine", | ||
STRESU = "Ratio") %>% | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wodnering if we need to say anything beyond 'ratio', like i could see users asking "ratio of what". For example, how by looking at the chart can you know the units of the creatinine and BUN? Idk what best practice is, may can ask Jim - could be a separate issue we can make if that makes sense to you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - I've opened a new issue #157 and lets ask Jim for best practice. |
||
select(-c("Blood Urea Nitrogen", "Creatinine")) %>% | ||
dplyr::bind_rows(adlb_) | ||
|
||
|
||
usethis::use_data(adlb, overwrite = TRUE) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,109 @@ library(safetyGraphics) | |
|
||
charts$nepexplorerMod$meta <- nepExplorer::meta_nepExplorer | ||
|
||
adam_adlbc <- safetyData::adam_adlbc |> | ||
mutate(STRESU = gsub("[\\(\\)]", "", regmatches(PARAM, gregexpr("\\(.*?\\)", PARAM))[[1]]), | ||
STRESU = ifelse(PARAM == "Creatinine (umol/L)", "mg/dL", STRESU), # convert creatine to mg/dL | ||
AVAL = ifelse(PARAM == "Creatinine (umol/L)", AVAL * .0113, AVAL), | ||
PARAM = ifelse(PARAM == "Creatinine (umol/L)", "Creatinine (mg/dL)", PARAM)) | ||
# Helper functions for unit conversions - shortened names | ||
convert_creat_to_mgdl <- function(value) { | ||
value / 88.4 | ||
} | ||
|
||
convert_bun_to_mgdl <- function(value) { | ||
value * 2.86 | ||
} | ||
|
||
convert_alb_to_mgdl <- function(value) { | ||
value * 100 | ||
} | ||
|
||
# Apply unit conversions and data cleaning | ||
adam_adlbc_ <- safetyData::adam_adlbc |> | ||
mutate( | ||
STRESU = gsub("[\\(\\)]", "", regmatches(PARAM, gregexpr("\\(.*?\\)", PARAM))[[1]]), | ||
# Use case_when for clearer conditional logic | ||
AVAL = case_when( | ||
PARAMCD == "CREAT" ~ convert_creat_to_mgdl(AVAL), | ||
PARAMCD == "BUN" ~ convert_bun_to_mgdl(AVAL), | ||
PARAMCD == "ALB" ~ convert_alb_to_mgdl(AVAL), | ||
TRUE ~ AVAL | ||
), | ||
BASE = case_when( | ||
PARAMCD == "CREAT" ~ convert_creat_to_mgdl(BASE), | ||
PARAMCD == "BUN" ~ convert_bun_to_mgdl(BASE), | ||
PARAMCD == "ALB" ~ convert_alb_to_mgdl(BASE), | ||
TRUE ~ BASE | ||
), | ||
CHG = case_when( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the same changes are being applied to base and aval, i don't think you'd need a unit conversion on CHG, I think that'd stay the same number since it's same division - double check my thinking though @Lovemore-Gakava, it's the morning and my mind is still getting started There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pburnsdata - I appreciate your feedback. The update extends beyond the ratio calculation. It aims to maintain consistency across all variables derived from or associated with BASE or AVAL/LBSTRESN, including CHG, A1LO, A1HI, and others. This ensures that users have reliable data for other various uses outside the BUN/CREAT chart. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. o I see, the is raw CHG, idk why I thought this was fold change - sounds good! |
||
PARAMCD == "CREAT" ~ convert_creat_to_mgdl(CHG), | ||
PARAMCD == "BUN" ~ convert_bun_to_mgdl(CHG), | ||
PARAMCD == "ALB" ~ convert_alb_to_mgdl(CHG), | ||
TRUE ~ CHG | ||
), | ||
A1LO = case_when( | ||
PARAMCD == "CREAT" ~ convert_creat_to_mgdl(A1LO), | ||
PARAMCD == "BUN" ~ convert_bun_to_mgdl(A1LO), | ||
PARAMCD == "ALB" ~ convert_alb_to_mgdl(A1LO), | ||
TRUE ~ A1LO | ||
), | ||
A1HI = case_when( | ||
PARAMCD == "CREAT" ~ convert_creat_to_mgdl(A1HI), | ||
PARAMCD == "BUN" ~ convert_bun_to_mgdl(A1HI), | ||
PARAMCD == "ALB" ~ convert_alb_to_mgdl(A1HI), | ||
TRUE ~ A1HI | ||
), | ||
LBSTRESN = case_when( | ||
PARAMCD == "CREAT" ~ convert_creat_to_mgdl(LBSTRESN), | ||
PARAMCD == "BUN" ~ convert_bun_to_mgdl(LBSTRESN), | ||
PARAMCD == "ALB" ~ convert_alb_to_mgdl(LBSTRESN), | ||
TRUE ~ LBSTRESN | ||
), | ||
STRESU = ifelse(PARAMCD %in% c("BUN", "CREAT", "ALB"), "mg/dL", STRESU), | ||
PARAM = case_when( | ||
PARAM == "Creatinine (umol/L)" ~ "Creatinine (mg/dL)", | ||
PARAM == "Blood Urea Nitrogen (mmol/L)" ~ "Blood Urea Nitrogen (mg/dL)", | ||
PARAM == "Albumin (g/L)" ~ "Albumin (mg/dL)", | ||
TRUE ~ PARAM | ||
) # todo: consider removing the units from the PARAM column - if this is implemented also update meta_nepExplorer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I don't think it affects the app in anyway, but could cause confusion in the documentation and examples if users see that and think "oh I need to have units in the param" when they don't. I created #155 for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks - lets discuss this further when we look at #155, as we might need to be consistent across the application such as what users see under filters and what is shown on the chart. For example |
||
) | ||
# derive BUN/serum creatinine ratio | ||
# Filter and select relevant columns | ||
adam_adlbc_filtered <- adam_adlbc_ %>% | ||
filter(PARAMCD %in% c("BUN", "CREAT", "ALB")) %>% | ||
select( | ||
-A1LO, -A1HI, -R2A1LO, -R2A1HI, -BR2A1LO, -BR2A1HI, | ||
-ALBTRVAL, -ANRIND, -BNRIND, -ABLFL, -AENTMTFL, -LBSEQ, | ||
-LBNRIND, -AVAL, -BASE, -CHG, -PARAMN, -PARAM | ||
) | ||
|
||
# Reshape the data | ||
adam_adlbc_wide <- adam_adlbc_filtered %>% | ||
tidyr::spread(PARAMCD, LBSTRESN) | ||
|
||
# Calculate BUN/CREAT ratio | ||
adam_adlbc_bc <- adam_adlbc_wide %>% | ||
mutate( | ||
LBSTRESN = BUN / CREAT, | ||
PARAMCD = "BUN/CREAT", | ||
PARAM = "Blood Urea Nitrogen/Creatinine", | ||
STRESU = "Ratio", | ||
AVAL = LBSTRESN | ||
) | ||
|
||
# Calculate ALB/CREAT ratio | ||
adam_adlbc_ac <- adam_adlbc_wide %>% | ||
mutate( | ||
LBSTRESN = ALB / CREAT, | ||
PARAMCD = "ALB/CREAT", | ||
PARAM = "Albumin/Creatinine", | ||
STRESU = "Ratio", | ||
AVAL = LBSTRESN | ||
) | ||
|
||
# Combine the data | ||
adam_adlbc_final <- adam_adlbc_ac %>% | ||
dplyr::bind_rows(adam_adlbc_bc, adam_adlbc_) %>% | ||
select(-BUN, -CREAT, -ALB) | ||
|
||
safetyGraphics::safetyGraphicsApp(domainData = list( | ||
labs = adam_adlbc, | ||
labs = adam_adlbc_final, | ||
aes = safetyData::adam_adae, | ||
dm = safetyData::adam_adsl, | ||
vitals = safetyData::adam_advs | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
I'm thinking this unit variabel name should be different since no uacr involved, also I think on safetygraphics app example it gives an error for this chart because there's no unit, we may want to cahnge this to check for units because the if(length) statement below crashes it. I think albumin/creat chart needs the same change
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.
Thanks Preston - uacr_unit references updated.