For initial analysis, or in times where more complex analysis - such as nonlinear mixed effects modeling - is unnecessary, noncompartmental analysis is frequently used. While there are R packages, such as metrumrg or PK packages, the functionality is too complex and does not provide the flexibility to easily perform most of the basic functions needed without massaging or wringing your data into the necessary formats. The NCA functions in PKPDmisc are designed to be robust, but generalizable, allowing multiple data designs and software to be easily utilized.

In addition, while it is possible to use these functions in base R, it is highly recommended to use dplyr to supplement much of the surrounding data manipulation for both speed and clarity.

While other resources are available to get started with dplyr, briefly, the general workflow will be as follows:

  • take raw data
  • filter unnecessary data
  • group data
  • use summarize or mutate for the calculations.

However, there are certain analyses that are frequently used enough that PKPDmisc provides wrapper functions to reduce the above steps to a single line of code.

For those getting accustomed to R, keep in mind that there is also simple examples provided with each function that are available by doing ?<function>, so for example ?auc_partial.

library(PKPDmisc)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
pkdat <- sd_oral_richpk
head(pkdat)
##   ID Time  Amt      Conc      Age   Weight Gender     Race Dose
## 1  1 0.00 5000  0.000000 56.09591 94.19649   Male Hispanic 5000
## 2  1 0.25    0  8.612809 56.09591 94.19649   Male Hispanic 5000
## 3  1 0.50    0 19.436818 56.09591 94.19649   Male Hispanic 5000
## 4  1 1.00    0 34.006699 56.09591 94.19649   Male Hispanic 5000
## 5  1 2.00    0 30.228800 56.09591 94.19649   Male Hispanic 5000
## 6  1 3.00    0 31.299610 56.09591 94.19649   Male Hispanic 5000

Common summary functions

For a number of tasks that are commonly run, summary functions reduce the number of steps necessary. While I will not highlight each here, a quick glance at the package source code can show which functions are available. The API follows that functions named s_<function> will provide these multiple steps at once.

In general, each function is designed to take a grouped dataframe from dplyr to provide the function insight as to how to handle the overall data, so in general the analysis will will look like:

df %>% group_by(<grouping var>) %>% s_<function>()

The first such function is s_pauc(). This function can give multiple partial auc values, with each column being named pAUC<tfirst>_<tlast>. Multiple partial AUC slices can be requested by passing a list of requested times.

pkdat %>% group_by(ID) %>%
  s_pauc(Time, Conc, list(c(0, 8), c(0, 24), c(8, 24))) %>%
  head
## Warning: `summarise_()` is deprecated as of dplyr 0.7.0.
## Please use `summarise()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## # A tibble: 6 x 4
## # Groups:   ID [6]
##      ID pAUC0_8 pAUC0_24 pAUC8_24
##   <int>   <dbl>    <dbl>    <dbl>
## 1     1    204.     386.     181.
## 2     2    523.    1203.     680.
## 3     3    316.     466.     150.
## 4     4    564.    1220.     655.
## 5     5    302.     488.     186.
## 6     6    154.     295.     141.

Similar to dplyr and ggplot2 the summary functions use non-standard evaluation (no quotes required), however this is not conducive to programming or for use inside of other functions. As such, a standard evaluation version is provided with the nomenclature s_<function>_

paucs <- pkdat %>% group_by(ID) %>%
  s_pauc_("Time", "Conc", list(c(0, 8), c(0, 24), c(8, 24)), digits =1)
head(paucs)
## # A tibble: 6 x 4
## # Groups:   ID [6]
##      ID pAUC0_8 pAUC0_24 pAUC8_24
##   <int>   <dbl>    <dbl>    <dbl>
## 1     1    204.     386.     181.
## 2     2    523.    1204.     680.
## 3     3    316.     466.     150.
## 4     4    564.    1220.     656.
## 5     5    302.     488.     186.
## 6     6    154      295.     141.

Often once AUC or cmax statistics have been calculated, quantiles are calculated to create quantile plots or other summary evaluations. Here, the s_quantiles function can be used.

paucs %>% ungroup() %>% s_quantiles(pAUC0_24, probs = c(0, 0.25, 0.5, 0.75, 1))
## # A tibble: 1 x 5
##   pAUC0_24_q0 pAUC0_24_q25 pAUC0_24_q50 pAUC0_24_q75 pAUC0_24_q100
##         <dbl>        <dbl>        <dbl>        <dbl>         <dbl>
## 1        161.         457.         590.         887.         1377.
paucs %>% ungroup() %>% s_quantiles_("pAUC0_24", probs = c(0, 0.25, 0.5, 0.75, 1))
## # A tibble: 1 x 5
##   pAUC0_24_q0 pAUC0_24_q25 pAUC0_24_q50 pAUC0_24_q75 pAUC0_24_q100
##         <dbl>        <dbl>        <dbl>        <dbl>         <dbl>
## 1        161.         457.         590.         887.         1377.
sessioninfo::session_info()
## ─ Session info ───────────────────────────────────────────────────────────────
##  setting  value                       
##  version  R version 3.6.2 (2019-12-12)
##  os       Ubuntu 18.04.4 LTS          
##  system   x86_64, linux-gnu           
##  ui       X11                         
##  language (EN)                        
##  collate  en_US.UTF-8                 
##  ctype    en_US.UTF-8                 
##  tz       America/New_York            
##  date     2020-08-10                  
## 
## ─ Packages ───────────────────────────────────────────────────────────────────
##  package     * version  date       lib source          
##  assertthat    0.2.1    2019-03-21 [1] CRAN (R 3.6.2)  
##  backports     1.1.8    2020-06-17 [1] CRAN (R 3.6.2)  
##  cli           2.0.2    2020-02-28 [1] CRAN (R 3.6.2)  
##  crayon        1.3.4    2017-09-16 [1] CRAN (R 3.6.2)  
##  desc          1.2.0    2018-05-01 [1] CRAN (R 3.6.2)  
##  digest        0.6.25   2020-02-23 [1] CRAN (R 3.6.2)  
##  dplyr       * 1.0.0    2020-05-29 [1] CRAN (R 3.6.2)  
##  ellipsis      0.3.1    2020-05-15 [1] CRAN (R 3.6.2)  
##  evaluate      0.14     2019-05-28 [1] CRAN (R 3.6.2)  
##  fansi         0.4.1    2020-01-08 [1] CRAN (R 3.6.2)  
##  fs            1.4.2    2020-06-30 [1] CRAN (R 3.6.2)  
##  generics      0.0.2    2018-11-29 [1] CRAN (R 3.6.2)  
##  glue          1.4.1    2020-05-13 [1] CRAN (R 3.6.2)  
##  htmltools     0.5.0    2020-06-16 [1] CRAN (R 3.6.2)  
##  knitr         1.29     2020-06-23 [1] CRAN (R 3.6.2)  
##  lazyeval      0.2.2    2019-03-15 [1] CRAN (R 3.6.2)  
##  lifecycle     0.2.0    2020-03-06 [1] CRAN (R 3.6.2)  
##  magrittr      1.5      2014-11-22 [1] CRAN (R 3.6.2)  
##  MASS          7.3-51.6 2020-04-26 [1] CRAN (R 3.6.2)  
##  memoise       1.1.0    2017-04-21 [1] CRAN (R 3.6.2)  
##  pillar        1.4.6    2020-07-10 [1] CRAN (R 3.6.2)  
##  pkgconfig     2.0.3    2019-09-22 [1] CRAN (R 3.6.2)  
##  pkgdown       1.5.1    2020-04-09 [1] CRAN (R 3.6.2)  
##  PKPDmisc    * 3.0.0    2020-08-10 [1] MPNDEV (R 3.6.2)
##  purrr         0.3.4    2020-04-17 [1] CRAN (R 3.6.2)  
##  R6            2.4.1    2019-11-12 [1] CRAN (R 3.6.2)  
##  Rcpp          1.0.5    2020-07-06 [1] CRAN (R 3.6.2)  
##  renv          0.11.0   2020-06-26 [1] CRAN (R 3.6.2)  
##  rlang         0.4.7    2020-07-09 [1] CRAN (R 3.6.2)  
##  rmarkdown     2.3      2020-06-18 [1] CRAN (R 3.6.2)  
##  rprojroot     1.3-2    2018-01-03 [1] CRAN (R 3.6.2)  
##  rstudioapi    0.11     2020-02-07 [1] CRAN (R 3.6.2)  
##  sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 3.6.2)  
##  stringi       1.4.6    2020-02-17 [1] CRAN (R 3.6.2)  
##  stringr       1.4.0    2019-02-10 [1] CRAN (R 3.6.2)  
##  tibble        3.0.3    2020-07-10 [1] CRAN (R 3.6.2)  
##  tidyselect    1.1.0    2020-05-11 [1] CRAN (R 3.6.2)  
##  utf8          1.1.4    2018-05-24 [1] CRAN (R 3.6.2)  
##  vctrs         0.3.2    2020-07-15 [1] CRAN (R 3.6.2)  
##  withr         2.2.0    2020-04-20 [1] CRAN (R 3.6.2)  
##  xfun          0.15     2020-06-21 [1] CRAN (R 3.6.2)  
##  yaml          2.2.1    2020-02-01 [1] CRAN (R 3.6.2)  
## 
## [1] /data/GHE/mpn/deployment/deployments/2020-08-10/renv/library/R-3.6/x86_64-pc-linux-gnu
## [2] /tmp/RtmpfK76hr/renv-system-library
## [3] /tmp/RtmpeDybAM/renv-system-library
## [4] /tmp/Rtmpqx2w42/renv-system-library