Skip to content
Merged
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
33 changes: 20 additions & 13 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 Expand Up @@ -415,7 +422,7 @@ adpc_aseq <- adpc_chg %>%
create_var_from_codelist(metacore, input_var = PARAMCD, out_var = PARAMN)

## ----r------------------------------------------------------------------------
#---- Derive additional baselines from VS ----
# ---- Derive additional baselines from VS ----

adpc_baselines <- adpc_aseq %>%
derive_vars_merged(
Expand Down
46 changes: 23 additions & 23 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 Expand Up @@ -585,7 +585,7 @@ Here we derive additional baseline values from `VS` for baseline height `HTBL` a

```{r}
#| label: Baselines
#---- Derive additional baselines from VS ----
# ---- Derive additional baselines from VS ----

adpc_baselines <- adpc_aseq %>%
derive_vars_merged(
Expand Down
32 changes: 20 additions & 12 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 Expand Up @@ -327,7 +335,7 @@ adppk_aseq <- adppk_aval %>%
)

## ----r------------------------------------------------------------------------
#---- Derive Covariates ----
# ---- Derive Covariates ----
# Include numeric values for STUDYIDN, USUBJIDN, SEXN, RACEN etc.

covar <- adsl %>%
Expand Down Expand Up @@ -384,7 +392,7 @@ covar_vslb <- covar %>%
BMIBL = compute_bmi(height = HTBL, weight = WTBL),
BSABL = compute_bsa(
height = HTBL,
weight = HTBL,
weight = WTBL,
method = "Mosteller"
),
CRCLBL = compute_egfr(
Expand Down Expand Up @@ -413,7 +421,7 @@ adppk_prefinal <- adppk_aseq %>%
RECSEQ = row_number(),
EXCLFCOM = "None"
) %>%
create_var_from_codelist(metacore, input_var = DVID, out_var = DVIDN) %>%
create_var_from_codelist(metacore, input_var = DVID, out_var = DVIDN, strict = FALSE) %>%
create_var_from_codelist(metacore, input_var = EXCLFCOM, out_var = EXCLF)

## ----r------------------------------------------------------------------------
Expand Down
Loading