-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpk_adnca.qmd
More file actions
192 lines (153 loc) · 4.55 KB
/
pk_adnca.qmd
File metadata and controls
192 lines (153 loc) · 4.55 KB
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
# PK Non-Compartmental Analysis (ADNCA)
```{r setup}
#| include: false
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
```
## Introduction
This chapter describes creating a PK Non-Compartmental Analysis ADaM
dataset (`ADNCA`). NCA analyses require concentration-time data from
the PC (Pharmacokinetic Concentrations) SDTM domain and dosing
information from the EX domain.
::: callout-note
NCA analyses are often performed using specialist PK software (e.g.
Phoenix WinNonlin, R `{PKNCA}`). This chapter focuses on the ADaM
programming steps needed to prepare the input dataset.
:::
```{r load-packages}
#| message: false
#| warning: false
library(admiral)
library(dplyr)
library(pharmaversesdtm)
library(lubridate)
```
## Programming Workflow
1. [Read in Data](#readdata)
2. [Derive Nominal and Actual Time Variables](#time)
3. [Derive Dose Variables](#dose)
4. [Assign `PARAMCD`, `PARAM`, `AVAL`](#paramcd)
5. [Derive Relative Time Variables (`NFRLT`, `AFRLT`, `NRRLT`, `ARRLT`)](#rlt)
6. [Add ADSL Variables](#adsl_vars)
7. [Derive Analysis Sequence Number](#aseq)
## Read in Data {#readdata}
```{r load-data}
pc <- pharmaversesdtm::pc |> convert_blanks_to_na()
ex <- pharmaversesdtm::ex |> convert_blanks_to_na()
adsl <- admiral::admiral_adsl
# Filter to subjects with PK data
pk_subjects <- unique(pc$USUBJID)
pc <- pc |> filter(USUBJID %in% pk_subjects)
ex <- ex |> filter(USUBJID %in% pk_subjects)
adsl <- adsl |> filter(USUBJID %in% pk_subjects)
```
## Derive Nominal and Actual Time Variables {#time}
Actual sample collection datetime (`ADTM`) is derived from `PCDTC`. The
nominal time (`NFRLT`) comes from `PCTPTNUM` in the PC domain:
```{r time-vars}
adpc <- pc |>
derive_vars_dtm(
dtc = PCDTC,
new_vars_prefix = "A",
flag_imputation = "none"
) |>
mutate(
NFRLT = PCTPTNUM, # Nominal time from first dose (hours)
ATPT = PCTPT,
ATPTN = PCTPTNUM
)
adpc |>
select(USUBJID, PCTRT, PCDTC, ADTM, NFRLT, ATPT) |>
head(8)
```
## Derive Dose Variables {#dose}
Dosing records from the EX domain provide the reference dose event for
each concentration record:
```{r dose-vars}
ex_dtm <- ex |>
derive_vars_dtm(
dtc = EXSTDTC,
new_vars_prefix = "EXST",
flag_imputation = "none"
)
# Merge the most recent dose before the concentration time
adpc <- adpc |>
derive_vars_joined(
ex_dtm,
by_vars = exprs(STUDYID, USUBJID),
new_vars = exprs(EXSTDTM, EXDOSE, EXDOSU, EXTRT),
join_vars = exprs(EXSTDTM),
join_type = "all",
filter_add = EXDOSE > 0 & !is.na(EXSTDTM),
filter_join = EXSTDTM <= ADTM,
order = exprs(EXSTDTM),
mode = "last"
)
adpc |>
select(USUBJID, PCTRT, ADTM, EXSTDTM, EXDOSE, EXTRT) |>
head(8)
```
## Assign `PARAMCD`, `PARAM`, `AVAL` {#paramcd}
```{r paramcd}
adpc <- adpc |>
mutate(
PARAMCD = PCTESTCD,
PARAM = PCTEST,
AVAL = PCSTRESN,
AVALU = PCSTRESU,
DTYPE = NA_character_ # will be set for derived records
)
adpc |>
select(USUBJID, PARAMCD, PARAM, AVAL, AVALU) |>
head(5)
```
## Derive Relative Time Variables {#rlt}
The key timing variables for NCA are:
- `NFRLT` — Nominal time from first dose (hours)
- `AFRLT` — Actual time from first dose (hours)
- `NRRLT` — Nominal time from most recent dose (hours)
- `ARRLT` — Actual time from most recent dose (hours)
```{r rlt}
adpc <- adpc |>
mutate(
AFRLT = as.numeric(difftime(ADTM, EXSTDTM, units = "hours")),
NRRLT = NFRLT, # In single-period studies, NRRLT = NFRLT
ARRLT = AFRLT # In single-period studies, ARRLT = AFRLT
)
adpc |>
select(USUBJID, ADTM, EXSTDTM, NFRLT, AFRLT, NRRLT, ARRLT) |>
head(8)
```
## Add ADSL Variables {#adsl_vars}
```{r adsl-vars}
adpc <- adpc |>
derive_vars_merged(
dataset_add = adsl,
new_vars = exprs(TRT01A, TRT01P, TRTSDT, AGE, SEX, RACE, WEIGHTBL),
by_vars = exprs(STUDYID, USUBJID)
)
adpc |>
select(USUBJID, PARAMCD, AVAL, TRT01A, AGE, SEX) |>
head(5)
```
## Derive Analysis Sequence Number {#aseq}
```{r aseq}
adpc <- adpc |>
derive_var_obs_number(
by_vars = exprs(STUDYID, USUBJID),
order = exprs(PARAMCD, ADTM, NFRLT),
new_var = ASEQ,
check_type = "error"
)
adpc |>
select(USUBJID, PARAMCD, ADTM, NFRLT, ASEQ) |>
head(5)
```
## Example Script
An ADNCA template script is available in the `{admiral}` package:
```r
use_ad_template("ADNCA")
```
## See Also
- [Creating a BDS Findings ADaM](bds_finding.qmd)
- [Date/Time Imputation](imputation.qmd)
- [Visit and Period Variables](visits_periods.qmd)