Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #8, when providing time to calculations within an interval, sub…
…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
1 parent
61a0d80
commit 61fd1fb
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
|
||
}) |