Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #90 #91 Update PPCAT and add urine records #92

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# pharmaversesdtm 0.3.0

## New Features

- Add URINE records to `pc` and `pp`. (#90)
- Update `PPCAT` so that it corresponds to `PCTEST`. (#91)

# pharmaversesdtm 0.2.0

## New Features
Expand Down
54 changes: 42 additions & 12 deletions data-raw/pc.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ for (t0 in t) {
(dmex1$k0 * (1 - exp(-dmex1$K * t0))) / (dmex1$V * dmex1$K), 0
)
}
# Urine estimate
dmex1$Urine <- -dmex1$K * t0 + dmex1$V / 2.5

if (t0 == -0.5) { # If first timepoint

PC <- dmex1
Expand All @@ -83,10 +86,28 @@ PC$PCSPEC <- "PLASMA"
PC$PCLLOQ <- 0.01
PC$PCTPTNUM <- PC$t

## PCSEQ; ----
PC <- PC %>%
group_by(STUDYID, USUBJID) %>%
dplyr::mutate(PCSEQ = row_number())
## PCTPT ----
PC$PCTPT <- ifelse(PC$PCTPTNUM == -0.5, "Pre-dose",
ifelse(PC$PCTPTNUM == 0.08, "5 Min Post-dose",
ifelse(PC$PCTPTNUM == 0.5, "30 Min Post-dose", paste0(PC$PCTPTNUM, "h Post-dose"))
)
)


PC_Urine <- PC %>%
filter(PCTPTNUM %in% c(6.00, 12.00, 24.00, 48.00)) %>%
mutate(
PCSPEC = "URINE",
PCTPT = case_when(
PCTPT == "6h Post-dose" ~ "0-6h Post-dose",
PCTPT == "12h Post-dose" ~ "6-12h Post-dose",
PCTPT == "24h Post-dose" ~ "12-24h Post-dose",
PCTPT == "48h Post-dose" ~ "24-48h Post-dose"
),
jeffreyad marked this conversation as resolved.
Show resolved Hide resolved
Conc = Urine
)

PC <- bind_rows(PC, PC_Urine)

## Concentration-related code ----
### Remove neg values due to pre-dose negative time ----
Expand All @@ -105,13 +126,6 @@ PC$Conc <- ifelse(PC$Conc < 0.01, "<BLQ", PC$Conc)
PC$PCORRES <- PC$Conc
PC$PCSTRESC <- PC$Conc

## PCTPT ----
PC$PCTPT <- ifelse(PC$PCTPTNUM == -0.5, "Pre-dose",
ifelse(PC$PCTPTNUM == 0.08, "5 Min Post-dose",
ifelse(PC$PCTPTNUM == 0.5, "30 Min Post-dose", paste0(PC$PCTPTNUM, "h Post-dose"))
)
)

## PCDTC ----
PC$PCDTC <- format(as.Date(PC$EXSTDTC) + minutes(round(PC$t * 60)), "%Y-%m-%dT%H:%M:%S")
PC$PCDY <- ifelse(PC$t == -0.5, -1,
Expand All @@ -120,6 +134,11 @@ PC$PCDY <- ifelse(PC$t == -0.5, -1,
)
)

## PCSEQ; ----
PC <- PC %>%
group_by(STUDYID, USUBJID) %>%
dplyr::mutate(PCSEQ = row_number())

## Select vars of interest ----
PC <- subset(PC, select = c(
"STUDYID", "DOMAIN", "USUBJID", "PCSEQ", "PCTESTCD", "PCTEST",
Expand Down Expand Up @@ -157,8 +176,19 @@ pc <- pc %>%
PCTPTNUM = "Planned Time Point Number"
)

## Subset for plots
pc_plasma <- pc %>%
filter(PCSPEC == "PLASMA")

pc_urine <- pc %>%
filter(PCSPEC == "URINE")

## Test to look the overall figure ----
plot <- ggplot(pc, aes(x = PCTPTNUM, y = PCSTRESN, group = USUBJID)) +
plot <- ggplot(pc_plasma, aes(x = PCTPTNUM, y = PCSTRESN, group = USUBJID)) +
geom_line() +
geom_point()

plot2 <- ggplot(pc_urine, aes(x = PCTPTNUM, y = PCSTRESN, group = USUBJID)) +
geom_line() +
geom_point()

Expand Down
70 changes: 51 additions & 19 deletions data-raw/pp.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,30 @@ blq_usubjid <- pc %>%
## Remove from PC, subjects with all blq (placebos) ----
remove_usubjid <- blq_usubjid %>% filter(PPORRES == 0)

pc1 <- anti_join(pc, remove_usubjid, by = c("STUDYID", "DOMAIN", "USUBJID"))
pc0 <- anti_join(pc, remove_usubjid, by = c("STUDYID", "DOMAIN", "USUBJID")) %>%
rename(PPCAT = PCTEST, PPSPEC = PCSPEC)

pc1 <- pc0 %>%
filter(PPSPEC == "PLASMA")

pc1u <- pc0 %>%
filter(PPSPEC == "URINE")

# PP usually only present values for applicable subjects;
## Calculate Cmax ----
pp_cmax <- pc1 %>%
group_by(STUDYID, DOMAIN, USUBJID) %>%
group_by(STUDYID, DOMAIN, USUBJID, PPCAT, PPSPEC) %>%
summarise(CMAX = max(PCSTRESN, na.rm = TRUE))

## Calculate Tmax ----
pp_tmax <- pc1 %>%
group_by(STUDYID, DOMAIN, USUBJID) %>%
group_by(STUDYID, DOMAIN, USUBJID, PPCAT, PPSPEC) %>%
filter(PCSTRESN == max(PCSTRESN, na.rm = TRUE)) %>%
arrange(STUDYID, DOMAIN, USUBJID, PCTPTNUM)
arrange(STUDYID, DOMAIN, USUBJID, PCTPTNUM) %>%
glimpse()

pp_tmax$TMAX <- pp_tmax$PCTPTNUM
pp_tmax <- subset(pp_tmax, select = c("STUDYID", "DOMAIN", "USUBJID", "TMAX"))
pp_tmax <- subset(pp_tmax, select = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC", "TMAX"))

## AUC 0_tlast ----
pc2 <- pc1
Expand All @@ -52,51 +61,64 @@ for (idx in 1:nrows) {
}

pp_AUC <- pc2 %>%
group_by(STUDYID, DOMAIN, USUBJID) %>%
group_by(STUDYID, DOMAIN, USUBJID, PPCAT, PPSPEC) %>%
summarise(AUC = max(AUC, na.rm = TRUE))

pc2 <- subset(pc2, select = -AUC)

# Elimination rate
pc3 <- merge(pc2, pp_tmax, by = c("STUDYID", "DOMAIN", "USUBJID"))
pc3 <- merge(pc2, pp_tmax, by = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC"))
pc3 <- pc3 %>% filter(PCTPTNUM >= TMAX)

pp_npts <- pc3 %>%
group_by(STUDYID, DOMAIN, USUBJID) %>%
group_by(STUDYID, DOMAIN, USUBJID, PPCAT, PPSPEC) %>%
summarise(npts = n())

## Break up pc3 by usubjid, then fit the specified model to each piece ----
# return a list
models <- plyr::dlply(pc3, c("STUDYID", "DOMAIN", "USUBJID"), function(df) {
models <- plyr::dlply(pc3, c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC"), function(df) {
lm(-log(PCSTRESN, base = exp(1)) ~ PCTPTNUM, data = df)
})
# summarym2=lapply(models,summary)
# lapply(summarym2,"[[","adj.r.squared") #This provides the Rs
# Apply coef to each model and return a data frame
pp_Ke <- plyr::ldply(models, coef)
pp_Ke$Ke <- pp_Ke$PCTPTNUM
pp_Ke <- subset(pp_Ke, select = c("STUDYID", "DOMAIN", "USUBJID", "Ke"))
pp_Ke <- subset(pp_Ke, select = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC", "Ke"))


## Halflife ----
pp_lambda <- pp_Ke
pp_lambda$lambda <- 0.693 / pp_lambda$Ke
pp_lambda <- subset(pp_lambda, select = c("STUDYID", "DOMAIN", "USUBJID", "lambda"))
pp_lambda <- subset(pp_lambda, select = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC", "lambda"))

## AUC_0_inf ----
pc4 <- pc3 %>%
group_by(STUDYID, DOMAIN, USUBJID) %>%
group_by(STUDYID, DOMAIN, USUBJID, PPCAT, PPSPEC) %>%
mutate(min = min(PCSTRESN, na.rm = TRUE))

pp_Clast <- pc4
pp_Clast$Clast <- pp_Clast$min
pp_Clast <- subset(pp_Clast, select = c("STUDYID", "DOMAIN", "USUBJID", "Clast"))
pp_Clast <- subset(pp_Clast, select = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC", "Clast"))

pc5 <- merge(pc4, pp_Ke, by = c("STUDYID", "DOMAIN", "USUBJID"))
pp_AUC_inf <- merge(pc5, pp_AUC, by = c("STUDYID", "DOMAIN", "USUBJID"))
pc5 <- merge(pc4, pp_Ke, by = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC"))
pp_AUC_inf <- merge(pc5, pp_AUC, by = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC"))

pp_AUC_inf$AUC_inf <- pp_AUC_inf$AUC + (pp_AUC_inf$min) / pp_AUC_inf$Ke
pp_AUC_inf <- subset(pp_AUC_inf, select = c("STUDYID", "DOMAIN", "USUBJID", "AUC_inf"))
pp_AUC_inf <- subset(pp_AUC_inf, select = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "PPSPEC", "AUC_inf"))

# Urine parameters
# Ae
pp_Ae <- pc1u %>%
group_by(STUDYID, DOMAIN, USUBJID, PPCAT, PPSPEC) %>%
summarise(pp_Ae = sum(PCSTRESN, na.rm = TRUE)) %>%
glimpse()

# CLR
pp_AUC_sub <- subset(pp_AUC, select = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT", "AUC"))
pp_CLR <- merge(pp_Ae, pp_AUC_sub, by = c("STUDYID", "DOMAIN", "USUBJID", "PPCAT")) %>%
mutate(pp_CLR = pp_Ae / AUC * 1000 / 60) %>%
glimpse()

## Add all require variables -----
pp_AUC$PPTESTCD <- "AUCLST"
Expand Down Expand Up @@ -140,15 +162,25 @@ pp_tmax$PPORRESU <- "h"
pp_tmax$PPORRES <- pp_tmax$TMAX
# R2ADJ C85553 R Squared Adjusted

# Urine parameters
pp_Ae$PPTESTCD <- "RCAMINT"
pp_Ae$PPTEST <- "Ae"
pp_Ae$PPORRESU <- "mg"
pp_Ae$PPORRES <- pp_Ae$pp_Ae

pp_CLR$PPTESTCD <- "RENALCL"
pp_CLR$PPTEST <- "CLR"
pp_CLR$PPORRESU <- "mL/min"
pp_CLR$PPORRES <- pp_CLR$pp_CLR


## Join all data ----
PP <- bind_rows(pp_tmax, pp_npts, pp_lambda, pp_Ke, pp_cmax, pp_Clast, pp_AUC, pp_AUC_inf)
PP <- bind_rows(pp_tmax, pp_npts, pp_lambda, pp_Ke, pp_cmax, pp_Clast, pp_AUC, pp_AUC_inf, pp_Ae, pp_CLR)

# Constant variables
PP$PPCAT <- "COMPARTMENTAL"
PP$PPSTRESC <- PP$PPORRES
PP$PPSTRESN <- PP$PPORRES
PP$PPSTRESU <- PP$PPORRESU
PP$PPSPEC <- "PLASMA"
PP$DOMAIN <- "PP"

## Sort ----
Expand Down
Binary file modified data/pc.rda
Binary file not shown.
Binary file modified data/pp.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/pc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/pp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading