Nothing
require(NonCompart)
# Regression test for the expected-value comparator in PQNCA().
#
# The comparator computed a relative difference and then required !is.na(rd), so a
# parameter that was NA on BOTH sides - not estimable for that profile, and not expected
# to be - was counted as a difference. Feeding the analysis its own output back in as
# `expected` therefore produced "expected-values DIFFER" and an overall NOT QUALIFIED for
# a correct analysis, whenever any profile lacked a terminal phase. The reproducibility
# check in the same function already treated NA/NA as equal, so the two comparators inside
# one report disagreed with each other.
Fail = function(msg) stop(paste("Test Failed!", msg))
pdfOut = tempfile(fileext = ".pdf")
on.exit(unlink(pdfOut), add = TRUE)
# Subject 2 has a single measurable concentration, so it has no terminal phase and every
# lambda-z-derived parameter is NA.
d = data.frame(ID = rep(1:2, each = 6),
Time = rep(c(0, 1, 2, 4, 8, 24), 2),
Conc = c(0, 10, 16, 12, 8, 1,
0, 0, 5, 0, 0, 0))
r = tblNCA(d, key = "ID", colTime = "Time", colConc = "Conc", dose = 1, R2ADJ = 0)
if (!is.na(r$LAMZHL[2])) Fail("fixture is wrong: subject 2 should have no terminal phase")
if (is.na(r$LAMZHL[1])) Fail("fixture is wrong: subject 1 should have a terminal phase")
runPQ = function(expected)
PQNCA(fileName = pdfOut, concData = d, key = "ID", colTime = "Time", colConc = "Conc",
dose = 1, R2ADJ = 0, expected = expected)
## 1. The analysis compared against its own output must agree on every value, including
## the NAs, and must not be failed on that account.
expected = r[, c("ID", "CMAX", "AUCLST", "AUCIFO", "LAMZHL")]
pq = runPQ(expected)
bad = Filter(function(e) !isTRUE(e$ok), pq$expected)
if (length(bad) > 0) {
Fail(paste("self-comparison reported", length(bad), "difference(s); first:",
bad[[1]]$param, "expected =", bad[[1]]$exp, "observed =", bad[[1]]$obs))
}
if (length(pq$expected) != 8) Fail(paste("expected 8 comparisons, got", length(pq$expected)))
## 2. A NA expected value against a real observed value is still a genuine difference.
e2 = expected
e2$LAMZHL[1] = NA # subject 1 does have a half-life
pq = runPQ(e2)
bad = Filter(function(x) !isTRUE(x$ok), pq$expected)
if (length(bad) != 1) Fail(paste("NA-vs-number should be 1 difference, got", length(bad)))
if (bad[[1]]$param != "LAMZHL") Fail(paste("wrong parameter flagged:", bad[[1]]$param))
## 3. And the mirror case: a real expected value against a NA observed value.
e3 = expected
e3$LAMZHL[2] = 99 # subject 2 has no half-life to find
pq = runPQ(e3)
bad = Filter(function(x) !isTRUE(x$ok), pq$expected)
if (length(bad) != 1) Fail(paste("number-vs-NA should be 1 difference, got", length(bad)))
if (bad[[1]]$param != "LAMZHL") Fail(paste("wrong parameter flagged:", bad[[1]]$param))
## 4. A real numeric disagreement is still caught.
e4 = expected
e4$CMAX[1] = e4$CMAX[1] * 2
pq = runPQ(e4)
bad = Filter(function(x) !isTRUE(x$ok), pq$expected)
if (length(bad) != 1) Fail(paste("a doubled CMAX should be 1 difference, got", length(bad)))
if (bad[[1]]$param != "CMAX") Fail(paste("wrong parameter flagged:", bad[[1]]$param))
## 5. The re-run (reproducibility) check must keep treating NA/NA as equal.
pq = runPQ(expected)
if (!isTRUE(pq$reproducible)) Fail("re-running the same analysis was reported as irreproducible")
## ---- profile identifiers must survive into the report intact -------------------------
## The PROFILE column was a fixed 14 (and 12) characters wide and the id was cut to fit, so
## a multi-column key rendered as "DA-4505/01-S" for every subject - identical text for
## profiles that are not the same. A numeric key column made it worse: as.character() on a
## double emits up to 15 significant digits.
d2 = data.frame(SPEC = rep(c("DA-4505", "M7a"), each = 12),
SUBJID = rep(rep(c("01-S001", "01-S002"), each = 6), 2),
Cycle = "C1",
DOSE = rep(c(185.209193784379, 370.418387568759), each = 12),
Time = rep(c(0, 1, 2, 4, 8, 24), 4),
Conc = rep(c(0, 10, 16, 12, 8, 1), 4))
k2 = c("SPEC", "SUBJID", "Cycle", "DOSE")
r2 = tblNCA(d2, key = k2, colTime = "Time", colConc = "Conc", dose = 1, R2ADJ = 0)
pq = PQNCA(fileName = pdfOut, concData = d2, key = k2, colTime = "Time", colConc = "Conc",
dose = 1, R2ADJ = 0, expected = r2[, c(k2, "CMAX", "AUCLST")])
ids = vapply(pq$profiles, function(p) p$id, "")
if (length(unique(ids)) != 4) Fail(paste("profile ids are not distinct:", paste(ids, collapse=" | ")))
for (s in c("01-S001", "01-S002"))
if (!any(grepl(s, ids, fixed = TRUE)))
Fail(paste("SUBJID", s, "missing from the profile ids:", paste(ids, collapse=" | ")))
## the 15-significant-digit dose must not be carried into the id verbatim
if (any(grepl("185.209193784379", ids, fixed = TRUE)))
Fail("the profile id still carries a 15-significant-digit key value")
if (!any(grepl("185.2092", ids, fixed = TRUE)))
Fail(paste("the dose is missing or misformatted in the id:", paste(ids, collapse=" | ")))
## and the same ids must reach the expected-value rows
eids = unique(vapply(pq$expected, function(e) as.character(e$id), ""))
if (!setequal(eids, ids))
Fail(paste("expected-value rows use different ids:", paste(eids, collapse=" | ")))
cat("Test-PQNCA.R: OK\n")
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.