Reference limits are specific for age and sex. Each laboratory institute has its own reference limits. This function is useful to query a dataset against this database.

lookup_limits(age, sex, table)

Arguments

age

numeric, patient age.

sex

character/factor, patient sex, has to be the same length as age.

table

data.frame, reference table, has to have the columns: "age", numeric (same units as in age, e.g. days or years, age of 0 matches all ages), "sex", factor (same levels for male and female as sex and a special level "both"), "lower" and "upper", numeric for the lower and upper reference limits. If an "param" column is given the "lower" and "upper" limits for all different values in "param" is returned. Additional columns are allowed (and ignored).

Value

matrix, with 2 columns ("lower", "upper") and as many rows as length(age).

Author

Sebastian Gibb

Examples

reference <- data.frame(
    param = c("albumin", rep("bilirubin", 4)),
    age = c(0, 1, 2, 3, 7),     # days
    sex = "both",
    units = c("g/l", rep("µmol/l", 4)), # ignored
    lower = c(35, rep(NA, 4)),  # no real reference values
    upper = c(52, 5, 8, 13, 18) # no real reference values
)

# lookup albumin reference values for 18 year old woman
lookup_limits(
    age = 18 * 365.25,
    sex = "female",
    table = reference[reference$param == "albumin",]
)
#>         lower upper
#> albumin    35    52

# lookup albumin and bilirubin values for 18 year old woman
lookup_limits(
    age = 18 * 365.25,
    sex = "female",
    table = reference
)
#>           lower upper
#> albumin      35    52
#> bilirubin    NA    18

# lookup bilirubin referenc values for infants
lookup_limits(
    age = 0:8,
    sex = rep(c("female", "male"), 5:4),
    table = reference[reference$param == "bilirubin",]
)
#>           lower upper
#> bilirubin    NA    NA
#> bilirubin    NA     5
#> bilirubin    NA     8
#> bilirubin    NA    13
#> bilirubin    NA    13
#> bilirubin    NA    13
#> bilirubin    NA    13
#> bilirubin    NA    18
#> bilirubin    NA    18