# \donttest{
# Normalize Hemoglobin values to age and sex
hemoglobin_data$quantile <- ln_normalize(
hemoglobin_data$value,
hemoglobin_data$age,
hemoglobin_data$sex,
"Hemoglobin"
)
# plot the quantiles vs values for age 50-60
library(ggplot2)
library(dplyr)
hemoglobin_data %>%
filter(age >= 50 & age <= 60) %>%
ggplot(aes(x = value, y = quantile, color = sex)) +
geom_point() +
theme_classic()
# Different units
hemoglobin_diff_units <- hemoglobin_data
hemoglobin_diff_units$value <- hemoglobin_diff_units$value * 0.1
hemoglobin_diff_units$quantile <- ln_normalize(
hemoglobin_data$value,
hemoglobin_data$age,
hemoglobin_data$sex,
"Hemoglobin",
"mg/mL"
)
# Multiple units
creatinine_diff_units <- creatinine_data
creatinine_diff_units$value <- c(
creatinine_diff_units$value[1:500] * 0.011312,
creatinine_diff_units$value[501:1000] * 11.312
)
creatinine_diff_units$quantile <- ln_normalize(
creatinine_diff_units$value,
creatinine_diff_units$age,
creatinine_diff_units$sex,
"Creatinine",
c(rep("umol/L", 500), rep("mmol/L", 500))
)
# Use UKBB as reference
hemoglobin_data_ukbb <- hemoglobin_data %>% filter(age >= 35 & age <= 80)
hemoglobin_data_ukbb$quantile_ukbb <- ln_normalize(
hemoglobin_data_ukbb$value,
hemoglobin_data_ukbb$age,
hemoglobin_data_ukbb$sex,
"Hemoglobin",
reference = "UKBB"
)
# plot UKBB vs Clalit
hemoglobin_data_ukbb %>%
filter(age >= 50 & age <= 60) %>%
ggplot(aes(x = quantile, y = quantile_ukbb, color = sex)) +
geom_point() +
geom_abline() +
theme_classic()
# }
# examples on the demo data
# \dontshow{
hemoglobin_data$quantile <- ln_normalize(
hemoglobin_data$value,
hemoglobin_data$age,
hemoglobin_data$sex,
"Hemoglobin",
reference = "Clalit-demo"
)
# }
library(dplyr)
multi_labs_df <- bind_rows(
hemoglobin_data %>% mutate(lab = "Hemoglobin"),
creatinine_data %>% mutate(lab = "Creatinine")
)
# \donttest{
multi_labs_df$quantile <- ln_normalize_multi(multi_labs_df)
# }
# on the demo data
# \dontshow{
multi_labs_df$quantile <- ln_normalize_multi(multi_labs_df, reference = "Clalit-demo")
# }
head(multi_labs_df)
Run the code above in your browser using DataLab