Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions adam/adpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ pc_dates <- pc %>%
# 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
DRUG = PCTEST
) %>%
derive_var_nfrlt(
new_var = NFRLT,
new_var_unit = FRLTU,
out_unit = "HOURS",
tpt_var = PCTPT,
visit_day = VISITDY
)

## ----r------------------------------------------------------------------------
Expand Down Expand Up @@ -85,11 +91,13 @@ ex_dates <- ex %>%
) %>%
# Derive event ID and nominal relative time from first dose (NFRLT)
mutate(
EVID = 1,
NFRLT = case_when(
VISITDY == 1 ~ 0,
TRUE ~ 24 * VISITDY
)
EVID = 1
) %>%
derive_var_nfrlt(
new_var = NFRLT,
new_var_unit = FRLTU,
out_unit = "HOURS",
visit_day = VISITDY
) %>%
# Set missing end dates to start date
mutate(AENDTM = case_when(
Expand Down Expand Up @@ -233,16 +241,17 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>%
new_var = AFRLT,
start_date = FANLDTM,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
# Derive Actual Relative Time from Reference Dose (ARRLT)
derive_vars_duration(
new_var = ARRLT,
new_var_unit = RRLTU,
start_date = ADTM_prev,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
Expand All @@ -251,7 +260,7 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>%
new_var = AXRLT,
start_date = ADTM_next,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
Expand Down Expand Up @@ -330,8 +339,6 @@ adpc_aval <- adpc_nrrlt %>%
) %>%
# Derive relative time units
mutate(
FRLTU = "h",
RRLTU = "h",
# Derive PARAMCD
PARAMCD = coalesce(PCTESTCD, "DOSE"),
ALLOQ = PCLLOQ,
Expand Down
44 changes: 22 additions & 22 deletions adam/adpc.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The Non-compartmental analysis (NCA) ADaM uses the CDISC Implementation Guide (<

## First Load Packages

First we will load the packages required for our project. We will use `{admiral}` for the creation of analysis data. `{admiral}` requires `{dplyr}`, `{lubridate}` and `{stringr}`. Find other `{admiral}` functions and related variables by searching [admiraldiscovery](<https://pharmaverse.github.io/admiraldiscovery/articles/reactable.html>). We will use `{metacore}` and `{metatools}` to store and manipulate metadata from our specifications. We will use `{xportr}` to perform checks on the final data and export to a transport file.
First we will load the packages required for our project. We will use `{admiral}` for the creation of analysis data. `{admiral}` requires `{dplyr}`, `{lubridate}` and `{stringr}`. Find other `{admiral}` functions and related variables by searching [admiraldiscovery](https://pharmaverse.github.io/admiraldiscovery/articles/reactable.html). We will use `{metacore}` and `{metatools}` to store and manipulate metadata from our specifications. We will use `{xportr}` to perform checks on the final data and export to a transport file.

The source SDTM data will come from the CDISC pilot study data stored in `{pharmaversesdtm}`.

Expand Down Expand Up @@ -71,7 +71,7 @@ vs <- convert_blanks_to_na(vs)

### Derive PC Dates

Here we use `{admiral}` functions for working with dates and we will also create a nominal time from first dose `NFRLT` for `PC` data based on `PCTPTNUM`.
Here we use `{admiral}` functions for working with dates and we will also create a nominal time from first dose `NFRLT` for `PC` data using `derive_var_nfrlt()`.

```{r}
#| label: PC Dates
Expand Down Expand Up @@ -101,8 +101,14 @@ pc_dates <- pc %>%
# 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
DRUG = PCTEST
) %>%
derive_var_nfrlt(
new_var = NFRLT,
new_var_unit = FRLTU,
out_unit = "HOURS",
tpt_var = PCTPT,
visit_day = VISITDY
)
```

Expand All @@ -112,7 +118,7 @@ print_df(pc_dates %>% select(USUBJID, PCTEST, ADTM, VISIT, PCTPT, NFRLT))

### Get Dosing Information

Here we also create nominal time from first dose `NFRLT` for `EX` data based on `VISITDY`.
Here we also create nominal time from first dose `NFRLT` for `EX` data based on `VISITDY` using `derive_var_nfrlt()`.

```{r}
#| label: Dosing
Expand Down Expand Up @@ -141,11 +147,13 @@ ex_dates <- ex %>%
) %>%
# Derive event ID and nominal relative time from first dose (NFRLT)
mutate(
EVID = 1,
NFRLT = case_when(
VISITDY == 1 ~ 0,
TRUE ~ 24 * VISITDY
)
EVID = 1
) %>%
derive_var_nfrlt(
new_var = NFRLT,
new_var_unit = FRLTU,
out_unit = "HOURS",
visit_day = VISITDY
) %>%
# Set missing end dates to start date
mutate(AENDTM = case_when(
Expand Down Expand Up @@ -230,8 +238,6 @@ adpc_first_dose <- pc_dates %>%
)
```



```{r eval=TRUE, echo=FALSE, purl=FALSE}
print_df(adpc_first_dose %>% select(USUBJID, FANLDTM, NFRLT, ADTM, AVISITN, AVISIT, PCTPT))
```
Expand Down Expand Up @@ -318,7 +324,6 @@ adpc_nom_next <- adpc_nom_prev %>%
print_df(adpc_nom_prev %>% select(USUBJID, NFRLT, AVISIT, PCTPT, NFRLT_prev))
```


### Combine PC and EX Data

Combine `PC` and `EX` records and derive the additional relative time variables.
Expand All @@ -341,16 +346,17 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>%
new_var = AFRLT,
start_date = FANLDTM,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
# Derive Actual Relative Time from Reference Dose (ARRLT)
derive_vars_duration(
new_var = ARRLT,
new_var_unit = RRLTU,
start_date = ADTM_prev,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
Expand All @@ -359,7 +365,7 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>%
new_var = AXRLT,
start_date = ADTM_next,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
Expand Down Expand Up @@ -406,12 +412,10 @@ adpc_nrrlt <- adpc_arrlt %>%
)
```


```{r eval=TRUE, echo=FALSE, purl=FALSE}
print_df(adpc_nrrlt %>% select(USUBJID, NFRLT, NRRLT, AVISIT, PCTPT))
```


### Derive Analysis Variables

Here we derive the analysis variables such as `AVAL` and `ATPTREF`.
Expand Down Expand Up @@ -458,8 +462,6 @@ adpc_aval <- adpc_nrrlt %>%
) %>%
# Derive relative time units
mutate(
FRLTU = "h",
RRLTU = "h",
# Derive PARAMCD
PARAMCD = coalesce(PCTESTCD, "DOSE"),
ALLOQ = PCLLOQ,
Expand Down Expand Up @@ -512,12 +514,10 @@ dtype <- adpc_aval %>%
derive_vars_dtm_to_tm(exprs(PCRFTDTM))
```


```{r eval=TRUE, echo=FALSE, purl=FALSE}
print_df(dtype %>% select(USUBJID, DTYPE, BASETYPE, ATPT, NFRLT, NRRLT, AFRLT, ARRLT))
```


### Combine Original and DTYPE Copy

Now the duplicated records are combined with the original records.
Expand Down
26 changes: 17 additions & 9 deletions adam/adppk.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ pc_dates <- pc %>%
# 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
DRUG = PCTEST
) %>%
derive_var_nfrlt(
new_var = NFRLT,
new_var_unit = FRLTU,
out_unit = "HOURS",
tpt_var = PCTPT,
visit_day = VISITDY
)

## ----r------------------------------------------------------------------------
Expand Down Expand Up @@ -90,11 +96,13 @@ ex_dates <- ex %>%
) %>%
# Derive event ID and nominal relative time from first dose (NFRLT)
mutate(
EVID = 1,
NFRLT = case_when(
VISITDY == 1 ~ 0,
TRUE ~ 24 * VISITDY
)
EVID = 1
) %>%
derive_var_nfrlt(
new_var = NFRLT,
new_var_unit = FRLTU,
out_unit = "HOURS",
visit_day = VISITDY
) %>%
# Set missing end dates to start date
mutate(AENDTM = case_when(
Expand Down Expand Up @@ -211,7 +219,7 @@ adppk_aprlt <- bind_rows(adppk_nom_prev, ex_exp) %>%
new_var = AFRLT,
start_date = FANLDTM,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
Expand All @@ -220,7 +228,7 @@ adppk_aprlt <- bind_rows(adppk_nom_prev, ex_exp) %>%
new_var = APRLT,
start_date = ADTM_prev,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
Expand Down
30 changes: 19 additions & 11 deletions adam/adppk.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ lb <- convert_blanks_to_na(lb)

### Derive PC Dates

Here we use `{admiral}` functions for working with dates and we will also create a nominal time from first dose `NFRLT` for `PC` data based on `PCTPTNUM`.
Here we use `{admiral}` functions for working with dates and we will also create a nominal time from first dose `NFRLT` for `PC` data using `derive_var_nfrlt()`.

```{r}
#| label: PC Dates
Expand Down Expand Up @@ -103,8 +103,14 @@ pc_dates <- pc %>%
# 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
DRUG = PCTEST
) %>%
derive_var_nfrlt(
new_var = NFRLT,
new_var_unit = FRLTU,
out_unit = "HOURS",
tpt_var = PCTPT,
visit_day = VISITDY
)
```

Expand All @@ -115,7 +121,7 @@ print_df(pc_dates %>% select(USUBJID, PCTEST, ADTM, VISIT, PCTPT, NFRLT))

### Get Dosing Information

Here we also create nominal time from first dose `NFRLT` for `EX` data based on `VISITDY`.
Here we also create nominal time from first dose `NFRLT` for `EX` data based on `VISITDY` using `derive_var_nfrlt()`.

```{r}
#| label: Dosing
Expand Down Expand Up @@ -145,11 +151,13 @@ ex_dates <- ex %>%
) %>%
# Derive event ID and nominal relative time from first dose (NFRLT)
mutate(
EVID = 1,
NFRLT = case_when(
VISITDY == 1 ~ 0,
TRUE ~ 24 * VISITDY
)
EVID = 1
) %>%
derive_var_nfrlt(
new_var = NFRLT,
new_var_unit = FRLTU,
out_unit = "HOURS",
visit_day = VISITDY
) %>%
# Set missing end dates to start date
mutate(AENDTM = case_when(
Expand Down Expand Up @@ -328,7 +336,7 @@ adppk_aprlt <- bind_rows(adppk_nom_prev, ex_exp) %>%
new_var = AFRLT,
start_date = FANLDTM,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
Expand All @@ -337,7 +345,7 @@ adppk_aprlt <- bind_rows(adppk_nom_prev, ex_exp) %>%
new_var = APRLT,
start_date = ADTM_prev,
end_date = ADTM,
out_unit = "hours",
out_unit = "HOURS",
floor_in = FALSE,
add_one = FALSE
) %>%
Expand Down
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ NCA
nDate
nDose
nestcolor
nfrlt
NFRLT
nFrom
nLTRs
Expand Down Expand Up @@ -733,6 +734,7 @@ TMPTC
toc
topleft
toupper
tpt
TPT
TPTNUM
traceback
Expand Down