Skip to content

Commit 74159a6

Browse files
committed
#92 update after review
1 parent 266a3d7 commit 74159a6

File tree

2 files changed

+65
-42
lines changed

2 files changed

+65
-42
lines changed

tlg/pharmacokinetic.R

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,37 @@ library(ggplot2)
66
library(nestcolor)
77
library(rlistings)
88

9+
# Read data from pharmaverseadam
10+
adpc <- pharmaverseadam::adpc
11+
adsl <- pharmaverseadam::adsl
912

10-
adsl <- pharmaverseadam::adsl %>%
13+
# Use tern::df_explicit_na() to end encode missing values as categorical
14+
adsl <- adsl %>%
1115
df_explicit_na()
1216

13-
# Keep only treated subjects for graph
14-
adsl_f <- adsl %>%
15-
filter(SAFFL == "Y" & TRT01A != "Placebo")
16-
17-
adpc <- pharmaverseadam::adpc %>%
17+
adpc <- adpc %>%
1818
df_explicit_na()
1919

2020
# For ADPC keep only concentration records and treated subjects
2121
# Keep only plasma records for this example
22+
# Remove DTYPE = COPY records with ANL02FL == "Y"
2223
adpc <- adpc %>%
23-
filter(PARAMCD != "DOSE" & TRT01A != "Placebo" & PCSPEC == "PLASMA" & ANL02FL == "Y")
24+
filter(PARAMCD != "DOSE" & TRT01A != "Placebo" & PARCAT1 == "PLASMA" & ANL02FL == "Y")
25+
2426

25-
# Setting up the data
26-
adpc_1 <- adpc %>%
27+
## ----r table------------------------------------------------------------------
28+
# Setting up the data for table
29+
adpc_t <- adpc %>%
2730
mutate(
2831
NFRLT = as.factor(NFRLT),
2932
AVALCAT1 = as.factor(AVALCAT1),
3033
NOMTPT = as.factor(paste(NFRLT, "/", PCTPT))
3134
) %>%
3235
select(NOMTPT, ACTARM, VISIT, AVAL, PARAM, AVALCAT1)
3336

34-
adpc_1$NOMTPT <- factor(
35-
adpc_1$NOMTPT,
36-
levels = levels(adpc_1$NOMTPT)[order(as.numeric(gsub(".*?([0-9\\.]+).*", "\\1", levels(adpc_1$NOMTPT))))]
37+
adpc_t$NOMTPT <- factor(
38+
adpc_t$NOMTPT,
39+
levels = levels(adpc_t$NOMTPT)[order(as.numeric(gsub(".*?([0-9\\.]+).*", "\\1", levels(adpc_t$NOMTPT))))]
3740
)
3841

3942
# Row structure
@@ -59,7 +62,6 @@ lyt_rows <- basic_table() %>%
5962
child_labels = "hidden"
6063
)
6164

62-
## ----r table------------------------------------------------------------------
6365
lyt <- lyt_rows %>%
6466
analyze_vars_in_cols(
6567
vars = c("AVAL", "AVALCAT1", rep("AVAL", 8)),
@@ -76,20 +78,26 @@ lyt <- lyt_rows %>%
7678
.aligns = "decimal"
7779
)
7880

79-
result <- build_table(lyt, df = adpc_1, alt_counts_df = adsl) %>% prune_table()
81+
result <- build_table(lyt, df = adpc_t, alt_counts_df = adsl) %>% prune_table()
8082

8183
# Decorating
8284
main_title(result) <- "Summary of PK Concentrations by Nominal Time and Treatment: PK Evaluable"
8385
subtitles(result) <- c(
8486
"Protocol: xxxxx",
85-
paste("Analyte: ", unique(adpc_1$PARAM)),
86-
paste("Treatment:", unique(adpc_1$ACTARM))
87+
paste("Analyte: ", unique(adpc_t$PARAM)),
88+
paste("Treatment:", unique(adpc_t$ACTARM))
8789
)
8890
main_footer(result) <- "NE: Not Estimable"
8991

9092
result
9193

9294
## ----r graph------------------------------------------------------------------
95+
96+
# Keep only treated subjects for graph
97+
adsl_f <- adsl %>%
98+
filter(SAFFL == "Y" & TRT01A != "Placebo")
99+
100+
# Set titles and footnotes
93101
use_title <- "Plot of Mean (+/- SD) Plasma Concentrations Over Time by Treatment, \nPK Evaluable Patients"
94102
use_subtitle <- "Analyte:"
95103
use_footnote <- "Program: \nOutput:"
@@ -121,12 +129,14 @@ plot <- result + theme(plot.caption = element_text(hjust = 0))
121129
plot
122130

123131
## ----r listing----------------------------------------------------------------
132+
# Get value of Analyte
124133
analyte <- unique(adpc$PARAM)
125134

135+
# Select columns for listing
126136
out <- adpc %>%
127137
select(ARM, USUBJID, VISIT, NFRLT, AFRLT, AVALCAT1)
128138

129-
139+
# Add descriptive labels
130140
var_labels(out) <- c(
131141
ARM = "Treatment Group",
132142
USUBJID = "Subject ID",
@@ -136,6 +146,7 @@ var_labels(out) <- c(
136146
AVALCAT1 = paste0("Concentration\n(", adpc$AVALU[1], ")")
137147
)
138148

149+
# Create listing
139150
lsting <- as_listing(
140151
out,
141152
key_cols = c("ARM", "USUBJID", "VISIT"),

tlg/pharmacokinetic.qmd

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ The packages used with a brief description of their purpose are as follows:
2424

2525
See catalog for PK TLGs here [PK TLG catalog](https://insightsengineering.github.io/tlg-catalog/stable/)
2626

27-
## Load Data and Required pharmaverse Package
27+
See the [`{admiral}` Guide for createing a PK NCA](https://pharmaverse.github.io/admiral/articles/pk_adnca.html) for more information about the structure of `ADPC`. See also `ADPC` under the ADaM section on the left panel.
2828

29-
After installation of packages, the first step is to load our pharmaverse packages and input data. Here, we are going to encode missing entries in a data frame `adsl` and `adpc`.
29+
## Data preprocessing
3030

31-
Note that `{tern}` depends on `{rtables}` so the latter is automatically attached.
31+
Here we set up the data for the table, graph and listing. We will read `ADPC` and `ADSL` from `{pharmaverseadam}`. We use `tern::df_explicit_na()` to set missing values as categorical. In `ADPC` we will keep only concentration records (dropping dosing records), and for this example we will only keep plasma concentrations (dropping urine). The `ADPC` data also includes duplicated records for analysis with `DYTPE == "COPY"` we will drop these as well (These are removed by selecting `ANL02FL == "Y"`).
3232

3333
```{r setup, message=FALSE, warning=FALSE, results='hold'}
3434
library(pharmaverseadam)
@@ -38,34 +38,42 @@ library(ggplot2)
3838
library(nestcolor)
3939
library(rlistings)
4040
41+
# Read data from pharmaverseadam
42+
adpc <- pharmaverseadam::adpc
43+
adsl <- pharmaverseadam::adsl
4144
42-
adsl <- pharmaverseadam::adsl %>%
45+
# Use tern::df_explicit_na() to end encode missing values as categorical
46+
adsl <- adsl %>%
4347
df_explicit_na()
4448
45-
# Keep only treated subjects for graph
46-
adsl_f <- adsl %>%
47-
filter(SAFFL == "Y" & TRT01A != "Placebo")
48-
49-
adpc <- pharmaverseadam::adpc %>%
49+
adpc <- adpc %>%
5050
df_explicit_na()
5151
5252
# For ADPC keep only concentration records and treated subjects
5353
# Keep only plasma records for this example
54+
# Remove DTYPE = COPY records with ANL02FL == "Y"
5455
adpc <- adpc %>%
55-
filter(PARAMCD != "DOSE" & TRT01A != "Placebo" & PCSPEC == "PLASMA" & ANL02FL == "Y")
56+
filter(PARAMCD != "DOSE" & TRT01A != "Placebo" & PARCAT1 == "PLASMA" & ANL02FL == "Y")
57+
58+
```
5659

57-
# Setting up the data
58-
adpc_1 <- adpc %>%
60+
## PK Table
61+
62+
Now we create the PK table.
63+
64+
```{r table}
65+
# Setting up the data for table
66+
adpc_t <- adpc %>%
5967
mutate(
6068
NFRLT = as.factor(NFRLT),
6169
AVALCAT1 = as.factor(AVALCAT1),
6270
NOMTPT = as.factor(paste(NFRLT, "/", PCTPT))
6371
) %>%
6472
select(NOMTPT, ACTARM, VISIT, AVAL, PARAM, AVALCAT1)
6573
66-
adpc_1$NOMTPT <- factor(
67-
adpc_1$NOMTPT,
68-
levels = levels(adpc_1$NOMTPT)[order(as.numeric(gsub(".*?([0-9\\.]+).*", "\\1", levels(adpc_1$NOMTPT))))]
74+
adpc_t$NOMTPT <- factor(
75+
adpc_t$NOMTPT,
76+
levels = levels(adpc_t$NOMTPT)[order(as.numeric(gsub(".*?([0-9\\.]+).*", "\\1", levels(adpc_t$NOMTPT))))]
6977
)
7078
7179
# Row structure
@@ -90,13 +98,7 @@ lyt_rows <- basic_table() %>%
9098
label_pos = "topleft",
9199
child_labels = "hidden"
92100
)
93-
```
94101
95-
## PK Table
96-
97-
Now we create the PK table.
98-
99-
```{r table}
100102
lyt <- lyt_rows %>%
101103
analyze_vars_in_cols(
102104
vars = c("AVAL", "AVALCAT1", rep("AVAL", 8)),
@@ -113,14 +115,14 @@ lyt <- lyt_rows %>%
113115
.aligns = "decimal"
114116
)
115117
116-
result <- build_table(lyt, df = adpc_1, alt_counts_df = adsl) %>% prune_table()
118+
result <- build_table(lyt, df = adpc_t, alt_counts_df = adsl) %>% prune_table()
117119
118120
# Decorating
119121
main_title(result) <- "Summary of PK Concentrations by Nominal Time and Treatment: PK Evaluable"
120122
subtitles(result) <- c(
121123
"Protocol: xxxxx",
122-
paste("Analyte: ", unique(adpc_1$PARAM)),
123-
paste("Treatment:", unique(adpc_1$ACTARM))
124+
paste("Analyte: ", unique(adpc_t$PARAM)),
125+
paste("Treatment:", unique(adpc_t$ACTARM))
124126
)
125127
main_footer(result) <- "NE: Not Estimable"
126128
@@ -133,6 +135,12 @@ result
133135
Now we create the PK graph.
134136

135137
```{r graph}
138+
139+
# Keep only treated subjects for graph
140+
adsl_f <- adsl %>%
141+
filter(SAFFL == "Y" & TRT01A != "Placebo")
142+
143+
# Set titles and footnotes
136144
use_title <- "Plot of Mean (+/- SD) Plasma Concentrations Over Time by Treatment, \nPK Evaluable Patients"
137145
use_subtitle <- "Analyte:"
138146
use_footnote <- "Program: \nOutput:"
@@ -169,12 +177,14 @@ plot
169177
Now we create an example PK listing.
170178

171179
```{r listing}
180+
# Get value of Analyte
172181
analyte <- unique(adpc$PARAM)
173182
183+
# Select columns for listing
174184
out <- adpc %>%
175185
select(ARM, USUBJID, VISIT, NFRLT, AFRLT, AVALCAT1)
176186
177-
187+
# Add descriptive labels
178188
var_labels(out) <- c(
179189
ARM = "Treatment Group",
180190
USUBJID = "Subject ID",
@@ -184,6 +194,7 @@ var_labels(out) <- c(
184194
AVALCAT1 = paste0("Concentration\n(", adpc$AVALU[1], ")")
185195
)
186196
197+
# Create listing
187198
lsting <- as_listing(
188199
out,
189200
key_cols = c("ARM", "USUBJID", "VISIT"),
@@ -209,3 +220,4 @@ head(lsting, 28)
209220

210221

211222

223+

0 commit comments

Comments
 (0)