# Introduction

PKNCA considers two types of data grouping within data sets: the group and the interval. A group typically identifies a single subject given a single intervention type (a “treatment”) with a single analyte. An interval subsets a group by times within the group, and primary noncompartmental analysis (NCA) calculations are performed within an interval.

As a concrete example, consider the figure below shows the concentration-time profile of a study subject in a multiple-dose study. The group is all points in the figure, and the interval for the last day (144 to 168 hr) is the area with blue shading.

## Formula for concentration:
##  conc ~ time | treatment + ID
## With 1 subjects defined in the 'ID' column.
## Nominal time column is not specified.
##
## First 6 rows of concentration data:
##    study treatment ID time      conc   analyte exclude volume duration
##  Study 1     Trt 1  1    0 0.0000000 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    1 0.6140526 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    2 0.8100022 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    4 0.8425422 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    6 0.7771994 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    8 0.7052469 Analyte 1    <NA>     NA        0

my.intervals <- data.frame(start=144, end=168, auclast=TRUE)
knitr::kable(my.intervals)
start end auclast
144 168 TRUE
PKNCAdata(d.conc, intervals=my.intervals)
## Formula for concentration:
##  conc ~ time | treatment + ID
## With 1 subjects defined in the 'ID' column.
## Nominal time column is not specified.
##
## First 6 rows of concentration data:
##    study treatment ID time      conc   analyte exclude volume duration
##  Study 1     Trt 1  1    0 0.0000000 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    1 0.6140526 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    2 0.8100022 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    4 0.8425422 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    6 0.7771994 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    8 0.7052469 Analyte 1    <NA>     NA        0
## No dosing information.
##
## With 1 rows of AUC specifications.
## No options are set differently than default.

# Group Matching

Group matching occurs by matching all overlapping column names between the groups and the interval data.frame. (Note that grouping columns cannot be the word start, end, or share a name with an NCA parameter.)

## Selecting the Subjects for an Interval

The groups for an interval prepare for summarization. Typically the groups will take a structure similar to the preferred summarization structure with groups nested in the logical method for summary. As an example, the group structure may be: study, treatment, day, analyte, and subject. The grouping names for an interval must be the same as or a subset of the grouping names used for the concentration data.

As the matching occurs with all available columns, the grouping columns names are only required to the level of specificity for the calculations desired. As an example, if you want AUCinf,obs in subjects who received single doses and AUClast on days 1 (0 to 24 hours) and 10 (216 to 240 hours) in subjects who received multiple doses, with treatment defined as “Drug 1 Single” or “Drug 1 Multiple”, the intervals could be defined as below.

my.intervals <- data.frame(treatment=c("Drug 1 Single", "Drug 1 Multiple", "Drug 1 Multiple"),
start=c(0, 0, 216),
end=c(Inf, 24, 240),
aucinf.obs=c(TRUE, FALSE, FALSE),
auclast=c(FALSE, TRUE, TRUE))
knitr::kable(my.intervals)
treatment start end aucinf.obs auclast
Drug 1 Single 0 Inf TRUE FALSE
Drug 1 Multiple 0 24 FALSE TRUE
Drug 1 Multiple 216 240 FALSE TRUE

# Intervals

Intervals are defined by data.frames with one row per interval, zero or more columns to match the groups from the PKNCAdata object, and one or more NCA parameters to calculate.

Selection of points within an interval occurs by choosing any point at or after the start and at or before the end.

## To Infinity

The end of an interval may be infinity. An interval to infinity works the same as any other interval in that points are selected by being at or after the start and at or before the end of the interval. Selecting Inf or any value at or after the maximum time yields no difference in effect, but Inf is simpler when scripting to ensure that all points are selected.

## Formula for concentration:
##  conc ~ time | treatment + ID
## With 1 subjects defined in the 'ID' column.
## Nominal time column is not specified.
##
## First 6 rows of concentration data:
##    study treatment ID time      conc   analyte exclude volume duration
##  Study 1     Trt 1  1    0 0.0000000 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    1 0.6140526 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    2 0.8100022 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    4 0.8425422 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    6 0.7771994 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    8 0.7052469 Analyte 1    <NA>     NA        0

my.intervals <- data.frame(start=0,
end=Inf,
auclast=TRUE,
aucinf.obs=TRUE)
print(my.intervals)
##   start end auclast aucinf.obs
## 1     0 Inf    TRUE       TRUE
my.data <- PKNCAdata(d.conc, intervals=my.intervals)

## Multiple Intervals

More than one interval may be specified for the same subject or group of subjects by providing more than one row of interval specifications. In the figure below, the blue and green shaded regions indicate the first and second rows of the intervals, respectively.

## Formula for concentration:
##  conc ~ time | treatment + ID
## With 1 subjects defined in the 'ID' column.
## Nominal time column is not specified.
##
## First 6 rows of concentration data:
##    study treatment ID time      conc   analyte exclude volume duration
##  Study 1     Trt 1  1    0 0.0000000 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    1 0.6140526 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    2 0.8100022 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    4 0.8425422 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    6 0.7771994 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    8 0.7052469 Analyte 1    <NA>     NA        0

my.intervals <- data.frame(start=c(0, 144),
end=c(24, 168),
auclast=TRUE)
knitr::kable(my.intervals)
start end auclast
0 24 TRUE
144 168 TRUE
my.data <- PKNCAdata(d.conc, intervals=my.intervals)

# Overlapping Intervals and Different Calculations by Interval

In some scenarios, multiple intervals may be needed where some intervals overlap. There is no issue with an interval specification that has two rows with overlapping times; the rows are considered separately. In the example below, the 0-24 interval is shared between both the first and second (shaded blue-green).

The example of overlapping intervals also illustrates that different calculations can be performed in different intervals. In this case, auclast is calculated in both intervals while aucinf.obs is only calculated in the 0-Inf interval.

## Formula for concentration:
##  conc ~ time | treatment + ID
## With 1 subjects defined in the 'ID' column.
## Nominal time column is not specified.
##
## First 6 rows of concentration data:
##    study treatment ID time      conc   analyte exclude volume duration
##  Study 1     Trt 1  1    0 0.0000000 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    1 0.6140526 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    2 0.8100022 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    4 0.8425422 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    6 0.7771994 Analyte 1    <NA>     NA        0
##  Study 1     Trt 1  1    8 0.7052469 Analyte 1    <NA>     NA        0

my.intervals <- data.frame(start=0,
end=c(24, Inf),
auclast=TRUE,
aucinf.obs=c(FALSE, TRUE))
knitr::kable(my.intervals)
start end auclast aucinf.obs
0 24 TRUE FALSE
0 Inf TRUE TRUE
my.data <- PKNCAdata(d.conc, intervals=my.intervals)

# Intervals with Duration

Some events have durations of times rather than instants in time associated with them. Two typical examples of duration data in NCA are intravenous infusions and urine or fecal sample collections. Inform PKNCA of durations with the duration argument to the PKNCAdose and PKNCAconc functions.

Durations data are selected based on both the beginning and ending of the duration existing within the interval.