The function ln_quantile_value calculates lab values at a specified quantile, using the default units for that lab. The function ln_patients_quantile_value does the same calculation for a specific group of patients.
Default units for a lab can be obtained using ln_lab_default_units.
If no quantile data is available for a particular lab, age, and sex, the function returns 'NA'.
It should be noted that the values of extreme quantiles (e.g. >0.95 or <0.05 on low resolution, >0.99 or <0.01 on high resolution) may not be reliable, as they may represent outliers in the data.

Note that ln_quantile_value returns values for all combinations of age, sex, and lab, while ln_patients_quantile_value returns values for a specific set of patients, similar to ln_normalize.

ln_quantile_value(
  quantiles,
  age,
  sex,
  lab,
  reference = "Clalit",
  allow_edge_quantiles = FALSE
)

ln_patients_quantile_value(
  quantiles,
  age,
  sex,
  lab,
  reference = "Clalit",
  allow_edge_quantiles = FALSE
)

Arguments

quantiles

a vector of quantiles (in the range 0-1) to compute the lab value for, or a vector with a quantile for each patient when running ln_patients_quantile_value.

age

a vector of ages to compute the lab values for or a vector with an age for each patient when running ln_patients_quantile_value. Note that the age should be in years, and would be floored to the nearest integer.

sex

the sexes to compute the lab values for, or a vector with a sex for each patient when running ln_patients_quantile_value. Note that for ln_quantile_value this parameter can only be either: "male", "female" or c("male", "female")

lab

The lab name.

reference

the reference distribution to use. Can be either "Clalit" or "UKBB" or "Clalit-demo". Please download the Clalit and UKBB reference distributions using ln_download_data().

allow_edge_quantiles

If TRUE (default) then the function will return the value for the edge quantiles (<0.01 or >0.99) even though they are not reliable. If FALSE then the function will return NA for those quantiles. Note that for the "Clalit-demo" reference, the threshold would be <0.05 or >0.95.

Value

ln_quantile_value returns a data frame which contains the values for each combination of quantile, age and sex. The data frame has the the following columns:

  • age: age in years

  • sex: "male" or "female"

  • quantile: he quantile

  • value: the lab value

  • unit: the lab unit

  • lab: the lab name

ln_patients_quantile_value returns a vector of value per patient.

Examples

# \donttest{
ln_quantile_value(c(0.05, 0.5, 0.95), 50, "male", "WBC")
#>   age  sex quantile     value     unit lab
#> 1  50 male     0.05  4.584943 x10E3/uL WBC
#> 2  50 male     0.50  7.182971 x10E3/uL WBC
#> 3  50 male     0.95 11.789079 x10E3/uL WBC

ln_quantile_value(
    c(0, 0.05, 0.1, 0.4, 0.5, 0.6, 0.9, 1),
    c(50, 60),
    c("male", "female"),
    "Glucose"
)
#>    age    sex quantile     value  unit     lab
#> 1   50   male     0.00        NA mg/dL Glucose
#> 2   50   male     0.05  76.63210 mg/dL Glucose
#> 3   50   male     0.10  80.92743 mg/dL Glucose
#> 4   50   male     0.40  90.84690 mg/dL Glucose
#> 5   50   male     0.50  92.98665 mg/dL Glucose
#> 6   50   male     0.60  95.83511 mg/dL Glucose
#> 7   50   male     0.90 111.93415 mg/dL Glucose
#> 8   50   male     1.00        NA mg/dL Glucose
#> 9   60   male     0.00        NA mg/dL Glucose
#> 10  60   male     0.05  77.98954 mg/dL Glucose
#> 11  60   male     0.10  81.92832 mg/dL Glucose
#> 12  60   male     0.40  92.60682 mg/dL Glucose
#> 13  60   male     0.50  94.97742 mg/dL Glucose
#> 14  60   male     0.60  97.86284 mg/dL Glucose
#> 15  60   male     0.90 113.95915 mg/dL Glucose
#> 16  60   male     1.00        NA mg/dL Glucose
#> 17  50 female     0.00        NA mg/dL Glucose
#> 18  50 female     0.05  75.29256 mg/dL Glucose
#> 19  50 female     0.10  78.77304 mg/dL Glucose
#> 20  50 female     0.40  87.97072 mg/dL Glucose
#> 21  50 female     0.50  90.91937 mg/dL Glucose
#> 22  50 female     0.60  92.91284 mg/dL Glucose
#> 23  50 female     0.90 106.98740 mg/dL Glucose
#> 24  50 female     1.00        NA mg/dL Glucose
#> 25  60 female     0.00        NA mg/dL Glucose
#> 26  60 female     0.05  77.70802 mg/dL Glucose
#> 27  60 female     0.10  80.54148 mg/dL Glucose
#> 28  60 female     0.40  90.41370 mg/dL Glucose
#> 29  60 female     0.50  92.59323 mg/dL Glucose
#> 30  60 female     0.60  95.86970 mg/dL Glucose
#> 31  60 female     0.90 110.90176 mg/dL Glucose
#> 32  60 female     1.00        NA mg/dL Glucose
# }

# on the demo data
# \dontshow{
ln_quantile_value(c(0.05, 0.5, 0.95), 50, "male", "WBC", reference = "Clalit-demo")
#>   age  sex quantile     value     unit lab
#> 1  50 male     0.05  4.584943 x10E3/uL WBC
#> 2  50 male     0.50  7.182971 x10E3/uL WBC
#> 3  50 male     0.95 11.789079 x10E3/uL WBC
# }

# \donttest{
hemoglobin_data$quantile <- ln_normalize(
    hemoglobin_data$value,
    hemoglobin_data$age,
    hemoglobin_data$sex,
    "Hemoglobin"
)

hemoglobin_data$value1 <- ln_patients_quantile_value(
    hemoglobin_data$quantile,
    hemoglobin_data$age,
    hemoglobin_data$sex,
    "Hemoglobin"
)
head(hemoglobin_data)
#>   age    sex value   quantile value1
#> 1  20   male  9.39 0.01882213   9.39
#> 2  20   male 14.03 0.18674720  14.03
#> 3  20   male 14.44 0.27947363  14.44
#> 4  20   male 15.80 0.75195053  15.80
#> 5  20 female 12.06 0.24249167  12.06
#> 6  20 female 12.89 0.57451617  12.89
# }

# \dontshow{
hemoglobin_data$quantile <- ln_normalize(
    hemoglobin_data$value,
    hemoglobin_data$age,
    hemoglobin_data$sex,
    "Hemoglobin",
    reference = "Clalit-demo"
)

hemoglobin_data$value1 <- ln_patients_quantile_value(
    hemoglobin_data$quantile,
    hemoglobin_data$age,
    hemoglobin_data$sex,
    "Hemoglobin",
    reference = "Clalit-demo"
)
head(hemoglobin_data)
#>   age    sex value   quantile value1
#> 1  20   male  9.39 0.03838718     NA
#> 2  20   male 14.03 0.18914947  14.03
#> 3  20   male 14.44 0.28589076  14.44
#> 4  20   male 15.80 0.75032395  15.80
#> 5  20 female 12.06 0.24222206  12.06
#> 6  20 female 12.89 0.55270091  12.89
# }