├── mangoNCA ├── LICENSE ├── data │ ├── shapeROutput.RData │ ├── wnl_data.csv │ ├── wnl_analysis_linlog.csv │ └── wnl_analysis.csv ├── inst │ └── testing │ │ ├── runit.auclast.R │ │ ├── runit.VZObs.R │ │ ├── runit.VZPred.R │ │ ├── runit.CLPred.R │ │ ├── runit.VSSPred.R │ │ ├── runit.CLObs.R │ │ ├── runit.VSSObs.R │ │ ├── runit.ncainitialized.R │ │ ├── runit.VSS.R │ │ ├── runit.VZ.R │ │ ├── runit.checkLambdaZStats.R │ │ ├── runit.MRTInfPredSD.R │ │ ├── runit.CminTmin.R │ │ ├── runit.checkpeaktrough.R │ │ ├── runit.MRTSD.R │ │ ├── runit.checkorderedvector.R │ │ ├── runit.pcExtrap.R │ │ ├── runit.CmaxTmax.R │ │ ├── runit.MRTInfObsSD.R │ │ ├── runit.clearance.R │ │ ├── runit.MRTInfPredSS.R │ │ ├── runit.ncapeaktrough.R │ │ ├── runit.clasttlast.R │ │ ├── runit.checksinglelogical.R │ │ ├── runit.checksinglecharacter.R │ │ ├── runit.auclin.R │ │ ├── runit.auclog.R │ │ ├── runit.checksinglenumeric.R │ │ ├── runit.getConcentration.R │ │ ├── runit.AUCInfPred.R │ │ ├── runit.AUCInfObs.R │ │ ├── runit.AUMCPartial.R │ │ └── runit.AUCPartial.R ├── man │ ├── getWhichVersion.Rd │ ├── isErrorWithMessage.Rd │ ├── pcExtrap.Rd │ ├── getLambdaz.Rd │ ├── MRTSD.Rd │ ├── VSS.Rd │ ├── runMangoNcaTests.Rd │ ├── VZ.Rd │ ├── ncaInitialized.Rd │ ├── MRTInfObsSD.Rd │ ├── MRTInfPredSD.Rd │ ├── clearance.Rd │ ├── chooseNumPointsAction.Rd │ ├── VZObs.Rd │ ├── VZPred.Rd │ ├── CminTmin.Rd │ ├── ClastTlast.Rd │ ├── usedPoints.Rd │ ├── CLObs.Rd │ ├── VSSObs.Rd │ ├── VSSPred.Rd │ ├── CLPred.Rd │ ├── CmaxTmax.Rd │ ├── ncaPeakTrough.Rd │ ├── predictConc.Rd │ ├── AUMCPartial.Rd │ ├── fixedPoints.Rd │ ├── AUCLin.Rd │ ├── getConcentration.Rd │ ├── AUCLog.Rd │ ├── getTerminalAUC.Rd │ ├── selectPoints.Rd │ ├── getPartialAUC.Rd │ ├── AUCPartial.Rd │ ├── AUCLast.Rd │ ├── lambdaZStatistics.Rd │ ├── AUCInfObs.Rd │ ├── AUCInfPred.Rd │ ├── ncaComplete.Rd │ └── ncaAnalysis.Rd ├── NAMESPACE ├── DESCRIPTION └── R │ ├── pcExtrap.R │ ├── MRTInfPredSS.R │ ├── testing.R │ ├── ncaInitialized.R │ ├── cmintmin.R │ ├── cmaxtmax.R │ ├── clasttlast.R │ ├── MRTInfSD.R │ ├── ncaPeaktrough.R │ ├── AUMCPartial.R │ ├── VZ.R │ └── VSS.R └── README.md /mangoNCA/LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2013-2017 2 | COPYRIGHT HOLDER: Mango Solutions -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mangoNCA 2 | 3 | RapidNCA 1.0.0-573 released at mangoNCA version 1.1.111932 -------------------------------------------------------------------------------- /mangoNCA/data/shapeROutput.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MangoTheCat/mangoNCA/master/mangoNCA/data/shapeROutput.RData -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.auclast.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MangoTheCat/mangoNCA/master/mangoNCA/inst/testing/runit.auclast.R -------------------------------------------------------------------------------- /mangoNCA/data/wnl_data.csv: -------------------------------------------------------------------------------- 1 | "SUBJECT","CONC","TIME","DOSE" 2 | 1007,0,0,10 3 | 1007,435,5.8,10 4 | 1007,363,6.8,10 5 | 1007,113,172.5,10 6 | 1007,47,343,10 7 | 1033,87,0,20 8 | 1033,1134,5.3,20 9 | 1033,525,76.3,20 10 | 1033,306,172.3,20 11 | 1033,241,244.1,20 12 | 1033,172,339.4,20 13 | 1037,3743,4.7,20 14 | 1037,2844,74.8,20 15 | 1037,1540,170.2,20 16 | 1037,1263,240,20 17 | 1037,730,337.4,20 18 | -------------------------------------------------------------------------------- /mangoNCA/man/getWhichVersion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ncaInitialized.R 3 | \name{getWhichVersion} 4 | \alias{getWhichVersion} 5 | \title{Function to return R version to R.NET} 6 | \usage{ 7 | getWhichVersion() 8 | } 9 | \value{ 10 | data frame with 1 column, Version and 1 character row 11 | } 12 | \description{ 13 | Get R Version 14 | } 15 | \details{ 16 | This is a trivial test used to confirm that R is running correctly. 17 | } 18 | \examples{ 19 | getWhichVersion() 20 | } 21 | \author{ 22 | Mango Solutions 23 | } 24 | \keyword{math} 25 | \keyword{nca} 26 | -------------------------------------------------------------------------------- /mangoNCA/man/isErrorWithMessage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/testing.R 3 | \name{isErrorWithMessage} 4 | \alias{isErrorWithMessage} 5 | \title{Check if object is error with given error message} 6 | \usage{ 7 | isErrorWithMessage(x, expectedMessage) 8 | } 9 | \arguments{ 10 | \item{x}{Object to check} 11 | 12 | \item{expectedMessage}{String with expected message} 13 | } 14 | \value{ 15 | TRUE or FALSE depending on whether or not x is as expected 16 | } 17 | \description{ 18 | Check if an object is of class "try-error", and that it contains a specific error message. 19 | } 20 | \author{ 21 | Mango Solutions 22 | } 23 | -------------------------------------------------------------------------------- /mangoNCA/man/pcExtrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pcExtrap.R 3 | \name{pcExtrap} 4 | \alias{pcExtrap} 5 | \title{Percentage Extrapolated} 6 | \usage{ 7 | pcExtrap(Whole, Measured) 8 | } 9 | \arguments{ 10 | \item{Whole}{Value of whole} 11 | 12 | \item{Measured}{Value of Whole which was measured} 13 | } 14 | \value{ 15 | Single numeric value (percentage) of Whole which was extrapolated 16 | } 17 | \description{ 18 | Percentage of Whole Extrapolated. 19 | } 20 | \note{ 21 | The formula used to calculate this 22 | quantity is \deqn{ 100 * (Whole - Measured) / Whole } 23 | } 24 | \examples{ 25 | pcExtrap(Whole = 100, Measured = 33) 26 | } 27 | \author{ 28 | Mango Solutions 29 | } 30 | \keyword{math} 31 | -------------------------------------------------------------------------------- /mangoNCA/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(AUCInfObs) 4 | export(AUCInfPred) 5 | export(AUCLast) 6 | export(AUCPartial) 7 | export(CLObs) 8 | export(CLPred) 9 | export(ClastTlast) 10 | export(CmaxTmax) 11 | export(MRTInfObsSD) 12 | export(MRTInfPredSD) 13 | export(MRTSD) 14 | export(VSS) 15 | export(VSSObs) 16 | export(VSSPred) 17 | export(VZ) 18 | export(VZObs) 19 | export(VZPred) 20 | export(clearance) 21 | export(fixedPoints) 22 | export(getConcentration) 23 | export(getPartialAUC) 24 | export(getWhichVersion) 25 | export(lambdaZStatistics) 26 | export(ncaAnalysis) 27 | export(ncaComplete) 28 | export(ncaInitialized) 29 | export(ncaPeakTrough) 30 | export(predictConc) 31 | export(runMangoNcaTests) 32 | export(selectPoints) 33 | export(usedPoints) 34 | -------------------------------------------------------------------------------- /mangoNCA/man/getLambdaz.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lambdaz.R 3 | \name{getLambdaz} 4 | \alias{getLambdaz} 5 | \title{Perform \code{lm} on logConc-Time data} 6 | \usage{ 7 | getLambdaz(timeConc) 8 | } 9 | \arguments{ 10 | \item{timeConc}{Data frame with columns logConc and Time used for calculating lambdaz.} 11 | } 12 | \value{ 13 | \code{"lm"} object to be used by \code{getLambdaZStatistics}. 14 | } 15 | \description{ 16 | Calculate lambdaz using lm 17 | } 18 | \details{ 19 | Calculates lambdaz for a data frame consisting of logConc and Time. 20 | The \code{lm} function is used to fit a linear regression of the last \code{numPoints} 21 | concentration against time. These are counted from (and include) the last measurable concentration. 22 | } 23 | -------------------------------------------------------------------------------- /mangoNCA/man/MRTSD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MRTInfSD.R 3 | \name{MRTSD} 4 | \alias{MRTSD} 5 | \title{Calculate Mean Residence Time} 6 | \usage{ 7 | MRTSD(AUC, AUMC, Dof = 0) 8 | } 9 | \arguments{ 10 | \item{AUC}{Single numeric value, area under the concentration time curve} 11 | 12 | \item{AUMC}{Single numeric value, area under the concentration time moment curve} 13 | 14 | \item{Dof}{Duration of infusion, single numeric value} 15 | } 16 | \value{ 17 | A single numeric vector. 18 | } 19 | \description{ 20 | Mean Residence Time (Single Dose) 21 | } 22 | \details{ 23 | Calculates mean residence time from AUMC, AUC and duration of infusion. 24 | The value returned is: 25 | \deqn{\frac{AUMC}{AUC} - \frac{Dof}{2}} 26 | } 27 | \author{ 28 | Mango Solutions 29 | } 30 | \keyword{math} 31 | -------------------------------------------------------------------------------- /mangoNCA/man/VSS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/VSS.R 3 | \name{VSS} 4 | \alias{VSS} 5 | \title{Volume Distribution at Steady-State (observed)} 6 | \usage{ 7 | VSS(MRT, CL, Safe = TRUE) 8 | } 9 | \arguments{ 10 | \item{MRT}{Single numeric value of time} 11 | 12 | \item{CL}{Single numeric value of clearance} 13 | 14 | \item{Safe}{Single logical value declaring whether to perform redundant data checks (default is TRUE).} 15 | } 16 | \value{ 17 | Single numeric value 18 | } 19 | \description{ 20 | Calculate Volume of Distribution at Steady-State. 21 | } 22 | \details{ 23 | This function simply calculates VSS from MRT and CL when they have already been calculated. 24 | \deqn{ VSS = MRT * CL } 25 | } 26 | \examples{ 27 | VSS(MRT = 20, CL = 0.1) 28 | } 29 | \author{ 30 | Mango Solutions 31 | } 32 | \keyword{math} 33 | -------------------------------------------------------------------------------- /mangoNCA/man/runMangoNcaTests.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/testing.R 3 | \name{runMangoNcaTests} 4 | \alias{runMangoNcaTests} 5 | \title{Run MangoNca Test Suite} 6 | \usage{ 7 | runMangoNcaTests(testPath = system.file(package = "MangoNca", "testing")) 8 | } 9 | \arguments{ 10 | \item{testPath}{A single string holding the path to the internal test suite scripts} 11 | } 12 | \value{ 13 | suiteResults 14 | } 15 | \description{ 16 | Execute the RUnit unit tests suites for the MangoNca package. 17 | Prints an html report with name "Unit_Test_Report_MangoNca___.html" 18 | The package version is extracted from the DESCRIPTION file 19 | } 20 | \examples{ 21 | \dontrun{ 22 | runMangoNcaTests() 23 | } 24 | } 25 | \author{ 26 | Mango Solutions 27 | } 28 | \keyword{debugging} 29 | \keyword{programming} 30 | -------------------------------------------------------------------------------- /mangoNCA/data/wnl_analysis_linlog.csv: -------------------------------------------------------------------------------- 1 | Rsq_adjusted,ROutput_intercept,No_points_lambda_z,Rsq,Corr_XY,AUC_.Extrap_obs....,AUC_.Extrap_pred....,AUCINF_obs..hr.ug.mL.,AUCINF_pred..hr.ug.mL.,AUClast..hr.ug.mL.,AUMC_.Extrap_obs....,AUMC_.Extrap_pred....,AUMCINF_obs..hr.hr.ug.mL.,AUMCINF_pred..hr.hr.ug.mL.,AUMClast..hr.hr.ug.mL.,Clast..ug.mL.,Cl_obs..mL.hr.kg.,Cl_pred..mL.hr.kg.,Cmax..ug.mL.,ROutput_Cmin,ROutput_Dof,ROutput_Dose,HL_Lambda_z..hr.,Lambda_z..1.hr.,Lambda_z_lower..hr.,Lambda_z_upper..hr.,MRTINF_obs..hr.,MRTINF_pred..hr.,MRTlast..hr.,ROutput_Peak,Tlast..hr.,Tmax..hr.,ROutput_Tmin,ROutput_Trough,Vss_obs..mL.kg.,Vss_pred..mL.kg.,Vz_obs..mL.kg.,Vz_pred..mL.kg.,ROutput_Error 2 | 1,NA,3,1,-1,0.4079,0.4082,6.2621,6.2621,6.2365,7.8284,7.8338,4.9574,4.9576,4.5693,0.008,1596.9134,1596.9086,18.01,NA,0,10000,2.2132,0.3132,8,12,0.7916,0.7917,0.7327,NA,12,0.0167,NA,NA,1264.1909,1264.2568,5098.8526,5098.8372,0 3 | -------------------------------------------------------------------------------- /mangoNCA/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: mangoNCA 2 | Type: Package 3 | Title: Mango Non-Compartmental Analysis 4 | Version: 1.1.111932 5 | Date: 2013-9-2 14:23:52 6 | Author: Mango Business Solutions 7 | Maintainer: Mango Business Solutions 8 | Description: This package is a Non-Compartmental Analysis (NCA) parameter calculation engine 9 | which returns pharmacokinetic parameters for concentration-time data. 10 | The interface function is ncaAnalysis. This function performs data checking then, 11 | provided that there are more than three rows of data, passes the data to ncaComplete. 12 | This function calls functions to return the PK parameters. 13 | Suggests: RUnit (>= 0.4.26) 14 | Depends: methods, stats, R (>= 2.11.0) 15 | License: MIT + file LICENSE 16 | URL: http://www.mango-solutions.com 17 | Copyright: 2013 Mango Business Solutions 18 | RoxygenNote: 6.0.1 19 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.VZObs.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: $ 3 | # Last changed by: $LastChangedBy: $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.VZObs <- function() 10 | { 11 | # TEST 1 : Contrived 12 | 13 | test1 <- VZObs(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, numPoints = 3, Dose = 133.0336246) 14 | checkEquals( test1, 15 | 10, tol = 1e-06, msg = " || TEST 1 : Contrived data set\n" ) 16 | 17 | # TEST 2 : Theoph data set 18 | 19 | Theoph2 <- subset(Theoph, Subject == 2) 20 | test2 <- VZObs(Conc = Theoph2$conc, Time = Theoph2$Time, numPoints = 3, Dose = Theoph2$Dose[1]) 21 | checkEquals( test2, 0.4235660279, tol = 1e-06, msg = " || TEST 2 : Theoph data set\n" ) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.VZPred.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: $ 3 | # Last changed by: $LastChangedBy: $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.VZPred <- function() 10 | { 11 | # TEST 1 : Contrived 12 | 13 | test1 <- VZPred(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, numPoints = 3, Dose = 13.19426) 14 | checkEquals( test1, 15 | 1, tol = 1e-06, msg = " || TEST 1 : Contrived data set\n" ) 16 | 17 | # TEST 2 : Theoph data set 18 | 19 | Theoph2 <- subset(Theoph, Subject == 2) 20 | test2 <- VZPred(Conc = Theoph2$conc, Time = Theoph2$Time, numPoints = 3, Dose = Theoph2$Dose[1]) 21 | checkEquals( test2, 0.4239718, tol = 1e-06, msg = " || TEST 2 : Theoph data set\n" ) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mangoNCA/man/VZ.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/VZ.R 3 | \name{VZ} 4 | \alias{VZ} 5 | \title{Volume Distribution at Steady-State (observed)} 6 | \usage{ 7 | VZ(lambdaz, AUCInf, Dose, Safe = TRUE) 8 | } 9 | \arguments{ 10 | \item{Safe}{Single logical value declaring whether to perform redundant data checks (default is TRUE).} 11 | 12 | \item{MRT}{Single numeric value of time} 13 | 14 | \item{CL}{Single numeric value of clearance} 15 | } 16 | \value{ 17 | Single numeric value 18 | } 19 | \description{ 20 | Calculate Volume of Distribution for single dose from terminal phase. 21 | } 22 | \details{ 23 | This function simply calculates VSS from MRT and CL when they have already been calculated. 24 | \deqn{ VSS = MRT * CL } 25 | } 26 | \examples{ 27 | VZ(lambdaz = 0.001, AUCInf = 1000, Dose = 10) 28 | } 29 | \author{ 30 | Mango Solutions 31 | } 32 | \keyword{math} 33 | -------------------------------------------------------------------------------- /mangoNCA/man/ncaInitialized.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ncaInitialized.R 3 | \name{ncaInitialized} 4 | \alias{ncaInitialized} 5 | \title{Function to return R version to R.NET} 6 | \usage{ 7 | ncaInitialized(rVersionMinor = 14.1) 8 | } 9 | \arguments{ 10 | \item{rVersionMinor}{single numeric or character string describing R version to test against} 11 | } 12 | \value{ 13 | data frame 14 | } 15 | \description{ 16 | Check MangoNca is Initialized 17 | } 18 | \details{ 19 | This is a second test used to confirm that R is running correctly. 20 | Returns a data frame with 3 columns and 1 row: 21 | \enumerate{ 22 | \item \code{rVersionOk} logical 23 | \item \code{rArchOk} logical 24 | \item \code{statsOk} logical 25 | } 26 | } 27 | \examples{ 28 | ncaInitialized() 29 | } 30 | \author{ 31 | Mango Solutions 32 | } 33 | \keyword{math} 34 | \keyword{nca} 35 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.CLPred.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 04/04/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.CLPred <- function() 10 | { 11 | # TEST 1 : Contrived 12 | 13 | test1 <- CLPred(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, numPoints = 3, Dose = 38.07059031) 14 | checkEquals( test1, 1, tol = 1e-06, msg = " || TEST 1 : Contrived data set\n" ) 15 | 16 | # TEST 2 : Theoph data set 17 | 18 | Theoph2 <- subset(Theoph, Subject == 2) 19 | test2 <- CLPred(Conc = Theoph2$conc, Time = Theoph2$Time, numPoints = 3, Dose = Theoph2$Dose[1]) 20 | checkEquals( test2, 0.04395041207, tol = 1e-06, msg = " || TEST 2 : Theoph data set\n" ) 21 | } 22 | 23 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.VSSPred.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.VSSPred <- function() 10 | { 11 | # TEST 1 : Contrived 12 | 13 | test1 <- VSSPred(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, numPoints = 3, Dose = 16.67643, Dof = 2) 14 | checkEquals( test1, 1, tol = 1e-06, msg = " || TEST 1 : Contrived data set\n" ) 15 | 16 | # TEST 2 : Theoph data set 17 | 18 | Theoph2 <- subset(Theoph, Subject == 2) 19 | test2 <- VSSPred(Conc = Theoph2$conc, Time = Theoph2$Time, numPoints = 3, Dose = Theoph2$Dose[1], Dof = 2) 20 | checkEquals( test2, 0.3942036, tol = 1e-06, msg = " || TEST 2 : Theoph data set\n" ) 21 | } 22 | 23 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.CLObs.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 04/04/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.CLObs <- function() 10 | { 11 | # TODO All testing 12 | # TEST 1 : Contrived 13 | 14 | test1 <- CLObs(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, numPoints = 3, Dose = 38.38539008) 15 | checkEquals( test1, 1, tol = 1e-06, msg = " || TEST 1 : Contrived data set\n" ) 16 | 17 | # TEST 2 : Theoph data set 18 | 19 | Theoph2 <- subset(Theoph, Subject == 2) 20 | test2 <- CLObs(Conc = Theoph2$conc, Time = Theoph2$Time, numPoints = 3, Dose = Theoph2$Dose[1]) 21 | checkEquals( test2, 0.04390834788, tol = 1e-06, msg = " || TEST 2 : Theoph data set\n" ) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.VSSObs.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 19/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.VSSObs <- function() 10 | { 11 | # TODO All testing 12 | # TEST 1 : Contrived 13 | 14 | test1 <- VSSObs(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, numPoints = 3, Dose = 16.36731493, Dof = 2) 15 | checkEquals( test1, 1, tol = 1e-06, msg = " || TEST 1 : Contrived data set\n" ) 16 | 17 | # TEST 2 : Theoph data set 18 | 19 | Theoph2 <- subset(Theoph, Subject == 2) 20 | test2 <- VSSObs(Conc = Theoph2$conc, Time = Theoph2$Time, numPoints = 3, Dose = Theoph2$Dose[1], Dof = 2) 21 | checkEquals( test2, 0.3948339484, tol = 1e-06, msg = " || TEST 2 : Theoph data set\n" ) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mangoNCA/man/MRTInfObsSD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MRTInfSD.R 3 | \name{MRTInfObsSD} 4 | \alias{MRTInfObsSD} 5 | \title{Calculate Mean Residence Time to infinity (observed) for steady-state data, model M3} 6 | \usage{ 7 | MRTInfObsSD(Conc, Time, numPoints, Dof = 0, addT0 = FALSE) 8 | } 9 | \arguments{ 10 | \item{Conc}{Vector of concentrations} 11 | 12 | \item{Time}{Vector of times. Must be sorted, and without duplicates} 13 | 14 | \item{numPoints}{Number of points to use for lambda z calculation. See \code{\link{lambdaZStatistics}}} 15 | 16 | \item{Dof}{Duration of infusion. Must be a} 17 | } 18 | \value{ 19 | A single numeric vector. The value returned is: 20 | \deqn{\frac{AUMCInfObs}{AUCInfObs} - \frac{Dof}{2}} 21 | } 22 | \description{ 23 | Mean Residence Time (Single Dose) Observed 24 | } 25 | \details{ 26 | Calculates the mean residence time to infinity (observed), for steady-state models of type "M3". 27 | } 28 | \author{ 29 | Mango Solutions 30 | } 31 | \keyword{math} 32 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.ncainitialized.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: ccampbell $ 3 | # Last changed by: $LastChangedBy: 19/01/2012 $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.ncaInitialized <- function() 10 | { 11 | # TEST 1 : Check Initialize Output 12 | 13 | test1 <- ncaInitialized() 14 | 15 | expectedOut <- data.frame(rVersionOk = TRUE, rArchOk = TRUE, statsOk = TRUE) 16 | 17 | # TODO: reconcile build and application R versions 18 | checkEquals(test1[, 2:3], expectedOut[, 2:3], msg = " || TEST 1 : Check Initilize Output\n" ) 19 | 20 | } 21 | 22 | test.getWhichVersion <- function() 23 | { 24 | # TEST 1 : Contrived check no errors 25 | 26 | test1 <- as.character(getWhichVersion()[[1]]) 27 | 28 | test1 <- substr(test1, 1, 13) 29 | 30 | checkEquals( test1, "R version 2.1", msg = " || TEST 1 : Check Version\n" ) 31 | 32 | } 33 | -------------------------------------------------------------------------------- /mangoNCA/man/MRTInfPredSD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MRTInfSD.R 3 | \name{MRTInfPredSD} 4 | \alias{MRTInfPredSD} 5 | \title{Calculate Mean Residence Time to infinity (predicted) for steady-state data, model M3} 6 | \usage{ 7 | MRTInfPredSD(Conc, Time, numPoints, Dof = 0, addT0 = FALSE) 8 | } 9 | \arguments{ 10 | \item{Conc}{Vector of concentrations} 11 | 12 | \item{Time}{Vector of times. Must be sorted, and without duplicates} 13 | 14 | \item{numPoints}{Number of points to use for lambda z calculation. See \code{\link{lambdaZStatistics}}} 15 | 16 | \item{Dof}{Duration of infusion, single numeric value} 17 | 18 | \item{addT0}{Single logical value determining whether T = 0 should be added} 19 | } 20 | \value{ 21 | A single numeric vector. The value returned is: 22 | \deqn{\frac{AUMCInfPred}{AUCInfPred} - \frac{Dof}{2}} 23 | } 24 | \description{ 25 | Mean Residence Time (Single Dose) Predicted 26 | } 27 | \details{ 28 | Calculates the mean residence time to infinity (predicted), for steady-state models of type "M3". 29 | } 30 | \author{ 31 | Mango Solutions 32 | } 33 | \keyword{math} 34 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.VSS.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 03/02/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.VSS <- function() 10 | { 11 | isErrorWithMessage <- MangoNca:::isErrorWithMessage 12 | 13 | # TEST 1 : Trivial Example 14 | 15 | test1 <- VSS(MRT = 100, CL = 0.5, Safe = TRUE) 16 | checkEquals( test1, 50, msg = " || TEST 1 : Trivial Example\n" ) 17 | 18 | # TEST 2 : Trivial Example unsafe 19 | 20 | test2 <- VSS(MRT = 200, CL = 0.25, Safe = FALSE) 21 | checkEquals( test2, 50, msg = " || TEST 2 : Trivial Example unsafe\n" ) 22 | 23 | # TEST 3 : MRT is NA 24 | 25 | test3 <- try(VSS(MRT = NA, CL = 0.5, Safe = TRUE), silent = TRUE) 26 | checkTrue(isErrorWithMessage( test3, "Error in checkSingleNumeric(MRT, description = \"MRT\", \"VSS\") : \n Error in VSS : MRT is not a numeric of length 1. Value is: NA\n")) 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mangoNCA/man/clearance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/clearance.R 3 | \name{clearance} 4 | \alias{clearance} 5 | \title{Clearance} 6 | \usage{ 7 | clearance(AUCInf, Dose, Safe = TRUE) 8 | } 9 | \arguments{ 10 | \item{AUCInf}{A numeric value} 11 | 12 | \item{Dose}{A numeric value} 13 | 14 | \item{Safe}{A single logical} 15 | } 16 | \value{ 17 | Single numeric of clearance 18 | } 19 | \description{ 20 | Clearance 21 | } 22 | \details{ 23 | Calculates Clearance, which is equal to administered Dose divided by AUCInf. 24 | } 25 | \note{ 26 | The following additional input processing/checks are performed: 27 | \enumerate{ 28 | \item \code{AUCInf} must be a numeric vector of length 1, otherwise an exception will be generated. If 29 | \code{AUCInf} is \code{NA}, 0 or less, \code{NA} will be returned for Observed 30 | \item \code{Dose} must be a numeric vector of length 1, otherwise an exception will be generated. If 31 | \code{Dose} is \code{NA}, 0 or less, \code{NA} will be returned for both 32 | } 33 | } 34 | \examples{ 35 | clearance(AUCInf = 100, Dose = 10) 36 | } 37 | \author{ 38 | Mango Business Solutions 39 | } 40 | \keyword{math} 41 | -------------------------------------------------------------------------------- /mangoNCA/R/pcExtrap.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: $ 3 | # Last changed by: $LastChangedBy: $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | #' Percentage of Whole Extrapolated. 11 | #' @param Whole Value of whole 12 | #' @param Measured Value of Whole which was measured 13 | #' @title Percentage Extrapolated 14 | #' @return Single numeric value (percentage) of Whole which was extrapolated 15 | #' @note The formula used to calculate this 16 | #' quantity is \deqn{ 100 * (Whole - Measured) / Whole } 17 | #' @author Mango Solutions 18 | #' @keywords math 19 | #' @examples 20 | #' pcExtrap(Whole = 100, Measured = 33) 21 | 22 | pcExtrap <- function(Whole, Measured) 23 | { 24 | checkSingleNumeric(Whole, description = "Whole") 25 | checkSingleNumeric(Measured, description = "Measured") 26 | 27 | if(is.na(Whole[1]) | Whole[1] <= 0 | Whole[1] == Inf | is.na(Measured[1]) | Measured[1] < 0 ) { 28 | return(as.numeric(NA)) 29 | } 30 | 31 | extrap <- 100 * (Whole - Measured) / Whole 32 | 33 | return(extrap) 34 | } 35 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.VZ.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 04/04/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.VZ <- function() 10 | { 11 | isErrorWithMessage <- MangoNca:::isErrorWithMessage 12 | 13 | # TEST 1 : Trivial Example 14 | 15 | test1 <- VZ(lambdaz = 0.001, AUCInf = 1000, Dose = 6, Safe = TRUE) 16 | checkEquals( test1, 6, msg = " || TEST 1 : Trivial Example\n" ) 17 | 18 | # TEST 2 : Trivial Example unsafe 19 | 20 | test2 <- VZ(lambdaz = 0.002, AUCInf = 2000, Dose = 40, Safe = FALSE) 21 | checkEquals( test2, 10, msg = " || TEST 2 : Trivial Example unsafe\n" ) 22 | 23 | # TEST 3 : lambdaz is NA 24 | 25 | test3 <- try(VZ(lambdaz = NA, AUCInf = 1000, Dose = 10, Safe = TRUE), silent = TRUE) 26 | checkTrue(isErrorWithMessage( test3, "Error in checkSingleNumeric(lambdaz, description = \"lambdaz\", functionName = \"VZ\") : \n Error in VZ : lambdaz is not a numeric of length 1. Value is: NA\n")) 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mangoNCA/man/chooseNumPointsAction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ncaComplete.R 3 | \name{chooseNumPointsAction} 4 | \alias{chooseNumPointsAction} 5 | \title{Choose how to handle numPoints} 6 | \usage{ 7 | chooseNumPointsAction(Conc = Conc, Time = Time, 8 | numPoints = as.numeric(NA), usePoints = NULL, excPoints = FALSE) 9 | } 10 | \arguments{ 11 | \item{Conc}{Vector of concentrations} 12 | 13 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 14 | 15 | \item{numPoints}{single numeric value declaring number of points to use} 16 | 17 | \item{usePoints}{If \code{NULL} (default) automatically select, else, logical vector of points to use for calculation of terminal phase. Used rows are flagged by usePoints as \code{TRUE}.} 18 | 19 | \item{Logical}{vector (\code{FALSE} by default) excludeing \code{TRUE} rows from automatic calculation of terminal phase.} 20 | } 21 | \value{ 22 | length 2 list with elements ACTION, a single character value, and MINROWSFORLAMBDAZ, a single numeric with value 3 23 | } 24 | \description{ 25 | Decide whether to use or automatically calculate numPoints 26 | } 27 | \author{ 28 | Mango Solutions 29 | } 30 | \keyword{math} 31 | -------------------------------------------------------------------------------- /mangoNCA/man/VZObs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/VZ.R 3 | \name{VZObs} 4 | \alias{VZObs} 5 | \title{Terminal Volume Distribution, Single Dose (observed)} 6 | \usage{ 7 | VZObs(Conc, Time, Dose, numPoints = NULL) 8 | } 9 | \arguments{ 10 | \item{Conc}{Vector of concentrations} 11 | 12 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 13 | 14 | \item{Dose}{Single numeric with dose amount} 15 | 16 | \item{numPoints}{Number of points to use for the lambda z calculation(s)} 17 | 18 | \item{Dof}{duration of infusion (default NULL)} 19 | } 20 | \value{ 21 | Single numeric value 22 | } 23 | \description{ 24 | Terminal Volume Distribution, Single Dose (observed) 25 | } 26 | \details{ 27 | Calculates volume distribution for single dose from terminal phase (observed). 28 | } 29 | \note{ 30 | All input checks / error handling for LambdaZStatistics and AUCInfPred apply. 31 | The formula used to calculate this quantity is 32 | \deqn{ Dose / {\lambda}_z * AUC({\inf})_Obs } 33 | } 34 | \examples{ 35 | Theoph1 <- subset(Theoph, Subject == 1) 36 | VZObs(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1]) 37 | } 38 | \author{ 39 | Mango Solutions 40 | } 41 | \keyword{math} 42 | -------------------------------------------------------------------------------- /mangoNCA/man/VZPred.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/VZ.R 3 | \name{VZPred} 4 | \alias{VZPred} 5 | \title{Terminal Volume Distribution, Single Dose (predicted)} 6 | \usage{ 7 | VZPred(Conc, Time, Dose, numPoints = NULL) 8 | } 9 | \arguments{ 10 | \item{Conc}{Vector of concentrations} 11 | 12 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 13 | 14 | \item{Dose}{Single numeric with dose amount} 15 | 16 | \item{numPoints}{Number of points to use for the lambda z calculation(s)} 17 | 18 | \item{Dof}{duration of infusion (default NULL)} 19 | } 20 | \value{ 21 | Single numeric value 22 | } 23 | \description{ 24 | Terminal Volume Distribution, Single Dose (predicted) 25 | } 26 | \details{ 27 | Calculates volume distribution for single dose from terminal phase (predicted). 28 | } 29 | \note{ 30 | All input checks / error handling for LambdaZStatistics and AUCInfPred apply. 31 | The formula used to calculate this quantity is 32 | \deqn{ Dose / {\lambda}_z * AUC({\inf})_Pred } 33 | } 34 | \examples{ 35 | Theoph1 <- subset(Theoph, Subject == 1) 36 | VZPred(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1]) 37 | } 38 | \author{ 39 | Mango Solutions 40 | } 41 | \keyword{math} 42 | -------------------------------------------------------------------------------- /mangoNCA/man/CminTmin.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmintmin.R 3 | \name{CminTmin} 4 | \alias{CminTmin} 5 | \title{Calculate Minimum Concentration and time of minimum concentration} 6 | \usage{ 7 | CminTmin(Conc, Time) 8 | } 9 | \arguments{ 10 | \item{Conc}{numeric vector of concentrations} 11 | 12 | \item{Time}{numeric vector of time points (parallel to \code{Conc})} 13 | } 14 | \value{ 15 | list with numeric scalar (length 1 vector) components "cmin", "tmin" and "index". 16 | } 17 | \description{ 18 | Finds the minimum concentration value and the first time point (in the sense of corresponding to the minimal index) 19 | with that concentration. 20 | } 21 | \note{ 22 | The following error checks / processing will be performed: 23 | \enumerate{ 24 | \item If \code{Conc} or \code{Time} are of length 0, NA is returned for both values 25 | \item If the sum of \code{Code} (after omitting missing values) is 0, NA is returned for both values 26 | \item \code{cmin} is computed by stripping NA values from \code{Conc} 27 | \item if \code{Conc} and \code{Time} are not equal length numeric vectors, an exception will be generated by \code{\link{checkNumericSameLength}} 28 | } 29 | } 30 | \examples{ 31 | Theoph2 <- subset(Theoph, Subject == 2) 32 | CminTmin( Theoph2$conc, Theoph2$Time ) 33 | } 34 | \keyword{math} 35 | -------------------------------------------------------------------------------- /mangoNCA/man/ClastTlast.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/clasttlast.R 3 | \name{ClastTlast} 4 | \alias{ClastTlast} 5 | \title{Calculate Last Measurable Concentration} 6 | \usage{ 7 | ClastTlast(Conc, Time) 8 | } 9 | \arguments{ 10 | \item{Conc}{numeric vector of concentrations} 11 | 12 | \item{Time}{numeric vector of time points (should be of equal length to Conc, and sorted).} 13 | } 14 | \value{ 15 | list with numeric scalar components \code{clast}, \code{tlast} and \code{index} 16 | } 17 | \description{ 18 | Finds the last measurable (non-zero) concentration value and the last time point 19 | with that concentration. 20 | } 21 | \note{ 22 | The following error checks / processing will be performed: 23 | \enumerate{ 24 | \item If \code{Conc} or \code{Time} are of length 0, a single NA is returned 25 | \item \code{Conc} and \code{Time} should be equal length numeric vectors, otherwise an exception will be generated 26 | \item It is assumed that these times and concentrations come from a single curve 27 | \item time should be sorted 28 | \item If the sum of \code{Conc} (after omitting missing values) is 0, returned values are NA 29 | } 30 | } 31 | \examples{ 32 | Theoph1 <- subset( Theoph, Subject == 1) 33 | ClastTlast( Conc = Theoph1$conc, Time = Theoph1$Time ) 34 | } 35 | \keyword{math} 36 | \keyword{utils} 37 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.checkLambdaZStats.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 21/10/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | test.checkLambdaZStats <- function() { 11 | 12 | if (!exists("checkLambdaZStats", mode = "function")) { checkLambdaZStats <- MangoNca:::checkLambdaZStats } 13 | 14 | # TEST 1: length 9 numeric 15 | 16 | lzVec <- c( 17 | Lambdaz = 1, 18 | intercept = exp(2), 19 | r2 = 1, 20 | adjr2 = 1, 21 | rhoXY = -1, 22 | tPhaseHalfLife = log(2), 23 | LambdazLower = 2, 24 | LambdazUpper = 2.75, 25 | numPoints = 4) 26 | 27 | test1 <- checkLambdaZStats(lzVec) 28 | checkTrue(is.null(test1), msg = " || TEST 1: length 9 numeric" ) 29 | 30 | # TEST 2: lambdaZStatistics output 31 | 32 | conc <- exp(seq(from = 0, by = -0.25, length.out = 4)) 33 | time <- seq(from = 2, by = 0.25, length.out = 4) 34 | 35 | lzOut <- lambdaZStatistics(Conc = conc, Time = time, numPoints = 4) 36 | 37 | test2 <- checkLambdaZStats(unlist(lzOut)) 38 | checkTrue(is.null(test2), msg = " || TEST 2: lambdaZStatistics output" ) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /mangoNCA/data/wnl_analysis.csv: -------------------------------------------------------------------------------- 1 | "Rsq_adjusted","ROutput_intercept","No_points_lambda_z","Rsq","Corr_XY","AUC_.Extrap_obs....","AUC_.Extrap_pred....","AUCINF_obs..hr.ug.mL.","AUCINF_pred..hr.ug.mL.","AUClast..hr.ug.mL.","AUMC_.Extrap_obs....","AUMC_.Extrap_pred....","AUMCINF_obs..hr.hr.ug.mL.","AUMCINF_pred..hr.hr.ug.mL.","AUMClast..hr.hr.ug.mL.","Clast..ug.mL.","Cl_obs..mL.hr.kg.","Cl_pred..mL.hr.kg.","Cmax..ug.mL.","ROutput_Cmin","ROutput_Dof","ROutput_Dose","HL_Lambda_z..hr.","Lambda_z..1.hr.","Lambda_z_lower..hr.","Lambda_z_upper..hr.","MRTINF_obs..hr.","MRTINF_pred..hr.","MRTlast..hr.","ROutput_Peak","Tlast..hr.","Tmax..hr.","ROutput_Tmin","ROutput_Trough","Vss_obs..mL.kg.","Vss_pred..mL.kg.","Vz_obs..mL.kg.","Vz_pred..mL.kg.","ROutput_Error" 2 | 0.9839,NA,3,0.9919,-0.996,12.3821,11.8247,62472.5045,62077.6234,54737.1,44.6599,43.3688,8791684.272,8591249.271,4865323.84,47,0.1601,0.1611,435,NA,1,10000,114.0803,0.0061,6.8,343,140.2289,137.8953,88.3853,NA,343,5.8,NA,NA,22.4465,22.2134,26.3449,26.5125,0 3 | 0.9729,NA,4,0.9819,-0.9909,22.5539,21.8344,182494.6244,180814.6948,141334.9,60.281,59.2792,39513521.78,38541345.3,15694359.48,172,0.1096,0.1106,1134,NA,1,20000,165.8706,0.0042,76.3,339.4,216.0188,212.6538,110.5438,NA,339.4,5.3,NA,NA,23.674,23.5217,26.2255,26.4692,0 4 | 0.978,NA,4,0.9853,-0.9926,18.4185,18.4421,788991.1026,789219.5496,643671,50.2295,50.2688,155206988.4,155329543.1,77247311.54,730,0.0253,0.0253,3743,NA,1,20000,137.9839,0.005,74.8,337.4,196.2158,196.3141,119.5106,NA,337.4,4.7,NA,NA,4.9738,4.9749,5.0462,5.0447,0 5 | -------------------------------------------------------------------------------- /mangoNCA/man/usedPoints.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/selectPoints.R 3 | \name{usedPoints} 4 | \alias{usedPoints} 5 | \title{Use Selection to Calculate Lambdaz} 6 | \usage{ 7 | usedPoints(Conc, Time, usePoints, excPoints = FALSE, minPoints = 3, 8 | Safe = TRUE) 9 | } 10 | \arguments{ 11 | \item{Conc}{Vector of concentrations} 12 | 13 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 14 | 15 | \item{usePoints}{Logical vector selecting points to use for calculation of terminal phase. Used rows are flagged by usePoints as \code{TRUE}.} 16 | 17 | \item{excPoints}{Logical vector (\code{FALSE} by default) excludeing \code{TRUE} rows from automatic calculation of terminal phase.} 18 | 19 | \item{minPoints}{Single numeric declaring minimum number of points requred for lambdaz calculation.} 20 | } 21 | \value{ 22 | Single numeric value 23 | } 24 | \description{ 25 | Use Selection to Calculate Lambdaz 26 | } 27 | \details{ 28 | Value is NA if selection would be less than minPoints. 29 | The number of points will not usually be related to the index of the points used, 30 | since any rows may be selected by the user 31 | } 32 | \examples{ 33 | usedPoints(Conc = c(435, 363, 113, 47,0), Time = 0:4, usePoints = c(TRUE, TRUE, TRUE, FALSE, FALSE)) 34 | usedPoints(Conc = c(435, 363, 113, 47,0), Time = 0:4, usePoints = rep(TRUE, 5), 35 | excPoints = c(FALSE, FALSE, TRUE, FALSE, FALSE)) 36 | } 37 | \author{ 38 | Mango Solutions 39 | } 40 | \keyword{math} 41 | -------------------------------------------------------------------------------- /mangoNCA/man/CLObs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/clearance.R 3 | \name{CLObs} 4 | \alias{CLObs} 5 | \title{Apparent Clearance (Observed)} 6 | \usage{ 7 | CLObs(Conc, Time, Dose, numPoints = NULL) 8 | } 9 | \arguments{ 10 | \item{Conc}{A numeric vector of concentration values} 11 | 12 | \item{Time}{A numeric vector of time values, parallel to \code{Conc} and of the same length. These should be sorted 13 | in ascending order.} 14 | 15 | \item{Dose}{A single numeric} 16 | 17 | \item{numPoints}{Number of points to use for the lambda z calculation, counted from the last measurable concentration. 18 | Must be a single integer greater than 1 and less than or equal to the length of \code{Time} and \code{Conc}. 19 | Default is NULL, numPoints is then calculated by \code{selectPoints}.} 20 | } 21 | \value{ 22 | apparent clearance (single numeric) 23 | } 24 | \description{ 25 | Calculates apparent clearance (observed), which is equal to administered dose divided by AUC0Inf_Obs. 26 | } 27 | \note{ 28 | The following additional input processing/checks are performed: 29 | \enumerate{ 30 | \item All checks for \code{AUCInfObs} apply 31 | \item \code{Dose} must be a numeric vector of length 1, otherwise an exception will be generated. If 32 | \code{Dose} is \code{NA}, 0 or less, \code{NA} will be returned 33 | } 34 | } 35 | \examples{ 36 | Theoph1 <- subset( Theoph, Subject == 1) 37 | CLObs( Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1]) 38 | } 39 | \author{ 40 | Mango Solutions 41 | } 42 | \keyword{math} 43 | -------------------------------------------------------------------------------- /mangoNCA/man/VSSObs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/VSS.R 3 | \name{VSSObs} 4 | \alias{VSSObs} 5 | \title{Volume Distribution at Steady-State (observed)} 6 | \usage{ 7 | VSSObs(Conc, Time, Dose, Dof, numPoints = NULL, Safe = TRUE) 8 | } 9 | \arguments{ 10 | \item{Conc}{Vector of concentrations} 11 | 12 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 13 | 14 | \item{Dose}{Single numeric with dose amount} 15 | 16 | \item{Dof}{duration of infusion} 17 | 18 | \item{numPoints}{Number of points to use for the lambda z calculation(s)} 19 | } 20 | \value{ 21 | Single numeric value 22 | } 23 | \description{ 24 | Function to Calculate Volume of Distribution at Steady State (Observed) 25 | } 26 | \details{ 27 | Calculates volume distribution at steady-state (observed). 28 | This is a convenience function for when using the R package. 29 | \code{\link{ncaComplete}} calls VSS directly since MRTInfObs and CLObs have already been calculated. 30 | \code{VSSObs} calls \code{\link{VSS}} after calling \code{\link{MRTInfObsSD}}, \code{\link{AUCinfobs}} and \code{\link{clearance}}. 31 | } 32 | \note{ 33 | All input checks / error handling for CLPred and MRTInfPredSD apply. The formula used to calculate this 34 | quantity is \deqn{ MRTPredSD_{\inf} * CLPred } 35 | } 36 | \examples{ 37 | Theoph1 <- subset( Theoph, Subject == 1) 38 | VSSObs( Conc = Theoph1$conc, Time = Theoph1$Time, numPoints = 3, Dose = Theoph1$Dose[1], Dof = 3 ) 39 | } 40 | \author{ 41 | Mango Solutions 42 | } 43 | \keyword{math} 44 | -------------------------------------------------------------------------------- /mangoNCA/man/VSSPred.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/VSS.R 3 | \name{VSSPred} 4 | \alias{VSSPred} 5 | \title{Volume Distribution at Steady-State (predicted)} 6 | \usage{ 7 | VSSPred(Conc, Time, Dose, Dof, numPoints = NULL, Safe = TRUE) 8 | } 9 | \arguments{ 10 | \item{Conc}{Vector of concentrations} 11 | 12 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 13 | 14 | \item{Dose}{Single numeric with dose amount} 15 | 16 | \item{Dof}{duration of infusion} 17 | 18 | \item{numPoints}{Number of points to use for the lambda z calculation(s)} 19 | } 20 | \value{ 21 | Single numeric value 22 | } 23 | \description{ 24 | Function to Calculate Volume of Distribution at Steady State (Predicted) 25 | } 26 | \details{ 27 | Calculates volume distribution at steady-state (predicted). 28 | This is a convenience function for when using the R package. 29 | \code{\link{ncaComplete}} calls VSS since MRTInfPred and CLPred have already been calculated. 30 | \code{VSSPred} calls \code{\link{VSS}} after calling \code{\link{MRTInfPredSD}}, 31 | \code{\link{AUCinfpred}} and \code{\link{clearance}}. 32 | } 33 | \note{ 34 | All input checks / error handling for CLPred and MRTInfPredSD apply. 35 | The formula used to calculate this quantity is 36 | \deqn{ MRTPredSD_{\inf} * CLPred } 37 | } 38 | \examples{ 39 | Theoph1 <- subset( Theoph, Subject == 1) 40 | VSSPred( Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1], Dof = 3 ) 41 | } 42 | \author{ 43 | Mango Solutions 44 | } 45 | \keyword{math} 46 | -------------------------------------------------------------------------------- /mangoNCA/man/CLPred.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/clearance.R 3 | \name{CLPred} 4 | \alias{CLPred} 5 | \title{Apparent Clearance (predicted)} 6 | \usage{ 7 | CLPred(Conc, Time, Dose, numPoints = NULL) 8 | } 9 | \arguments{ 10 | \item{Conc}{A numeric vector of concentration values} 11 | 12 | \item{Time}{A numeric vector of time values, parallel to \code{Conc} and of the same length. These should be sorted 13 | in ascending order.} 14 | 15 | \item{Dose}{A single numeric} 16 | 17 | \item{numPoints}{Number of points to use for the lambda z calculation, counted from the last measurable concentration. 18 | Must be a single integer greater than 1 and less than or equal to the length of \code{Time} and \code{Conc}. 19 | Default is NULL, numPoints is then calculated by \code{selectPoints}.} 20 | } 21 | \value{ 22 | apparent clearance (single numeric) 23 | } 24 | \description{ 25 | Calculates apparent clearance (predicted), which is equal to administered dose divided by AUC0Inf_Pred. 26 | } 27 | \note{ 28 | The following additional input processing/checks are performed: 29 | \enumerate{ 30 | \item All checks for \code{AUCInfPred} apply 31 | \item \code{Dose} must be a numeric vector of length 1, otherwise an exception will be generated. If 32 | \code{Dose} is \code{NA}, 0 or less, \code{NA} will be returned 33 | } 34 | } 35 | \examples{ 36 | Theoph1 <- subset( Theoph, Subject == 1) 37 | CLPred(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1]) 38 | } 39 | \author{ 40 | Mango Solutions 41 | } 42 | \keyword{math} 43 | -------------------------------------------------------------------------------- /mangoNCA/man/CmaxTmax.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cmaxtmax.R 3 | \name{CmaxTmax} 4 | \alias{CmaxTmax} 5 | \title{Calculate Maximum Concentration and time of maximum concentration} 6 | \usage{ 7 | CmaxTmax(Conc, Time) 8 | } 9 | \arguments{ 10 | \item{Conc}{numeric vector of concentrations} 11 | 12 | \item{Time}{numeric vector of time points (parallel to \code{Conc})} 13 | } 14 | \value{ 15 | list with numeric scalar (length 1 vector) components "cmax", "tmax" and "index". See notes for further processing. 16 | } 17 | \description{ 18 | Calculate Maximum Concentration and time of maximum concentration 19 | } 20 | \details{ 21 | Finds the maximum concentration value and the first time point 22 | (in the sense of corresponding to the minimal index) 23 | with that concentration. 24 | } 25 | \note{ 26 | The following error checks / processing will be performed: 27 | \enumerate{ 28 | \item If \code{Conc} or \code{Time} are of length 0, NA is returned for both values 29 | \item If the sum of \code{Code} (after omitting missing values) is 0, NA is returned for both values 30 | \item If \code{cmax} is 0, NA is returned for \code{tmax} 31 | \item \code{cmax} is computed by stripping NA values from \code{Conc} 32 | \item if \code{Conc} and \code{Time} are not equal length numeric vectors, an exception will be generated by 33 | \code{\link{checkNumericSameLength}} 34 | } 35 | } 36 | \examples{ 37 | Theoph.2 <- subset(Theoph, Subject == 2) 38 | CmaxTmax( Theoph.2$conc, Theoph.2$Time ) 39 | } 40 | \keyword{math} 41 | -------------------------------------------------------------------------------- /mangoNCA/man/ncaPeakTrough.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ncaPeaktrough.R 3 | \name{ncaPeakTrough} 4 | \alias{ncaPeakTrough} 5 | \title{PeakTrough Vector of pre- and post-dose identifiers (TROUGHCODE and PEAKCODE respectively). There must not be more than one of each. NULL is replaced with 0.} 6 | \usage{ 7 | ncaPeakTrough(Conc, Time, Dose, Dof, PeakTrough = NULL, Safe = TRUE, 8 | ROutput) 9 | } 10 | \arguments{ 11 | \item{Conc}{Vector of concentrations.} 12 | 13 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates.} 14 | 15 | \item{Dose}{Single numeric value of dose.} 16 | 17 | \item{Dof}{Single numeric value of duration of infusion.} 18 | 19 | \item{Safe}{Single logical value declaring whether to perform redundant data checks (default is TRUE).} 20 | 21 | \item{ROutput}{Named vector consisting of 38 NA and 1 zero with names which should match expected output names.} 22 | } 23 | \value{ 24 | Data frame 25 | } 26 | \description{ 27 | Return Concentration values coded as PEAKCODE or TROUGHCODE for sparse data 28 | } 29 | \details{ 30 | Calculates Peak through (pre / post dose concentrations) for individuals on Time concentration curves. 31 | PEAKCODE is 2, TROUGHCODE is 1, if there is more than one of each of these, this is a data error. 32 | } 33 | \examples{ 34 | load(system.file(package = "MangoNca", "data", "shapeROutput.RData")) 35 | Theoph1 <- subset(Theoph, Subject == 1) 36 | ncaPeakTrough(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1], Dof = 1, PeakTrough = c(1, 0, 0, 0, 2, rep(0, 6)), ROutput = shapeROutput) 37 | } 38 | \author{ 39 | Mango Solutions 40 | } 41 | -------------------------------------------------------------------------------- /mangoNCA/man/predictConc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/predictConc.R 3 | \name{predictConc} 4 | \alias{predictConc} 5 | \title{Predict Concentration at Time} 6 | \usage{ 7 | predictConc(Conc, Time, predTime, numPoints = NULL, lambdaZStats = NULL, 8 | usePoints = NULL, excPoints = FALSE, minPoints = 3, addT0 = FALSE) 9 | } 10 | \arguments{ 11 | \item{Conc}{Vector of concentrations.} 12 | 13 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates.} 14 | 15 | \item{predTime}{time at which Conc should be calculated. if predTime is NA, NA is returned.} 16 | 17 | \item{numPoints}{Number of points to use for lambda-z calculation.} 18 | 19 | \item{lambdaZStats}{if not \code{NULL}, a list with 9 elements (see details). Must be provided if numPoints is not.} 20 | 21 | \item{usePoints}{If \code{NULL} (default) automatically select, else, logical vector of points to use for calculation of terminal phase. Used rows are flagged by usePoints as \code{TRUE}.} 22 | 23 | \item{excPoints}{If \code{NULL} (default) automatically select, else, logical vector of points to exclude from automatic calculation of terminal phase. Excluded rows are flagged by excPoints as \code{TRUE}.} 24 | 25 | \item{addT0}{single logical declaring whether to add T = 0 and remove missing values if TRUE or generate exception if FALSE (default is FALSE)} 26 | } 27 | \value{ 28 | Single numeric of predicted concentration at prediction time 29 | } 30 | \description{ 31 | Predict Concentration at Time 32 | } 33 | \details{ 34 | Calculate Concentration at Time. 35 | } 36 | \seealso{ 37 | \code{\link{lambdaZStatistics}} for more about the numPoints parameter 38 | } 39 | \author{ 40 | Mango Business Solutions 41 | } 42 | \keyword{math} 43 | -------------------------------------------------------------------------------- /mangoNCA/man/AUMCPartial.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUMCPartial.R 3 | \name{AUMCPartial} 4 | \alias{AUMCPartial} 5 | \title{Partial Area Under Moment Curve} 6 | \usage{ 7 | AUMCPartial(Conc, Time, endTime, numPoints, addT0 = TRUE) 8 | } 9 | \arguments{ 10 | \item{Conc}{Vector of concentrations} 11 | 12 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 13 | 14 | \item{endTime}{: last time at which area should be calculated. Must be greater than the smallest element of Time, else NA is returned.} 15 | 16 | \item{numPoints}{: Number of points to use for lambda-z calculation. This will only be used if endTime > tlast to 17 | extrapolate a new concentration point} 18 | } 19 | \value{ 20 | Single numeric 21 | } 22 | \description{ 23 | Area Under the Concentration Time Moment Curve from T = 0 to T = endTime 24 | } 25 | \details{ 26 | Calculates the area under a concentration-time moment curve from the first time up until the \code{endTime}. \code{endTime} 27 | need not be one of the elements of \code{Time}, but it should like between the minimum and maximum times 28 | Note, all error checks that apply to \code{\link{AUC}} apply here. If \code{endTime} is less than 29 | \code{tmin} \code{NA} is returned. There should be no missing times. 30 | If the endTime does not coincide with an existing time element, the following interpolation formula will be 31 | used to calculated a new concentration (if time is less than tlast): 32 | \deqn{c_{inter} = c_1 + \left| \frac{ t^{end} - t_1}{t_2 - t_1} \right| (c_2 - c_1)}. If endTime is greater than 33 | tlast, then another concentration is extrapolated via the formula \deqn{c_{extr} = c_0 + \exp(- \lambda_z * endTime) } 34 | } 35 | \author{ 36 | Mango Solutions 37 | } 38 | \keyword{math} 39 | -------------------------------------------------------------------------------- /mangoNCA/man/fixedPoints.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/selectPoints.R 3 | \name{fixedPoints} 4 | \alias{fixedPoints} 5 | \title{Fixed Points for Calculating Terminal Rate Constant} 6 | \usage{ 7 | fixedPoints(Conc, Time, numPoints, excPoints = FALSE, minPoints = 3, 8 | Safe = TRUE) 9 | } 10 | \arguments{ 11 | \item{Conc}{Vector of concentrations.} 12 | 13 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates.} 14 | 15 | \item{excPoints}{Logical vector (\code{FALSE} by default) excludeing \code{TRUE} rows from automatic calculation of terminal phase.} 16 | 17 | \item{minPoints}{Minimum number of points to use for the Lambdaz calculation(s), 3 by default. Single positive integer.} 18 | 19 | \item{Safe}{Single logical value declaring whether to perform redundant data checks (default is TRUE).} 20 | 21 | \item{minPoints}{Single numeric declaring minimum acceptable number of rows for linear model.} 22 | } 23 | \value{ 24 | List consisting of numPoints, a single numeric value, and result, a length 9 numeric vector. 25 | } 26 | \description{ 27 | Use Fixed Number of Trailing Points for Terminal Rate Constant (Lambdaz) Calculation. 28 | } 29 | \details{ 30 | Returns input numPoints and results for Terminal Rate Constant (Lambdaz) calculation 31 | fixedPoints calls \code{\link{lambdaZStatistics}} to perform regressions using the specified number of trailing non-zero rows 32 | Rows prior to Cmax may be used. 33 | Exclusion of rows prior to the end of infusion is not currently implemented. 34 | Zero or missing values will error. 35 | } 36 | \examples{ 37 | Theoph1 <- subset(Theoph, Subject == 1) 38 | fixedPoints(Conc = Theoph1$conc, Time = Theoph1$Time, numPoints = 3) 39 | } 40 | \author{ 41 | Mango Solutions 42 | } 43 | \keyword{math} 44 | -------------------------------------------------------------------------------- /mangoNCA/man/AUCLin.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUC.R 3 | \name{AUCLin} 4 | \alias{AUCLin} 5 | \title{Calculate AUC Using Linear Trapezoidal Rules} 6 | \usage{ 7 | AUCLin(Conc, Time) 8 | } 9 | \arguments{ 10 | \item{Conc}{numeric vector of concentrations} 11 | 12 | \item{Time}{numeric vector of time points (same length as and parallel to Conc). 13 | These elements should be sorted in ascending order, otherwise an exception will be generated.} 14 | } 15 | \value{ 16 | numeric vector of trapezium AUC values. 17 | } 18 | \description{ 19 | Calculates the area under a time-concentration curve (AUC) using the linear trapezium rule. 20 | } 21 | \details{ 22 | A vector of areas under individual trapezoids (not the total area) is returned. 23 | These will be the individual AUC values at a given time/concentration index. 24 | In other words, auc[i] is the area under the trapezium bounded by time[i], conc[i] and time[i+1], conc[i+1]. 25 | This function is called by \code{AUCLast}. 26 | For a given time interval (t1:t2), the AUC can be calculated as follows: 27 | AUC_t1_t2 = (C1 + C2) * (t2 - t1) / 2 28 | } 29 | \note{ 30 | It is assumed that these times and concentrations come from a single curve. 31 | The following error checks / processing will be performed: 32 | \enumerate{ 33 | \item If \code{Conc} or \code{Time} are of length 0, a single NA is returned 34 | \item \code{Conc} and \code{Time} should be equal length numeric vectors, 35 | otherwise an exception will be generated 36 | \item if \code{Time[i]} or \code{Conc[i]} is \code{NA} and \code{auc <- AUCLin(Conc,Time)}, 37 | then \code{auc[i]} and \code{auc[i - 1]} will be \code{NA}. 38 | } 39 | } 40 | \examples{ 41 | Theoph2 <- subset(Theoph, Subject == 2) 42 | x <- MangoNca:::AUCLin(Theoph2$conc, Theoph2$Time) 43 | sum(x) # 91.5268 44 | } 45 | \keyword{math} 46 | -------------------------------------------------------------------------------- /mangoNCA/man/getConcentration.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getConcentration.R 3 | \name{getConcentration} 4 | \alias{getConcentration} 5 | \title{Concentration at Time at T = firstTime and T = secondTime} 6 | \usage{ 7 | getConcentration(Conc = NULL, Time = NULL, firstTime = NA, 8 | secondTime = NA, numPoints = NULL, usePoints = NULL, excPoints = NULL, 9 | Safe = TRUE, inter = "Linear") 10 | } 11 | \arguments{ 12 | \item{Conc}{Vector of concentrations} 13 | 14 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 15 | 16 | \item{firstTime}{single numeric value, first time at which Concentration should be calculated} 17 | 18 | \item{secondTime}{single numeric value, second time at which Concentration should be calculated} 19 | 20 | \item{numPoints}{single numeric value declaring number of points to use} 21 | 22 | \item{usePoints}{If \code{NULL} (default) automatically select, else, logical vector of points to use for calculation of terminal phase. Used rows are flagged by usePoints as \code{TRUE}.} 23 | 24 | \item{excPoints}{If \code{NULL} (default) automatically select, else, logical vector of points to exclude from automatic calculation of terminal phase. Excluded rows are flagged by excPoints as \code{TRUE}.} 25 | 26 | \item{Safe}{single logical value declaring whether error checking should be performed} 27 | 28 | \item{inter}{Single character stating whether the interpolation method used is \code{"Linear"} (default), \code{"Lin up Log down"} or \code{"Linear Log"}} 29 | } 30 | \value{ 31 | Data frame 32 | } 33 | \description{ 34 | Concentration at Time at T = firstTime and T = secondTime 35 | } 36 | \details{ 37 | This function calculates Concentration at Time 38 | Returns a data frame with 1 row containing columns: 39 | \enumerate{ 40 | \item \code{firstTime} 41 | \item \code{secondTime} 42 | \item \code{firstConc} 43 | \item \code{secondConc} 44 | \item \code{numPoints} 45 | \item \code{Error} 46 | } 47 | } 48 | \author{ 49 | Mango Solutions 50 | } 51 | \keyword{math} 52 | -------------------------------------------------------------------------------- /mangoNCA/R/MRTInfPredSS.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: 23459 $ 2 | # Date of last change: $LastChangedDate: 2010-12-07 11:23:47 +0000 (Tue, 07 Dec 2010) $ 3 | # Last changed by: $LastChangedBy: fgochez $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | #' Mean Residence Time to infinity (predicted) for steady-state data 10 | #' 11 | #' Calculate the mean residence time to infinity (predicted), for steady-state models of type "M3". 12 | #' The value returned is 13 | #' \deqn{\frac{(AUMC_{tau} + tau * (AUCInfPred - AUC_{tau}))}{ AUC_{tau} } - dof/2}. 14 | #' AUC_{tau} is the partial area under the time-concentration curve up to tau (similarly for AUMC_{tau}). 15 | #' All error checks for \code{AUCInfPred} apply. 16 | #' If \code{tau} or \code{dof} is not a numeric of length 1, an exception will be generated. 17 | #' 18 | #' @param Conc Vector of concentrations 19 | #' @param Time Vector of times. Must be sorted, and without duplicates 20 | #' @param numPoints Number of points to use for lambda z calculation. See \code{\link{lambdaZStatistics}} 21 | #' @param tau Dosing interval. Must lie in the range of time values, otherwise an exception will be generated 22 | #' @param dof Duration of infusion, single numeric 23 | #' @return single numeric vector 24 | #' @author Mango Solutions 25 | #' @keywords math 26 | #' @noRd 27 | 28 | MRTInfPredSS <- function( Conc, Time, numPoints, tau, dof, addT0 = TRUE) 29 | { 30 | checkSingleNumeric(dof, description = "duration of infusion") 31 | 32 | # AUMCtau : single numeric with partial area under moment curve from first time to tau 33 | # AUCtau : single numeric with partial area under curve from first time to tau 34 | 35 | AUMCtau <- AUMCPartial(Conc = Conc, Time = Time, endTime = tau, numPoints = numPoints, addT0 = addT0) 36 | 37 | AUCtau <- AUCPartial(Conc = Conc, Time = Time, endTime = tau, numPoints = numPoints, addT0 = addT0) 38 | 39 | AUCip <- AUCInfPred(Conc = Conc, Time = Time, numPoints = numPoints, addT0 = addT0) 40 | 41 | MRTipss <- ((AUMCtau + tau * (AUCip - AUCtau)) / AUCtau) - dof / 2 42 | 43 | return(MRTipss) 44 | } 45 | -------------------------------------------------------------------------------- /mangoNCA/man/AUCLog.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUC.R 3 | \name{AUCLog} 4 | \alias{AUCLog} 5 | \title{Calculate AUC Using Logarithmic Trapezoidal Rule} 6 | \usage{ 7 | AUCLog(Conc, Time) 8 | } 9 | \arguments{ 10 | \item{Conc}{numeric vector of concentrations} 11 | 12 | \item{Time}{numeric vector of time points (same length as and parallel to Conc). 13 | These elements should be sorted in ascending order, otherwise an exception will be generated.} 14 | } 15 | \value{ 16 | numeric vector of trapezium AUC values. 17 | } 18 | \description{ 19 | Calculates the area under a time-concentration curve (AUC) using the logarithmic trapezoidal rule. 20 | } 21 | \details{ 22 | The logarithmic trapezoidal method uses logarithmic interpolation between data points to calculate the AUC. 23 | This method represents more closely decreasing concentrations since they are equivalent to first order 24 | elimination (linear on a logarithmic scale). This function is called by \code{AUCLast}. 25 | 26 | A vector of areas under individual trapezoids (not the total area) is returned. 27 | These will be the individual AUC values at a given time/concentration index. 28 | In other words, auc[i] is the area under the trapezium bounded by time[i], conc[i] and time[i + 1], conc[i + 1]. 29 | For a given time interval (t1:t2), the AUC can be calculated as follows: 30 | AUC_t1_t2 = (t2 - t1) * (C2 - C1) / log(C2 / C1) 31 | } 32 | \note{ 33 | It is assumed that these times and concentrations come from a single curve. 34 | The following error checks / processing will be performed: 35 | \enumerate{ 36 | \item If \code{Conc} or \code{Time} are of length 1 or 0, a single NA is returned 37 | \item \code{Conc} and \code{Time} should be equal length numeric vectors, 38 | otherwise an exception will be generated 39 | \item if \code{Time[i]} or \code{Conc[i]} is \code{NA} and \code{auc = AUCLin(Conc,Time)}, 40 | then \code{auc[i]} and \code{auc[i - 1]} will be \code{NA}. 41 | \item If \code{Conc[i]} equals \code{Conc[i + 1]}, linear interpolation will be used 42 | } 43 | } 44 | \examples{ 45 | Theoph2 <- subset(Theoph, Subject == 2) 46 | x <- MangoNca:::AUCLog( Theoph2$conc, Theoph2$Time ) 47 | sum(x) # 48 | } 49 | \keyword{math} 50 | -------------------------------------------------------------------------------- /mangoNCA/man/getTerminalAUC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCPartial.R 3 | \name{getTerminalAUC} 4 | \alias{getTerminalAUC} 5 | \title{Area Under Terminal Concentration Time Curve} 6 | \usage{ 7 | getTerminalAUC(Conc, Time, endTime, lambdaZStats = NULL, numPoints = NULL, 8 | usePoints = NULL, excPoints = FALSE, minPoints = 3, useObs = FALSE) 9 | } 10 | \arguments{ 11 | \item{Conc}{Vector of concentrations} 12 | 13 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 14 | 15 | \item{endTime}{: single numeric, last time until which area should be calculated} 16 | 17 | \item{lambdaZStats}{if not \code{NULL}, a list with 9 elements (see details). Must be provided if numPoints is not.} 18 | 19 | \item{numPoints}{: single numeric, number of points to use for lambdaz calculation} 20 | 21 | \item{usePoints}{If NULL (default) automatically select, else, logical vector of points to use (\code{TRUE}) for calculation of terminal phase.} 22 | 23 | \item{excPoints}{Logical vector (\code{FALSE} by default) excludeing \code{TRUE} rows from automatic calculation of terminal phase.} 24 | 25 | \item{useObs}{: single logical, use observed rather than predicted CLast, defaults to FALSE} 26 | } 27 | \value{ 28 | Single numeric with partial area under curve from TLast to endTime 29 | } 30 | \description{ 31 | Area Under Terminal Concentration Time Curve from T = Last to T = endTime 32 | } 33 | \details{ 34 | This function calculates the area under the terminal phase exponential 35 | from TLast to endTime. This calculation is the integral of the Terminal 36 | phase exponential decay function: 37 | \deqn{\int intercept \ast exp\left ( -\lambda _{z} \ast T\right ) dT = 38 | -intercept / \left ( \lambda _{z} \ast exp\left ( \lambda _{z} \ast T\right )\right)} 39 | The partial area under the terminal concentration time curve can be calculated 40 | by subtracting modeled AUC0Tlast from modeled AUC0endTime. 41 | This is intended to be used as an internal function from \code{\link{AUCPartial}}, so no 42 | data checking is performed so clean data is assumed (see \code{\link{cleanConcTime}}). 43 | } 44 | \seealso{ 45 | \code{\link{lambdaZStatistics}} for more about the numPoints parameter 46 | } 47 | \author{ 48 | Mango Business Solutions 49 | } 50 | \keyword{math} 51 | -------------------------------------------------------------------------------- /mangoNCA/R/testing.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: 20/08/2013 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | #' Execute the RUnit unit tests suites for the MangoNca package. 10 | #' Prints an html report with name "Unit_Test_Report_MangoNca___.html" 11 | #' The package version is extracted from the DESCRIPTION file 12 | #' 13 | #' @param testPath A single string holding the path to the internal test suite scripts 14 | #' @title Run MangoNca Test Suite 15 | #' @return suiteResults 16 | #' @author Mango Solutions 17 | #' @keywords debugging programming 18 | #' @examples 19 | #' \dontrun{ 20 | #' runMangoNcaTests() 21 | #' } 22 | #' @export 23 | 24 | runMangoNcaTests <- function(testPath = system.file(package = "MangoNca", "testing")) 25 | { 26 | require(RUnit) 27 | 28 | # testSuite : object of class RUnitTestSTuite. This will describe the internal unit test suite to be executed 29 | testSuite <- defineTestSuite(name = "MangoNca Unit Test Suite", dirs = testPath, 30 | testFileRegexp = "^runit.+\\.[rR]$", testFuncRegexp = "^test.+" ) 31 | 32 | if (length(grep("^runit.+\\.[rR]$", testPath) == 0)) { stop("no files found called runit.name.R in directory", testPath) } 33 | 34 | # suiteResults : object of class RUnitTestData 35 | suiteResults <- runTestSuite(testSuite) 36 | 37 | pack <- installed.packages() 38 | 39 | vers <- pack["MangoNca", "Version"] 40 | 41 | vers <- gsub("\\.", "_", vers) 42 | 43 | printHTMLProtocol(suiteResults, fileName = paste("Unit_Test_Report_MangoNca_", vers, ".html", sep = "")) 44 | 45 | return(suiteResults) 46 | } 47 | 48 | # miscellaneous testing routines 49 | 50 | #' Check if an object is of class "try-error", and that it contains a specific error message. 51 | #' @param x Object to check 52 | #' @param expectedMessage String with expected message 53 | #' @title Check if object is error with given error message 54 | #' @return TRUE or FALSE depending on whether or not x is as expected 55 | #' @author Mango Solutions 56 | 57 | 58 | isErrorWithMessage <- function(x, expectedMessage) 59 | { 60 | return(is(x, "try-error") & as.character(x) == expectedMessage) 61 | } 62 | 63 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.MRTInfPredSD.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 16/03/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | test.MRTInfPredSD <- function() 11 | { 12 | # TEST 1 : contrived data, standard example 13 | 14 | # AUMCInfPred = 67.93626429, AUCInfPred = 25.90989137 15 | test1 <- MRTInfPredSD( Time = 0:6, Conc = 7:1, numPoints = 3, Dof = 5, addT0 = FALSE) 16 | checkEquals( test1, 67.93626429 / 25.90989137 - 5/2, tol = 1e-8, msg = " || TEST 1 : simple contrived data" ) 17 | 18 | 19 | # TEST 2 : stock data set 20 | 21 | Theoph2 <- subset(Theoph, Subject == 2) 22 | test2 <- MRTInfPredSD(Time = Theoph2$Time, Conc = Theoph2$conc, numPoints = 3, Dof = 2 ) 23 | 24 | checkEquals(test2, 998.052942912161 / 100.1128269954017 - 1 , tol = 1e-5, msg = " || TEST 2 : stock data set" ) 25 | 26 | # TEST 3 : Dof is less than 0 : NA should be returned. 27 | 28 | test3 <- MRTInfPredSD(Time = Theoph2$Time, Conc = Theoph2$conc, numPoints = 3, Dof = -1 ) 29 | checkTrue(is.na(test3), msg = " || TEST 3 : negative Dof causes NA to be returned") 30 | 31 | } 32 | 33 | 34 | test.MRTInfPredSD_errorHandling <- function() 35 | { 36 | 37 | isErrorWithMessage <- MangoNca:::isErrorWithMessage 38 | 39 | # TEST 1 : duration of infusion is of length > 1 40 | 41 | test1 <- try( MRTInfPredSD( Time = 0:6, Conc = 7:1, numPoints = 3, Dof = 1:2), silent = TRUE) 42 | 43 | checkTrue( isErrorWithMessage(test1, "Error in checkSingleNumeric(Dof, description = \"Duration of infusion\") : \n Error in MRTInfPredSD : Duration of infusion is not a numeric of length 1. Value is: 1 2\n" ), 44 | msg = " || TEST 1 : duration of infusion is of length > 1" ) 45 | 46 | # TEST 2 : duration of infusion is not numeric 47 | 48 | test2 <- try( MRTInfPredSD( Time = 0:6, Conc = 7:1, numPoints = 3, Dof = "1"), silent = TRUE) 49 | checkTrue( isErrorWithMessage(test2, "Error in checkSingleNumeric(Dof, description = \"Duration of infusion\") : \n Error in MRTInfPredSD : Duration of infusion is not a numeric of length 1. Value is: 1\n" ), 50 | msg = " || TEST 2 : duration of infusion is not numeric" ) 51 | 52 | } 53 | -------------------------------------------------------------------------------- /mangoNCA/R/ncaInitialized.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 16/03/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: plobb 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | #' Get R Version 10 | #' 11 | #' This is a trivial test used to confirm that R is running correctly. 12 | #' @title Function to return R version to R.NET 13 | #' @return data frame with 1 column, Version and 1 character row 14 | #' @export 15 | #' @author Mango Solutions 16 | #' @keywords math 17 | #' @keywords nca 18 | #' @examples 19 | #' getWhichVersion() 20 | 21 | 22 | getWhichVersion <- function() 23 | { 24 | 25 | thisVersion <- R.Version()$version.string 26 | 27 | return(data.frame(Version = thisVersion)) 28 | } 29 | 30 | 31 | #' Check MangoNca is Initialized 32 | #' 33 | #' This is a second test used to confirm that R is running correctly. 34 | #' Returns a data frame with 3 columns and 1 row: 35 | #' \enumerate{ 36 | #' \item \code{rVersionOk} logical 37 | #' \item \code{rArchOk} logical 38 | #' \item \code{statsOk} logical 39 | #' } 40 | #' 41 | #' @title Function to return R version to R.NET 42 | #' @param rVersionMinor single numeric or character string describing R version to test against 43 | #' @return data frame 44 | #' @export 45 | #' @author Mango Solutions 46 | #' @keywords math 47 | #' @keywords nca 48 | #' @examples 49 | #' ncaInitialized() 50 | 51 | ncaInitialized <- function(rVersionMinor = 14.1) 52 | { 53 | # versions to validate against 54 | 55 | rVersionMajor <- "2" 56 | rArch <- "i386" 57 | 58 | rVersionOk <- FALSE 59 | 60 | # Check version 61 | 62 | RVersion <- R.Version() 63 | 64 | rVersionMajor <- c(rVersionMajor) %in% RVersion$major 65 | rVersionMinor <- c(rVersionMinor) %in% RVersion$minor 66 | 67 | if (isTRUE(rVersionMajor) && isTRUE(rVersionMinor)) { 68 | rVersionOk <- TRUE 69 | } 70 | 71 | # Check Architecture 72 | 73 | rArchOk <- c(rArch) %in% RVersion$arch 74 | 75 | 76 | # Check stats loaded 77 | 78 | packagesInSession <- search() 79 | 80 | statsInSession <- "package:stats" %in% packagesInSession 81 | 82 | TestResultsSummary <- data.frame(rVersionOk = rVersionOk, 83 | rArchOk = rArchOk, 84 | statsOk = statsInSession) 85 | 86 | return(TestResultsSummary) 87 | 88 | } 89 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.CminTmin.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 20/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # tests CminTmin function 10 | 11 | test.CminTmin <- function() 12 | { 13 | 14 | if (!exists("CminTmin", mode = "function")) { CminTmin <- MangoNca:::CminTmin } 15 | 16 | # TEST 1 : standard case 17 | 18 | test1 <- CminTmin( Conc = c(NA, 10, 9:2), Time = c(1:10) ) 19 | checkEquals( test1, list(cmin = 2, tmin = 10, index = 10), msg = " || simple case is correct") 20 | 21 | # TEST 2 : 3 minima, check that minimal time is retrieved 22 | 23 | test2 <- CminTmin( Conc = c(2:4, rep(1, times = 7) ), Time = c(10:1) ) 24 | checkEquals( test2, list(cmin = 1, tmin = 7, index = 4), msg = " || simple case is correct") 25 | 26 | # TEST 3 : basic error handling - vectors should be of same length 27 | 28 | test3 <- try( CminTmin( 1:10, 1:9 ), silent = TRUE) 29 | checkTrue( is(test3, "try-error"), msg = " || TEST3 : exception generated ") 30 | # FIXME : need to check that the exception message is correct 31 | 32 | # TEST 4 : one of the times corresponding to cmin is NA 33 | 34 | test4 <- CminTmin( c(2, 3, 1, 1), c(1, 2, 3, NA) ) 35 | checkEquals( test4, list( cmin = 1, tmin = 3, index = 3), msg = "|| TEST4: multiple values of concentration, one is NA" ) 36 | 37 | # TEST 5 : only time corresponding to cmin is NA 38 | 39 | test5 <- CminTmin( 3:1, c(1, 2, NA) ) 40 | checkEquals( test5, list( cmin = 1, tmin = as.numeric(NA), index = 3), msg = "|| TEST5: time corresponding to min concentration is NA" ) 41 | 42 | # TEST 6 : concentrations add up to 0 43 | 44 | test6 <- CminTmin(Time = 1:4, Conc = rep(0, 4) ) 45 | checkEquals( test6, list(cmin = NA, tmin = NA, index = NA), msg = " || TEST6 : concentrations add up to 0 causes NA values to be returned" ) 46 | 47 | # TEST 7 : min concentration is 0 48 | 49 | test7 <- CminTmin(Time = 1:2, Conc = c(1, 0) ) 50 | checkEquals( test7, list(cmin = 0, tmin = 2, index = 2), msg = " || TEST7 : min concentration is 0" ) 51 | 52 | # TEST 8 : no non-missing concentrations. Return should be NA 53 | 54 | test8 <- CminTmin( Time = 1:3, Conc = rep(NA, 3) ) 55 | checkEquals( test8, list(cmin = NA, tmin = NA, index = NA), msg = " || No non-missing concentrations. Return should be NA") 56 | } 57 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.checkpeaktrough.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 18/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # tests the checkPeakTrough function in checkdata.R 10 | 11 | test.checkPeakTrough <- function() 12 | { 13 | if (!exists("checkPeakTrough", mode = "function")) { checkPeakTrough <- MangoNca:::checkPeakTrough } 14 | 15 | # TEST 1 : base case - ordered vector, returns NULL 16 | 17 | test1 <- checkPeakTrough( 1:5 ) 18 | checkTrue(is.null(test1), msg = " || TEST 1 : base case - ordered vector, returns NULL") 19 | 20 | # TEST 2 : ordered vector, with NAs 21 | 22 | test2 <- checkPeakTrough(c(NA, 1)) 23 | checkTrue(is.null(test2), msg = " || TEST 2 : ordered vector, with NAs") 24 | 25 | # TEST 3 : length 0 vector is ordered 26 | 27 | test3 <- checkPeakTrough(numeric(0)) 28 | checkTrue(is.null(test3), msg = " || TEST 3 : length 0 vector is ordered") 29 | 30 | # TEST 4 : repeated PEAKCODE with no NA 31 | 32 | test4 <- try( checkPeakTrough(c(1, 0, 2, 0, 0, 2), functionName = "func"), silent = TRUE ) 33 | checkEquals(as.character(test4), 34 | "Error in checkPeakTrough(c(1, 0, 2, 0, 0, 2), functionName = \"func\") : \n Error in func: PeakTrough is miscoded. Actual value is 1 0 2 0 0 2\n", 35 | msg = " || repeated PEAKCODE with no NA" ) 36 | 37 | # TEST 5 : repeated TROUGHCODE with NA 38 | 39 | test5 <- try( checkPeakTrough(c(1, NA, 1, 2, 0, NA, 0), functionName = "func"), silent = TRUE ) 40 | checkTrue(is(test5, "try-error"), msg = " || TEST 5 : repeated TROUGHCODE with NA") 41 | checkEquals(as.character(test5), 42 | "Error in checkPeakTrough(c(1, NA, 1, 2, 0, NA, 0), functionName = \"func\") : \n Error in func: PeakTrough is miscoded. Actual value is 1 NA 1 2 0 NA 0\n", 43 | msg = " || repeated TROUGHCODE with NA error message" ) 44 | 45 | 46 | # TEST 6 : non-vector 47 | 48 | test6 <- try( checkPeakTrough( Theoph["Time"], functionName = "func"), silent = TRUE ) 49 | checkTrue(is(test6, "try-error"), msg = " || TEST 6 : exception generated since non-vector") 50 | checkEquals(as.character(test6), "Error in checkPeakTrough(Theoph[\"Time\"], functionName = \"func\") : \n Error in func: PeakTrough, is not a vector\n", 51 | msg = " || unordered vector with no NA" ) 52 | 53 | } 54 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.MRTSD.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 27/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | test.MRTSD <- function() 11 | { 12 | 13 | # TEST 1 : trivial example 14 | 15 | test1 <- MRTSD(AUC = 2, AUMC = 4, Dof = 2) 16 | checkEquals( test1, 1, msg = " || TEST 1 : trivial example" ) 17 | 18 | # TEST 2 : AUC > AUMC 19 | 20 | test2 <- MRTSD(AUC = 4, AUMC = 2, Dof = 3) 21 | checkEquals( test2, -1, msg = " || TEST 2 : AUC > AUMC" ) # is this desired behaviour or NA? 22 | 23 | # TEST 3 : simple contrived data 24 | 25 | AUMCio <- AUCInfObs( Time = 0:6, Conc = 7:1, numPoints = 3, calculation = "moment", addT0 = FALSE) # 67.23701252 26 | AUCio <- AUCInfObs( Time = 0:6, Conc = 7:1, numPoints = 3, calculation = "standard", addT0 = FALSE) # 25.82047845 27 | mrtio <- AUMCio / AUCio - 5/2 28 | test3 <- MRTSD(AUC = AUCio, AUMC = AUMCio, Dof = 5) 29 | checkEquals( test3, mrtio, msg = " || TEST 3 : simple contrived data" ) 30 | 31 | } 32 | 33 | 34 | test.MRTSD_errorHandling <- function() 35 | { 36 | isErrorWithMessage <- MangoNca:::isErrorWithMessage 37 | 38 | # TEST 1 : duration of infusion is of length > 1 39 | 40 | test1 <- try( MRTSD(AUC = 5387, AUMC = 3456549, Dof = 1:2), silent = TRUE) 41 | 42 | checkTrue( isErrorWithMessage(test1, "Error in checkSingleNumeric(Dof, description = \"Duration of infusion\") : \n Error in MRTSD : Duration of infusion is not a numeric of length 1. Value is: 1 2\n" ), 43 | msg = " || TEST 1 : duration of infusion is of length > 1" ) 44 | 45 | # TEST 2 : duration of infusion is not numeric 46 | 47 | test2 <- try( MRTSD(AUC = 1387, AUMC = 1256549, Dof = "1"), silent = TRUE) 48 | checkTrue( isErrorWithMessage(test2, "Error in checkSingleNumeric(Dof, description = \"Duration of infusion\") : \n Error in MRTSD : Duration of infusion is not a numeric of length 1. Value is: 1\n" ), 49 | msg = " || TEST 2 : duration of infusion is not numeric" ) 50 | 51 | # TEST 3 : AUC and AUMC are of length > 1 52 | 53 | test3 <- try( MRTSD(AUC = c(7825, 3847), AUMC = c(315674, 959267), Dof = 1), silent = TRUE) 54 | 55 | checkTrue( isErrorWithMessage(test3, "Error in checkSingleNumeric(AUC, description = \"AUC\") : \n Error in MRTSD : AUC is not a numeric of length 1. Value is: 7825 3847\n"), 56 | msg = " || TEST 3 : duration of infusion is of length > 1" ) 57 | 58 | } 59 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.checkorderedvector.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: 23459 $ 2 | # Date of last change: $LastChangedDate: 2010-12-07 11:23:47 +0000 (Tue, 07 Dec 2010) $ 3 | # Last changed by: $LastChangedBy: fgochez $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # tests the checkOrderedVector function in checkdata.R 10 | 11 | test.checkOrderedVector <- function() 12 | { 13 | if (!exists("checkOrderedVector", mode = "function")) { checkOrderedVector <- MangoNca:::checkOrderedVector } 14 | 15 | # TEST 1 : base case - ordered vector, returns NULL 16 | 17 | test1 <- checkOrderedVector( 1:5 ) 18 | checkTrue(is.null(test1), msg = " || TEST 1 : base case - ordered vector, returns NULL") 19 | 20 | # TEST 2 : ordered vector, with NAs 21 | 22 | test2 <- checkOrderedVector(c(NA, 1)) 23 | checkTrue(is.null(test2), msg = " || TEST 2 : ordered vector, with NAs") 24 | 25 | # TEST 3 : length 0 vector is ordered 26 | 27 | test3 <- checkOrderedVector(numeric(0)) 28 | checkTrue(is.null(test3), msg = " || TEST 3 : length 0 vector is ordered") 29 | 30 | # TEST 4 : unordered vector with no NA 31 | 32 | test4 <- try( checkOrderedVector(c(1.00001, 1), functionName = "func"), silent = TRUE ) 33 | checkEquals(as.character(test4), 34 | "Error in checkOrderedVector(c(1.00001, 1), functionName = \"func\") : \n Error in func: x is not ordered. Actual value is 1.00001 1\n", 35 | msg = " || unordered vector with no NA" ) 36 | 37 | # TEST 5 : unordered vector with NA 38 | 39 | test5 <- try( checkOrderedVector(c(NA, 0, 1.00001, NA, 1), functionName = "func", description = "y"), silent = TRUE ) 40 | checkTrue(is(test5, "try-error"), msg = " || TEST 5 : exception generated since vector is unordered") 41 | checkEquals(as.character(test5), 42 | "Error in checkOrderedVector(c(NA, 0, 1.00001, NA, 1), functionName = \"func\", : \n Error in func: y is not ordered. Actual value is NA 0 1.00001 NA 1\n", 43 | msg = " || unordered vector with no NA" ) 44 | 45 | 46 | # TEST 6 : non-vector 47 | 48 | test6 <- try( checkOrderedVector( Theoph, functionName = "func", description = "Theoph"), silent = TRUE ) 49 | checkTrue(is(test6, "try-error"), msg = " || TEST 6 : exception generated since vector is unordered") 50 | checkEquals(as.character(test6), 51 | "Error in checkOrderedVector(Theoph, functionName = \"func\", description = \"Theoph\") : \n Error in func: Theoph is not a vector\n", 52 | msg = " || unordered vector with no NA" ) 53 | 54 | } 55 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.pcExtrap.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 16/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # Tests the pcExtrap function 10 | 11 | test.pcExtrap <- function() 12 | { 13 | if (!exists("pcExrap", mode = "function")) { pcExtrap <- MangoNca:::pcExtrap } 14 | 15 | # TEST 1 : standard data set, no NA or 0 values 16 | 17 | test1 <- pcExtrap(Whole = 100, Measured = 60) 18 | checkEquals(test1, 40, msg = " || TEST 1 : standard data set, no NA or 0 values") 19 | 20 | # TEST 2 : Whole is 0 21 | 22 | test2 <- pcExtrap(Whole = 0, Measured = 60) 23 | checkEquals(test2, as.numeric(NA), msg = " || TEST 2 : Whole is 0") 24 | 25 | # TEST 3 : Measured is 0 26 | 27 | test3 <- pcExtrap(Whole = 1000, Measured = 0) 28 | checkEquals(test3, 100, msg = " || TEST 3 : Measured is 0") 29 | 30 | # TEST 4 : Infinite Whole 31 | 32 | test4 <- pcExtrap(Whole = Inf, Measured = 10000) 33 | checkEquals(test4, as.numeric(NA), msg = " || TEST 4 : Infinite Whole") 34 | 35 | # TEST 5 : 0 length vector 36 | 37 | test5 <- try(pcExtrap(Whole = numeric(0), Measured = pi), silent = TRUE ) 38 | checkTrue( is(test5, "try-error"), msg = " || TEST 5 : 0 length vector" ) 39 | checkEquals(as.character(test5), "Error in checkSingleNumeric(Whole, description = \"Whole\") : \n Error in pcExtrap : Whole is not a numeric of length 1. Value is: \n", 40 | msg = " || TEST 5 : 0 length vector yields correct exception message ") 41 | 42 | # TEST 6 : Complex Whole 43 | 44 | test6 <- try(pcExtrap(Whole = 1+0i, Measured = pi), silent = TRUE ) 45 | checkTrue( is(test6, "try-error"), msg = " || TEST 6 : Complex Whole" ) 46 | checkEquals(as.character(test6), "Error in checkSingleNumeric(Whole, description = \"Whole\") : \n Error in pcExtrap : Whole is not a numeric of length 1. Value is: 1+0i\n", 47 | msg = " || TEST 6 : Complex Whole yields correct exception message") 48 | 49 | # TEST 7 : basic data check 50 | 51 | test7 <- try( pcExtrap(Whole = "pi", Measured = pi), silent = TRUE ) 52 | checkTrue( is(test7, "try-error"), msg = " || TEST 7 : basic data check yields exception" ) 53 | checkEquals( as.character(test7), "Error in checkSingleNumeric(Whole, description = \"Whole\") : \n Error in pcExtrap : Whole is not a numeric of length 1. Value is: pi\n", 54 | msg = " || TEST 7 : basic data check yields correct exception message" ) 55 | } 56 | 57 | -------------------------------------------------------------------------------- /mangoNCA/man/selectPoints.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/selectPoints.R 3 | \name{selectPoints} 4 | \alias{selectPoints} 5 | \title{Number of Points for Calculating Terminal Rate Constant} 6 | \usage{ 7 | selectPoints(Conc, Time, minPoints = 3, method = "ars", excPoints = FALSE, 8 | Safe = TRUE) 9 | } 10 | \arguments{ 11 | \item{Conc}{Vector of concentrations.} 12 | 13 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates.} 14 | 15 | \item{minPoints}{Minimum number of points to use for the Lambdaz calculation(s), 3 by default. Single positive integer.} 16 | 17 | \item{method}{Method of selecting points (only Adjusted R-Squared Method implemented).} 18 | 19 | \item{excPoints}{Logical vector (\code{FALSE} by default) excludeing \code{TRUE} rows from automatic calculation of terminal phase.} 20 | 21 | \item{Safe}{Single logical value declaring whether to perform redundant data checks (default is TRUE).} 22 | } 23 | \value{ 24 | List consisting of numPoints, a single numeric value, and result, a length 9 numeric vector. 25 | } 26 | \description{ 27 | Choose Number of Trailing Points to use for Terminal Rate Constant (Lambdaz) Calculation. 28 | } 29 | \details{ 30 | Calculates number of points to use for Terminal Rate Constant (Lambdaz) calculation based on Adjusted R-squared method. 31 | selectPoints calls \code{\link{lambdaZStatistics}} to perform regressions using the last three rows, 32 | then the last four rows, last five, etc. Rows prior to Cmax are not used. 33 | Exclusion of rows prior to the end of infusion is not currently implemented. 34 | For each regression, an adjusted R2 is computed. The regression with the largest adjusted R2 is 35 | selected to estimate lambdaz, with these caveats: 36 | \enumerate{ 37 | \item Number of rows with the greatest number of rows AND within MAXDIFFRSQ (0.0001) of the largest adjusted R2 value is selected. 38 | \item Rows where Conc <= 0 are not used in the calculation 39 | \item Trailing rows where Conc <= 0 are removed by \code{stripTrailingZeros} and not counted in number returned 40 | \item Cmax is not included in Lambdaz calculation (User Requirements PEX-010) 41 | \item lambdaz must be greater than MINLAMBDAZ (0) 42 | \item lambdaz must be calculated using at least minPoints (3) data rows 43 | \item adjr2 must be at least MINADJR2 (0.8) 44 | \item tPhaseHalfLife must be less than lambdaz interval (LambdazUpper - LambdazLower) 45 | } 46 | Zero or missing values will be removed with a warning. 47 | } 48 | \examples{ 49 | Theoph1 <- subset(Theoph, Subject == 1) 50 | selectPoints(Conc = Theoph1$conc, Time = Theoph1$Time) 51 | } 52 | \author{ 53 | Mango Solutions 54 | } 55 | \keyword{math} 56 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.CmaxTmax.R: -------------------------------------------------------------------------------- 1 | # SVN revision: 2 | # Date of last change: 18/06/2013 3 | # Last changed by: ccampbell 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # test the CmaxTmax function from maxmin.R 10 | 11 | test.CmaxTmax <- function() 12 | { 13 | 14 | # minimum number of cases = 4 15 | 16 | # TEST 1 : standard case 17 | 18 | test1 <- CmaxTmax( Conc = c(NA, 10, 9:2), Time = c(1:10) ) 19 | checkEquals( test1, list(cmax = 10, tmax = 2, index = 2), msg = " || simple case is correct") 20 | 21 | # TEST 2 : 1 < maxima, check that minimal time is retrieved 22 | 23 | test2 <- CmaxTmax( Conc = c(1:3, rep(10, times = 7) ), Time = c(10:1) ) 24 | checkEquals( test2, list(cmax = 10, tmax = 7, index = 4), msg = " || simple case is correct") 25 | 26 | # TEST 3 : basic error handling - vectors should be of same length 27 | 28 | test3 <- try( CmaxTmax( 1:10, 1:9 ), silent = TRUE) 29 | checkTrue( is(test3, "try-error"), msg = " || TEST3 : exception generated ") 30 | # FIXME : need to check that the exception message is correct 31 | 32 | # TEST 4 : one of the times corresponding to cmax is NA 33 | 34 | test4 <- CmaxTmax( c(1, 2, 3, 3), c(1, 2, 3, NA) ) 35 | checkEquals( test4, list( cmax = 3, tmax = 3, index = 3), msg = "|| TEST4: multiple values of concentration, one is NA" ) 36 | 37 | # TEST 5 : only time corresponding to cmax is NA 38 | 39 | test5 <- CmaxTmax( 1:3, c(1, 2, NA) ) 40 | checkEquals( test5, list( cmax = 3, tmax = as.numeric(NA), index = 3), msg = "|| TEST5: time corresponding to max concentration is NA" ) 41 | 42 | # TEST 6 : concentrations add up to 0 43 | 44 | test6 <- CmaxTmax(Time = 1:4, Conc = rep(0, 4) ) 45 | checkEquals( test6, list(cmax = NA, tmax = NA, index = NA), msg = " || TEST6 : concentrations add up to 0 causes NA values to be returned" ) 46 | 47 | # TEST 7 : max concentration is 0 48 | 49 | test7 <- CmaxTmax(Time = 1:2, Conc = c(-1, 0) ) 50 | checkEquals( test7, list(cmax = 0, tmax = NA, index = 2), msg = " || TEST7 : max concentration is 0, so NA is returned for time" ) 51 | 52 | # TEST 8 : no non-missing concentrations. Return should be NA (?) 53 | 54 | test8 <- CmaxTmax( Time = 1:3, Conc = rep(NA, 3) ) 55 | checkEquals( test8, list(cmax = NA, tmax = NA, index = NA), msg = " || No non-missing concentrations. Return should be NA") 56 | 57 | # TEST 9 : 3 maxima, check that minimal time is retrieved 58 | 59 | test9 <- CmaxTmax(Conc = c(1, 10, 8, 10, 7, 10, 6, 4, 3.5, 2.8), Time = 0:9 ) 60 | checkEquals( test9, list(cmax = 10, tmax = 1, index = 2), msg = " || simple case is correct") 61 | } 62 | -------------------------------------------------------------------------------- /mangoNCA/man/getPartialAUC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getPartialAUC.R 3 | \name{getPartialAUC} 4 | \alias{getPartialAUC} 5 | \title{Partial Area Under Curve} 6 | \usage{ 7 | getPartialAUC(Conc = NULL, Time = NULL, startTime = NULL, 8 | endTime = NULL, numPoints = NULL, usePoints = NULL, excPoints = NULL, 9 | Safe = TRUE, inter = "Linear") 10 | } 11 | \arguments{ 12 | \item{Conc}{Vector of concentrations} 13 | 14 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 15 | 16 | \item{startTime}{Single numeric value, first time from which area should be calculated} 17 | 18 | \item{endTime}{Single numeric value, last time to which area should be calculated} 19 | 20 | \item{numPoints}{single numeric value declaring number of points to use} 21 | 22 | \item{usePoints}{If \code{NULL} (default) automatically select, else, logical vector of points to use for calculation of terminal phase. Used rows are flagged by usePoints as \code{TRUE}.} 23 | 24 | \item{excPoints}{If \code{NULL} (default) automatically select, else, logical vector of points to exclude from automatic calculation of terminal phase. Excluded rows are flagged by excPoints as \code{TRUE}.} 25 | 26 | \item{Safe}{Single logical value, if FALSE don't perform additional error checks} 27 | 28 | \item{inter}{Single character stating whether the interpolation method used is \code{"Linear"} (default), \code{"Lin up Log down"} or \code{"Linear Log"}} 29 | } 30 | \value{ 31 | Data frame 32 | } 33 | \description{ 34 | Area Under the Concentration Time Curve from T = startTime to T = endTime 35 | } 36 | \details{ 37 | This is a wrapper function designed to be the interface for performing a partial AUC calculation. 38 | \code{getPartialAUC} returns the area under a time-concentration curve from \code{firstTime} up until \code{endTime}. 39 | The calculation is performed by subtracting AUC_0_startTime from AUC_0_endTime using \code{AUCPartial}. 40 | \code{endTime} need not be one of the elements of \code{Time}. 41 | If \code{endTime} does not coincide with an existing time element and is less than tlast, 42 | the following interpolation formula will be used to calculated a new concentration: 43 | \deqn{c_{inter} = c_1 + \left| \frac{ t^{end} - t_1}{t_2 - t_1} \right| (c_2 - c_1)}. 44 | If endTime is greater than tlast, then another concentration is extrapolated via the formula: 45 | \deqn{c_{extr} = c_0 + \exp(- \lambda_z * endTime) }. 46 | \code{numPoints} is calculated by \code{\link{selectPoints}}. 47 | Returns a data frame with 1 row containing columns: 48 | \enumerate{ 49 | \item \code{startTime} 50 | \item \code{endTime} 51 | \item \code{AUCPartial} 52 | \item \code{numPoints} 53 | \item \code{Error} 54 | } 55 | } 56 | \author{ 57 | Mango Solutions 58 | } 59 | \keyword{math} 60 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.MRTInfObsSD.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 27/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | test.MRTInfObsSD <- function() 11 | { 12 | 13 | # TEST 1 : contrived data, standard example 14 | 15 | AUMCio <- AUCInfObs( Time = 0:6, Conc = 7:1, numPoints = 3, calculation = "moment", addT0 = FALSE) # 67.23701252 16 | AUCio <- AUCInfObs( Time = 0:6, Conc = 7:1, numPoints = 3, calculation = "standard", addT0 = FALSE) # 25.82047845 17 | mrto <- AUMCio / AUCio - 5/2 18 | checkEquals( 0.1040188465, mrto, tol = 1e-9, msg = " || TEST 1(a) : simple contrived data" ) 19 | mrt <- MRTSD(AUC = 25.82047845, AUMC = 67.23701252, Dof = 5) 20 | checkEquals( 0.1040188465, mrto, tol = 1e-9, msg = " || TEST 1(b) : simple contrived data" ) 21 | 22 | test1 <- MRTInfObsSD( Time = 0:6, Conc = 7:1, numPoints = 3, Dof = 5, addT0 = FALSE) 23 | checkEquals( test1, mrto, tol = 1e-6, msg = " || TEST 1(c) : simple contrived data" ) 24 | 25 | 26 | # TEST 2 : stock data set 27 | 28 | Theoph2 <- subset(Theoph, Subject == 2) 29 | test2 <- MRTInfObsSD(Time = Theoph2$Time, Conc = Theoph2$conc, numPoints = 3, Dof = 2 ) 30 | 31 | checkEquals( test2, 8.992229665, tol = 1e-6, msg = " || TEST 2 : stock data set" ) 32 | 33 | # TEST 3 : Dof is less than 0 : NA should be returned. 34 | 35 | test3 <- MRTInfObsSD(Time = Theoph2$Time, Conc = Theoph2$conc, numPoints = 3, Dof = -1 ) 36 | checkTrue( is.na( test3 ), msg = " || TEST 3 : negative Dof causes NA to be returned" ) 37 | 38 | } 39 | 40 | 41 | test.MRTInfObsSD_errorHandling <- function() 42 | { 43 | isErrorWithMessage <- MangoNca:::isErrorWithMessage 44 | 45 | # TEST 1 : duration of infusion is of length > 1 46 | 47 | test1 <- try( MRTInfObsSD( Time = 0:6, Conc = 7:1, numPoints = 3, Dof = 1:2), silent = TRUE) 48 | 49 | checkTrue( isErrorWithMessage(test1, "Error in checkSingleNumeric(Dof, description = \"Duration of infusion\") : \n Error in MRTInfObsSD : Duration of infusion is not a numeric of length 1. Value is: 1 2\n" ), 50 | msg = " || TEST 1 : duration of infusion is of length > 1" ) 51 | 52 | # TEST 2 : duration of infusion is not numeric 53 | 54 | test2 <- try( MRTInfObsSD( Time = 0:6, Conc = 7:1, numPoints = 3, Dof = "1"), silent = TRUE) 55 | checkTrue( isErrorWithMessage(test2, "Error in checkSingleNumeric(Dof, description = \"Duration of infusion\") : \n Error in MRTInfObsSD : Duration of infusion is not a numeric of length 1. Value is: 1\n" ), 56 | msg = " || TEST 2 : duration of infusion is not numeric" ) 57 | 58 | } 59 | -------------------------------------------------------------------------------- /mangoNCA/R/cmintmin.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 20/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | #' Finds the minimum concentration value and the first time point (in the sense of corresponding to the minimal index) 10 | #' with that concentration. 11 | #' 12 | #' @title Calculate Minimum Concentration and time of minimum concentration 13 | #' @param Conc numeric vector of concentrations 14 | #' @param Time numeric vector of time points (parallel to \code{Conc}) 15 | #' @return list with numeric scalar (length 1 vector) components "cmin", "tmin" and "index". 16 | #' @note The following error checks / processing will be performed: 17 | #' \enumerate{ 18 | #' \item If \code{Conc} or \code{Time} are of length 0, NA is returned for both values 19 | #' \item If the sum of \code{Code} (after omitting missing values) is 0, NA is returned for both values 20 | #' \item \code{cmin} is computed by stripping NA values from \code{Conc} 21 | #' \item if \code{Conc} and \code{Time} are not equal length numeric vectors, an exception will be generated by \code{\link{checkNumericSameLength}} 22 | #' } 23 | #' @examples 24 | #' Theoph2 <- subset(Theoph, Subject == 2) 25 | #' CminTmin( Theoph2$conc, Theoph2$Time ) 26 | #' @keywords math 27 | 28 | CminTmin<- function(Conc, Time){ 29 | 30 | checkNumericSameLength(Time, Conc, "Time", "Concentration") 31 | 32 | # timeConc : data.frame which holds time and concentration in a single object 33 | timeConc <- data.frame(Time, Conc) 34 | 35 | # Initialize variables, set default value to NA 36 | # cmin : single element numeric vector, will hold minimum concentration 37 | # tmin : single element numeric vector, will hold first time of minimum concentration 38 | 39 | cmin <- NA 40 | tmin <- NA 41 | index <- NA 42 | 43 | ## Do Data check : there should be at least one conc/time element, and sum of concentrations should be non-zero 44 | if(nrow(timeConc) < 1){ 45 | return(list(cmin = cmin, tmax = tmin, index = index)) 46 | } 47 | 48 | if(sum(timeConc$Conc, na.rm=TRUE) == 0){ 49 | return(list(cmin = cmin, tmin = tmin, index = index)) 50 | } 51 | 52 | # Find the minimum concentration value (ignore NA values). 53 | 54 | cmin <- min(timeConc$Conc, na.rm = TRUE) 55 | 56 | # Get the indices that match cmin and then find the minimum index value. 57 | # This assumes that x is sorted in assending order of time to get the first occurance of cmin. 58 | 59 | index <- min(which(timeConc$Conc == cmin)) 60 | 61 | tmin <- timeConc[index, "Time"] 62 | 63 | 64 | return(list(cmin = cmin, tmin = tmin, index = index)) 65 | } 66 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.clearance.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 25/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # Tests the clearance function 10 | 11 | test.clearance <- function() 12 | { 13 | 14 | # TEST 1 : Nonzero AUCInf 15 | 16 | test1 <- clearance(AUCInf = 20000, Dose = 20 * 1000) 17 | checkEquals( test1, 1.0, msg = " || TEST 1 : Nonzero AUCInf" ) 18 | 19 | # TEST 2 : AUCInf NA 20 | 21 | test2 <- clearance(AUCInf = as.numeric(NA), Dose = 15 * 1000) 22 | checkEquals(test2, as.numeric(NA), msg = " || TEST 2 : AUCInf NA") 23 | 24 | # TEST 3 : negative AUCInf 25 | 26 | test3 <- clearance(AUCInf = -50000, Dose = 20 * 1000) 27 | checkEquals(test3, as.numeric(NA), msg = " || TEST 3 : negative AUCInf is NA") 28 | 29 | # TEST 4a : Infinite AUC 30 | 31 | test4a <- clearance(AUCInf = Inf, Dose = 1000 * 1000) 32 | checkEquals(test4a, as.numeric(0), msg = " || TEST 4a : Infinite AUCInf is 0") 33 | 34 | # TEST 4b : Infinite AUC 35 | 36 | test4b <- clearance(AUCInf = -Inf, Dose = 1000 * 1000) 37 | checkEquals(test4b, as.numeric(NA), msg = " || TEST 4 : negative Inf AUCInf is NA") 38 | 39 | # TEST 5 : 0 length vector 40 | 41 | test5 <- try(clearance(AUCInf = numeric(0), Dose = pi), silent = TRUE ) 42 | checkTrue( is(test5, "try-error"), msg = " || TEST 5 : 0 length vector" ) 43 | checkEquals(as.character(test5), "Error in checkSingleNumeric(AUCInf, description = \"AUCInf\", functionName = \"clearance\") : \n Error in clearance : AUCInf is not a numeric of length 1. Value is: \n", 44 | msg = " || TEST 5 : 0 length vector yields correct exception message ") 45 | 46 | # TEST 6 : AUC is zero 47 | 48 | test6 <- try(clearance(AUCInf = FALSE, Dose = 1), silent = TRUE ) 49 | checkTrue( is(test6, "try-error"), msg = " || TEST 6 : AUC is zero" ) 50 | checkEquals(as.character(test6), "Error in checkSingleNumeric(AUCInf, description = \"AUCInf\", functionName = \"clearance\") : \n Error in clearance : AUCInf is not a numeric of length 1. Value is: FALSE\n", 51 | msg = " || TEST 6 : 0 AUC is zero yields correct exception message") 52 | 53 | # TEST 7 : basic data check 54 | 55 | test7 <- try( clearance(AUCInf = "BLQ", Dose = 1), silent = TRUE ) 56 | checkTrue( is(test7, "try-error"), msg = " || TEST 7 : basic data check yields exception" ) 57 | checkEquals( as.character(test7), "Error in checkSingleNumeric(AUCInf, description = \"AUCInf\", functionName = \"clearance\") : \n Error in clearance : AUCInf is not a numeric of length 1. Value is: BLQ\n", 58 | msg = " || TEST 7 : basic data check yields correct exception message" ) 59 | } 60 | 61 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.MRTInfPredSS.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 03/04/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | test.MRTPredInfSS <- function() 11 | { 12 | if (!exists("MRTInfPredSS", mode = "function")) { MRTInfPredSS <- MangoNca:::MRTInfPredSS } 13 | 14 | # TODO check calcs 15 | # needs verification if required by tool 16 | 17 | # TEST 1 : contrived data, standard example 18 | 19 | # AUMCtau = 8; AUCtau = 5.5; tau = 2; dof = 5; AUCInfPred = 19.40989 20 | # (AUMCtau + tau * (AUCInfPred - AUCtau)) / AUCtau - dof/2 21 | # [1] 4.012687273 22 | 23 | test1 <- MRTInfPredSS( Time = 0:6, Conc = 7:1, numPoints = 3, tau = 2, dof = 5, addT0 = FALSE) 24 | checkEquals( test1, 0.7349818947, tol = 1e-7, msg = " || TEST 1 : simple contrived data" ) 25 | 26 | # TEST 2 : stock data set 27 | 28 | Theoph2 <- subset(Theoph, Subject == 2) 29 | test2 <- MRTInfPredSS(Time = Theoph2$Time, Conc = Theoph2$conc, tau = 18, numPoints = 3, dof = 2 ) 30 | 31 | # AUMCtau = 565; AUCtau = 82; tau = 18; dof = 3; AUCInfPred = 100 32 | # (AUMCtau + tau * (AUCInfPred - AUCtau)) / AUCtau - dof/2 33 | # [1] 9.341463415 34 | 35 | checkEquals(test2, 9.711059145, tol = 1e-7, msg = " || TEST 2 : stock data set" ) 36 | 37 | # TEST 3 : tau is greater than the largest element of Time, so extrapolation will be tested 38 | 39 | test3 <- MRTInfPredSS(Time = Theoph2$Time, Conc = Theoph2$conc, tau = 26, numPoints = 3, dof = 2 ) 40 | 41 | checkEquals(test3, 8.634078618, tol = 1e-7, msg = " || TEST 3 : tau is greater than the largest element of Time ") 42 | } 43 | 44 | 45 | test.MRTPredInfSS_errorHandling <- function() 46 | { 47 | if (!exists("MRTInfPredSS", mode = "function")) { MRTInfPredSS <- MangoNca:::MRTInfPredSS } 48 | 49 | # TEST 1 : duration of infusion is of length > 1 50 | 51 | test1 <- try( MRTInfPredSS( Time = 0:6, Conc = 7:1, numPoints = 3, tau = 2, dof = 1:2), silent = TRUE) 52 | 53 | checkTrue(MangoNca:::isErrorWithMessage(test1, "Error in checkSingleNumeric(dof, description = \"duration of infusion\") : \n Error in MRTInfPredSS : duration of infusion is not a numeric of length 1. Value is: 1 2\n" ), 54 | msg = " || TEST 1 : duration of infusion is of length > 1" ) 55 | 56 | # TEST 2 : duration of infusion is not numeric 57 | 58 | test2 <- try( MRTInfPredSS( Time = 0:6, Conc = 7:1, numPoints = 3, tau = 2, dof = "1"), silent = TRUE) 59 | checkTrue(MangoNca:::isErrorWithMessage(test2, "Error in checkSingleNumeric(dof, description = \"duration of infusion\") : \n Error in MRTInfPredSS : duration of infusion is not a numeric of length 1. Value is: 1\n" ), 60 | msg = " || TEST 2 : duration of infusion is not numeric") 61 | 62 | } 63 | -------------------------------------------------------------------------------- /mangoNCA/man/AUCPartial.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCPartial.R 3 | \name{AUCPartial} 4 | \alias{AUCPartial} 5 | \title{Partial Area Under Concentration Time Curve} 6 | \usage{ 7 | AUCPartial(Conc, Time, endTime, numPoints = NULL, lambdaZStats = NULL, 8 | usePoints = NULL, excPoints = FALSE, minPoints = 3, addT0 = FALSE, 9 | inter = "Linear") 10 | } 11 | \arguments{ 12 | \item{Conc}{Vector of concentrations} 13 | 14 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 15 | 16 | \item{endTime}{: last time at which area should be calculated} 17 | 18 | \item{numPoints}{: Number of points to use for lambdaz calculation.} 19 | 20 | \item{lambdaZStats}{if not \code{NULL}, a list with 9 elements (see details). Must be provided if numPoints is not.} 21 | 22 | \item{usePoints}{If NULL (default) automatically select, else, logical vector of points to use (\code{TRUE}) for calculation of terminal phase.} 23 | 24 | \item{excPoints}{Logical vector (\code{FALSE} by default) excludeing \code{TRUE} rows from automatic calculation of terminal phase.} 25 | 26 | \item{minPoints}{single numeric, the fewest points for which a linear model fit should be attempted (default 3)} 27 | 28 | \item{addT0}{single logical, should T=0, C=0 be added to the input data if T0 is missing? (default \code{FALSE})} 29 | 30 | \item{inter}{Single character stating whether the interpolation method used is \code{"Linear"} (default), \code{"Lin up Log down"} or \code{"Linear Log"}} 31 | } 32 | \value{ 33 | Single numeric with partial area under curve 34 | } 35 | \description{ 36 | Area Under the Concentration Time Curve from T = 0 to T = endTime 37 | } 38 | \details{ 39 | Calculates the area under a time-concentration curve from the first time up until the \code{endTime}. 40 | \code{endTime} need not be one of the elements of \code{Time}, but it should not lie before the minimum time. 41 | If the endTime does not coincide with an existing time element and is less than tlast, the following 42 | interpolation formula will be used to calculated a new concentration: 43 | \deqn{c_{inter} = c_1 + \left| \frac{ t^{end} - t_1}{t_2 - t_1} \right| (c_2 - c_1)}. 44 | If endTime is greater than tlast the extrapolated area is calculated using \code{getTerminalAUC} 45 | which calculates the area under the terminal phase exponential from TLast to endTime. 46 | \code{numPoints} is calculated by \code{\link{getPartialAUC}} . 47 | This calculation is the integral of the Terminal phase exponential decay function: 48 | \deqn{\int intercept \ast exp\left ( -\lambda _{z} \ast T\right ) dT = 49 | -intercept / \left ( \lambda _{z} \ast exp\left ( \lambda _{z} \ast T\right )\right)} 50 | The partial area under the terminal concentration time curve can be calculated 51 | by subtracting modeled AUC0Tlast from modeled AUC0endTime. 52 | \code{numPoints} may be NA provided endTime < Tlast. 53 | } 54 | \seealso{ 55 | \code{\link{lambdaZStastics}} for more about the numPoints parameter 56 | } 57 | \author{ 58 | Mango Business Solutions 59 | } 60 | \keyword{math} 61 | -------------------------------------------------------------------------------- /mangoNCA/man/AUCLast.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCLast.R 3 | \name{AUCLast} 4 | \alias{AUCLast} 5 | \title{Calculate Area Under Curve Until Last Measurable Concentration} 6 | \usage{ 7 | AUCLast(Conc, Time, addT0 = FALSE, Safe = TRUE, inter = "Linear") 8 | } 9 | \arguments{ 10 | \item{Conc}{A numeric vector of concentration values} 11 | 12 | \item{Time}{A numeric vector of time values, parallel to \code{Conc} and of the same length. These should be sorted in ascending order.} 13 | 14 | \item{addT0}{Single logical value declaring whether T0 should be added if missing provided execution is Safe (default TRUE).} 15 | 16 | \item{Safe}{Single logical value declaring whether to perform data checks and data cleaning (default is TRUE).} 17 | 18 | \item{inter}{Single character stating whether the interpolation method used is \code{"Linear"} (default), 19 | \code{"Lin up Log down"} or \code{"Linear Log"} (not case or space sensitive).} 20 | } 21 | \value{ 22 | single numeric - area under the concentration/time curve until the last measurable concentration. 23 | } 24 | \description{ 25 | Area Under the Curve to from Time = 0 to Time = Last 26 | } 27 | \details{ 28 | AUCLast calculates the area under a time/concentration curve from the first point up until the last 29 | measurable concentration using one of three methods. 30 | \code{Linear} rule calculates the area of the trapezia bounded by each sequential pair of time and concentration points (see \code{AUCLin}). 31 | 32 | \code{Linear Log} rule is a combination of the Linear trapezoidal rule and the Log trapezoidal rule (see \code{AUCLog}). Before Cmax 33 | (as in the absorption phase), the linear trapezoidal method is used. After Cmax 34 | (as in the elimination phase), the logarithmic trapezoidal method is used. 35 | 36 | \code{Lin Up Log Down} rule is a combination of the Linear trapezoidal rule and the Log trapezoidal rule. When concentrations are increasing 37 | (as in the absorption phase), the linear trapezoidal method is used. When concentrations are decreasing 38 | (as in the elimination phase), the logarithmic trapezoidal method is used. 39 | 40 | These alternative methods to the Linear is often preferred because 41 | the linear method is often a good approximation of drug absorption while logarithmic decline is well represented 42 | by the logarithmic trapezoidal method during drug elimination. 43 | 44 | Calculations are performed for the area bounded by T0 and the time of the last nonzero, non-missing concentration. 45 | For comparison with WinNonLin, a timepoint at T = 0 is added if it does not exist. 46 | Missing values are removed before further calculations are performed. 47 | } 48 | \note{ 49 | The following error checks / processing will be performed: 50 | \enumerate{ 51 | \item If \code{Conc} or \code{Time} are of length 1 or 0, a single NA is returned 52 | \item \code{Conc} and \code{Time} should be equal length numeric vectors, otherwise an exception will be generated. 53 | \item If \code{clast} or \code{tlast} is NA, NA will be returned 54 | \item There should be no duplicated time entries 55 | } 56 | } 57 | \examples{ 58 | Theoph1 <- subset(Theoph, Subject == 1) 59 | AUCLast(Theoph1$conc, Theoph1$Time) 60 | } 61 | \author{ 62 | Mango Solutions 63 | } 64 | \keyword{math} 65 | -------------------------------------------------------------------------------- /mangoNCA/R/cmaxtmax.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 24/02/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | #' Calculate Maximum Concentration and time of maximum concentration 11 | #' 12 | #' Finds the maximum concentration value and the first time point 13 | #' (in the sense of corresponding to the minimal index) 14 | #' with that concentration. 15 | #' 16 | #' @title Calculate Maximum Concentration and time of maximum concentration 17 | #' @param Conc numeric vector of concentrations 18 | #' @param Time numeric vector of time points (parallel to \code{Conc}) 19 | #' @return list with numeric scalar (length 1 vector) components "cmax", "tmax" and "index". See notes for further processing. 20 | #' @export 21 | #' @note The following error checks / processing will be performed: 22 | #' \enumerate{ 23 | #' \item If \code{Conc} or \code{Time} are of length 0, NA is returned for both values 24 | #' \item If the sum of \code{Code} (after omitting missing values) is 0, NA is returned for both values 25 | #' \item If \code{cmax} is 0, NA is returned for \code{tmax} 26 | #' \item \code{cmax} is computed by stripping NA values from \code{Conc} 27 | #' \item if \code{Conc} and \code{Time} are not equal length numeric vectors, an exception will be generated by 28 | #' \code{\link{checkNumericSameLength}} 29 | #' } 30 | #' @examples 31 | #' Theoph.2 <- subset(Theoph, Subject == 2) 32 | #' CmaxTmax( Theoph.2$conc, Theoph.2$Time ) 33 | #' @keywords math 34 | 35 | CmaxTmax <- function(Conc, Time) { 36 | 37 | checkNumericSameLength(Time, Conc, "Time", "Concentration") 38 | 39 | # timeConc : data.frame which holds time and concentration in a single object 40 | 41 | timeConc <- data.frame(Time, Conc) 42 | 43 | # Initialize variables, set default value to NA 44 | # cmax : single element numeric vector, will hold maximum concentration 45 | # tmax : single element numeric vector, will hold first time of maximum concentration 46 | # index : single element numeric vector, will hold index of maximum concentration 47 | 48 | cmax <- NA 49 | tmax <- NA 50 | index <- NA 51 | 52 | ## Do Data check : there should be at least one conc/time element, and sum of concentrations should be non-zero 53 | 54 | if(nrow(timeConc) < 1){ 55 | return(list(cmax = cmax, tmax = tmax, index = index)) 56 | } 57 | if(sum(timeConc$Conc, na.rm=TRUE) == 0){ 58 | return(list(cmax = cmax, tmax = tmax, index = index)) 59 | } 60 | 61 | # Find the maximum concentration value (ignore NA values). 62 | 63 | cmax <- max(timeConc$Conc, na.rm = TRUE) 64 | 65 | # Get the indexes that match cm and then find the minimum index value. 66 | # This assumes that x is sorted in assending order of time to get the first occurance of cm. 67 | 68 | index <- min(which(timeConc$Conc == cmax)) 69 | tmax <- timeConc[index, "Time"] 70 | 71 | # cmax should be greater than 0, else tmax is NA 72 | 73 | if( cmax == 0 ){ 74 | tmax <- NA 75 | } 76 | 77 | return(list(cmax = cmax, tmax = tmax, index = index)) 78 | } 79 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.ncapeaktrough.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 16/03/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.ncaPeakTrough <- function() 10 | { 11 | load(system.file(package = "MangoNca", "data", "shapeROutput.RData")) 12 | 13 | # TEST 1 : Contrived check no errors 14 | 15 | test1 <- ncaPeakTrough(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, Dose = 10, Dof = 2, PeakTrough = c(1, 0, 2, rep(0, 6)), ROutput = shapeROutput) 16 | checkEquals( test1[["ROutput_Error"]], 0, msg = " || TEST 1(a) : No Errors, contrived data set\n" ) 17 | checkEquals( test1[["ROutput_Peak"]], 8, msg = " || TEST 1(b) : Contrived data set\n" ) 18 | 19 | # TEST 2 : Contrived check NAs in PeakTrough 20 | 21 | test2 <- ncaPeakTrough(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, Dose = 10, Dof = 2, PeakTrough = c(1, NA, NA, rep(0, 6)), ROutput = shapeROutput) 22 | checkEquals( test2[["ROutput_Error"]], 0, msg = " || TEST 2(a) : No Errors, contrived data set with NAs\n" ) 23 | checkEquals( test2[["ROutput_Trough"]], 4, msg = " || TEST 2(b) : Contrived data set\n" ) 24 | checkTrue( is.na(test2[["ROutput_Peak"]]), msg = " || TEST 2(c) : Contrived data set, missing code returns NA\n" ) 25 | 26 | # TEST 3 : Contrived check errors in PeakTrough 27 | 28 | test3 <- ncaPeakTrough(Conc = c(4, 9, 8, 6, 4:1, 1), Time = 0:8, Dose = 10, Dof = 2, PeakTrough = c(1, 2, 2, rep(0, 6)), ROutput = shapeROutput) 29 | checkEquals( test3[["ROutput_Error"]], " Error in checkPeakTrough(PeakTrough, functionName = \"ncaPeakTrough\") : \n Error in ncaPeakTrough: PeakTrough is miscoded. Actual value is 1 2 2 0 0 0 0 0 0\n ", 30 | msg = " || TEST 3(a) : Errors in PeakTrough with contrived data set\n" ) 31 | checkTrue( is.na(test3[["ROutput_Peak"]]), msg = " || TEST 3(c) : Contrived data set, Error returns NA for Peak\n" ) 32 | 33 | ## TEST 4 : Theoph data set 34 | 35 | Theoph2 <- subset(Theoph, Subject == 2) 36 | 37 | test4 <- ncaPeakTrough(Conc = Theoph2$conc, Time = Theoph2$Time, 38 | Dose = Theoph2$Dose[1], Dof = 1, PeakTrough = c(1, rep(0, 3), 2, rep(0, 6)), ROutput = shapeROutput) 39 | checkEquals( test4[["ROutput_Trough"]], 0, msg = " || TEST 4 : Theoph data set\n" ) 40 | 41 | ## TEST 5 : Theoph data, miscoded Trough 42 | 43 | test5 <- ncaPeakTrough(Conc = Theoph2$conc, Time = Theoph2$Time, 44 | Dose = Theoph2$Dose[1], Dof = 1, PeakTrough = c(-1, rep(0, 3), 2, rep(0, 6)), ROutput = shapeROutput) 45 | checkEquals( test5[["ROutput_Error"]], 0, msg = " || TEST 5(a) : Theoph data set, miscoded Trough no error\n" ) 46 | checkTrue( is.na(test5[["ROutput_Trough"]]), msg = " || TEST 5(b) : Theoph data set, miscoded Trough missing\n" ) 47 | 48 | ## TEST 6 : Theoph data set, time out of sequence 49 | 50 | test6 <- ncaPeakTrough(Conc = Theoph2$conc, Time = rev(Theoph2$Time), 51 | Dose = Theoph2$Dose[1], Dof = 1, PeakTrough = c(1, rep(0, 3), 2, rep(0, 6)), ROutput = shapeROutput) 52 | checkEquals( test6[["ROutput_Error"]], 53 | "Error in checkOrderedVector(Time, description = \"Time\", functionName = \"ncaPeakTrough\") : \n Error in ncaPeakTrough: Time is not ordered. Actual value is 24.3 12 9 7.03 5.02 3.5 1.92 1 0.52 0.27 0\n ", 54 | msg = " || TEST 6 : Theoph data set, time out of sequence \n" ) 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /mangoNCA/R/clasttlast.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | #' Finds the last measurable (non-zero) concentration value and the last time point 10 | #' with that concentration. 11 | #' 12 | #' @title Calculate Last Measurable Concentration 13 | #' @param Conc numeric vector of concentrations 14 | #' @param Time numeric vector of time points (should be of equal length to Conc, and sorted). 15 | #' @note The following error checks / processing will be performed: 16 | #' \enumerate{ 17 | #' \item If \code{Conc} or \code{Time} are of length 0, a single NA is returned 18 | #' \item \code{Conc} and \code{Time} should be equal length numeric vectors, otherwise an exception will be generated 19 | #' \item It is assumed that these times and concentrations come from a single curve 20 | #' \item time should be sorted 21 | #' \item If the sum of \code{Conc} (after omitting missing values) is 0, returned values are NA 22 | #' } 23 | #' @return list with numeric scalar components \code{clast}, \code{tlast} and \code{index} 24 | #' @examples 25 | #' Theoph1 <- subset( Theoph, Subject == 1) 26 | #' ClastTlast( Conc = Theoph1$conc, Time = Theoph1$Time ) 27 | #' @keywords math utils 28 | #' @export 29 | 30 | ClastTlast <- function(Conc, Time) 31 | { 32 | 33 | checkNumericSameLength(Time, Conc, "Time", "Concentration") 34 | 35 | # check that the time vector is ordered, and generated an exception if it is not 36 | # TimeOrder : a numeric vector holding the ordering of the Time vector (with NA removed) 37 | 38 | TimeOrder <- order(na.omit(Time)) 39 | 40 | if( !all( TimeOrder == seq_along(na.omit(Time)) ) ) { 41 | stop("Time vector is not sorted!") 42 | } 43 | 44 | # concTime: data.frame holding columns of times and concentrations 45 | concTime <- data.frame(Time, Conc) 46 | 47 | # clast : single length numeric holding last measurable concentration 48 | # tlast : single length numeric holding time of last measureable concentration 49 | # indexlast : single length numeric holding last Measurable Concentration Index 50 | 51 | clast <- as.numeric(NA) 52 | tlast <- as.numeric(NA) 53 | indexlast <- as.numeric(NA) 54 | 55 | # Do Data check. There should be at least one concentration/time record, and the sum of the concentrations (after removing 56 | # NAs) should not be 0 57 | 58 | if( nrow(concTime) < 1 || sum(concTime$Conc, na.rm = TRUE) <= 0) 59 | { 60 | return(list(clast = clast, tlast = tlast, index = indexlast)) 61 | } 62 | 63 | # now find the last measurable concentration. 64 | # concentrationIsMeasurable : a logical vector of the same length as Conc which indicates if corresponding elements of 65 | # concentration are nonzero and non-missing 66 | # indexlast : either a 0-length numeric vector (if there were no non-missing concentrations) or a 67 | # length-one numeric vector holding the highest index of measurable concetration data 68 | 69 | concentrationIsMeasurable <- !( is.na(concTime$Conc) | ( concTime$Conc == 0 ) ) 70 | indexlast <- tail( which(concentrationIsMeasurable), 1 ) 71 | 72 | # no non-measurable concentrations, so return missing values 73 | 74 | if( length(indexlast) == 0 ) 75 | { 76 | return(list(clast = clast,tlast = tlast, index = as.numeric(NA))) 77 | } 78 | 79 | clast <- concTime$Conc[indexlast] 80 | tlast <- concTime$Time[indexlast] 81 | 82 | return(list(clast = clast, tlast = tlast, index = indexlast)) 83 | } 84 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.clasttlast.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: 22683 $ 2 | # Date of last change: $LastChangedDate: 2010-11-16 15:15:02 +0000 (Tue, 16 Nov 2010) $ 3 | # Last changed by: $LastChangedBy: fgochez $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # Tests the ClastTlast function 10 | 11 | test.ClastTlast <- function() 12 | { 13 | # use theophiline data 14 | # Theoph1 will be a data.frame with the Theoph data for subject 1 15 | 16 | Theoph1 <- subset( Theoph, Subject == 1) 17 | 18 | # TEST 1 : standard data set, no NA or 0 values 19 | 20 | test1 <- ClastTlast( Conc = Theoph1$conc, Time = Theoph1$Time ) 21 | checkEquals( test1, list(clast = 3.28, tlast = 24.37, index = 11), msg = " || TEST 1 : standard data set, no NA or 0 values" ) 22 | 23 | # TEST 2 : data set with mix of 0s and NAs, and only one measurable concentration 24 | 25 | test2 <- ClastTlast(Conc = c(0, 0, NA, 0, 0, 1, NA, NA, 0, 0, NA), Time = 1:11 ) 26 | checkEquals(test2, list(clast = 1, tlast = 6, index = 6), msg = " || TEST 2 : data set with mix of 0s and NAs, and only one measurable concentration") 27 | 28 | # TEST 3 : data with mix of 0s, NAs, and several measurable concentrations 29 | 30 | test3 <- ClastTlast(Conc = c(0, 0, NA, 0, 0, 1, NA, 2, 0, 0, NA), Time = 1:11 ) 31 | checkEquals(test3, list(clast = 2, tlast = 8, index = 8), msg = " || TEST 3 : data with mix of 0s, NAs, and several measurable concentrations") 32 | 33 | # TEST 4 : only first concentration is measurable 34 | 35 | test4 <- ClastTlast(Conc = c(1, 0, NA, 0, 0, 0), Time = 1:6 ) 36 | checkEquals(test4, list(clast = 1, tlast = 1, index = 1), msg = " || TEST 4 : only first concentration is measurable") 37 | 38 | # TEST 5 : only last concentration is measurable 39 | 40 | test5 <- ClastTlast(Conc = c(NA, 0, NA, 0, 0, 1), Time = 1:6 ) 41 | checkEquals(test5, list(clast = 1, tlast = 6, index = 6), msg = " || TEST 5 : only last concentration is measurable") 42 | 43 | # TEST 6 : no measurable concentrations 44 | 45 | naResult <- list(clast = as.numeric(NA), tlast = as.numeric(NA), index = as.numeric(NA)) 46 | test6 <- ClastTlast(Conc = c(NA, 0, NA, 0, 0, 0), Time = 1:6 ) 47 | checkEquals(test6, naResult, msg = " || TEST 6 : no measurable concentrations") 48 | 49 | # TEST 7 : 0 length vectors 50 | 51 | test7 <- ClastTlast(Conc = numeric(0), Time = numeric(0)) 52 | checkEquals(test7, naResult, msg = " || TEST 7 : 0 length vectors") 53 | 54 | # TEST 8 : concentrations add up to 0 55 | 56 | test8 <- ClastTlast(Conc = c(0, NA, 1, NA, -1), Time = 6:10) 57 | checkEquals(test8, naResult, msg = " || TEST 8 : concentrations add up to 0") 58 | 59 | # TEST 9 : basic data check 60 | 61 | test9 <- try( ClastTlast( Conc = 1, Time = "b" ), silent = TRUE ) 62 | checkTrue( is(test9, "try-error"), msg = " || TEST 9 : non-numeric time yields exception" ) 63 | checkEquals( as.character(test9), "Error in checkNumericSameLength(Time, Conc, \"Time\", \"Concentration\") : \n Error in ClastTlast: Time is not a numeric vector\n", 64 | msg = " || TEST 9 : non-numeric time yields correct exception message " ) 65 | 66 | # TEST 10 : unsorted time generates exception 67 | test10 <- try( ClastTlast( Conc = 1:2, Time = 2:1 ), silent = TRUE ) 68 | checkTrue(is(test10, "try-error"), msg = " || TEST 10 : exception generated due to unsorted time") 69 | checkEquals(as.character(test10), "Error in ClastTlast(Conc = 1:2, Time = 2:1) : Time vector is not sorted!\n", msg = " || TEST 10: correct exception message generated") 70 | 71 | } 72 | 73 | -------------------------------------------------------------------------------- /mangoNCA/man/lambdaZStatistics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lambdaz.R 3 | \name{lambdaZStatistics} 4 | \alias{lambdaZStatistics} 5 | \title{Calculate lambdaz and related parameters} 6 | \usage{ 7 | lambdaZStatistics(Conc, Time, numPoints = 3, Safe = TRUE, 8 | checkCmax = TRUE, minPoints = 3) 9 | } 10 | \arguments{ 11 | \item{Conc}{numeric vector of concentrations} 12 | 13 | \item{Time}{numeric vector of time points. Must be sorted in ascending order} 14 | 15 | \item{numPoints}{Number of points to use for the linear regression, counted from the end of the concentration/time vectors. 16 | Must be a single integer greater than minPoints and less than or equal to the length of \code{Time} and \code{Conc}.} 17 | 18 | \item{Safe}{Single logical value declaring whether to perform redundant data checks (default is TRUE).} 19 | 20 | \item{checkCmax}{Single logical value declaring whether Cmax is included in the data (default is TRUE).} 21 | 22 | \item{minPoints}{Single numeric declaring minimum acceptable number of rows for linear model. Default is 3, minimum accepted value is 2.} 23 | } 24 | \value{ 25 | A list with a set of length 1 numeric vectors. 26 | } 27 | \description{ 28 | Try to Calculate lambdaz and Related Parameters 29 | } 30 | \details{ 31 | Calculates the lambdaz estimate and related parameters. 32 | The \code{lm} function is used to fit a linear regression of the last \code{numPoints} 33 | concentration against time. 34 | These are counted from (and include) the last measurable concentration. 35 | The number of points does not necessarily correspond to the index of the input dataset since rows may be removed at a previous step. 36 | Components of the \code{"lm"} object are then used to compute lambdaz and related statistics. 37 | Returns a list of single numeric values: 38 | \enumerate{ 39 | \item \code{Lambdaz}: The negation of the slope of the regression line of the last 40 | \item \code{intercept}: The exponential of the intercept term of the regression 41 | \item \code{r2}: The R^2 of the regression fit 42 | \item \code{adjr2}: The adjusted R^2 of the regression fit 43 | \item \code{rhoXY}: The correlation coefficient of the observed fit. 44 | \item \code{tPhaseHalfLife}: Terminal phase half-life, equal to ln(2) / Lambdaz 45 | \item \code{LambdazLower}: Lower bound of time used in lambda z calculation 46 | \item \code{LambdazUpper}: Upper bound of time used in lambda z calculation 47 | \item \code{numPoints}: Number of points used in calculation 48 | } 49 | Note that the following additional error checking / additional processing will be performed on the inputs: 50 | \enumerate{ 51 | \item Missing elements (NA) of the time and concentration vectors will be removed during regression 52 | (a missing entry in one vector will cause the corresponding value in the other to be removed as well) 53 | \item If the sum of the (last \code{numPoints}) concentrations is 0, missing values will be returned for all elements of the returned list. 54 | \item \code{Conc} and \code{Time} must be numeric vectors of equal length, or an exception will be generated 55 | \item \code{Conc} has fewer than 2 elements, NA will be returned for all values 56 | \item If the linear regression fails for some reason, a warning will be emitted and NA will be returned for all values 57 | \item An exception will be generated if numPoints is not a single integer numeric between 3 and \code{length(Conc)} (inclusive) 58 | } 59 | This function is called from \code{selectPoints} that removes rows containing Cmax before passing them to \code{lambdaZStatistics}. 60 | Therefore there is the option to supress Cmax check by setting the argument checkCmax to \code{FALSE} 61 | } 62 | \examples{ 63 | Theoph2 <- subset(Theoph, Subject == 2) 64 | lambdazStatistics(Theoph2$conc, Theoph2$Time) 65 | } 66 | \keyword{math} 67 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.checksinglelogical.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 03/02/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | 11 | # tests the function checkSingleLogical from checkdata.R 12 | 13 | test.checkSingleLogical <- function() 14 | { 15 | if (!exists("checkSingleLogical", mode = "function")) { checkSingleLogical <- MangoNca:::checkSingleLogical } 16 | 17 | # TEST 1 : standard case 18 | 19 | test1 <- checkSingleLogical( FALSE ) 20 | checkTrue( is.null( test1 ), msg = " || TEST1: standard check - length 1 Logical " ) 21 | 22 | # TEST 2 : 0 length vectors 23 | 24 | test2 <- try(checkSingleLogical(logical(0), functionName = "try"), silent = TRUE) 25 | checkTrue(is(test2, "try-error"), msg = " || TEST2: exception generated" ) 26 | checkEquals(as.character(test2), 27 | "Error in checkSingleLogical(logical(0), functionName = \"try\") : \n Error in try : x is not a logical of length 1. Value is: \n", 28 | msg = " || TEST2: length 0 vector check message") 29 | 30 | # TEST 3 : All NA vector used 31 | 32 | test3 <- checkSingleLogical(as.logical(NA)) 33 | checkTrue( is.null( test3 ), msg = " || TEST3: NA vectors still Logical ") 34 | 35 | # TEST 4 : Logical matrix used, this should fail as inputs must be vectors 36 | 37 | test4 <-try(checkSingleLogical(matrix(TRUE), functionName = "try"), silent = TRUE) 38 | checkTrue(is(test4, "try-error"), msg = " || TEST4(a): exception generated" ) 39 | checkEquals(as.character(test4), 40 | "Error in checkSingleLogical(matrix(TRUE), functionName = \"try\") : \n Error in try : x is not a logical of length 1. Value is: \n [,1]\n\n [1,] TRUE\n" , 41 | msg = " || TEST4(b) check error message" ) 42 | 43 | # TEST 5 : length > 1 44 | 45 | test5 <- try(checkSingleLogical(c(TRUE, FALSE), functionName = "try"), silent = TRUE ) 46 | checkTrue(is(test5, "try-error"), msg = " || TEST5(a) exception generated" ) 47 | checkEquals(as.character(test5), 48 | "Error in checkSingleLogical(c(TRUE, FALSE), functionName = \"try\") : \n Error in try : x is not a logical of length 1. Value is: TRUE FALSE\n", 49 | msg = " || TEST5(b) check error message" ) 50 | 51 | # TEST 6 : Non-Logical vector used 52 | 53 | test6 <- try(checkSingleLogical('TRUE', functionName = "try"), silent = TRUE) 54 | checkTrue(is(test6, "try-error"), msg = " || TEST 6(a) exception generated" ) 55 | checkEquals(as.character(test6), 56 | "Error in checkSingleLogical(\"TRUE\", functionName = \"try\") : \n Error in try : x is not a logical of length 1. Value is: TRUE\n", 57 | msg = "|| TEST 6(b) error message as expected" ) 58 | 59 | # TEST 7 : Object and description are not length 1 60 | 61 | test7 <- checkSingleLogical(F, "F", functionName = "try") 62 | checkTrue( is.null( test7 ), msg = " || TEST 7: shortcut F is logical " ) 63 | 64 | # TEST 8 : Logical Value 65 | 66 | test8 <- try( checkSingleLogical(0, functionName = "try"), silent = TRUE) 67 | checkTrue(is(test8, "try-error"), msg = " || TEST 8 : Logical Value" ) 68 | checkEquals(as.character(test8), 69 | "Error in checkSingleLogical(0, functionName = \"try\") : \n Error in try : x is not a logical of length 1. Value is: 0\n", 70 | msg = "|| TEST 8 : Numeric Value error message as expected" ) 71 | 72 | # TEST 9 : Missing First Argument 73 | 74 | test9 <- try( checkSingleLogical(, functionName = "try"), silent = TRUE) 75 | checkTrue(is(test9, "try-error"), msg = " || TEST 9(a) Missing First Argument" ) 76 | checkEquals(as.character(test9), 77 | "Error in checkSingleLogical(, functionName = \"try\") : \n Error in try: x is missing with no default\n", 78 | msg = " || TEST 9(a) Missing First Argument error message as expected" ) 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.checksinglecharacter.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 24/05/2013 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | 11 | # tests the function checkSingleCharacter from checkdata.R 12 | 13 | test.checkSingleCharacter <- function() 14 | { 15 | if (!exists("checkSingleCharacter", mode = "function")) { checkSingleCharacter <- MangoNca:::checkSingleCharacter } 16 | 17 | # TEST 1 : standard case 18 | 19 | test1 <- checkSingleCharacter("text") 20 | checkTrue( is.null( test1 ), msg = " || TEST1: standard check - length 1 Character " ) 21 | 22 | # TEST 2 : 0 length vectors 23 | 24 | test2 <- try(checkSingleCharacter(character(0), functionName = "try"), silent = TRUE) 25 | checkTrue(is(test2, "try-error"), msg = " || TEST2: exception generated" ) 26 | checkEquals(as.character(test2), 27 | "Error in checkSingleCharacter(character(0), functionName = \"try\") : \n Error in try : x is not a character of length 1. Value is: \n", 28 | msg = " || TEST2: length 0 vector check message") 29 | 30 | # TEST 3 : All NA vector used 31 | 32 | test3 <- checkSingleCharacter(as.character(NA)) 33 | checkTrue( is.null( test3 ), msg = " || TEST3: NA vectors still Character ") 34 | 35 | # TEST 4 : Character matrix used, this should fail as inputs must be vectors 36 | 37 | test4 <-try(checkSingleCharacter(matrix("a"), functionName = "try"), silent = TRUE) 38 | checkTrue(is(test4, "try-error"), msg = " || TEST4(a): exception generated" ) 39 | checkEquals(as.character(test4), 40 | "Error in checkSingleCharacter(matrix(\"a\"), functionName = \"try\") : \n Error in try : x is not a character of length 1. Value is: \n [,1]\n\n [1,] \"a\" \n", 41 | msg = " || TEST4(b) check error message" ) 42 | 43 | # TEST 5 : length > 1 44 | 45 | test5 <- try(checkSingleCharacter(LETTERS[1:2], functionName = "try"), silent = TRUE ) 46 | checkTrue(is(test5, "try-error"), msg = " || TEST5(a) exception generated" ) 47 | checkEquals(as.character(test5), 48 | "Error in checkSingleCharacter(LETTERS[1:2], functionName = \"try\") : \n Error in try : x is not a character of length 1. Value is: A B\n", 49 | msg = " || TEST5(b) check error message" ) 50 | 51 | # TEST 6 : Non-Character vector used 52 | 53 | test6 <- try(checkSingleCharacter(TRUE, functionName = "try"), silent = TRUE) 54 | checkTrue(is(test6, "try-error"), msg = " || TEST 6(a) exception generated" ) 55 | checkEquals(as.character(test6), 56 | "Error in checkSingleCharacter(TRUE, functionName = \"try\") : \n Error in try : x is not a character of length 1. Value is: TRUE\n", 57 | msg = "|| TEST 6(b) error message as expected" ) 58 | 59 | # TEST 7 : Object and description are not length 1 60 | 61 | test7 <- checkSingleCharacter("F", "F", functionName = "try") 62 | checkTrue( is.null( test7 ), msg = " || TEST 7: F is character " ) 63 | 64 | # TEST 8 : Character Value 65 | 66 | test8 <- try( checkSingleCharacter(0, functionName = "try"), silent = TRUE) 67 | checkTrue(is(test8, "try-error"), msg = " || TEST 8 : Character Value" ) 68 | checkEquals(as.character(test8), 69 | "Error in checkSingleCharacter(0, functionName = \"try\") : \n Error in try : x is not a character of length 1. Value is: 0\n", 70 | msg = "|| TEST 8 : Numeric Value error message as expected" ) 71 | 72 | # TEST 9 : Missing First Argument 73 | 74 | test9 <- try( checkSingleCharacter(, functionName = "try"), silent = TRUE) 75 | checkTrue(is(test9, "try-error"), msg = " || TEST 9(a) Missing First Argument" ) 76 | checkEquals(as.character(test9), 77 | "Error in checkSingleCharacter(, functionName = \"try\") : \n Error in try: x is missing with no default\n", 78 | msg = " || TEST 9(a) Missing First Argument error message as expected" ) 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /mangoNCA/man/AUCInfObs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCInfObs.R 3 | \name{AUCInfObs} 4 | \alias{AUCInfObs} 5 | \title{Calculate Area Under Curve or Moment Curve To "Infinity" (Observed)} 6 | \usage{ 7 | AUCInfObs(Conc, Time, numPoints = NULL, lambdaZStats = NULL, 8 | calculation = c("standard", "moment"), minPoints = 3, addT0 = FALSE, 9 | Safe = TRUE, inter = "Linear") 10 | } 11 | \arguments{ 12 | \item{Conc}{A numeric vector of concentration values} 13 | 14 | \item{Time}{A numeric vector of time values, parallel to \code{Conc} and of the same length. These should be sorted 15 | in ascending order.} 16 | 17 | \item{numPoints}{Number of points to use for the lambdaz calculation, counted from the end of the concentration/time vectors.} 18 | 19 | \item{lambdaZStats}{if not \code{NULL}, a list with 9 elements (see details). Must be provided if numPoints is not.} 20 | 21 | \item{calculation}{Must be either the string "standard" or "moment". If the former, calculates the standard area under 22 | the curve. For the latter, it will calculate the area under the moment curve} 23 | 24 | \item{minPoints}{Minimum number of points to use for the Lambdaz calculation(s), 3 by default. Single positive integer.} 25 | 26 | \item{addT0}{Single logical value declaring whether T0 should be added if missing provided execution is Safe (default \code{TRUE}).} 27 | 28 | \item{Safe}{Single logical value declaring whether to perform data checks and data cleaning (default is \code{TRUE}).} 29 | 30 | \item{inter}{Single character stating whether the interpolation method used is \code{"Linear"} (default) or \code{"Linear Log"}} 31 | } 32 | \value{ 33 | A numeric vector with a single element holding the area under the concentration/time curve until "infinity". 34 | } 35 | \description{ 36 | Area under the Concentration Time Curve from T = 0 to T = Inf using extrapolation from Observed Clast 37 | } 38 | \details{ 39 | AUCInfObs calculates the area under a time/concentration (or first moment) curve from the first point up to 40 | "infinity" using the linear trapezium rule. This is performed by calculating the area under the concentration-time 41 | curve until the last measurable concentration (see \code{\link{AUCLast}}), and then adding an extrapolated 42 | AUC which is the area bounded by the exponential decay curve with rate constant -lambdaz from observed Clast. 43 | Analogous calculations for AUMC are used if appropriate. \cr 44 | There are two methods for calculating AUC and AUMC. 45 | Lambdaz stats can be calculated within the function. In this case, numPoints should be provided. 46 | numPoints must be a single integer greater than minPonts (which should be at least 2) and less than or equal to the length of \code{Time} and \code{Conc}. 47 | numPoints is NULL by default. Must be provided if lambdaZStats is not. 48 | The lambdaz statistics may be provided directly to this function; it should be a length 9 numeric vector with named elements: 49 | \enumerate{ 50 | \item Lambdaz 51 | \item intercept 52 | \item r2 53 | \item adjr2 54 | \item rhoXY 55 | \item tPhaseHalfLife 56 | \item LambdazLower 57 | \item LambdazUpper 58 | \item numPoints 59 | } 60 | Use \code{unlist} to pass \code{lambdaZStatistics} output to this function. 61 | } 62 | \note{ 63 | The following error checks / processing will be performed: 64 | \enumerate{ 65 | \item all error checks for \code{AUCLast} apply 66 | \item If any relevant lambda z calculations are NA, NA will be returned 67 | \item An exception will be generated if numPoints is not a single integer numeric between 2 and \code{length(Conc)} (inclusive) 68 | } 69 | The algorithm for calculating the observed AUC is as follows: 70 | \deqn{AUCPredInf = AUCLast + Clast / \lambda_z} 71 | For the observed AUMC, the calculation is 72 | \deqn{AUMCPredInf = AUMCLast + Clast * tlast / \lambda_z + Clast / \lambda_z^2} 73 | Here \eqn{c_0} is the exponential of the intercept term from the lambda z regression, and \eqn{t_{upper}} is the 74 | last time point used in that regression 75 | } 76 | \examples{ 77 | Theoph1 <- subset(Theoph, Subject == 1) 78 | AUCInfObs(Conc = Theoph1$conc, Time = Theoph1$Time, numPoints = 4, calculation = "standard") 79 | } 80 | \seealso{ 81 | \code{\link{lambdaZStatistics}}, \code{\link{AUCLast}} 82 | } 83 | \author{ 84 | Mango Solutions 85 | } 86 | \keyword{math} 87 | -------------------------------------------------------------------------------- /mangoNCA/man/AUCInfPred.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AUCInfPred.R 3 | \name{AUCInfPred} 4 | \alias{AUCInfPred} 5 | \title{Calculate Area Under Curve or Moment Curve To "Infinity" (Predicted)} 6 | \usage{ 7 | AUCInfPred(Conc, Time, numPoints = NULL, lambdaZStats = NULL, 8 | calculation = c("standard", "moment"), minPoints = 3, addT0 = FALSE, 9 | Safe = TRUE, inter = "Linear") 10 | } 11 | \arguments{ 12 | \item{Conc}{A numeric vector of concentration values} 13 | 14 | \item{Time}{A numeric vector of time values, parallel to \code{Conc} and of the same length. These should be sorted 15 | in ascending order.} 16 | 17 | \item{numPoints}{Number of points to use for the lambda z calculation, counted from the end of the concentration/time vectors.} 18 | 19 | \item{lambdaZStats}{if not \code{NULL}, a list with 9 elements (see details). Must be provided if numPoints is not.} 20 | 21 | \item{calculation}{Must be either the string "standard" or "moment". If the former, calculates the standard area under 22 | the curve. For the latter, it will calculate the area under the moment curve} 23 | 24 | \item{minPoints}{Minimum number of points to use for the Lambdaz calculation(s), 3 by default. Single positive integer.} 25 | 26 | \item{addT0}{Single logical value declaring whether T0 should be added if missing provided execution is Safe (default TRUE).} 27 | 28 | \item{Safe}{Single logical value declaring whether to perform data checks and data cleaning (default is TRUE).} 29 | 30 | \item{inter}{Single character stating whether the interpolation method used is \code{"Linear"} (default) or \code{"Linear Log"}} 31 | } 32 | \value{ 33 | A numeric vector with a single element holding the area under the concentration/time curve until "infinity". 34 | } 35 | \description{ 36 | Area Under the Concentration Time Curve from Time = 0 to Time = Inf using extrapolation from Predicted Clast 37 | } 38 | \details{ 39 | AUCInfPred calculates the area under a time/concentration (or first moment) curve from the first point up to 40 | "infinity" using the linear trapezium rule. This is performed by calculating the area under the concentration-time 41 | curve until the last measurable concentration (see \code{\link{AUCLast}}), and then adding an extrapolated 42 | AUC which is the area bounded by the exponential decay curve with rate constant -lambdaz from observed Clast. 43 | Analogous calculations for AUMC are used if appropriate. \cr 44 | There are two methods for calculating AUC and AUMC. 45 | Lambdaz stats can be calculated within the function. In this case, numPoints should be provided. 46 | numPoints must be a single integer greater than minPonts (which should be at least 2) and less than or equal to the length of \code{Time} and \code{Conc}. 47 | numPoints is NULL by default. Must be provided if lambdaZStats is not. 48 | The lambdaz statistics may be provided directly to this function; it should have length 1 numeric elements: 49 | \enumerate{ 50 | \item Lambdaz 51 | \item intercept 52 | \item r2 53 | \item adjr2 54 | \item rhoXY 55 | \item tPhaseHalfLife 56 | \item LambdazLower 57 | \item LambdazUpper 58 | \item numPoints 59 | } 60 | Use \code{unlist} to pass \code{lambdaZStatistics} output to this function. 61 | } 62 | \note{ 63 | The following error checks / processing will be performed: 64 | \enumerate{ 65 | \item all error checks for \code{AUCLast} apply 66 | \item If any relevant lambda z calculations are NA, NA will be returned 67 | \item An exception will be generated if numPoints is not a single integer numeric between 2 and \code{length(Conc)} (inclusive) 68 | } 69 | The algorithm for calculating the extrapolated AUC is as follows: 70 | \deqn{ClastExtrap = \exp(-\lambda_z * t_{upper}) * c_0} 71 | \deqn{AUCPredInf = AUCLast + ClastExtrap / \lambda_z} 72 | For the extrapolated AUMC, the calculation is 73 | \deqn{AUMCPredInf = AUMCLast + ClastExtrap * tlast / \lambda_z + ClastExtrap / \lambda_z^2} 74 | Here \eqn{c_0} is the exponential of the intercept term from the lambda z regression, and \eqn{t_{upper}} is the 75 | last time point used in that regression 76 | } 77 | \examples{ 78 | Theoph1 <- subset(Theoph, Subject == 1) 79 | AUCInfPred(Theoph1$conc, Theoph1$Time, numPoints = 4) 80 | } 81 | \seealso{ 82 | \code{\link{lambdaZStatistics}}, \code{\link{AUCLast}} 83 | } 84 | \author{ 85 | Mango Solutions 86 | } 87 | \keyword{math} 88 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.auclin.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 24/07/2013 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.AUCLin <- function() 10 | { 11 | if (!exists("AUCLin", mode = "function")) { AUCLin <- MangoNca:::AUCLin } 12 | if (!exists("trapez", mode = "function")) { trapez <- MangoNca:::trapezium } 13 | 14 | # TEST 1 : only 1 element 15 | 16 | test1 <- AUCLin( 1, 1 ) 17 | checkEquals(test1, 0, msg = " || TEST 1 : only one concentration means only 0 is returned\n") 18 | 19 | # TEST 2 : 0 elements 20 | 21 | test2 <- AUCLin( numeric(0), numeric(0) ) 22 | checkTrue(is.na( test2 ), msg = " || TEST 1 : 0 elements means only NA is returned\n") 23 | 24 | # TEST 3 : 2 elements, one NA present. 25 | 26 | test3 <- AUCLin( c(0, NA), 0:1 ) 27 | checkTrue(is.na ( test3 ), msg = " || TEST 3 : NA present - only NA should be returned") 28 | 29 | # TEST 4 : "standard" data set. Use built-in theophiline data set 30 | # NOTE: result is validated against trapezium function 31 | 32 | Theoph12 <- subset(Theoph, Subject == 12 ) 33 | test4 <- AUCLin(Conc = Theoph12$conc, Time = Theoph12$Time ) 34 | checkEquals( sum(test4), trapez(Theoph12$Time, Theoph12$conc), msg = " || TEST 4 : Total AUC is equal to AUC determined by trapezium rule" ) 35 | 36 | # TEST 5 : contrived data set 37 | 38 | test5 <- AUCLin( Time = 1:100, Conc = rep(2, 100) ) 39 | checkEquals( test5, rep(2, 99), msg = " || TEST 5 : for contrived data, individual AUCs should all be 2\n" ) 40 | 41 | # TEST 6 : another contrived data set 42 | 43 | test6 <- AUCLin( Time = c(0, 1, 2.5, 3) , c(0, 1, 0.5, 0.25)) 44 | checkEquals(test6, c(0.5, 1.125, 0.1875), msg = " || TEST 6 : second contrived data set\n") 45 | 46 | # TEST 7 : Missing values in various locations 47 | 48 | test7 <- AUCLin(Time = c(1, NA, 2, NA, 3), Conc = c(NA, 1, NA, 2, NA)) 49 | checkEquals( test7, as.numeric(c(NA, NA, NA, NA)), msg = " || TEST 7 : all values should be missing " ) 50 | 51 | # TEST 8 : single missing time 52 | 53 | test8 <- AUCLin(Time = c(1, NA, 2, 4, 5), Conc = c(1, 2, 3, 4, 5)) 54 | checkEquals( test8, c(NA, NA, 7, 4.5 ), msg = " || TEST 8 : single missing time" ) 55 | 56 | # TEST 9 : single missing concentration 57 | 58 | test9 <- AUCLin(Time = c(1, 1.5, 2, 4, 5), Conc = c(1, 2, NA, 4, 5)) 59 | checkEquals(test9, c(0.75, NA, NA, 4.5 ), msg = " || TEST 9 : single missing concentration" ) 60 | 61 | # TEST 10 : 2 elements only 62 | 63 | test10 <- AUCLin(Time = c(1, 1000), c(1, 1.5)) 64 | checkEquals(test10, 1248.75, msg = " || TEST 10 : 2 elements" ) 65 | 66 | # TEST 11 : vectors of different length 67 | 68 | test11 <- try( AUCLin( Time = 1:10, Conc = 1:9 ), silent = TRUE) 69 | checkTrue(is(test11, "try-error"), msg = " || TEST 11 : exception generated due differing vector lengths " ) 70 | 71 | # TEST 12 : unordered time vector should generate an exception 72 | 73 | test12 <- try(AUCLin( Time = 3:1, Conc = 1:3), silent = TRUE) 74 | checkTrue(MangoNca:::isErrorWithMessage(test12, "Error in checkOrderedVector(Time, \"Time\", \"AUCLin\") : \n Error in AUCLin: Time is not ordered. Actual value is 3 2 1\n" ), msg = " || TEST 12 : exception generated due to unsorted time") 75 | 76 | # TEST 13 : unordered time vector (with missing values) should generate an exception 77 | 78 | test13 <- try(AUCLin( Time = c(1,2, NA, 1.5), Conc = 4:1), silent = TRUE) 79 | checkTrue(MangoNca:::isErrorWithMessage(test13, "Error in checkOrderedVector(Time, \"Time\", \"AUCLin\") : \n Error in AUCLin: Time is not ordered. Actual value is 1 2 NA 1.5\n"), msg = " || TEST 13 : exception generated due to unsorted time (with missing values)") 80 | 81 | # TEST 14 : WNL example Log interpolation 82 | # http://forum.bebac.at/forum_entry.php?id=3723 83 | 84 | c14 <- c(0, 0.12, 1.85, 2.92, 1.85, 0.73, 0.42, 0.19) 85 | t14 <- c(0, 0.5, 1, 1.5, 2, 4, 6, 8) 86 | 87 | test14 <- AUCLin(Conc = c14, Time = t14) 88 | checkEquals(round(sum(test14), digits = 5), 7.2475, msg = " || TEST 14 : WNL example Log interpolation") 89 | 90 | } 91 | -------------------------------------------------------------------------------- /mangoNCA/R/MRTInfSD.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 27/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | #' Mean Residence Time (Single Dose) 11 | #' 12 | #' Calculates mean residence time from AUMC, AUC and duration of infusion. 13 | #' The value returned is: 14 | #' \deqn{\frac{AUMC}{AUC} - \frac{Dof}{2}} 15 | #' 16 | #' @param AUC Single numeric value, area under the concentration time curve 17 | #' @param AUMC Single numeric value, area under the concentration time moment curve 18 | #' @param Dof Duration of infusion, single numeric value 19 | #' @title Calculate Mean Residence Time 20 | #' @return A single numeric vector. 21 | #' @author Mango Solutions 22 | #' @export 23 | #' @keywords math 24 | 25 | 26 | MRTSD <- function(AUC, AUMC, Dof = 0) 27 | { 28 | checkSingleNumeric(AUC, description = "AUC") 29 | checkSingleNumeric(AUMC, description = "AUMC") 30 | checkSingleNumeric(Dof, description = "Duration of infusion") 31 | 32 | if( Dof < 0 ) 33 | { 34 | return(as.numeric(NA)) 35 | } 36 | 37 | mrt <- AUMC / AUC - Dof / 2 38 | 39 | return(mrt) 40 | } 41 | 42 | 43 | #' Mean Residence Time (Single Dose) Predicted 44 | #' 45 | #' Calculates the mean residence time to infinity (predicted), for steady-state models of type "M3". 46 | #' @param Conc Vector of concentrations 47 | #' @param Time Vector of times. Must be sorted, and without duplicates 48 | #' @param numPoints Number of points to use for lambda z calculation. See \code{\link{lambdaZStatistics}} 49 | #' @param Dof Duration of infusion, single numeric value 50 | #' @param addT0 Single logical value determining whether T = 0 should be added 51 | #' @title Calculate Mean Residence Time to infinity (predicted) for steady-state data, model M3 52 | #' @return A single numeric vector. The value returned is: 53 | #' \deqn{\frac{AUMCInfPred}{AUCInfPred} - \frac{Dof}{2}} 54 | #' @author Mango Solutions 55 | #' @export 56 | #' @keywords math 57 | 58 | MRTInfPredSD <- function(Conc, Time, numPoints, Dof = 0, addT0 = FALSE) 59 | { 60 | checkSingleNumeric(Dof, description = "Duration of infusion") 61 | checkSingleNumeric(numPoints, description = "Number of Points") 62 | checkNumericSameLength(Time, Conc, "Time", "Concentration", "MRTInfPredSD") 63 | 64 | if( Dof < 0 ) 65 | { 66 | return(as.numeric(NA)) 67 | } 68 | 69 | AUMCIP <- AUCInfPred(Conc = Conc, Time = Time, numPoints = numPoints, calculation = "moment", addT0 = addT0) 70 | AUCIP <- AUCInfPred(Conc = Conc, Time = Time, numPoints = numPoints, addT0 = addT0) 71 | 72 | mrtp <- MRTSD(AUC = AUCIP, AUMC = AUMCIP, Dof = Dof) 73 | 74 | return(mrtp) 75 | } 76 | 77 | 78 | #' Mean Residence Time (Single Dose) Observed 79 | #' 80 | #' Calculates the mean residence time to infinity (observed), for steady-state models of type "M3". 81 | #' @param Conc Vector of concentrations 82 | #' @param Time Vector of times. Must be sorted, and without duplicates 83 | #' @param numPoints Number of points to use for lambda z calculation. See \code{\link{lambdaZStatistics}} 84 | #' @param Dof Duration of infusion. Must be a 85 | #' @title Calculate Mean Residence Time to infinity (observed) for steady-state data, model M3 86 | #' @return A single numeric vector. The value returned is: 87 | #' \deqn{\frac{AUMCInfObs}{AUCInfObs} - \frac{Dof}{2}} 88 | #' @author Mango Solutions 89 | #' @export 90 | #' @keywords math 91 | 92 | MRTInfObsSD <- function(Conc, Time, numPoints, Dof = 0, addT0 = FALSE) 93 | { 94 | checkSingleNumeric(Dof, description = "Duration of infusion") 95 | checkSingleNumeric(numPoints, description = "Number of Points") 96 | checkNumericSameLength(Time, Conc, "Time", "Concentration", "MRTInfObs") 97 | 98 | if( Dof < 0 ) 99 | { 100 | return(as.numeric(NA)) 101 | } 102 | 103 | AUMCIO <- AUCInfObs(Conc = Conc, Time = Time, numPoints = numPoints, calculation = "moment", addT0 = addT0) 104 | AUCIO <- AUCInfObs(Conc = Conc, Time = Time, numPoints = numPoints, addT0 = addT0) 105 | 106 | mrto <- MRTSD(AUC = AUCIO, AUMC = AUMCIO, Dof = Dof) 107 | 108 | return(mrto) 109 | } 110 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.auclog.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 28/05/2013 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | test.AUCLog <- function() 10 | { 11 | if (!exists("AUCLog", mode = "function")) { AUCLog <- MangoNca:::AUCLog } 12 | 13 | rdiff <- function(x) { x[-length(x)] - x[-1] } 14 | 15 | # TEST 1 : only 1 element 16 | 17 | test1 <- AUCLog(1, 1) 18 | checkEquals(test1, 0, msg = " || TEST 1 : only one concentration means only 0 is returned\n") 19 | 20 | # TEST 2 : 0 elements 21 | 22 | test2 <- AUCLog(numeric(0), numeric(0)) 23 | checkTrue(is.na(test2), msg = " || TEST 1 : 0 elements means only NA is returned\n") 24 | 25 | # TEST 3 : 2 elements, one NA present. 26 | 27 | test3 <- AUCLog(c(0, NA), 0:1) 28 | checkTrue(is.na (test3), msg = " || TEST 3 : NA present - only NA should be returned") 29 | 30 | # TEST 4 : "standard" data set, using built-in theophiline data set 31 | 32 | Theoph12 <- subset(Theoph, Subject == 12 ) 33 | test4 <- AUCLog(Conc = Theoph12$conc, Time = Theoph12$Time) 34 | checkEquals(sum(test4), 114.85723004832, tol = 1e-8, msg = " || TEST 4 : Total AUC is equal to number" ) 35 | 36 | # TEST 5 : contrived data set 37 | 38 | test5 <- AUCLog(Time = 1:100, Conc = rep(2, 100)) 39 | checkEquals(test5, rep(2, 99), msg = " || TEST 5 : for contrived data, individual AUCs should all be 2\n" ) 40 | 41 | # TEST 6 : exp vals cf integration 42 | 43 | test6 <- AUCLog(Time = (0:5)^2, Conc = 25 * exp(-(1/pi) * (0:5)^2)) 44 | checkEquals(test6, rdiff(25 / (1/pi) * exp(-(1/pi) * (0:5)^2)), msg = " || TEST 6 : exp vals cf integration\n") 45 | 46 | # TEST 7 : Missing values in various locations 47 | 48 | test7 <- AUCLog( Time = c(1, NA, 2, NA, 3), Conc = c( NA, 1, NA, 2, NA ) ) 49 | checkEquals( test7, as.numeric(c(NA, NA, NA, NA)), msg = " || TEST 7 : all values should be missing " ) 50 | 51 | # TEST 8 : Single missing time 52 | 53 | test8 <- AUCLog(Time = c(1, NA, 2, 4, 5), Conc = c( 1, 2, 3, 4, 5)) 54 | checkEquals(round(test8, 2), c(NA, NA, 6.95, 4.48), msg = " || TEST 8 : Single missing time") 55 | 56 | # TEST 9 : similar to the above, but missing concentrations 57 | 58 | test9 <- AUCLog( Time = c(1, 1.5, 2, 4, 5), Conc = c( 1, 2, NA, 4, 5)) 59 | checkEquals(round(test9, 2), c(0.72, NA, NA, 4.48 ), msg = " || TEST 9 : single missing concentration " ) 60 | 61 | # TEST 10 : 2 elements only 62 | 63 | test10 <- AUCLog(Time = c(1, 1000), c(1, 1.5)) 64 | checkEquals(round(test10, 5), 1231.91857, msg = " || TEST 10 : 2 elements " ) 65 | 66 | # TEST 11 : vectors of different length 67 | 68 | test11 <- try( AUCLog(Time = 1:10, Conc = 1:9), silent = TRUE) 69 | checkTrue(is(test11, "try-error"), msg = " || TEST 11 : exception generated due differing vector lengths " ) 70 | 71 | # TEST 12 : unordered time vector should generate an exception 72 | 73 | test12 <- try(AUCLog(Time = 3:1, Conc = 1:3), silent = TRUE) 74 | checkTrue(MangoNca:::isErrorWithMessage(test12, "Error in checkOrderedVector(Time, \"Time\", functionName = \"AUCLog\") : \n Error in AUCLog: Time is not ordered. Actual value is 3 2 1\n" ), 75 | msg = " || TEST 12 : exception generated due to unsorted time") 76 | 77 | # TEST 13 : unordered time vector (with missing values) should generate an exception 78 | 79 | test13 <- try(AUCLog( Time = c(1, 2, NA, 1.5), Conc = 4:1), silent = TRUE) 80 | checkTrue(MangoNca:::isErrorWithMessage(test13, "Error in checkOrderedVector(Time, \"Time\", functionName = \"AUCLog\") : \n Error in AUCLog: Time is not ordered. Actual value is 1 2 NA 1.5\n"), 81 | msg = " || TEST 13 : exception generated due to unsorted time (with missing values)") 82 | 83 | # TEST 14 : WNL example Log interpolation 84 | # http://forum.bebac.at/forum_entry.php?id=3723 85 | 86 | #c14 <- c(0, 0.12, 1.85, 2.92, 1.85, 0.73, 0.42, 0.19) 87 | #t14 <- c(0, 0.5, 1, 1.5, 2, 4, 6, 8) 88 | 89 | #test14 <- AUCLog(Conc = c14, Time = t14) 90 | #checkEquals(round(sum(test14), digits = 5), 6.8010, msg = " || TEST 14 : WNL example Log interpolation") 91 | 92 | } 93 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.checksinglenumeric.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 27/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | 11 | # tests the function checkSingleNumeric from checkdata.R 12 | 13 | test.checkSingleNumeric <- function() 14 | { 15 | if (!exists("checkSingleNumeric", mode = "function")) { checkSingleNumeric <- MangoNca:::checkSingleNumeric } 16 | 17 | # TEST 1 : standard case 18 | 19 | test1 <- checkSingleNumeric( 1 ) 20 | checkTrue( is.null( test1 ), msg = " || TEST1: standard check - length 1 numeric " ) 21 | 22 | # TEST 2 : 0 length vectors 23 | 24 | test2 <- try(checkSingleNumeric(numeric(0), functionName = "try"), silent = TRUE) 25 | checkTrue(is(test2, "try-error"), msg = " || TEST2: exception generated" ) 26 | checkEquals(as.character(test2), "Error in checkSingleNumeric(numeric(0), functionName = \"try\") : \n Error in try : x is not a numeric of length 1. Value is: \n", 27 | msg = " || TEST2: length 0 vector check message") 28 | 29 | # TEST 3 : All NA vector used 30 | 31 | test3 <- checkSingleNumeric(as.numeric(NA)) 32 | checkTrue( is.null( test3 ), msg = " || TEST3: NA vectors still numeric ") 33 | 34 | # TEST 4 : Numeric matrix used, this should fail as inputs must be vectors 35 | 36 | test4 <-try(checkSingleNumeric(matrix(1), 1, functionName = "try"), silent = TRUE) 37 | checkTrue(is(test4, "try-error"), msg = " || TEST4(a): exception generated" ) 38 | checkEquals(as.character(test4), "Error in checkSingleNumeric(matrix(1), 1, functionName = \"try\") : \n Error in try : 1 is not a numeric of length 1. Value is: \n [,1]\n\n [1,] 1\n" , 39 | msg = " || TEST4(b) check error message" ) 40 | 41 | # TEST 5 : length > 1 42 | 43 | test5 <- try(checkSingleNumeric(1:5, functionName = "try"), silent = TRUE ) 44 | checkTrue(is(test5, "try-error"), msg = " || TEST5(a) exception generated" ) 45 | checkEquals(as.character(test5), "Error in checkSingleNumeric(1:5, functionName = \"try\") : \n Error in try : x is not a numeric of length 1. Value is: 1 2 3 4 5\n", 46 | msg = " || TEST5(b) check error message" ) 47 | 48 | # TEST 6 : Non-numeric vector used 49 | 50 | test6 <- try(checkSingleNumeric('1', 1, functionName = "try"), silent = TRUE) 51 | checkTrue(is(test6, "try-error"), msg = " || TEST6 exception generated" ) 52 | checkEquals(as.character(test6), "Error in checkSingleNumeric(\"1\", 1, functionName = \"try\") : \n Error in try : 1 is not a numeric of length 1. Value is: 1\n", 53 | msg = "|| TEST6 error message as expected" ) 54 | 55 | # TEST 7 : Object and description are not length 1 56 | 57 | test7 <- try(checkSingleNumeric(1:2, c("multiple", "elements"), functionName = "try"), silent = TRUE) 58 | checkTrue( is(test7, "try-error"), msg = " || TEST 7(a) : Other vector is not length 1" ) 59 | checkEquals(as.character(test7), "Error in checkSingleNumeric(1:2, c(\"multiple\", \"elements\"), functionName = \"try\") : \n Error in try : multiple is not a numeric of length 1. Value is: 1 2Error in try : elements is not a numeric of length 1. Value is: 1 2\n", 60 | msg = "|| TEST 7(b) : Object and description are not length 1error message as expected" ) 61 | 62 | # TEST 8 : Logical Value 63 | 64 | test8 <- try( checkSingleNumeric(TRUE, functionName = "try"), silent = TRUE) 65 | checkTrue(is(test8, "try-error"), msg = " || TEST 8 : Logical Value" ) 66 | checkEquals(as.character(test8), "Error in checkSingleNumeric(TRUE, functionName = \"try\") : \n Error in try : x is not a numeric of length 1. Value is: TRUE\n", 67 | msg = "|| TEST 8 : Logical Value error message as expected" ) 68 | 69 | # TEST 9 : Missing First Argument 70 | 71 | test9 <- try( checkSingleNumeric(, functionName = "try"), silent = TRUE) 72 | checkTrue(is(test9, "try-error"), msg = " || TEST 9(a) Missing First Argument" ) 73 | checkEquals(as.character(test9), 74 | "Error in checkSingleNumeric(, functionName = \"try\") : \n Error in try: x is missing with no default\n" , msg = " || TEST 9(a) Missing First Argument error message as expected" ) 75 | 76 | } 77 | 78 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.getConcentration.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 16/03/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # tests getConcentration function from getConcentration.R 10 | 11 | test.getConcentration <- function() 12 | { 13 | time <- 0:9 14 | conc <- 10:1 15 | 16 | # TEST 1 - 3 : secondTime is an element of time - normal and boundary cases 17 | 18 | test1 <- getConcentration(Conc = conc, Time = time, firstTime = 0, secondTime = 9) 19 | checkEquals(as.numeric(test1[1, c("firstConc", "secondConc")]), c(10, 1), msg = " || TEST 1 : firstTime 1st, secondTime final element of Time" ) 20 | 21 | test2 <- getConcentration(Conc = conc, Time = time, firstTime = 3, secondTime = 2) 22 | checkEquals(as.numeric(test2[1, c("firstConc", "secondConc")]), c(7, 8), msg = " || TEST 2 : firstTime 4th, secondTime 3rd element of Time") 23 | 24 | test3 <- getConcentration(Conc = conc, Time = time, firstTime = 2, secondTime = NA) 25 | checkEquals(test3[["firstConc"]], 8, msg = " || TEST 3 (a) : firstTime is 3rd element") 26 | checkEquals(test3[["secondConc"]], as.numeric(NA), msg = " || TEST 3 (b) : secondTime is NULL") 27 | 28 | ## TEST 4-6 : secondTime is not an element of Time, but is inside the lower and upper limits 29 | 30 | test4 <- getConcentration(Conc = conc, Time = time, firstTime = 0, secondTime = 1.75) 31 | checkEquals(test4[["secondConc"]], 8.25, msg = " || TEST 4 : secondTime lies between 2nd and 3rd elements of Time") 32 | 33 | test5 <- getConcentration(Conc = conc, Time = time, firstTime = NA, secondTime = 8.4) 34 | checkEquals(test5[["firstConc"]], as.numeric(NA), msg = " || TEST 5 (a) : firstTime is NA") 35 | checkEquals(test5[["secondConc"]], 1.6, msg = " || TEST 5 (b) : secondTime lies between last 2 elements of Time ") 36 | 37 | test6 <- getConcentration(Conc = conc, Time = time, firstTime = 2.1e-8, secondTime = as.numeric(NA)) 38 | checkEquals(test6[["firstConc"]], 10, msg = " || TEST 6 : secondTime just after 1st element of Time" ) 39 | 40 | # TEST 7 : alternative data set 41 | 42 | Theoph2 <- subset(Theoph, Subject == 2) 43 | test7 <- getConcentration(Conc = Theoph2$conc, Time = Theoph2$Time, firstTime = 1, secondTime = 18) 44 | checkEquals(as.numeric(test7[1, c("firstConc", "secondConc")]), c(8.31, 1.980731707), tol = 1e-7, msg = " || TEST 7 Theoph data set, secondTime between last 2 elements of Time") 45 | 46 | # TEST 8 - 9 : check for secondTime > tlast 47 | 48 | test8 <- getConcentration(Conc = c(1, 6, 5, 4, 2, 1), Time = 0:5, firstTime = as.numeric(NA), secondTime = 6) 49 | checkEquals(test8[["secondConc"]], 0.5, msg = " || TEST 8 : secondTime < Time[1]") 50 | 51 | test9 <- getConcentration(Conc = Theoph2$conc, Time = Theoph2$Time, firstTime = 0, secondTime = 26) 52 | checkEquals(test9[["secondConc"]], 0.7445239941, msg = " || TEST 9 : secondTime > last time, checking extrapolation" ) 53 | 54 | } 55 | 56 | test.getConcentration_errorHandling <- function() 57 | { 58 | 59 | # TEST 1 : missing values present 60 | 61 | test1 <- try( getConcentration(Conc = c(NA, 6, 5, 4, 2, 1), Time = 0:5, secondTime = 6), silent = TRUE ) 62 | checkEquals( test1[["Error"]], "Error in try(if (any(is.na(Conc))) { : Missing values in Conc\n", 63 | msg = " || TEST 1 : missing numPoints") 64 | 65 | # TEST 2 : secondTime is not a length 1 66 | 67 | test2 <- getConcentration(Conc = 2:1, Time = 1:2, firstTime = 0, secondTime = c(1, 2)) 68 | checkEquals(test2[["Error"]], "Error in checkSingleNumeric(secondTime, description = \"secondTime\", \"getConcentration\") : \n Error in getConcentration : secondTime is not a numeric of length 1. Value is: 1 2\n", 69 | msg = " || TEST 2 : secondTime is not of length 1") 70 | 71 | # TEST 3 : firstTime is not numeric 72 | 73 | test3 <- getConcentration(Conc = 2:1, Time = 1:2, firstTime = "1", secondTime = 3) 74 | checkEquals(test3[["Error"]], "Error in checkSingleNumeric(firstTime, description = \"firstTime\", \"getConcentration\") : \n Error in getConcentration : firstTime is not a numeric of length 1. Value is: 1\n", 75 | msg = " || TEST 3 : firstTime is not numeric ") 76 | 77 | } 78 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.AUCInfPred.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 16/03/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | test.AUCInfPred <- function() 11 | { 12 | 13 | # TEST 1 : contrived data 14 | 15 | test1 <- AUCInfPred(Time = 0:10, Conc = c(0, 0, exp(8:2), 0, 0), numPoints = 4) 16 | 17 | lambdaz <- 1 18 | tlast <- 8 19 | inter <- exp(10) 20 | 21 | cEst <- exp(-lambdaz * tlast) * inter 22 | AUCextra <- cEst / lambdaz 23 | 24 | # 4707.811 is equal to AUCLast(Time = 1:10, Conc = c(0, exp(8:2) ,0, 0)) 25 | 26 | checkEquals( test1, 4707.811 + AUCextra, tol = 1e-7, 27 | msg = " || TEST 1 : contrived data set, multiple 0 elements at the end" ) 28 | 29 | # TEST 2 : Theoph data 30 | 31 | Theoph3 <- subset(Theoph, Subject == 3 ) 32 | 33 | test2 <- AUCInfPred(Time = Theoph3$Time, Conc = Theoph3$conc , numPoints = 5) 34 | 35 | lambdaz <- 0.0945763 36 | tlast <- 24.17 37 | inter <- exp( 2.3747828) 38 | 39 | cEst <- exp(-lambdaz * tlast) * inter 40 | AUCextra <- cEst / lambdaz 41 | 42 | checkEquals(test2, 99.2865 + AUCextra, tol = 1e-7, 43 | msg = " || TEST 2 : theoph data set calculation correct") 44 | 45 | # TEST 3 : failed lambda z calculation, should get NA 46 | 47 | test3 <- AUCInfPred( Conc = 0:3, Time = c(0, 2:4), numPoints = 3 ) 48 | checkEquals(test3, as.numeric(NA), msg = " || TEST 3 : NA value returned because lambda z regression fit failed") 49 | 50 | # TEST 4 : Moment curve test 1 51 | 52 | test4 <- AUCInfPred(Time = 0:10, Conc = c(0, 0, exp(8:2), 0, 0), numPoints = 4, calculation = "moment") 53 | 54 | lambdaz <- 1 55 | tlast <- 8 56 | inter <- exp(10) 57 | 58 | cEst <- exp(-lambdaz * tlast) * inter 59 | AUMCextra <- cEst* tlast / lambdaz + cEst / lambdaz^2 60 | 61 | checkEquals( test4, 12105.3403019096 + AUMCextra, tol = 1e-7, 62 | msg = " || TEST 4 : contrived data set (AUMC), multiple 0 elements at the end" ) 63 | 64 | # TEST 5 : Moment curve test 2 65 | 66 | test5 <- AUCInfPred(Time = Theoph3$Time, Conc = Theoph3$conc , numPoints = 5, calculation = "moment") 67 | 68 | lambdaz <- 0.0945762934220462 69 | tlast <- 24.17 70 | inter <- 10.7486780713157 71 | 72 | cEst <- exp(-lambdaz * tlast) * inter 73 | AUMCextra <- cEst * tlast / lambdaz + cEst / lambdaz^2 74 | 75 | checkEquals(test5, 803.18587 + AUMCextra, tol = 1e-7, 76 | msg = " || TEST 5 : theoph data set AUMC calculation correct") 77 | 78 | # TEST 6 : invalid numPoints 79 | 80 | test6 <- AUCInfPred(Time = Theoph3$Time, Conc = Theoph3$conc , numPoints = 2, calculation = "moment") 81 | checkTrue( is.na(test6), msg = " || TEST 6 : invalid numPoints") 82 | } 83 | 84 | test.AUCInfPred_errorHandling <- function() 85 | { 86 | isErrorWithMessage <- MangoNca:::isErrorWithMessage 87 | 88 | # TEST 1 : different length vectors generates error 89 | 90 | test1 <- try(AUCInfPred(Time = 1:4, Conc = 3:1), silent = TRUE ) 91 | checkTrue( isErrorWithMessage( test1, 92 | "Error in checkNumericSameLength(Time, Conc, \"Time\", \"Concentration\", \"AUCInfPred\") : \n Error in AUCInfPred: lengths of Time and Concentration do not match\n" ) ) 93 | 94 | # TEST 2 : Time not ordered 95 | 96 | test2 <- try(AUCInfPred(Time = c(1:4, 3), Conc = c(4:1, 1), numPoints = 1), silent = TRUE) 97 | checkTrue( isErrorWithMessage(test2, 98 | "Error in checkOrderedVector(Time, description = \"Time\", functionName = \"AUCInfPred\") : \n Error in AUCInfPred: Time is not ordered. Actual value is 1 2 3 4 3\n"), 99 | msg = " || TEST 2 : Time not ordered") 100 | 101 | # TEST 3 : numPoints invalid 102 | 103 | test3 <- try(AUCInfPred(Time = c(1:5), Conc = c(4:1, 1), numPoints = 3:4, addT0 = TRUE), silent = TRUE) 104 | checkTrue( isErrorWithMessage(test3, 105 | "Error in checkSingleNumeric(numPoints, description = \"numPoints\") : \n Error in AUCInfPred : numPoints is not a numeric of length 1. Value is: 3 4\n"), 106 | msg = " || TEST 3 : numPoints invalid") 107 | } 108 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.AUCInfObs.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 27/01/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | test.AUCInfObs <- function() 11 | { 12 | # TEST 1 : contrived data 13 | 14 | test1 <- AUCInfObs(Time = 0:10, Conc = c(0, 0, exp(8:2), 0, 0), numPoints = 4) # 4715.2 15 | 16 | lambdaz <- 1 17 | tlast <- 8 18 | inter <- exp(10) 19 | 20 | clast <- exp(2) 21 | 22 | AUCextra <- clast / lambdaz 23 | 24 | # 4707.811 is equal to AUCLast(Time = 1:10, Conc = c(0, exp(8:2) ,0, 0), addT0 = TRUE) 25 | 26 | checkEquals( test1, 4707.811 + AUCextra, tol = 1e-7, 27 | msg = " || TEST 1 : contrived data set, multiple 0 elements at the end" ) 28 | 29 | # TEST 2 : Theoph data 30 | 31 | Theoph3 <- subset(Theoph, Subject == 3 ) 32 | 33 | test2 <- AUCInfObs(Time = Theoph3$Time, Conc = Theoph3$conc , numPoints = 3) 34 | 35 | lambdaz <- 0.1024443141094 # lm(log(conc) ~ Time, data = Theoph3[9:11, ]) 36 | tlast <- 24.17 37 | inter <- exp(2.5297115014586) 38 | 39 | clast <- tail(Theoph3$conc, 1) 40 | 41 | AUCextra <- clast / lambdaz 42 | 43 | checkEquals(test2, 99.2865 + AUCextra, tol = 1e-6, 44 | msg = " || TEST 2 : theoph data set calculation") 45 | 46 | # TEST 3 : failed lambda z calculation, should get NA 47 | 48 | test3 <- AUCInfObs( Conc = 0:3, Time = c(0, 2:4), numPoints = 3 ) 49 | checkEquals(test3, as.numeric(NA), msg = " || TEST 3 : NA value returned because lambda z regression fit failed") 50 | 51 | # TEST 4 : Moment curve test 1 52 | 53 | test4 <- AUCInfObs(Time = 0:10, Conc = c(0, 0, exp(8:2), 0, 0), numPoints = 4, calculation = "moment") 54 | 55 | lambdaz <- 1 56 | tlast <- 8 57 | inter <- exp(10) 58 | 59 | clast <- exp(2) 60 | 61 | AUMCextra <- clast* tlast / lambdaz + clast / lambdaz^2 62 | 63 | checkEquals( test4, 12105.3403019096 + AUMCextra, tol = 1e-7, 64 | msg = " || TEST 4 : contrived data set (AUMC), multiple 0 elements at the end" ) 65 | 66 | # TEST 5 : Moment curve test 2 67 | 68 | test5 <- AUCInfObs(Time = Theoph3$Time, Conc = Theoph3$conc , numPoints = 5, calculation = "moment") 69 | 70 | lambdaz <- 0.0945762934220462 # lm(log(conc) ~ Time, data = Theoph3[7:11, ]) 71 | tlast <- 24.17 72 | inter <- exp(2.37478277690206) 73 | 74 | clast <- tail(Theoph3$conc, 1) 75 | 76 | AUMCextra <- clast * tlast / lambdaz + clast / lambdaz^2 77 | 78 | checkEquals(test5, 803.18587 + AUMCextra, tol = 1e-7, 79 | msg = " || TEST 5 : theoph data set AUMC calculation correct") 80 | 81 | 82 | # TEST 6 : invalid numPoints 83 | 84 | test6 <- AUCInfObs(Time = Theoph3$Time, Conc = Theoph3$conc , numPoints = 2, calculation = "moment") 85 | checkTrue( is.na(test6), msg = " || TEST 6 : invalid numPoints") 86 | } 87 | 88 | test.AUCInfObs_errorHandling <- function() 89 | { 90 | isErrorWithMessage <- MangoNca:::isErrorWithMessage 91 | 92 | # TEST 1 : different length vectors generates error 93 | 94 | test1 <- try(AUCInfObs(Time = 1:4, Conc = 3:1), silent = TRUE ) 95 | checkTrue( isErrorWithMessage( test1, 96 | "Error in checkNumericSameLength(Time, Conc, \"Time\", \"Concentration\", \"AUCInfObs\") : \n Error in AUCInfObs: lengths of Time and Concentration do not match\n" ), 97 | msg = " || TEST 1 : different length vectors generates error" ) 98 | 99 | # TEST 2 : Time not ordered 100 | 101 | test2 <- try(AUCInfObs(Time = c(1:4, 3), Conc = c(4:1, 1), numPoints = 1), silent = TRUE) 102 | checkTrue( isErrorWithMessage(test2, 103 | "Error in checkOrderedVector(Time, description = \"Time\", functionName = \"AUCInfObs\") : \n Error in AUCInfObs: Time is not ordered. Actual value is 1 2 3 4 3\n"), 104 | msg = " || TEST 2 : Time not ordered") 105 | 106 | # TEST 3 : numPoints invalid 107 | 108 | test3 <- try(AUCInfObs(Time = c(1:5), Conc = c(4:1, 1), numPoints = 3:4, addT0 = TRUE), silent = TRUE) 109 | checkTrue( isErrorWithMessage(test3, 110 | "Error in checkSingleNumeric(numPoints, description = \"numPoints\") : \n Error in AUCInfObs : numPoints is not a numeric of length 1. Value is: 3 4\n"), 111 | msg = " || TEST 3 : numPoints invalid") 112 | } 113 | -------------------------------------------------------------------------------- /mangoNCA/man/ncaComplete.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ncaComplete.R 3 | \name{ncaComplete} 4 | \alias{ncaComplete} 5 | \title{Non compartment analysis on Time Concentration data} 6 | \usage{ 7 | ncaComplete(Conc, Time, Dose, Dof, PeakTrough = NULL, 8 | numPoints = as.numeric(NA), usePoints = NULL, excPoints = FALSE, 9 | Safe = TRUE, addT0 = FALSE, inter = "Linear", ROutput) 10 | } 11 | \arguments{ 12 | \item{Conc}{Vector of Concentrations} 13 | 14 | \item{Time}{Vector of times, must be ordered in ascending order and should not have duplicates} 15 | 16 | \item{Dose}{Single numeric of amount of compound delivered to system} 17 | 18 | \item{Dof}{Single numeric of duration of infusion.} 19 | 20 | \item{PeakTrough}{Optional vector of numeric coding of length Time (default is NULL).} 21 | 22 | \item{numPoints}{If NA (default) number of points for calculation of terminal phase is calculated by \code{selectPoints}, otherwise a single integer declaring number of points to use. If numPoints is zero or less, supress terminal phase calculations} 23 | 24 | \item{usePoints}{If NULL (default) automatically select, else, logical vector of points to use (\code{TRUE}) for calculation of terminal phase.} 25 | 26 | \item{excPoints}{Logical vector (\code{FALSE} by default) excludeing \code{TRUE} rows from automatic calculation of terminal phase.} 27 | 28 | \item{Safe}{Single logical value declaring whether to perform redundant data checks (default is TRUE).} 29 | 30 | \item{addT0}{Single logical value declaring whether to add row at T = 0 if missing (default is FALSE).} 31 | 32 | \item{inter}{Single character stating whether the interpolation method used is \code{"Linear"} (default) or \code{"Linear Log"}} 33 | 34 | \item{ROutput}{Named vector consisting of 38 NA and 1 zero with names which should match expected output names.} 35 | } 36 | \value{ 37 | Data frame 38 | } 39 | \description{ 40 | Perform Non-Compartmental Analysis for Complete Concentration-Time Datasets 41 | } 42 | \details{ 43 | This function is not expected to be used directly. The output structure is passed from \code{ncaAnalysis}. 44 | \code{ncaComplete} calculates NCA parameters for individuals returning as many parameters as are calculable. 45 | \code{ROutput_Peak} and \code{ROutput_Trough} will always be returned where possible. 46 | The final column of the return is \code{ROutput_Error}. This should be zero. 47 | \code{ncaComplete} will \code{try} to call the functions to calculate the NCA parameters. 48 | If it is not, an error has occured. 49 | The text of each error will appear in this column as a single character string with 50 | individual messages separated by a newline. 51 | Returns a data frame with 1 row containing columns: 52 | \enumerate{ 53 | \item \code{ROutput_adjr2} 54 | \item \code{ROutput_intercept} 55 | \item \code{ROutput_numPoints} 56 | \item \code{ROutput_r2} 57 | \item \code{ROutput_rhoXY} 58 | \item \code{ROutput_AUC_Percent_Extrapolated_obs} 59 | \item \code{ROutput_AUC_Percent_Extrapolated_pred} 60 | \item \code{ROutput_AUCInfObs} 61 | \item \code{ROutput_AUCInfPred} 62 | \item \code{ROutput_AUCLast} 63 | \item \code{ROutput_AUMC_Percent_Extrapolated_obs} 64 | \item \code{ROutput_AUMC_Percent_Extrapolated_pred} 65 | \item \code{ROutput_AUMCInfObs} 66 | \item \code{ROutput_AUMCInfPred} 67 | \item \code{ROutput_AUMCLast} 68 | \item \code{ROutput_CLast} 69 | \item \code{ROutput_ClObs} 70 | \item \code{ROutput_ClPred} 71 | \item \code{ROutput_Cmax} 72 | \item \code{ROutput_Cmin} 73 | \item \code{ROutput_Dof} 74 | \item \code{ROutput_Dose} 75 | \item \code{ROutput_HalfLife} 76 | \item \code{ROutput_LambdaZ} 77 | \item \code{ROutput_LambdazLower} 78 | \item \code{ROutput_LambdazUpper} 79 | \item \code{ROutput_MRTInfObs} 80 | \item \code{ROutput_MRTInfPred} 81 | \item \code{ROutput_MRTLast} 82 | \item \code{ROutput_Peak} 83 | \item \code{ROutput_TLast} 84 | \item \code{ROutput_Tmax} 85 | \item \code{ROutput_Tmin} 86 | \item \code{ROutput_Trough} 87 | \item \code{ROutput_VssObs} 88 | \item \code{ROutput_VssPred} 89 | \item \code{ROutput_VzObs} 90 | \item \code{ROutput_VzPred} 91 | \item \code{ROutput_Error} 92 | } 93 | } 94 | \examples{ 95 | load(system.file(package = "MangoNca", "data", "shapeROutput.RData")) 96 | Theoph1 <- subset(Theoph, Subject == 1) 97 | ncaComplete(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1], Dof = 1, ROutput = shapeROutput) 98 | } 99 | \author{ 100 | Mango Solutions 101 | } 102 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.AUMCPartial.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 03/04/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | 11 | 12 | # tests AUMCPartial function from AUMCPartial.R 13 | 14 | test.AUMCPartial <- function() 15 | { 16 | if (!exists("AUMCPartial", mode = "function")) { AUMCPartial <- MangoNca:::AUMCPartial } 17 | 18 | time <- 0:10 19 | conc <- c(0, 10:1) 20 | 21 | # TEST 1 - 3 : endTime is an element of time 22 | 23 | test1 <- AUMCPartial(Conc = conc, Time = time, endTime = 10, numPoints = 3, addT0 = FALSE) 24 | checkEquals(test1, AUCLast(Conc = conc * time, Time = time, addT0 = FALSE), msg = " || TEST 1 : endTime is the final element of Time" ) 25 | 26 | test2 <- AUMCPartial(Conc = conc, Time = time, endTime = 2, numPoints = 3, addT0 = FALSE) 27 | checkEquals(test2, AUCLast(Time = 0:2, Conc = c(0, 10:9) * 0:2, addT0 = FALSE), " || TEST 2 : endTime is the second element of Time") 28 | 29 | test3 <- AUMCPartial(Conc = conc, Time = time, endTime = 3, numPoints = 3) 30 | checkEquals(test3, AUCLast(Time = 0:3, Conc = c(0, 10:8) * 0:3 ), " || TEST 3 : endTime is the third element of Time ") 31 | 32 | # TEST 4-6 : endTime is not an element of Time, but is inside the lower and upper limits 33 | 34 | test4 <- AUMCPartial(Conc = conc, Time = time, endTime = 1.75, numPoints = 3, addT0 = FALSE) 35 | test4comp <- MangoNca:::trapezium(c(0, 1, 1.75), c(0, 10, 9.25 * 1.75)) 36 | checkEquals(test4, test4comp, tol = 1e-7, msg = " || TEST 4 : endTime lies between first two elements of Time") 37 | 38 | test5 <- AUMCPartial(Conc = conc, Time = time, endTime = 9.25, numPoints = 3) 39 | checkEquals(test5, AUCLast(Conc = c(0, 10:2, 1.75) * c(0:9, 9.25), Time = c(0:9, 9.25)), , msg = " || TEST 5 : endTime lies between last 2 elements of Time ") 40 | 41 | 42 | test6 <- AUMCPartial(Conc = conc, Time = time, endTime = 5.2, numPoints = 3) 43 | checkEquals(test6, AUCLast(Conc = c(0, 10:6, 5.8) * c(0:5, 5.2), Time = c(0:5, 5.2)), msg = " || TEST 5 : endTime lies between middle elements of Time" ) 44 | 45 | # TEST 7 : alternative data set 46 | 47 | Theoph2 <- subset(Theoph, Subject == 2) 48 | test7 <- AUMCPartial(Conc = Theoph2$conc, Time = Theoph2$Time, endTime = 18, numPoints = 3) 49 | checkEquals(test7, AUCLast(Time = Theoph2$Time[1:10], Conc = Theoph2$Time[1:10] * Theoph2$conc[1:10]) + 215.3195, tol = 1e-7, msg = " || TEST 7 Theoph data set, endTime between last 2 elements of Time") 50 | 51 | # TEST 8 : NA should be returned if endTime < earliest time 52 | 53 | test8 <- AUMCPartial(Conc = 4:1,Time = 0:3, endTime = -1, numPoints = 3, addT0 = FALSE) 54 | checkTrue(is.na(test8), msg = " || TEST 8 : endTime < Time[1]") 55 | 56 | # TEST 9 : check for endTime > tlast 57 | 58 | test9 <- AUMCPartial(Conc = Theoph2$conc, Time = Theoph2$Time, endTime = 26, numPoints = 5) 59 | checkEquals(test9, 707.9921, tol = 1e-7) 60 | 61 | } 62 | 63 | test.AUMCPartial_errorHandling <- function() 64 | { 65 | if (!exists("AUMCPartial", mode = "function")) { AUMCPartial <- MangoNca:::AUMCPartial } 66 | 67 | # TEST 1 : missing numPoints 68 | 69 | Theoph2 <- Theoph[Theoph$Subject == 2, ] 70 | 71 | test1 <- try( AUMCPartial(Conc = Theoph2$conc, Time = Theoph2$Time, endTime = 26), silent = TRUE ) 72 | checkTrue( MangoNca:::isErrorWithMessage(test1, "Error in checkSingleNumeric(numPoints, description = \"numPoints\", functionName = \"AUMCPartial\") : \n Error in AUMCPartial: numPoints is missing with no default\n"), 73 | msg = " || TEST 1 : missing numPoints") 74 | 75 | # TEST 2 : endTime is not a numeric of length 1 76 | 77 | test2 <- try( AUMCPartial(Conc = 3:1, Time = 0:2, endTime = c(1, 2), numPoints = 3), silent = TRUE ) 78 | checkTrue( MangoNca:::isErrorWithMessage(test2, "Error in checkSingleNumeric(endTime, description = \"endTime\", functionName = \"AUMCPartial\") : \n Error in AUMCPartial : endTime is not a numeric of length 1. Value is: 1 2\n"), 79 | msg = " || TEST 2 : endTime is not of length 1") 80 | 81 | # TEST 3 : endTime is not numeric 82 | 83 | test3 <- try( AUMCPartial(Conc = 3:1, Time = 0:2, endTime = "1", numPoints = 3), silent = TRUE ) 84 | checkTrue(MangoNca:::isErrorWithMessage(test3, "Error in checkSingleNumeric(endTime, description = \"endTime\", functionName = \"AUMCPartial\") : \n Error in AUMCPartial : endTime is not a numeric of length 1. Value is: 1\n"), 85 | msg = " || TEST 3 : endTime is not numeric ") 86 | } 87 | -------------------------------------------------------------------------------- /mangoNCA/R/ncaPeaktrough.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 16/03/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: plobb 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | #' Return Concentration values coded as PEAKCODE or TROUGHCODE for sparse data 10 | #' 11 | #' Calculates Peak through (pre / post dose concentrations) for individuals on Time concentration curves. 12 | #' PEAKCODE is 2, TROUGHCODE is 1, if there is more than one of each of these, this is a data error. 13 | #' 14 | #' @title PeakTrough Vector of pre- and post-dose identifiers (TROUGHCODE and PEAKCODE respectively). There must not be more than one of each. NULL is replaced with 0. 15 | #' @param Conc Vector of concentrations. 16 | #' @param Time Vector of times, must be ordered in ascending order and should not have duplicates. 17 | #' @param Dose Single numeric value of dose. 18 | #' @param Dof Single numeric value of duration of infusion. 19 | #' @param Safe Single logical value declaring whether to perform redundant data checks (default is TRUE). 20 | #' @param ROutput Named vector consisting of 38 NA and 1 zero with names which should match expected output names. 21 | #' @return Data frame 22 | #' @author Mango Solutions 23 | #' @export 24 | #' @examples 25 | #' load(system.file(package = "MangoNca", "data", "shapeROutput.RData")) 26 | #' Theoph1 <- subset(Theoph, Subject == 1) 27 | #' ncaPeakTrough(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1], Dof = 1, PeakTrough = c(1, 0, 0, 0, 2, rep(0, 6)), ROutput = shapeROutput) 28 | 29 | ncaPeakTrough <- function(Conc, Time, Dose, Dof, PeakTrough = NULL, Safe = TRUE, ROutput) { 30 | 31 | checkSafe <- try(checkSingleLogical(Safe, description = "Safe", functionName = "ncaPeakTrough"), silent = TRUE) 32 | 33 | if( class(checkSafe) == "try-error" ) { 34 | 35 | ROutput <- as.data.frame(as.list(ROutput)) 36 | 37 | ROutput["ROutput_Error"] <- paste(checkSafe, collapse = "\n") 38 | 39 | return(ROutput) 40 | } 41 | 42 | if( Safe ) { 43 | 44 | # Check data for gross errors 45 | 46 | check01 <- try(checkOrderedVector(Time, description = "Time", functionName = "ncaPeakTrough"), silent = TRUE) 47 | 48 | check02 <- try(checkNumericSameLength(Time, Conc, "Time", "Concentration", "ncaPeakTrough"), silent = TRUE) 49 | 50 | if( is.null( PeakTrough ) ) { 51 | PeakTrough <- rep(0, times = length(Time)) 52 | } 53 | 54 | check03 <- try(checkNumericSameLength(Time, PeakTrough, "Time", "Peak/Trough", "ncaPeakTrough"), silent = TRUE) 55 | 56 | check04 <- try(checkPeakTrough(PeakTrough, functionName = "ncaPeakTrough"), silent = TRUE) 57 | 58 | check05 <- try(checkSingleNumeric(Dose, description = "Dose", "ncaPeakTrough"), silent = TRUE) 59 | 60 | check06 <- try(checkSingleNumeric(Dof, description = "Duration of Infusion", "ncaPeakTrough"), silent = TRUE) 61 | 62 | if(missing(ROutput) || 63 | !identical(as.integer(39), length(ROutput)) || 64 | is.null(names(ROutput))) { check07 <- "error in ncaPeakTrough: ROutput should be a named vector of length 39" } else { check07 <- NULL } 65 | 66 | # return if gross data errors present coerce output to data frame add errors and return 67 | 68 | ROutput_Error <- paste(check01, check02, check04, check05, check06, check07, collapse = "\n") 69 | 70 | if( ROutput_Error != "" ) { 71 | 72 | ROutput <- as.data.frame(as.list(ROutput)) 73 | 74 | ROutput["ROutput_Error"] <- ROutput_Error 75 | 76 | return(ROutput) 77 | } 78 | 79 | } 80 | 81 | ROutput["ROutput_Dose"] <- Dose 82 | 83 | ROutput["ROutput_Dof"] <- Dof 84 | 85 | ################################################################################################## 86 | 87 | ## Locate Peak and Trough if present 88 | 89 | PEAKCODE <- 2 90 | TROUGHCODE <- 1 91 | 92 | PeakIndex <- which( PeakTrough == PEAKCODE )[1] 93 | 94 | ROutput["ROutput_Peak"] <- Conc[PeakIndex] 95 | 96 | TroughIndex <- which( PeakTrough == TROUGHCODE )[1] 97 | 98 | ROutput["ROutput_Trough"] <- Conc[TroughIndex] 99 | 100 | ################################################################################################## 101 | 102 | ## Coerce to dataframe and return 103 | 104 | ROutput <- as.data.frame(as.list(ROutput)) 105 | 106 | return(ROutput) 107 | 108 | } 109 | -------------------------------------------------------------------------------- /mangoNCA/inst/testing/runit.AUCPartial.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 03/04/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | # tests AUCPartial function from AUCPartial.R 10 | 11 | test.AUCPartial <- function() 12 | { 13 | if (!exists("AUCPartial", mode = "function")) { AUCPartial <- MangoNca:::AUCPartial } 14 | 15 | time <- 0:10 16 | conc <- c(0, 10:1) 17 | 18 | # TEST 1 - 3 : endTime is an element of time - normal and boundary cases 19 | 20 | test1 <- AUCPartial(Conc = conc, Time = time, endTime = 10, numPoints = 3, addT0 = TRUE) 21 | checkEquals(test1, AUCLast(Time = time, Conc = conc ), msg = " || TEST 1 : endTime is the final element of Time" ) 22 | 23 | test2 <- AUCPartial(Conc = conc, Time = time, endTime = 2, numPoints = 3, addT0 = TRUE) 24 | checkEquals(test2, AUCLast(Time = 0:2, Conc = c(0, 10:9)), msg = " || TEST 2 : endTime is the second element of Time") 25 | 26 | test3 <- AUCPartial(Conc = conc, Time = time, endTime = 3, numPoints = 3) 27 | checkEquals(test3, AUCLast(Time = 0:3, Conc = c(0, 10:8)), msg = " || TEST 3 : endTime is the third element of Time ") 28 | 29 | # TEST 4-6 : endTime is not an element of Time, but is inside the lower and upper limits 30 | 31 | test4 <- AUCPartial(Conc = conc, Time = time, endTime = 1.75, numPoints = 3) 32 | checkEquals(test4, AUCLast(Conc = c(0, 10, 9.25), Time = c(0, 1, 1.75)), msg = " || TEST 4 : endTime lies between first two elements of Time") 33 | 34 | test5 <- AUCPartial(Conc = conc, Time = time, endTime = 9.25, numPoints = 3) 35 | checkEquals(test5, AUCLast(Conc = c(0, 10:2, 1.75), Time = c(0:9, 9.25)), msg = " || TEST 5 : endTime lies between last 2 elements of Time ") 36 | 37 | 38 | test6 <- AUCPartial(Conc = conc, Time = time, endTime = 5.2, numPoints = 3) 39 | checkEquals(test6, AUCLast(Conc = c(0, 10:6, 5.8), Time = c(0:5, 5.2)), msg = " || TEST 6 : endTime lies between middle elements of Time" ) 40 | 41 | # TEST 7 : alternative data set 42 | 43 | Theoph2 <- subset(Theoph, Subject == 2) 44 | test7 <- AUCPartial(Conc = Theoph2$conc, Time = Theoph2$Time, endTime = 18, numPoints = 3) 45 | checkEquals(test7, AUCLast(Time = Theoph2$Time[1:10], Conc = Theoph2$conc[1:10]) + 14.97220, tol = 1e-7, msg = " || TEST 7 Theoph data set, endTime between last 2 elements of Time") 46 | 47 | # TEST 8 : NA should be returned if endTime < earliest time 48 | 49 | test8 <- AUCPartial(Conc = 4:1,Time = 0:3, endTime = -1, numPoints = 3, addT0 = FALSE) 50 | checkTrue(is.na(test8), msg = " || TEST 8 : endTime < Time[1]") 51 | 52 | # TEST 9 : check for tau > tlast 53 | 54 | test9 <- AUCPartial(Conc = Theoph2$conc, Time = Theoph2$Time, endTime = 26, numPoints = 5) 55 | 56 | checkEquals(test9, 92.93229975, msg = " || TEST 9 : endTime > last time, checking extrapolation" ) 57 | 58 | # TEST 10 : endTime is T = 0 59 | 60 | test10 <- AUCPartial(Conc = conc, Time = time, endTime = 0, numPoints = 3, addT0 = TRUE) 61 | checkEquals(test10, 0, msg = " || TEST 10 : endTime is the first element of Time" ) 62 | 63 | } 64 | 65 | test.AUCPartial_errorHandling <- function() 66 | { 67 | if (!exists("AUCPartial", mode = "function")) { AUCPartial <- MangoNca:::AUCPartial } 68 | isErrorWithMessage <- MangoNca:::isErrorWithMessage 69 | 70 | # TEST 1 : missing numPoints 71 | 72 | Theoph2 <- Theoph[Theoph$Subject == 2, ] 73 | 74 | test1 <- try( AUCPartial(Conc = Theoph2$conc, Time = Theoph2$Time, endTime = 26), silent = TRUE ) 75 | checkTrue( isErrorWithMessage(test1, "Error in checkSingleNumeric(numPoints, description = \"numPoints\", functionName = \"AUCPartial\") : \n Error in AUCPartial : numPoints is not a numeric of length 1. Value is: \n NULL\n"), 76 | msg = " || TEST 1 : missing numPoints") 77 | 78 | # TEST 2 : endTime is not a length 1 79 | 80 | test2 <- try( AUCPartial(Conc = 3:1, Time = 0:2, endTime = c(1, 2), numPoints = 3), silent = TRUE ) 81 | checkTrue( isErrorWithMessage(test2, "Error in checkSingleNumeric(endTime, description = \"endTime\", functionName = \"AUCPartial\") : \n Error in AUCPartial : endTime is not a numeric of length 1. Value is: 1 2\n"), 82 | msg = " || TEST 2 : endTime is not of length 1") 83 | 84 | # TEST 3 : endTime is not numeric 85 | 86 | test3 <- try( AUCPartial(Conc = 3:1, Time = 0:2, endTime = "1", numPoints = 3), silent = TRUE ) 87 | checkTrue(isErrorWithMessage(test3, "Error in checkSingleNumeric(endTime, description = \"endTime\", functionName = \"AUCPartial\") : \n Error in AUCPartial : endTime is not a numeric of length 1. Value is: 1\n"), 88 | msg = " || TEST 3 : endTime is not numeric ") 89 | } 90 | -------------------------------------------------------------------------------- /mangoNCA/R/AUMCPartial.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 03/04/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | #' Area Under the Concentration Time Moment Curve from T = 0 to T = endTime 11 | #' 12 | #' Calculates the area under a concentration-time moment curve from the first time up until the \code{endTime}. \code{endTime} 13 | #' need not be one of the elements of \code{Time}, but it should like between the minimum and maximum times 14 | #' Note, all error checks that apply to \code{\link{AUC}} apply here. If \code{endTime} is less than 15 | #' \code{tmin} \code{NA} is returned. There should be no missing times. 16 | #' If the endTime does not coincide with an existing time element, the following interpolation formula will be 17 | #' used to calculated a new concentration (if time is less than tlast): 18 | #' \deqn{c_{inter} = c_1 + \left| \frac{ t^{end} - t_1}{t_2 - t_1} \right| (c_2 - c_1)}. If endTime is greater than 19 | #' tlast, then another concentration is extrapolated via the formula \deqn{c_{extr} = c_0 + \exp(- \lambda_z * endTime) } 20 | #' 21 | #' @param Conc Vector of concentrations 22 | #' @param Time Vector of times, must be ordered in ascending order and should not have duplicates 23 | #' @param endTime : last time at which area should be calculated. Must be greater than the smallest element of Time, else NA is returned. 24 | #' @param numPoints : Number of points to use for lambda-z calculation. This will only be used if endTime > tlast to 25 | #' extrapolate a new concentration point 26 | #' @title Partial Area Under Moment Curve 27 | #' @return Single numeric 28 | #' @author Mango Solutions 29 | #' @keywords math 30 | 31 | 32 | AUMCPartial <- function(Conc, Time, endTime, numPoints, addT0 = TRUE) 33 | { 34 | 35 | checkOrderedVector(Time, description = "Time", functionName = "AUMCPartial") 36 | checkSingleNumeric(endTime, description = "endTime", functionName = "AUMCPartial") 37 | checkSingleNumeric(numPoints, description = "numPoints", functionName = "AUMCPartial") 38 | 39 | # Add T = 0 if it is missing and remove missing values 40 | 41 | cleanData <- try(cleanConcTime(Conc = Conc, Time = Time, addT0 = addT0), silent = TRUE) 42 | 43 | if( is(cleanData, "try-error") ) { 44 | 45 | stop(paste("Error in AUMCPartial: Error during data cleaning", as.character(cleanData), collapse = "\n")) 46 | 47 | } 48 | 49 | Conc <- cleanData$Conc 50 | Time <- cleanData$Time 51 | 52 | aucp <- as.numeric(NA) 53 | 54 | 55 | ############################################################################### 56 | 57 | # check endTime occurs during Time 58 | 59 | if( endTime < min(Time) ){ 60 | 61 | return(aucp) 62 | 63 | } 64 | 65 | 66 | ############################################################################### 67 | 68 | # if endTime is actually an element of the Time vector, we can fall back on standard AUC functions 69 | 70 | if(endTime %in% Time) 71 | { 72 | # endTimeIndex : integer with index of endTime inside Time 73 | endTimeIndex <- match(endTime, Time ) 74 | 75 | aucp <- sum(AUCLin( Time = head(Time, n = endTimeIndex), Conc = head(Conc, n = endTimeIndex) * head(Time, n = endTimeIndex) )) 76 | 77 | return(aucp) 78 | } 79 | 80 | 81 | ############################################################################### 82 | 83 | # if endTime > tlast, we need to extrapolate a new concentration element. 84 | 85 | cLastTLast <- ClastTlast( Conc = Conc, Time = Time ) 86 | 87 | if(endTime > cLastTLast$tlast) 88 | { 89 | 90 | auclast <- AUCLast(Conc = Conc * Time, Time = Time) 91 | 92 | # calculate the terminal AUMC using integral of exponential function (aucterm) 93 | 94 | lambdaZStats <- lambdaZStatistics(Conc = Conc, Time = Time, numPoints = numPoints) 95 | 96 | intercept <- lambdaZStats$intercept 97 | lambdaz <- lambdaZStats$Lambdaz 98 | 99 | auc0last <- -intercept / (lambdaz * exp(lambdaz * cLastTLast$tlast)) 100 | auc0end <- -intercept / (lambdaz * exp(lambdaz * endTime)) 101 | 102 | aucterm <- auc0end - auc0last 103 | 104 | aucp <- auclast + aucterm 105 | 106 | return(aucp) 107 | 108 | } 109 | 110 | 111 | ############################################################################### 112 | 113 | # endTime occurs between T0 and TLast 114 | 115 | # find the last element which endTime exceeds 116 | # t1Index the index of the largest time less than endTime 117 | # t2Index is next next time after t1Index 118 | 119 | t1Index <- tail( which(Time < endTime), n = 1 ) 120 | t2Index <- t1Index + 1 121 | 122 | # t1, t2 = left time, right time (of interval containing endTime) 123 | # c1, c2 = left concentration, right concentration (of interval containing endTime) 124 | 125 | t1 <- Time[t1Index] 126 | t2 <- Time[t2Index] 127 | c1 <- Conc[t1Index] 128 | c2 <- Conc[t2Index] 129 | 130 | # cInter is the interpolated concentration 131 | 132 | cInter <- c1 + abs( (endTime - t1) / (t2 - t1) ) * (c2 - c1) 133 | 134 | # concBeforeEndTime, timeBeforeEndTime : vectors of concentrations and times that occur before endTime 135 | 136 | concBeforeEndTime <- head(Conc, n = t1Index) 137 | timeBeforeEndTime <- head(Time, n = t1Index) 138 | 139 | aucp <- sum(AUCLin( Conc = c(concBeforeEndTime * timeBeforeEndTime, cInter * endTime), Time = c(timeBeforeEndTime, endTime ) ) ) 140 | 141 | return(aucp) 142 | } 143 | 144 | -------------------------------------------------------------------------------- /mangoNCA/R/VZ.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 04/04/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: ccampbell 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | #' Terminal Volume Distribution, Single Dose (predicted) 11 | #' 12 | #' Calculates volume distribution for single dose from terminal phase (predicted). 13 | #' 14 | #' @param Conc Vector of concentrations 15 | #' @param Time Vector of times, must be ordered in ascending order and should not have duplicates 16 | #' @param numPoints Number of points to use for the lambda z calculation(s) 17 | #' @param Dose Single numeric with dose amount 18 | #' @param Dof duration of infusion (default NULL) 19 | #' @title Terminal Volume Distribution, Single Dose (predicted) 20 | #' @note All input checks / error handling for LambdaZStatistics and AUCInfPred apply. 21 | #' The formula used to calculate this quantity is 22 | #' \deqn{ Dose / {\lambda}_z * AUC({\inf})_Pred } 23 | #' @return Single numeric value 24 | #' @author Mango Solutions 25 | #' @keywords math 26 | #' @examples 27 | #' Theoph1 <- subset(Theoph, Subject == 1) 28 | #' VZPred(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1]) 29 | #' @export 30 | 31 | VZPred <- function(Conc, Time, Dose, numPoints = NULL) 32 | { 33 | # check Conc, Time, numPoints and Dose, and calculate numPoints if missing 34 | 35 | checkOrderedVector(Time, description = "Time", functionName = "VZPred") 36 | checkNumericSameLength(Time, Conc, "Time", "Concentration", functionName = "VZPred") 37 | checkSingleNumeric(Dose, "Dose", functionName = "VZPred") 38 | 39 | if(is.na(Dose) || Dose <= 0 ) 40 | { 41 | return(as.numeric(NA)) 42 | 43 | } 44 | 45 | if(is.null(numPoints)) 46 | { 47 | numPoints <- selectPoints(Conc = Conc, Time = Time) 48 | 49 | } else 50 | { 51 | checkSingleNumeric(numPoints, "Number of Points lambdaz", functionName = "VZPred") 52 | 53 | } 54 | 55 | Lambda_Z_Stats <- lambdaZStatistics(Conc = Conc, Time = Time, numPoints = numPoints) 56 | 57 | AUCinfpred <- AUCInfPred(Conc = Conc, Time = Time, numPoints = numPoints, calculation = "standard") 58 | 59 | VZ_F <- VZ(lambdaz = Lambda_Z_Stats$Lambdaz, AUCInf = AUCinfpred, Dose = Dose) # volume of distribution HL 60 | 61 | return(VZ_F) 62 | } 63 | 64 | 65 | 66 | #' Terminal Volume Distribution, Single Dose (observed) 67 | #' 68 | #' Calculates volume distribution for single dose from terminal phase (observed). 69 | #' 70 | #' @param Conc Vector of concentrations 71 | #' @param Time Vector of times, must be ordered in ascending order and should not have duplicates 72 | #' @param numPoints Number of points to use for the lambda z calculation(s) 73 | #' @param Dose Single numeric with dose amount 74 | #' @param Dof duration of infusion (default NULL) 75 | #' @title Terminal Volume Distribution, Single Dose (observed) 76 | #' @note All input checks / error handling for LambdaZStatistics and AUCInfPred apply. 77 | #' The formula used to calculate this quantity is 78 | #' \deqn{ Dose / {\lambda}_z * AUC({\inf})_Obs } 79 | #' @return Single numeric value 80 | #' @author Mango Solutions 81 | #' @keywords math 82 | #' @examples 83 | #' Theoph1 <- subset(Theoph, Subject == 1) 84 | #' VZObs(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1]) 85 | #' @export 86 | 87 | VZObs <- function(Conc, Time, Dose, numPoints = NULL) 88 | { 89 | # check Conc, Time, numPoints and Dose, and calculate numPoints if missing 90 | 91 | checkOrderedVector(Time, description = "Time", functionName = "VZObs") 92 | checkNumericSameLength(Time, Conc, "Time", "Concentration", functionName = "VZObs") 93 | checkSingleNumeric(Dose, "Dose", functionName = "VZObs") 94 | 95 | if(is.na(Dose) || Dose <= 0 ) 96 | { 97 | return(as.numeric(NA)) 98 | 99 | } 100 | 101 | if(is.null(numPoints)) 102 | { 103 | numPoints <- selectPoints(Conc = Conc, Time = Time) 104 | 105 | } else 106 | { 107 | checkSingleNumeric(numPoints, "Number of Points lambdaz", functionName = "VZObs") 108 | 109 | } 110 | 111 | Lambda_Z_Stats <- lambdaZStatistics(Conc = Conc, Time = Time, numPoints = numPoints) 112 | 113 | AUCinfobs <- AUCInfObs(Conc = Conc, Time = Time, numPoints = numPoints, calculation = "standard") 114 | 115 | VZ_F <- VZ(lambdaz = Lambda_Z_Stats$Lambdaz, AUCInf = AUCinfobs, Dose = Dose) # volume of distribution HL 116 | 117 | return(VZ_F) 118 | } 119 | 120 | 121 | 122 | 123 | #' Calculate Volume of Distribution for single dose from terminal phase. 124 | #' 125 | #' This function simply calculates VSS from MRT and CL when they have already been calculated. 126 | #' \deqn{ VSS = MRT * CL } 127 | #' 128 | #' @param MRT Single numeric value of time 129 | #' @param CL Single numeric value of clearance 130 | #' @param Safe Single logical value declaring whether to perform redundant data checks (default is TRUE). 131 | #' @title Volume Distribution at Steady-State (observed) 132 | #' @return Single numeric value 133 | #' @export 134 | #' @author Mango Solutions 135 | #' @keywords math 136 | #' @examples 137 | #' VZ(lambdaz = 0.001, AUCInf = 1000, Dose = 10) 138 | 139 | VZ <- function(lambdaz, AUCInf, Dose, Safe = TRUE) 140 | { 141 | 142 | checkSingleLogical(Safe, description = "Safe", functionName = "VZ") 143 | 144 | if( Safe ) { 145 | 146 | checkSingleNumeric(lambdaz, description = "lambdaz", functionName = "VZ") 147 | checkSingleNumeric(AUCInf, description = "AUCInf", functionName = "VZ") 148 | checkSingleNumeric(Dose, description = "Dose", functionName = "VZ") 149 | 150 | } 151 | 152 | VZ <- Dose / (lambdaz * AUCInf) # volume of distribution HL 153 | 154 | return(VZ) 155 | } 156 | -------------------------------------------------------------------------------- /mangoNCA/man/ncaAnalysis.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ncaAnalysis.R 3 | \name{ncaAnalysis} 4 | \alias{ncaAnalysis} 5 | \title{API wrapper for NCA analysis pharmacodynamic data} 6 | \usage{ 7 | ncaAnalysis(Conc = NULL, Time = NULL, Dose = NULL, Dof = NULL, 8 | PeakTrough = NULL, numPoints = NULL, usePoints = NULL, 9 | excPoints = NULL, Safe = TRUE, inter = "Linear") 10 | } 11 | \arguments{ 12 | \item{Conc}{Vector of Conc} 13 | 14 | \item{Time}{Vector of Time, must be ordered in ascending order and should not have duplicates} 15 | 16 | \item{Dose}{Single numeric value of dose} 17 | 18 | \item{Dof}{Single numeric value of duration of infusion} 19 | 20 | \item{PeakTrough}{Optional vector of numeric coding of Peak and Trough values, length equal to length of Time, otherwise \code{NULL}.} 21 | 22 | \item{numPoints}{If \code{NULL} (default) automatically select, else, single numeric number of points for calculation of terminal phase.} 23 | 24 | \item{usePoints}{If \code{NULL} (default) automatically select, else, logical vector of points to use for calculation of terminal phase. Used rows are flagged by usePoints as \code{TRUE}.} 25 | 26 | \item{excPoints}{If \code{NULL} (default) automatically select, else, logical vector of points to exclude from automatic calculation of terminal phase. Excluded rows are flagged by excPoints as \code{TRUE}.} 27 | 28 | \item{Safe}{Single logical value declaring whether to perform redundant data checks (default is \code{TRUE}).} 29 | 30 | \item{inter}{Single character stating whether the interpolation method used is \code{"Linear"} (default), \code{"Lin up Log down"} or \code{"Linear Log"}} 31 | } 32 | \value{ 33 | Data frame 34 | } 35 | \description{ 36 | Perform Non-Compartmental Analysis for a Concentration-Time repeated measures dataset. 37 | } 38 | \details{ 39 | This is a wrapper function designed to be the interface for performing a complete Non-Compartmental Analysis. 40 | The function has required arguments: \enumerate{ 41 | \item Conc, a vector of concentration values of length equal to \code{length(Time)} 42 | \item Time, a corresponding vector of measurement time values 43 | \item Dose, a single numeric value declaring dose 44 | \item Dof (duration of infusion), a single numeric value declaring duration of infusion. 45 | } 46 | Optional arguments are: \enumerate{ 47 | \item PeakTrough, numeric vector of length equal to \code{length(Time)} coding time values 48 | for no more than one trough (1) and peak (2) concentration records, and 0 elsewhere. 49 | \item numPoints, a single integer value declaring number of points to use in \code{lambdazStatistics} 50 | when calculating terminal phase elimination. 51 | If numPoints is 0 (zero), terminal phase calculations are supressed. 52 | By default, numPoints is NULL, declaring that numPoints should automatically be calculated by \code{selectPoints} using the default method. 53 | \item usePoints suppresses automatic selection of terminal phase; 54 | all rows which are \code{TRUE} will be used to calculate lambdaz. This argument must not be used with numPoints. 55 | \item excPoints uses automatic selection, but all rows which are \code{TRUE} are excluded 56 | from the terminal phase calculation. If usePoints and excPoints are both supplied, then automatic selection will be supressed, 57 | but excPoints will be omitted in addition to rows excluded by usePoints. 58 | If supplied with numPoints, excluded values will not be counted in points used for lambdaz. 59 | \item Safe, a single logical stating that redundant checking should be performed in each function. 60 | \item inter, a single character stating whether the interpolation method used is \code{"Linear"} (default) or \code{"Linear Log"} 61 | } 62 | No unit conversion is performed by these functions. 63 | \code{ncaAnalysis} returns a data frame with 39 columns containing 1 row of numeric results. 64 | The final column of the return is \code{ROutput_Error}. This should be zero. If it is not, an error 65 | has occured. The text of each error will appear in this column as a single character string with 66 | individual messages separated by a newline. 67 | If there are three or fewer rows, data is passed to \code{\link{ncaPeakTrough}} for Peak/Trough identification only. 68 | If there are four or more rows, data is passed to \code{\link{ncaComplete}} for full non-compartmental analysis. 69 | Returns a data frame with 1 row containing columns: 70 | \enumerate{ 71 | \item \code{ROutput_adjr2} 72 | \item \code{ROutput_intercept} 73 | \item \code{ROutput_numPoints} 74 | \item \code{ROutput_r2} 75 | \item \code{ROutput_rhoXY} 76 | \item \code{ROutput_AUC_Percent_Extrapolated_obs} 77 | \item \code{ROutput_AUC_Percent_Extrapolated_pred} 78 | \item \code{ROutput_AUCInfObs} 79 | \item \code{ROutput_AUCInfPred} 80 | \item \code{ROutput_AUCLast} 81 | \item \code{ROutput_AUMC_Percent_Extrapolated_obs} 82 | \item \code{ROutput_AUMC_Percent_Extrapolated_pred} 83 | \item \code{ROutput_AUMCInfObs} 84 | \item \code{ROutput_AUMCInfPred} 85 | \item \code{ROutput_AUMCLast} 86 | \item \code{ROutput_CLast} 87 | \item \code{ROutput_ClObs} 88 | \item \code{ROutput_ClPred} 89 | \item \code{ROutput_Cmax} 90 | \item \code{ROutput_Cmin} 91 | \item \code{ROutput_Dof} 92 | \item \code{ROutput_Dose} 93 | \item \code{ROutput_HalfLife} 94 | \item \code{ROutput_LambdaZ} 95 | \item \code{ROutput_LambdazLower} 96 | \item \code{ROutput_LambdazUpper} 97 | \item \code{ROutput_MRTInfObs} 98 | \item \code{ROutput_MRTInfPred} 99 | \item \code{ROutput_MRTLast} 100 | \item \code{ROutput_Peak} 101 | \item \code{ROutput_TLast} 102 | \item \code{ROutput_Tmax} 103 | \item \code{ROutput_Tmin} 104 | \item \code{ROutput_Trough} 105 | \item \code{ROutput_VssObs} 106 | \item \code{ROutput_VssPred} 107 | \item \code{ROutput_VzObs} 108 | \item \code{ROutput_VzPred} 109 | \item \code{ROutput_Error} 110 | } 111 | } 112 | \examples{ 113 | Theoph1 <- subset(Theoph, Subject == 1) 114 | ncaAnalysis(Conc = Theoph1$conc, Time = Theoph1$Time, Dose = 10, Dof = 1) 115 | } 116 | \author{ 117 | Mango Solutions 118 | } 119 | \keyword{math} 120 | \keyword{nca} 121 | -------------------------------------------------------------------------------- /mangoNCA/R/VSS.R: -------------------------------------------------------------------------------- 1 | # SVN revision: $Rev: $ 2 | # Date of last change: $LastChangedDate: 03/02/2012 $ 3 | # Last changed by: $LastChangedBy: ccampbell $ 4 | # 5 | # Original author: fgochez 6 | # Copyright Mango Solutions, Chippenham, UK 7 | ############################################################################### 8 | 9 | 10 | #' Function to Calculate Volume of Distribution at Steady State (Predicted) 11 | #' 12 | #' Calculates volume distribution at steady-state (predicted). 13 | #' This is a convenience function for when using the R package. 14 | #' \code{\link{ncaComplete}} calls VSS since MRTInfPred and CLPred have already been calculated. 15 | #' \code{VSSPred} calls \code{\link{VSS}} after calling \code{\link{MRTInfPredSD}}, 16 | #' \code{\link{AUCinfpred}} and \code{\link{clearance}}. 17 | #' 18 | #' @param Conc Vector of concentrations 19 | #' @param Time Vector of times, must be ordered in ascending order and should not have duplicates 20 | #' @param numPoints Number of points to use for the lambda z calculation(s) 21 | #' @param Dose Single numeric with dose amount 22 | #' @param Dof duration of infusion 23 | #' @title Volume Distribution at Steady-State (predicted) 24 | #' @return Single numeric value 25 | #' @export 26 | #' @note All input checks / error handling for CLPred and MRTInfPredSD apply. 27 | #' The formula used to calculate this quantity is 28 | #' \deqn{ MRTPredSD_{\inf} * CLPred } 29 | #' @author Mango Solutions 30 | #' @keywords math 31 | #' @examples 32 | #' Theoph1 <- subset( Theoph, Subject == 1) 33 | #' VSSPred( Conc = Theoph1$conc, Time = Theoph1$Time, Dose = Theoph1$Dose[1], Dof = 3 ) 34 | 35 | VSSPred <- function(Conc, Time, Dose, Dof, numPoints = NULL, Safe = TRUE) 36 | { 37 | # check Conc, Time, numPoints and Dose, and calculate numPoints if missing 38 | 39 | checkOrderedVector(Time, description = "Time", functionName = "VSSPred") 40 | checkNumericSameLength(Time, Conc, "Time", "Concentration", functionName = "VSSPred") 41 | checkSingleNumeric(Dose, "Dose", functionName = "VSSPred") 42 | checkSingleNumeric(Dof, "Duration of Infusion", functionName = "VSSPred") 43 | 44 | if(is.na(Dose) || Dose <= 0 ) 45 | { 46 | return(as.numeric(NA)) 47 | 48 | } 49 | 50 | if(is.null(numPoints)) 51 | { 52 | numPoints <- selectPoints(Conc = Conc, Time = Time) 53 | 54 | } else 55 | { 56 | checkSingleNumeric(numPoints, "Number of Points lambdaz", functionName = "VSSPred") 57 | 58 | } 59 | 60 | MRT <- MRTInfPredSD(Conc = Conc, Time = Time, numPoints = numPoints, Dof = Dof) 61 | 62 | AUCinfpred <- AUCInfPred(Conc = Conc, Time = Time, 63 | numPoints = numPoints, calculation = "standard", Safe = Safe) 64 | 65 | CL <- clearance(AUCInf = AUCinfpred, Dose = Dose) 66 | 67 | VSSpred <- VSS(MRT = MRT, CL = CL, Safe = Safe) 68 | 69 | return(VSSpred) 70 | } 71 | 72 | 73 | #' Function to Calculate Volume of Distribution at Steady State (Observed) 74 | #' 75 | #' Calculates volume distribution at steady-state (observed). 76 | #' This is a convenience function for when using the R package. 77 | #' \code{\link{ncaComplete}} calls VSS directly since MRTInfObs and CLObs have already been calculated. 78 | #' \code{VSSObs} calls \code{\link{VSS}} after calling \code{\link{MRTInfObsSD}}, \code{\link{AUCinfobs}} and \code{\link{clearance}}. 79 | #' 80 | #' @param Conc Vector of concentrations 81 | #' @param Time Vector of times, must be ordered in ascending order and should not have duplicates 82 | #' @param numPoints Number of points to use for the lambda z calculation(s) 83 | #' @param Dose Single numeric with dose amount 84 | #' @param Dof duration of infusion 85 | #' @title Volume Distribution at Steady-State (observed) 86 | #' @return Single numeric value 87 | #' @export 88 | #' @note All input checks / error handling for CLPred and MRTInfPredSD apply. The formula used to calculate this 89 | #' quantity is \deqn{ MRTPredSD_{\inf} * CLPred } 90 | #' @author Mango Solutions 91 | #' @keywords math 92 | #' @examples 93 | #' Theoph1 <- subset( Theoph, Subject == 1) 94 | #' VSSObs( Conc = Theoph1$conc, Time = Theoph1$Time, numPoints = 3, Dose = Theoph1$Dose[1], Dof = 3 ) 95 | 96 | VSSObs <- function(Conc, Time, Dose, Dof, numPoints = NULL, Safe = TRUE) 97 | { 98 | # check Conc, Time, numPoints and Dose, and calculate numPoints if missing 99 | 100 | checkOrderedVector(Time, description = "Time", functionName = "VSSObs") 101 | checkNumericSameLength(Time, Conc, "Time", "Concentration", functionName = "VSSObs") 102 | checkSingleNumeric(Dose, "Dose", functionName = "VSSObs") 103 | checkSingleNumeric(Dof, "Duration of Infusion", functionName = "VSSObs") 104 | 105 | if(is.na(Dose) || Dose <= 0 ) 106 | { 107 | return(as.numeric(NA)) 108 | 109 | } 110 | 111 | if(is.null(numPoints)) 112 | { 113 | numPoints <- selectPoints(Conc = Conc, Time = Time) 114 | 115 | } else 116 | { 117 | checkSingleNumeric(numPoints, "Number of Points lambdaz", functionName = "VSSObs") 118 | 119 | } 120 | 121 | MRT <- MRTInfObsSD(Conc = Conc, Time = Time, numPoints = numPoints, Dof = Dof) 122 | 123 | AUCinfobs <- AUCInfObs(Conc = Conc, Time = Time, 124 | numPoints = numPoints, calculation = c("standard"), Safe = Safe) 125 | 126 | CL <- clearance(AUCInf = AUCinfobs, Dose = Dose) 127 | 128 | VSSObs <- VSS(MRT = MRT, CL = CL, Safe = Safe) 129 | 130 | return(VSSObs) 131 | } 132 | 133 | 134 | #' Calculate Volume of Distribution at Steady-State. 135 | #' 136 | #' This function simply calculates VSS from MRT and CL when they have already been calculated. 137 | #' \deqn{ VSS = MRT * CL } 138 | #' 139 | #' @param MRT Single numeric value of time 140 | #' @param CL Single numeric value of clearance 141 | #' @param Safe Single logical value declaring whether to perform redundant data checks (default is TRUE). 142 | #' @title Volume Distribution at Steady-State (observed) 143 | #' @return Single numeric value 144 | #' @export 145 | #' @author Mango Solutions 146 | #' @keywords math 147 | #' @examples 148 | #' VSS(MRT = 20, CL = 0.1) 149 | 150 | VSS <- function(MRT, CL, Safe = TRUE) 151 | { 152 | 153 | checkSingleLogical(Safe, description = "Safe", functionName = "VSS") 154 | 155 | if( Safe ) { 156 | 157 | checkSingleNumeric(MRT, description = "MRT", "VSS") 158 | checkSingleNumeric(CL, description = "CL", "VSS") 159 | 160 | } 161 | 162 | VSS <- MRT * CL 163 | 164 | return(VSS) 165 | } 166 | 167 | 168 | --------------------------------------------------------------------------------