full-nca-analysis.rmd

Load libraries

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
library(qpNCA)
library(knitr)

Define mutate_cond and locf functions

mutate_cond <- function (.data, condition, ..., envir = parent.frame()){
  condition <- eval(substitute(condition), .data, envir)
  if(!any(condition))return(.data) # do nothing if nothing to do
  .data[condition, ] <- .data[condition, ] %>% mutate(...)
  .data
}
locf <- function(x){
  good <- !is.na(x)
  positions <- seq(length(x))
  good.positions <- good * positions
  last.good.position <- cummax(good.positions)
  last.good.position[last.good.position == 0] <- NA
  x[last.good.position]
}

Check out Theoph data and prepare data for NCA

We use the internal Theoph dataset as input file, modify the data and add necessary columns
Furthermore, we introduce some missing values, LOQ values and time deviations

head(Theoph) %>% kable()
Subject Wt Dose Time conc
1 79.6 4.02 0.00 0.74
1 79.6 4.02 0.25 2.84
1 79.6 4.02 0.57 6.57
1 79.6 4.02 1.12 10.50
1 79.6 4.02 2.02 9.66
1 79.6 4.02 3.82 8.58
input.data <- Theoph

#we need nominal time variable for some tasks.
ntad <- data.frame(rn=c(1:11),ntad=c(0,0.25,0.5,1,2,4,5,7,9,12,24))

input.data %<>% 
           group_by(Subject) %>%
           mutate(subject=as.numeric(Subject),
                  rn=row_number(),
                  dose=Dose*Wt,
                  bloq=ifelse(conc==0,1,0),
                  loq=0.1,
                  excl_th=0
                  ) %>%
           left_join(ntad) %>%
           ungroup %>%
           arrange(subject,ntad) %>%
           select(subject,ntad,tad=Time,conc,dose,bloq,loq,excl_th)
## Joining with `by = join_by(rn)`
input.data %<>%
           mutate_cond(condition=subject==2&ntad%in%c(24),conc=NA) %>%
           mutate_cond(condition=subject==4&ntad%in%c(9),conc=NA) %>%
           mutate_cond(condition=subject==3&ntad==9,excl_th=1) %>%
           mutate_cond(condition=subject==6&ntad==24,conc=0,bloq=1) %>%
           filter(!(subject==5&ntad==12))

Run full NCA analysis

# Create a covariates file, containing at least the dose given

cov = input.data %>%
      distinct(subject,dose)

nca = qpNCA(
      input.data,
      by = "subject",
      nomtimevar = "ntad",
      timevar = "tad",
      depvar = "conc",
      bloqvar = "bloq",
      loqvar = "loq",
      loqrule = 1,
      includeCmax = "Y",
      exclvar = "excl_th",
      plotdir = NA,
      timelab = "Time (h)",
      deplab = "Conc (ng/mL)",
      tau = 24,
      tstart = 4,
      tend = 9,
      teval = 12,
      covariates = cov,
      dose = "dose",
      factor = 1,
      reg = "sd",
      ss = "n",
      route = "EV",
      method = 1
      )
## 
## Checking function arguments...
## all OK!
## Applying LOQ rules...
## Performing Thalf estimation...
## Creating regression plots in standard output...
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

## 
## [[6]]

## 
## [[7]]

## 
## [[8]]

## 
## [[9]]

## 
## [[10]]

## 
## [[11]]

## 
## [[12]]

## 
## Calculating Cmax/Tmax...
## Applying time deviation corrections and missing concentration imputations...
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Joining with `by = join_by(ptime)`
## Creating correction tables...
## Calculating parameters that do not need lambda_z...
## Calculating parameters that DO need lambda_z...
## Joining with `by = join_by(subject, route)`
## Combining all parameters...
## Writing results...
## Done!