-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quarto_CDISC_ADNCA.qmd
1215 lines (944 loc) · 29.4 KB
/
Quarto_CDISC_ADNCA.qmd
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Programming CDISC ADaM ADNCA using R and `{admiral}`"
author: "Jeff Dickinson, Navitas Data Sciences"
format:
revealjs:
#incremental: true
theme: simple
embed-resources: true
editor: visual
logo: ./images/Navitas.PNG
---
## Agenda
- Basic Concepts of Non-Compartmental Analysis NCA
- Quick overview of `{admiral}`
- Coding Steps for ADNCA
- New Functionality Highlights
- Conclusions
- Questions and Answers
::: notes
Here's quick overview for today
:::
## CDISC Standards for Non-Compartmental Analysis
[![](./images/CDISC_ADNCA_ADaM_Capture.PNG)](https://www.cdisc.org/standards/foundational/adam/adamig-non-compartmental-analysis-input-data-v1-0)
::: notes
This CDISC guidance for non-compartmental analysis was published in November of 2021
In using admiral for NCA data programming I have followed this guidance closely
I will be using terms ADNCA and ADPC interchangeably
:::
[https://www.cdisc.org/standards/foundational/adam/adamig-non-compartmental-analysis-input-data-v1-0](https://www.cdisc.org/standards/foundational/adam/adamig-non-compartmental-analysis-input-data-v1-0){target="_blank"}
## Non-Compartmental Analysis (NCA)
[![Example PK Curve with Parameters](./images/PK_curve.PNG)](https://www.cdisc.org/standards/foundational/adam/adamig-non-compartmental-analysis-input-data-v1-0)
::: notes
Non-compartmental analysis (NCA) is one way to model the level of exposure following administration of a drug Here you can see a sample PK curve and the types of parameters that may be estimated
:::
## Important Components of ADNCA datasets
- Inclusion of Both PK Concentration records `PC` and Dosing Records `EX`
- Timing Variables for Nominal and Actual Time
- Duplicated Records for Analysis
- Exclusion Flags
Note: I will be using terms `ADNCA` and `ADPC` interchangeably
## Time Variables
| Variable | Variable Label |
|----------|----------------------------------------|
| NFRLT | Nom. Rel. Time from Analyte First Dose |
| AFRLT | Act. Rel. Time from Analyte First Dose |
| NRRLT | Nominal Rel. Time from Ref. Dose |
| ARRLT | Actual Rel. Time from Ref. Dose |
| MRRLT | Modified Rel. Time from Ref. Dose |
Note: a relative time variable may refer to previous dose or next dose
::: notes
Here is a list of important nominal and actual relative time variables
Timing Variables may refer to previous dose or next dose
Actual times may be used to calculate parameters Nominal times may be used to group output in tables
:::
## Duplicated Records for Analysis
- Use One Record in More than One Way
- Record may be both "24 Hour Post-Dose" and "Pre-Dose"
- Or "Cycle 2 Day 1 Pre-Dose" and "Cycle 1 Day 28 Post-Dose"
- Relative Times for "Pre-Dose" will be Negative
- Create `DTYPE` = "COPY" Records
- Original `PCSEQ` is Retained
::: notes
Here is an overview of duplicated records for analysis
:::
## Brief Overview of `{admiral}`
[![](./images/admiral.png){width="574"}](https://github.com/pharmaverse/admiral)
[https://github.com/pharmaverse/admiral](https://github.com/pharmaverse/admiral){target="_blank"}
## `{admiral}`
::: incremental
- `AD`a`M i`n `R A`sset `L`ibrary
- `{admiral}` is Open Source and Collaborative
- `{admiral}` is Modular
- `{admiral}` is Part of Pharmaverse
:::
## `{admiral}` is Open Source and Collaborative
![{admiral} Ecosystem](images/AdmiralEcosystem.png)
::: notes
admiral began as a collaboration between Roche and GSK The ecosystem has since expanded to include many contributors from multiple companies
:::
## `{admiral}` is Modular
- Not One Large Function (e.g. `create_adpc()`)
- Multiple Coordinated Functions
::: columns
::: {.column width="50%"}
![](images/ModularPicture3.png){width="100%"}
:::
::: {.column width="50%"}
![](images/ModularPicture4.png){width="100%"}
:::
:::
## `{admiral}` is Part of Pharmaverse
[![](./images/Pharmavers.png)](https://github.com/pharmaverse)
[https://github.com/pharmaverse](https://github.com/pharmaverse){target="_blank"}
::: notes
Pharmaverse a connected network of companies and individuals working to promote collaborative development of open source R packages for clinical reporting usage across our industry, in a space where previously we would only ever have worked in silos on our own closed source and duplicative solutions
:::
## `{admiral}` updates for PK
(March 6, 2023 release 0.10.0)
- New `ad_adpc.R` Template
- New PK Programming Vignette
- Updates to `create_single_dose_dataset()` function
## Programming Workflow
::: incremental
- Read in Data
- Expand Dosing Records
- Find First Dose and Calculate First Datetime
- Find Reference Dose Dates Corresponding to PK Records
- Combine `PC` and `EX` Records and Derive Relative Time Variables
- Derive Analysis Variables
:::
## Programming Workflow (Continued)
::: incremental
- Create Duplicated Records for Analysis
- Combine `ADPC` data with Duplicated Records
- Calculate Baseline and Change from Baseline
- Assign `ASEQ`
- Add Additional Baseline Variables
- Add ADSL variables
- Add Labels and Attributes
:::
## `{admiral}` Libraries
```{r echo=TRUE, message=FALSE}
library(admiral)
library(admiraldev)
library(admiral.test)
library(dplyr)
library(lubridate)
library(stringr)
```
::: notes
Here are the required packages
:::
## Read in Data
```{r echo=TRUE, message=FALSE}
data("admiral_adsl")
data("admiral_ex")
data("admiral_pc")
data("admiral_vs")
adsl <- admiral_adsl
ex <- convert_blanks_to_na(admiral_ex)
pc <- convert_blanks_to_na(admiral_pc)
vs <- convert_blanks_to_na(admiral_vs)
```
::: notes
We read in the test dataset from the admiral.test library Note we convert blanks to NA so they are handled consistently within R The test data for EX/PC consist of a daily patch
:::
```{r echo=FALSE}
options(max.print=25)
ex <- filter(ex, USUBJID %in% c("01-701-1028"))
pc <- filter(pc, USUBJID %in% c("01-701-1028"))
param_lookup <- tibble::tribble(
~PCTESTCD, ~PARAMCD, ~PARAM, ~PARAMN,
"XAN", "XAN", "Pharmacokinetic concentration of Xanomeline", 1,
"DOSE", "DOSE", "Xanomeline Patch Dose", 2,
)
print_df <- function(dataset, display_vars = NULL) {
display_vars <- assert_vars(display_vars, optional = TRUE)
assert_data_frame(dataset, required_vars = display_vars)
out <- dataset %>%
select(!!!display_vars)
head(out, n = 20)
}
```
## `PC` Rawdata
```{r}
print_df(
pc,
display_vars = exprs(
USUBJID, PCTEST, PCDTC, VISIT, PCTPT, PCSTRESN
)
)
```
This CDISC test `PC` data has concentrations over 48 hours from a daily patch
::: notes
Here is our PC rawdata This shows concentrations over 48 hours from a daily patch
:::
## Join `ADSL` with `PC`
- Use function `derive_vars_merged()`
- Convert Dates to Numeric
- Functions
- `derive_vars_dtm()`
- `derive_vars_dtm_to_dt()`
- `derive_vars_dtm_to_tm()`
- `derive_vars_dy()`
- Derive `NFRLT` for `PC` data based on `PCTPTNUM`
::: notes
First we join ADSL with our PC data
:::
## `PC` Merge Code
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|5-9|11-15|24"
adsl_vars <- exprs(TRTSDT, TRTSDTM, TRT01P, TRT01A)
adpc <- pc %>%
# Join ADSL with PC (need TRTSDT for ADY derivation)
derive_vars_merged(
dataset_add = adsl,
new_vars = adsl_vars,
by_vars = exprs(STUDYID, USUBJID)
) %>%
# Calculate ADTM, ADT, ADY
derive_vars_dtm(
new_vars_prefix = "A",
dtc = PCDTC,
time_imputation = "00:00:00"
) %>%
# Derive dates and times from date/times
derive_vars_dtm_to_dt(exprs(ADTM)) %>%
derive_vars_dtm_to_tm(exprs(ADTM)) %>%
derive_vars_dy(reference_date = TRTSDT, source_vars = exprs(ADT)) %>%
# Derive event ID and nominal relative time from first dose (NFRLT)
mutate(
EVID = 0,
DRUG = PCTEST,
NFRLT = if_else(PCTPTNUM < 0, 0, PCTPTNUM), .after = USUBJID
)
```
::: notes
Here is the code for joining ADSL with PC
:::
## `PC` Merge Code Output
```{r eval=TRUE, echo=FALSE}
print_df(adpc,
display_vars = exprs(USUBJID, PCTEST, ADTM, VISIT, PCTPT, NFRLT))
```
Note numeric datetimes and Nominal Relative Time from Analyte First Dose (`NFRLT`)
::: notes
Here is the output of joining ADSL with PC Note Numeric Datetimes and Nominal Relative Time from Analyte First Dose `NFRLT`
:::
## `EX` Rawdata
```{r}
print_df(
ex,
display_vars = exprs(
USUBJID, EXTRT, EXDOSFRQ, EXSTDTC, EXENDTC, VISIT, VISITDY
)
)
```
This CDISC test exposure data is for a daily patch
::: notes
Here is our exposure data This is a daily patch
:::
## Merge `ADSL` with `EX`
- Use Function `derive_vars_merged()`
- Keep Only Non-Zero Dose
- Convert Dates to Numeric
- Impute missing times to 0:00\*
- Functions
- `derive_vars_dtm()`
- `derive_vars_dtm_to_dt()`
- Derive `NFRLT` based on `VISITDY`
::: notes
First we merge with ADSL
:::
## `EX` Merge Code
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|4-8|14-18|27"
#|
# ---- Get dosing information ----
ex <- ex %>%
derive_vars_merged(
dataset_add = adsl,
new_vars = adsl_vars,
by_vars = exprs(STUDYID, USUBJID)
) %>%
# Keep records with nonzero dose
filter(EXDOSE > 0) %>%
# Add time and set missing end date to start date
# Impute missing time to 00:00:00
# Derive Analysis Start and End Dates
derive_vars_dtm(
new_vars_prefix = "AST",
dtc = EXSTDTC,
time_imputation = "00:00:00"
) %>%
derive_vars_dtm(
new_vars_prefix = "AEN",
dtc = EXENDTC,
time_imputation = "00:00:00"
) %>%
# Derive event ID and nominal relative time from first dose (NFRLT)
mutate(
EVID = 1,
NFRLT = 24 * (VISITDY - 1), .after = USUBJID
) %>%
# Set missing end dates to start date
mutate(AENDTM = case_when(
is.na(AENDTM) ~ ASTDTM,
TRUE ~ AENDTM
)) %>%
# Derive dates from date/times
derive_vars_dtm_to_dt(exprs(ASTDTM)) %>%
derive_vars_dtm_to_dt(exprs(AENDTM))
```
## `EX` Merge Output
```{r eval=TRUE, echo=FALSE}
print_df(
ex,
display_vars = exprs(
USUBJID, EXTRT, EXDOSFRQ, ASTDT, AENDT, VISITDY, NFRLT
)
)
```
Note numeric dates and Nominal Relative Time from Analyte First Dose (`NFRLT`)
::: notes
Here is the output of our merge Note Numeric Dates and Nominal Relative Time from Analyte First Dose `NFRLT`
:::
## Expand Dosing Records
- Need to add records between start date and end date
- Use function `create_single_dose_dataset()`
- Need to also expand nominal relative time `NFRLT`
- For example `EXDOSFRQ` = "QD" will expand `NFRLT` by 24 hours
- New feature of function
::: notes
Next we need to expand dosing records between start date and end date
:::
## Expansion Example Code
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|4-18|10|22,23"
# ---- Expand dosing records between start and end dates ----
ex_exp <- ex %>%
create_single_dose_dataset(
dose_freq = EXDOSFRQ,
start_date = ASTDT,
start_datetime = ASTDTM,
end_date = AENDT,
end_datetime = AENDTM,
nominal_time = NFRLT,
lookup_table = dose_freq_lookup,
lookup_column = CDISC_VALUE,
keep_source_vars = exprs(
STUDYID, USUBJID, EVID, EXDOSFRQ, EXDOSFRM,
NFRLT, EXDOSE, EXDOSU, EXTRT, ASTDT, ASTDTM, AENDT, AENDTM,
VISIT, VISITNUM, VISITDY,
TRT01A, TRT01P, DOMAIN, EXSEQ, !!!adsl_vars
)
) %>%
# Derive AVISIT based on nominal relative time
mutate(
AVISITN = NFRLT %/% 24 + 1,
AVISIT = paste("Day", AVISITN),
ADTM = ASTDTM,
DRUG = EXTRT,
) %>%
# Derive dates and times from datetimes
derive_vars_dtm_to_dt(exprs(ADTM)) %>%
derive_vars_dtm_to_tm(exprs(ADTM)) %>%
derive_vars_dtm_to_tm(exprs(ASTDTM)) %>%
derive_vars_dtm_to_tm(exprs(AENDTM)) %>%
derive_vars_dy(reference_date = TRTSDT, source_vars = exprs(ADT))
```
::: notes
Here is our expansion code Note new parameter of create_single_dose_dataset()
:::
## Expansion Code Output
```{r eval=TRUE, echo=FALSE}
print_df(
ex_exp,
display_vars = exprs(USUBJID, DRUG, EXDOSFRQ, ASTDT, AVISIT, NFRLT)
)
```
Note: `NFRLT` is expanded by 24 hours for each record `AVISIT` has values "Day 1", "Day 2", "Day 3", etc.
::: notes
Here is the output of our expansion expansion Note that `NFRLT` is expanded by 24 hours for each record And we have updated `AVISIT` to "Day 1", "Day 2", etc.
:::
## Find First Dose and Calculate `FANLDTM`
- Use Function `derive_vars_merged()`
- Parameter `new_vars` used to derive `FANLDTM`
- Recalculate `AVISIT` and `AVISITN` based on `NFRLT` for this study
`FANLDTM` = First Datetime of Dose for Analyte
::: notes
Next we find our first dose datetime
:::
## First Dose Code
```{r eval=TRUE, echo=TRUE, message=FALSE}
#| code-line-numbers: "|5-12|8|16-17"
# ---- Find first dose per treatment per subject ----
# ---- Join with ADPC data and keep only subjects with dosing ----
adpc <- adpc %>%
derive_vars_merged(
dataset_add = ex_exp,
filter_add = (EXDOSE > 0 & !is.na(ADTM)),
new_vars = exprs(FANLDTM = ADTM),
order = exprs(ADTM, EXSEQ),
mode = "first",
by_vars = exprs(STUDYID, USUBJID, DRUG)
) %>%
filter(!is.na(FANLDTM)) %>%
# Derive AVISIT from nominal relative time
mutate(
AVISITN = NFRLT %/% 24 + 1,
AVISIT = paste("Day", AVISITN),
)
```
::: notes
Here is the code for first dose datetime
:::
## First Dose Output
```{r eval=TRUE, echo=FALSE}
print_df(
adpc,
display_vars = exprs(USUBJID, FANLDTM, AVISIT, ADTM, PCTPT)
)
```
`FANLDTM` = First Datetime of Dose for Analyte
::: notes
Here is the output for first dose datetime Note `FANLDTM` = First Datetime of Dose for Analyte
:::
## Find Reference Dose Dates Corresponding to PK Records
- Use Function `derive_vars_joined()`
- Parameter `filter_join` used to set condition
::: notes
Next we find our reference dose dates corresponding to PK records
:::
## Find Reference Dose Dates Code
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|6-19|16"
# ---- Find previous dose ----
# Use derive_vars_joined() for consistency with other variables
# This is equivalent to derive_vars_last_dose() in this case
adpc <- adpc %>%
derive_vars_joined(
dataset_add = ex_exp,
by_vars = exprs(USUBJID),
order = exprs(ADTM),
new_vars = exprs(
ADTM_prev = ADTM, EXDOSE_prev = EXDOSE, AVISIT_prev = AVISIT,
AENDTM_prev = AENDTM
),
join_vars = exprs(ADTM),
filter_add = NULL,
filter_join = ADTM > ADTM.join,
mode = "last",
check_type = "none"
)
```
::: notes
Here is our code for finding reference dose dates corresponding to PK records Note `filter_join` condition This is comparing the datetime of the concentration record with the datetime of the previous dose
:::
## Find Reference Dose Dates Output
```{r eval=TRUE, echo=FALSE}
print_df(
adpc,
display_vars = exprs(
USUBJID,
VISIT, ADTM, VISIT, PCTPT, ADTM_prev, AVISIT_prev
)
)
```
`ADTM_prev` is the datetime of the previous dose `AVISIT_prev` is the analysis visit of the previous dose
::: notes
Here the output from the reference dose dates Note ADTM_prev is the datetime for the previous dose
:::
## Find Next Dose
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|4-17|14"
# ---- Find next dose ----
adpc <- adpc %>%
derive_vars_joined(
dataset_add = ex_exp,
by_vars = exprs(USUBJID),
order = exprs(ADTM),
new_vars = exprs(
ADTM_next = ADTM, EXDOSE_next = EXDOSE, AVISIT_next = AVISIT,
AENDTM_next = AENDTM
),
join_vars = exprs(ADTM),
filter_add = NULL,
filter_join = ADTM <= ADTM.join,
mode = "first",
check_type = "none"
)
```
::: notes
Similarly we find the next dose Note ADTM_next is the datetime for the next dose
:::
## Find Next Dose Output
```{r eval=TRUE, echo=FALSE}
print_df(
adpc,
display_vars = exprs(
USUBJID,
VISIT, ADTM, VISIT, PCTPT, ADTM_next, AVISIT_next
)
)
```
`ADTM_next` is the datetime of the next dose
::: notes
Here is our output for finding next dose Note ADTM_next is the datetime for the next dose And AVISIT_next is the Analysis Visit for next dose
:::
## Find Previous Nominal Dose
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|4-14|11"
# ---- Find previous nominal time ----
adpc <- adpc %>%
derive_vars_joined(
dataset_add = ex_exp,
by_vars = exprs(USUBJID),
order = exprs(NFRLT),
new_vars = exprs(NFRLT_prev = NFRLT),
join_vars = exprs(NFRLT),
filter_add = NULL,
filter_join = NFRLT > NFRLT.join,
mode = "last",
check_type = "none"
)
```
::: notes
We will do the same thing with nominal times In real studies you will find the nominal time does not always match the actual time
:::
## Find Next Nominal Dose
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|4-14|11"
# ---- Find next nominal time ----
adpc <- adpc %>%
derive_vars_joined(
dataset_add = ex_exp,
by_vars = exprs(USUBJID),
order = exprs(NFRLT),
new_vars = exprs(NFRLT_next = NFRLT),
join_vars = exprs(NFRLT),
filter_add = NULL,
filter_join = NFRLT <= NFRLT.join,
mode = "first",
check_type = "none"
)
```
::: notes
Here we also find the Next Nominal Time
:::
## Find Next Nominal Dose Output
```{r eval=TRUE, echo=FALSE}
print_df(
adpc,
display_vars = exprs(
USUBJID, NFRLT, PCTPT, NFRLT_prev, NFRLT_next
)
)
```
`NFRLT_prev` is the nominal relative time from the previous dose `NFRLT_next` is the nominal relative time for the next dose
::: notes
Here is the output from these steps Note `NFRLT_prev` is the Nominal Relative Time from the Previous Dose `NFRLT_next` is the Nominal Relative Time for the Next Dose
:::
## Combine PC and EX Records and Derive Relative Time Variables {#relative}
- Include both dosing and concentration records
- Use function `derive_vars_duration()`
- Create Actual Relative Time `AFRLT`
::: notes
Next we combine PC and EX records and derive relative time variables
:::
## Combine PC and EX Records and Derive Relative Time Variables Code
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|5|8|16-23|25-32|34-41|43,50"
# ---- Combine ADPC and EX data ----
# Derive Relative Time Variables
adpc <- bind_rows(adpc, ex_exp) %>%
group_by(USUBJID, DRUG) %>%
mutate(
FANLDTM = min(FANLDTM, na.rm = TRUE),
min_NFRLT = min(NFRLT_prev, na.rm = TRUE),
maxdate = max(ADT[EVID == 0], na.rm = TRUE), .after = USUBJID
) %>%
arrange(USUBJID, ADTM) %>%
ungroup() %>%
filter(ADT <= maxdate) %>%
# Derive Actual Relative Time from First Dose (AFRLT)
derive_vars_duration(
new_var = AFRLT,
start_date = FANLDTM,
end_date = ADTM,
out_unit = "hours",
floor_in = FALSE,
add_one = FALSE
) %>%
# Derive Actual Relative Time from Reference Dose (ARRLT)
derive_vars_duration(
new_var = ARRLT,
start_date = ADTM_prev,
end_date = ADTM,
out_unit = "hours",
floor_in = FALSE,
add_one = FALSE
) %>%
# Derive Actual Relative Time from Next Dose (AXRLT not kept)
derive_vars_duration(
new_var = AXRLT,
start_date = ADTM_next,
end_date = ADTM,
out_unit = "hours",
floor_in = FALSE,
add_one = FALSE
) %>%
mutate(
ARRLT = case_when(
EVID == 1 ~ 0,
is.na(ARRLT) ~ AXRLT,
TRUE ~ ARRLT
),
# Derive Reference Dose Date
PCRFTDTM = case_when(
EVID == 1 ~ ADTM,
is.na(ADTM_prev) ~ ADTM_next,
TRUE ~ ADTM_prev
)
) %>%
# Derive dates and times from datetimes
derive_vars_dtm_to_dt(exprs(FANLDTM)) %>%
derive_vars_dtm_to_tm(exprs(FANLDTM)) %>%
derive_vars_dtm_to_dt(exprs(PCRFTDTM)) %>%
derive_vars_dtm_to_tm(exprs(PCRFTDTM))
```
::: notes
Here our code for combining PC and EX records and deriving relative time variables
:::
## Derive Relative Time Output
```{r eval=TRUE, echo=FALSE}
print_df(
adpc,
display_vars = exprs(USUBJID, FANLDT, AVISIT, PCTPT, AFRLT, ARRLT, AXRLT)
)
```
`AFRLT` = Actual Relative Time from Analyte First Dose `ARRLT` = Actual Relative Time from Reference Dose
::: notes
Here the output after combining PC and EX records and deriving relative time variables Note `AFRLT` Actual Relative Time from Analyte First Dose `ARRLT` Actual Relative Time from Reference Dose We do not keep `AXRLT` but it is the actual time to the next dose
:::
## Find Nominal Relative Times
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|4|9"
adpc <- adpc %>%
# Derive Nominal Relative Time from Reference Dose (NRRLT)
mutate(
NRRLT = case_when(
EVID == 1 ~ 0,
is.na(NFRLT_prev) ~ NFRLT - min_NFRLT,
TRUE ~ NFRLT - NFRLT_prev
),
NXRLT = case_when(
EVID == 1 ~ 0,
TRUE ~ NFRLT - NFRLT_next
)
)
```
::: notes
Next we Find Nominal Relative Times
:::
## Nominal Relative Times Output
```{r eval=TRUE, echo=FALSE}
print_df(
adpc,
display_vars = exprs(USUBJID, AVISIT, PCTPT, NFRLT, NRRLT, NXRLT)
)
```
`NFRLT` = Nominal Relative Time from Analyte First Dose `NRRLT` = Nominal Relative Time from Reference Dose
::: notes
Here is the output from derviing nominal relative times Note `NFRLT` Nominal Relative Time from Analyte First Dose `NRRLT` Nominal Relative Time from Reference Dose
:::
## Derive Analysis Variables
```{r eval=TRUE, echo=TRUE}
adpc <- adpc %>%
mutate(
ATPTN = case_when(
EVID == 1 ~ 0,
TRUE ~ PCTPTNUM
),
ATPT = case_when(
EVID == 1 ~ "Dose",
TRUE ~ PCTPT
),
ATPTREF = case_when(
EVID == 1 ~ AVISIT,
is.na(AVISIT_prev) ~ AVISIT_next,
TRUE ~ AVISIT_prev
),
# Derive baseline flag for pre-dose records
ABLFL = case_when(
ATPT == "Pre-dose" ~ "Y",
TRUE ~ NA_character_
),
# Derive BASETYPE
BASETYPE = paste(ATPTREF, "Baseline"),
# Derive Actual Dose
DOSEA = case_when(
EVID == 1 ~ EXDOSE,
is.na(EXDOSE_prev) ~ EXDOSE_next,
TRUE ~ EXDOSE_prev
),
# Derive Planned Dose
DOSEP = case_when(
TRT01P == "Xanomeline High Dose" ~ 81,
TRT01P == "Xanomeline Low Dose" ~ 54
),
DOSEU = "mg",
) %>%
mutate(
FRLTU = "h",
RRLTU = "h",
PARAMCD = coalesce(PCTESTCD, "DOSE"),
ALLOQ = PCLLOQ,
AVAL = case_when(
EVID == 1 ~ EXDOSE,
PCSTRESC == "<BLQ" & NFRLT == 0 ~ 0,
PCSTRESC == "<BLQ" & NFRLT > 0 ~ 0.5 * ALLOQ,
TRUE ~ PCSTRESN
),
AVALU = case_when(
EVID == 1 ~ EXDOSU,
TRUE ~ PCSTRESU
),
AVALCAT1 = if_else(PCSTRESC == "<BLQ", PCSTRESC, prettyNum(signif(AVAL, digits = 3))),
) %>%
# Add SRCSEQ
mutate(
SRCDOM = DOMAIN,
SRCVAR = "SEQ",
SRCSEQ = coalesce(PCSEQ, EXSEQ)
)
```
::: notes
Next we derive an number of analysis variables Including `ATPTREF` Analysis Timepoint Reference and `AVAL` Analysis Value
:::
## Analysis Variable Output
```{r eval=TRUE, echo=FALSE}
print_df(
adpc,
display_vars = exprs(USUBJID, NFRLT, AVISIT, ATPT, ABLFL, ATPTREF, AVAL, AVALCAT1)
)
```
`ATPT` Analysis Timepoint `ATPTREF` Analysis Timepoint Reference `AVAL` Analysis Value
::: notes
Here is the output of these derivations Note `ATPT` Analysis Timepoint `ATPTREF` Analysis Timepoint Reference `AVAL` Analysis Value
:::
## Create Duplicated Records for Analysis
- Use One Record in More than One Way
- Record may be both "24 Hour Post-Dose" and "Pre-Dose"
- Create `DTYPE` = "COPY" Records
- Original `PCSEQ` is retained
- Change "24h Post-dose" to "Pre-dose"
- `ABLFL` is set to "Y"
::: notes
We will create duplicated records for analysis "24 Hour Post-Dose" will also become "Pre-Dose"
:::
## Duplicated Records for Analysis Code
```{r eval=TRUE, echo=TRUE}
#| code-line-numbers: "|10,11|15,18"
# ---- Create DTYPE copy records ----
dtype <- adpc %>%
filter(NFRLT > 0 & NXRLT == 0 & EVID == 0 & !is.na(AVISIT_next)) %>%
select(-PCRFTDT, -PCRFTTM) %>%
# Re-derive variables in for DTYPE copy records
mutate(
ABLFL = NA_character_,
ATPTREF = AVISIT_next,
ARRLT = AXRLT,
NRRLT = NXRLT,
PCRFTDTM = ADTM_next,
DOSEA = EXDOSE_next,
BASETYPE = paste(AVISIT_next, "Baseline"),
ATPT = "Pre-dose",
ATPTN = NFRLT,
ABLFL = "Y",
DTYPE = "COPY"
) %>%
derive_vars_dtm_to_dt(exprs(PCRFTDTM)) %>%
derive_vars_dtm_to_tm(exprs(PCRFTDTM))
```
::: notes
Here is the code for the duplicated records ATPT is changed to "Pre-dose" Note `DTYPE` = "COPY"
:::
## Duplicated Records for Analysis Output
```{r eval=TRUE, echo=FALSE}
print_df(
dtype,
display_vars = exprs(USUBJID, DTYPE, BASETYPE, ATPT, NFRLT, NRRLT, AFRLT, ARRLT )
)
```
Note that `NRRLT` and `ARRLT` equal zero for next dose
::: notes
Here output for duplicated records ATPT is changed to "Pre-dose" Note `DTYPE` = "COPY" Note that `NRRLT` and `ARRLT` equal zero for next dose
:::
## Combine `ADPC` data with Duplicated Records
```{r eval=TRUE, echo=TRUE}
# ---- Combine original records and DTYPE copy records ----
adpc <- bind_rows(adpc, dtype) %>%