/
v03-selection-of-calculation-intervals.Rmd
334 lines (293 loc) · 12.4 KB
/
v03-selection-of-calculation-intervals.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
---
title: "Selection of Calculation Intervals"
author: "Bill Denney"
output:
rmarkdown::html_vignette:
toc: yes
toc_depth: 6
vignette: >
%\VignetteIndexEntry{Selection of Calculation Intervals}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=TRUE,
fig.width=6,
fig.height=4)
library(cowplot)
library(PKNCA)
library(knitr)
library(ggplot2)
source("../tests/testthat/generate.data.R")
scale_colour_discrete <- scale_colour_hue
scale_fill_discrete <- scale_fill_hue
```
```{r check-ggplot, include=!requireNamespace("ggplot2"), results="asis"}
cat("ggplot2 is required for this vignette to work correctly. Please install the ggplot2 library and retry building the vignette.")
```
# 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.
```{r intro_interval_plot, echo=FALSE}
# Simulate concentration-time data and setup the PKNCAconc object
d_conc <-
PKNCAconc(
generate.conc(nsub=1,
ntreat=1,
time.points=c(0, 1, 2, 4, 6, 8, 12, 24, 36, 48),
nstudies=1,
nanalytes=1,
resid=0),
conc~time|treatment+ID)
print(d_conc)
# Use superposition to simulate multiple doses
d_conc_multi <-
superposition(d_conc,
tau=168,
dose.times=seq(0, 168-24, by=24),
n.tau=1)
```
```{r intro_interval_plot-visualization, eval=requireNamespace("ggplot2")}
# Plot the concentration-time data and the interval
ggplot(d_conc_multi, aes(x=time, y=conc)) +
geom_ribbon(data=d_conc_multi[d_conc_multi$time >= 144,],
aes(ymax=conc, ymin=0),
fill="skyblue") +
geom_point() + geom_line() +
scale_x_continuous(breaks=seq(0, 168, by=12)) +
scale_y_continuous(limits=c(0, NA)) +
labs(x="Time Since First Dose (hr)",
y="Concentration\n(arbitrary units)")
```
```{r intro_interval_spec}
intervals_manual <- data.frame(start=144, end=168, auclast=TRUE)
knitr::kable(intervals_manual)
PKNCAdata(d_conc, intervals=intervals_manual)
```
# 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 AUC~inf,obs~ in subjects who received single doses and AUC~last~ 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.
```{r select_group}
intervals_manual <-
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(intervals_manual)
```
# Intervals
Intervals are defined by `data.frame`s 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.
```{r infinity_interval_plot, echo=FALSE}
# Simulate concentration-time data and setup the PKNCAconc object
d_conc <-
PKNCAconc(
generate.conc(nsub=1,
ntreat=1,
time.points=c(0, 1, 2, 4, 6, 8, 12, 24, 36, 48),
nstudies=1,
nanalytes=1,
resid=0),
conc~time|treatment+ID)
print(d_conc)
```
```{r infinity_interval_plot-visualization, eval=requireNamespace("ggplot2")}
# Use superposition to simulate multiple doses
ggplot(as.data.frame(d_conc)[as.data.frame(d_conc)$time <= 48,], aes(x=time, y=conc)) +
geom_ribbon(data=as.data.frame(d_conc),
aes(ymax=conc, ymin=0),
fill="skyblue") +
geom_point() + geom_line() +
scale_x_continuous(breaks=seq(0, 72, by=12)) +
scale_y_continuous(limits=c(0, NA)) +
labs(x="Time Since First Dose (hr)",
y="Concentration\n(arbitrary units)")
```
```{r infinity_interval_spec}
intervals_manual <-
data.frame(
start=0,
end=Inf,
auclast=TRUE,
aucinf.obs=TRUE
)
print(intervals_manual)
my.data <- PKNCAdata(d_conc, intervals=intervals_manual)
```
## 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.
```{r multiple_intervals_plot, echo=FALSE}
# Simulate concentration-time data and setup the PKNCAconc object
d_conc <-
PKNCAconc(
generate.conc(nsub=1,
ntreat=1,
time.points=c(0, 1, 2, 4, 6, 8, 12, 24, 36, 48),
nstudies=1,
nanalytes=1,
resid=0),
conc~time|treatment+ID)
print(d_conc)
# Use superposition to simulate multiple doses
d_conc_multi <-
superposition(d_conc,
tau=168,
dose.times=seq(0, 168-24, by=24),
n.tau=1)
```
```{r multiple_intervals_plot-visualization, eval=requireNamespace("ggplot2")}
# Plot the concentration-time data and the interval
ggplot(d_conc_multi, aes(x=time, y=conc)) +
geom_ribbon(data=d_conc_multi[d_conc_multi$time <= 24,],
aes(ymax=conc, ymin=0),
fill="skyblue") +
geom_ribbon(data=d_conc_multi[d_conc_multi$time >= 144,],
aes(ymax=conc, ymin=0),
fill="lightgreen") +
geom_point() + geom_line() +
scale_x_continuous(breaks=seq(0, 168, by=12)) +
scale_y_continuous(limits=c(0, NA)) +
labs(x="Time Since First Dose (hr)",
y="Concentration\n(arbitrary units)")
```
```{r multiple_intervals_spec}
intervals_manual <-
data.frame(
start=c(0, 144),
end=c(24, 168),
auclast=TRUE
)
knitr::kable(intervals_manual)
my.data <- PKNCAdata(d_conc, intervals=intervals_manual)
```
# 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.
```{r overlapping_intervals_plot, echo=FALSE}
# Simulate concentration-time data and setup the PKNCAconc object
d_conc <-
PKNCAconc(
generate.conc(nsub=1,
ntreat=1,
time.points=c(0, 1, 2, 4, 6, 8, 12, 24, 36, 48),
nstudies=1,
nanalytes=1,
resid=0),
conc~time|treatment+ID)
print(d_conc)
```
```{r overlapping_intervals_plot-visualization, eval=requireNamespace("ggplot2")}
# Use superposition to simulate multiple doses
ggplot(as.data.frame(d_conc), aes(x=time, y=conc)) +
geom_ribbon(data=as.data.frame(d_conc),
aes(ymax=conc, ymin=0),
fill="lightgreen",
alpha=0.5) +
geom_ribbon(data=as.data.frame(d_conc)[as.data.frame(d_conc)$time <= 24,],
aes(ymax=conc, ymin=0),
fill="skyblue",
alpha=0.5) +
geom_point() + geom_line() +
scale_x_continuous(breaks=seq(0, 168, by=12)) +
scale_y_continuous(limits=c(0, NA)) +
labs(x="Time Since First Dose (hr)",
y="Concentration\n(arbitrary units)")
```
```{r overlapping_intervals_spec}
intervals_manual <-
data.frame(
start=0,
end=c(24, Inf),
auclast=TRUE,
aucinf.obs=c(FALSE, TRUE)
)
knitr::kable(intervals_manual)
my.data <- PKNCAdata(d_conc, intervals=intervals_manual)
```
# 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.
```{r interval_yes_no, echo=FALSE, eval=requireNamespace("ggplot2")}
ggplot_intervals <- function(definition, intervals) {
intervals$within <-
c("No", "Yes")[intervals$interval.start >= min(definition$start.x) &
intervals$interval.end >= max(definition$start.x)]
intervals$within <-
factor(intervals$within, levels=c("Yes", "No"))
ggplot(intervals,
aes(x=interval.start,
xend=interval.end,
y=y,
yend=y,
linetype=within)) +
geom_segment() +
geom_segment(data=definition,
mapping=aes(x=start.x, xend=start.x, y=start.y, yend=end.y),
arrow=arrow(),
inherit.aes=FALSE) +
geom_point(aes(x=interval.start, y=1),
shape="|",
size=4) +
geom_point(aes(x=max(interval.end), y=1),
shape="|",
size=4) +
scale_y_continuous(breaks=NULL) +
labs(x="Time",
y=NULL)
}
interval_definition <-
data.frame(start.x=c(0, 24),
start.y=0.5,
end.y=0.9)
show_intervals <-
data.frame(interval.start=c(0, 4, 12, 24),
interval.end=c(4, 12, 24, 48),
y=1)
ggplot_intervals(interval_definition,
show_intervals)
interval_definition <-
data.frame(start.x=c(0, 16),
start.y=0.5,
end.y=0.9)
show_intervals <-
data.frame(interval.start=c(0, 4, 12, 24),
interval.end=c(4, 12, 24, 48),
y=1)
ggplot_intervals(interval_definition,
show_intervals)
```
# Parameters Available for Calculation in an Interval
The following parameters are available in an interval. For more information about the parameter, see the documentation for the function.
```{r parameters-available, echo=FALSE}
interval_spec <- get.interval.cols()
interval_spec <- interval_spec[sort(names(interval_spec))]
get_function_for_calc <- function(x) {
if (is.na(x$FUN)) {
if (is.null(x$depends)) {
"(none)"
} else {
paste("See the parameter name", x$depends)
}
} else {
x$FUN
}
}
kable(
data.frame(
`Parameter Name`=names(interval_spec),
`Unit Type`=vapply(X = interval_spec, FUN = "[[", "unit_type", FUN.VALUE = ""),
`Parameter Description`=vapply(X = interval_spec, FUN = "[[", "desc", FUN.VALUE = ""),
`Function for Calculation`=vapply(X = interval_spec, FUN = get_function_for_calc, FUN.VALUE = ""),
check.names=FALSE,
stringsAsFactors=FALSE
),
row.names=FALSE
)
```