Title: | Z(log) Transformation for Laboratory Measurements |
---|---|
Description: | Transformation of laboratory measurements into z or z(log)-value based on given or empirical reference limits as proposed in Hoffmann et al. 2017 <doi:10.1515/labmed-2016-0087>. |
Authors: | Sebastian Gibb [aut, cre] |
Maintainer: | Sebastian Gibb <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.2 |
Built: | 2024-11-12 05:27:00 UTC |
Source: | https://github.com/ampel-leipzig/zlog |
Impute NA
values with the logmean, mean, minimal or maximum reference value.
impute_df(x, limits, method = c("logmean", "mean", "min", "max"))
impute_df(x, limits, method = c("logmean", "mean", "min", "max"))
x |
|
limits |
|
method |
|
data.frame
, the same as x
but missing values are replaced by
the corresponding logmean, mean, minimal or maximal reference values
depending on the chosen method
.
Imputation should be done prior to z()
/zlog()
transformation.
Afterwards the NA
could replaced by zero (for mean-imputation) via
d[is.na(d)] <- 0
.
Sebastian Gibb
l <- data.frame( param = c("alb", "bili"), age = c(0, 0), sex = c("both", "both"), units = c("mg/l", "µmol/l"), lower = c(35, 2), upper = c(52, 21) ) x <- data.frame( age = 40:48, sex = rep(c("female", "male"), c(5, 4)), # from Hoffmann et al. 2017 alb = c(42, NA, 38, NA, 50, 42, 27, 31, 24), bili = c(11, 9, NA, NA, 22, 42, NA, 200, 20) ) impute_df(x, l) impute_df(x, l, method = "min") zlog_df(impute_df(x, l), l)
l <- data.frame( param = c("alb", "bili"), age = c(0, 0), sex = c("both", "both"), units = c("mg/l", "µmol/l"), lower = c(35, 2), upper = c(52, 21) ) x <- data.frame( age = 40:48, sex = rep(c("female", "male"), c(5, 4)), # from Hoffmann et al. 2017 alb = c(42, NA, 38, NA, 50, 42, 27, 31, 24), bili = c(11, 9, NA, NA, 22, 42, NA, 200, 20) ) impute_df(x, l) impute_df(x, l, method = "min") zlog_df(impute_df(x, l), l)
Inverse function to z or z(log) for laboratory measurement standardisation as proposed in Hoffmann 2017 et al.
iz(x, limits, probs = c(0.025, 0.975)) izlog(x, limits, probs = c(0.025, 0.975))
iz(x, limits, probs = c(0.025, 0.975)) izlog(x, limits, probs = c(0.025, 0.975))
x |
|
limits |
|
probs |
|
The inverse z value is calculated as follows (assuming that the limits where
0.025 and 0.975 quantiles):
The inverse z(log) value is calculated as follows (assuming that the limits
where 0.025 and 0.975 quantiles):
numeric
, laboratory measurements.
Sebastian Gibb
Georg Hoffmann, Frank Klawonn, Ralf Lichtinghagen, and Matthias Orth. 2017. "The Zlog-Value as Basis for the Standardization of Laboratory Results." LaboratoriumsMedizin 41 (1): 23–32. doi:10.1515/labmed-2016-0087.
iz(z(1:10, limits = c(2, 8)), limits = c(2, 8)) # from Hoffmann et al. 2017 albuminzlog <- c(-0.15, -2.25, -1.15, 0.08, 1.57, -0.15, -4.53, -3.16, -5.70) izlog(albuminzlog, limits = c(35, 52)) bilirubinzlog <- c(0.85, 0.57, -1.96, -0.43, 2.04, 3.12, 2.90, 5.72, 1.88) limits <- cbind( lower = rep(c(35, 2), c(length(albuminzlog), length(bilirubinzlog))), upper = rep(c(52, 21), c(length(albuminzlog), length(bilirubinzlog))) ) izlog(c(albuminzlog, bilirubinzlog), limits = limits)
iz(z(1:10, limits = c(2, 8)), limits = c(2, 8)) # from Hoffmann et al. 2017 albuminzlog <- c(-0.15, -2.25, -1.15, 0.08, 1.57, -0.15, -4.53, -3.16, -5.70) izlog(albuminzlog, limits = c(35, 52)) bilirubinzlog <- c(0.85, 0.57, -1.96, -0.43, 2.04, 3.12, 2.90, 5.72, 1.88) limits <- cbind( lower = rep(c(35, 2), c(length(albuminzlog), length(bilirubinzlog))), upper = rep(c(52, 21), c(length(albuminzlog), length(bilirubinzlog))) ) izlog(c(albuminzlog, bilirubinzlog), limits = limits)
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)
lookup_limits(age, sex, table)
age |
|
sex |
|
table |
|
matrix
, with 2 columns ("lower", "upper") and as many rows as
length(age)
.
Sebastian Gibb
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",] ) # lookup albumin and bilirubin values for 18 year old woman lookup_limits( age = 18 * 365.25, sex = "female", table = reference ) # lookup bilirubin referenc values for infants lookup_limits( age = 0:8, sex = rep(c("female", "male"), 5:4), table = reference[reference$param == "bilirubin",] )
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",] ) # lookup albumin and bilirubin values for 18 year old woman lookup_limits( age = 18 * 365.25, sex = "female", table = reference ) # lookup bilirubin referenc values for infants lookup_limits( age = 0:8, sex = rep(c("female", "male"), 5:4), table = reference[reference$param == "bilirubin",] )
Calculates the lower and upper reference limit for given probabilities.
reference_limits(x, probs = c(0.025, 0.975), na.rm = TRUE)
reference_limits(x, probs = c(0.025, 0.975), na.rm = TRUE)
x |
|
probs |
|
na.rm |
|
numeric
of length 2 with the lower and upper limit.
Sebastian Gibb
reference_limits(1:10)
reference_limits(1:10)
Sometimes reference limits are not specified. That is often the case for biomarkers that are related to infection or cancer. Using zero as lower boundary results in skewed distributions (Hoffmann et al. 2017; fig. 7). Haeckel et al. 2015 suggested to set the lower reference limit to 0.15 of the upper one.
set_missing_limits(x, fraction = c(0.15, 20/3))
set_missing_limits(x, fraction = c(0.15, 20/3))
x |
|
fraction |
|
data.frame
, the same as x
but the "lower" and "upper" columns are
modified if there were NA
before.
Sebastian Gibb
Georg Hoffmann, Frank Klawonn, Ralf Lichtinghagen, and Matthias Orth. 2017. "The Zlog-Value as Basis for the Standardization of Laboratory Results." LaboratoriumsMedizin 41 (1): 23–32. doi:10.1515/labmed-2016-0087.
Rainer Haeckel, Werner Wosniok, Ebrhard Gurr and Burkhard Peil. 2015. "Permissible limits for uncertainty of measurement in laboratory medicine" Clinical Chemistry and Laboratory Medicine 53 (8): 1161-1171. doi:10.1515/cclm-2014-0874.
reference <- data.frame( param = c("albumin", rep("bilirubin", 4)), age = c(0, 1, 2, 3, 7), # ignored sex = "both", # ignored 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 ) set_missing_limits(reference) set_missing_limits(reference, fraction = c(0.2, 5))
reference <- data.frame( param = c("albumin", rep("bilirubin", 4)), age = c(0, 1, 2, 3, 7), # ignored sex = "both", # ignored 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 ) set_missing_limits(reference) set_missing_limits(reference, fraction = c(0.2, 5))
Calculates the z or z(log) values for laboratory measurement standardisation as proposed in Hoffmann 2017 et al.
z(x, limits, probs = c(0.025, 0.975), log = FALSE) zlog(x, limits, probs = c(0.025, 0.975))
z(x, limits, probs = c(0.025, 0.975), log = FALSE) zlog(x, limits, probs = c(0.025, 0.975))
x |
|
limits |
|
probs |
|
log |
|
The z value is calculated as follows (assuming that the limits where 0.025
and 0.975 quantiles):
.
The z(log) value is calculated as follows (assuming that the limits where 0.025
and 0.975 quantiles):
.
zlog
is an alias for z(..., log = TRUE)
.
numeric
, z or z(log) values.
Sebastian Gibb
Georg Hoffmann, Frank Klawonn, Ralf Lichtinghagen, and Matthias Orth. 2017. "The Zlog-Value as Basis for the Standardization of Laboratory Results." LaboratoriumsMedizin 41 (1): 23–32. doi:10.1515/labmed-2016-0087.
z(1:10, limits = c(2, 8)) # from Hoffmann et al. 2017 albumin <- c(42, 34, 38, 43, 50, 42, 27, 31, 24) zlog(albumin, limits = c(35, 52)) bilirubin <- c(11, 9, 2, 5, 22, 42, 37, 200, 20) limits <- cbind( lower = rep(c(35, 2), c(length(albumin), length(bilirubin))), upper = rep(c(52, 21), c(length(albumin), length(bilirubin))) ) zlog(c(albumin, bilirubin), limits = limits)
z(1:10, limits = c(2, 8)) # from Hoffmann et al. 2017 albumin <- c(42, 34, 38, 43, 50, 42, 27, 31, 24) zlog(albumin, limits = c(35, 52)) bilirubin <- c(11, 9, 2, 5, 22, 42, 37, 200, 20) limits <- cbind( lower = rep(c(35, 2), c(length(albumin), length(bilirubin))), upper = rep(c(52, 21), c(length(albumin), length(bilirubin))) ) zlog(c(albumin, bilirubin), limits = limits)
Calculates the z or z(log) values for laboratory measurement standardisation
as proposed in Hoffmann 2017 et al. for a complete data.frame
.
z_df(x, limits, probs = c(0.025, 0.975), log = FALSE) zlog_df(x, limits, probs = c(0.025, 0.975))
z_df(x, limits, probs = c(0.025, 0.975), log = FALSE) zlog_df(x, limits, probs = c(0.025, 0.975))
x |
|
limits |
|
probs |
|
log |
|
This is a wrapper function for z()
and lookup_limits()
. Please find
the details for the z/z(log) calculation at z()
.
zlog_df
is an alias for z_df(..., log = TRUE)
.
data.frame
, with the columns: "age", "sex" and all numeric
columns z/zlog transformed. If a column name is missing in limits$param
a warning is thrown and the column is set to NA
.
Sebastian Gibb
Georg Hoffmann, Frank Klawonn, Ralf Lichtinghagen, and Matthias Orth. 2017. "The Zlog-Value as Basis for the Standardization of Laboratory Results." LaboratoriumsMedizin 41 (1): 23–32. doi:10.1515/labmed-2016-0087.
l <- data.frame( param = c("alb", "bili"), age = c(0, 0), sex = c("both", "both"), units = c("mg/l", "µmol/l"), lower = c(35, 2), upper = c(52, 21) ) x <- data.frame( age = 40:48, sex = rep(c("female", "male"), c(5, 4)), # from Hoffmann et al. 2017 alb = c(42, 34, 38, 43, 50, 42, 27, 31, 24), bili = c(11, 9, 2, 5, 22, 42, 37, 200, 20) ) z_df(x, l) zlog_df(x, l)
l <- data.frame( param = c("alb", "bili"), age = c(0, 0), sex = c("both", "both"), units = c("mg/l", "µmol/l"), lower = c(35, 2), upper = c(52, 21) ) x <- data.frame( age = 40:48, sex = rep(c("female", "male"), c(5, 4)), # from Hoffmann et al. 2017 alb = c(42, 34, 38, 43, 50, 42, 27, 31, 24), bili = c(11, 9, 2, 5, 22, 42, 37, 200, 20) ) z_df(x, l) zlog_df(x, l)
This function provides a color gradient depending on the zlog value as described in Hoffmann et al. 2017. The colours are only roughly equal to the one found in the article.
zcol(x)
zcol(x)
x |
|
character
, of length(x)
with the corresponding color hex code.
Sebastian Gibb
Hoffmann, Georg, Frank Klawonn, Ralf Lichtinghagen, and Matthias Orth. 2017. "The Zlog-Value as Basis for the Standardization of Laboratory Results." LaboratoriumsMedizin 41 (1): 23–32. doi:10.1515/labmed-2016-0087.
z <- -10:10 image(matrix(z, ncol = 1), col = zcol(z), xaxt = "n", yaxt = "n") text(seq(0, 1, length.out=length(z)), 0, label = z)
z <- -10:10 image(matrix(z, ncol = 1), col = zcol(z), xaxt = "n", yaxt = "n") text(seq(0, 1, length.out=length(z)), 0, label = z)