Skip to content

Commit

Permalink
Fixes #8, when providing time to calculations within an interval, sub…
Browse files Browse the repository at this point in the history
…tract away the time for th beginning of the interval. For example, Tmax on day 14 should be between 0 and 24 not 2*7*24+c(0, 24)
  • Loading branch information
billdenney committed Dec 22, 2015
1 parent 61a0d80 commit 61fd1fb
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/pk.calc.all.R
Expand Up @@ -146,7 +146,9 @@ pk.nca.interval <- function(conc, time, interval, options=list()) {
if (arg == "conc") {
call.args[[arg]] <- conc
} else if (arg == "time") {
call.args[[arg]] <- time
## Realign the time to be relative to the start of the
## interval
call.args[[arg]] <- time - interval$start[1]
} else if (arg == "options") {
call.args[[arg]] <- options
} else if (any(mask.arg <- ret$PPTESTCD %in% arg)) {
Expand Down
72 changes: 72 additions & 0 deletions tests/testthat/test-pk.calc.all.R
@@ -1,2 +1,74 @@
context("All NCA calculations")

source("generate.data.R")

test_that("pk.nca", {
## Note that generate.conc sets the random seed, so it doesn't have
## to happen here.
tmpconc <- generate.conc(2, 1, 0:24)
tmpdose <- generate.dose(tmpconc)
myconc <- PKNCAconc(tmpconc, conc~time|treatment+ID)
mydose <- PKNCAdose(tmpdose, dose~time|treatment+ID)
mydata <- PKNCAdata(myconc, mydose)
myresult <- pk.nca(mydata)

expect_equal(names(myresult),
c("result", "data", "provenance"),
info="Make sure that the result has the expected names (and only the expected names) in it.")

## Test each of the pieces for myresult for accuracy

expect_equal(myresult$data, {
tmp <- mydata
## The options should be the default options after the
## calculations are done.
tmp$options <- PKNCA.options()
tmp
}, info="The data is just a copy of the input data plus an instantiation of the PKNCA.options")

## The specific order of the levels isn't important-- the fact that
## they are factors and that the set doesn't change is important.
test.code.levels <- levels(myresult$result$PPTESTCD)
verify.result <-
data.frame(
start=0,
end=c(24, rep(Inf, 12),
24, rep(Inf, 12)),
treatment="Trt 1",
ID=rep(c(1, 2), each=13),
PPTESTCD=factor(rep(c("auclast", "cmax", "tmax", "tlast",
"lambda.z", "r.squared", "adj.r.squared",
"lambda.z.time.first", "lambda.z.n.points",
"clast.pred", "half.life", "span.ratio",
"aucinf"),
times=2),
levels=test.code.levels),
PPORRES=c(13.54, 0.9998, 4.000, 24.00,
0.04297, 0.9072, 0.9021, 5.000,
20.00, 0.3356, 16.13, 1.178,
21.55, 14.03, 0.9410, 2.000,
24.00, 0.05689, 0.9000, 0.8944,
5.000, 20.00, 0.3011, 12.18,
1.560, 19.56),
stringsAsFactors=FALSE)
expect_equal(myresult$result, verify.result,
tol=0.001)

## Dosing not at time 0
tmpconc.multi <- generate.conc(2, 1, 0:24)
tmpdose.multi <- generate.dose(tmpconc)
tmpconc.multi$time <- tmpconc.multi$time + 2
tmpdose.multi$time <- tmpdose.multi$time + 2
myconc.multi <- PKNCAconc(tmpconc.multi, conc~time|treatment+ID)
mydose.multi <- PKNCAdose(tmpdose.multi, dose~time|treatment+ID)
mydata.multi <- PKNCAdata(myconc.multi, mydose.multi)
myresult.multi <- pk.nca(mydata.multi)

verify.result.multi <- verify.result
verify.result.multi$start <- verify.result.multi$start + 2
verify.result.multi$end <- verify.result.multi$end + 2
expect_equal(myresult.multi$result, verify.result.multi,
tol=0.001,
info="Shifted dosing works the same as un-shifted where time parameters like tmax and tlast are reported relative to the start of the interval")

})

0 comments on commit 61fd1fb

Please sign in to comment.