diff --git a/NEWS.md b/NEWS.md index b06984e..62df931 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/data-raw/pc.R b/data-raw/pc.R index 413d630..f176ab7 100644 --- a/data-raw/pc.R +++ b/data-raw/pc.R @@ -8,6 +8,7 @@ library(dplyr) library(lubridate) library(labelled) library(admiral) +library(ggplot2) # Create pc ---- data("ex") @@ -64,6 +65,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 @@ -83,10 +87,34 @@ 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" + ), + PCTPTNUM = case_when( + PCTPT == "0-6h Post-dose" ~ 3, + PCTPT == "6-12h Post-dose" ~ 9, + PCTPT == "12-24h Post-dose" ~ 18, + PCTPT == "24-48h Post-dose" ~ 37 + ), + Conc = Urine + ) + +PC <- bind_rows(PC, PC_Urine) ## Concentration-related code ---- ### Remove neg values due to pre-dose negative time ---- @@ -105,13 +133,6 @@ PC$Conc <- ifelse(PC$Conc < 0.01, "% + group_by(STUDYID, USUBJID) %>% + dplyr::mutate(PCSEQ = row_number()) + ## Select vars of interest ---- PC <- subset(PC, select = c( "STUDYID", "DOMAIN", "USUBJID", "PCSEQ", "PCTESTCD", "PCTEST", @@ -157,8 +183,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() diff --git a/data-raw/pp.R b/data-raw/pp.R index ed8ff7d..315863a 100644 --- a/data-raw/pp.R +++ b/data-raw/pp.R @@ -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 @@ -52,22 +61,22 @@ 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) @@ -75,28 +84,41 @@ models <- plyr::dlply(pc3, c("STUDYID", "DOMAIN", "USUBJID"), function(df) { # 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" @@ -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 ---- diff --git a/data/pc.rda b/data/pc.rda index da0c1d3..1b5d3c4 100644 Binary files a/data/pc.rda and b/data/pc.rda differ diff --git a/data/pp.rda b/data/pp.rda index 852a978..edce1cf 100644 Binary files a/data/pp.rda and b/data/pp.rda differ diff --git a/man/pc.Rd b/man/pc.Rd index c4d103f..4748b75 100644 --- a/man/pc.Rd +++ b/man/pc.Rd @@ -5,7 +5,7 @@ \alias{pc} \title{Pharmacokinetics Concentrations Dataset} \format{ -An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 3556 rows and 20 columns. +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4572 rows and 20 columns. } \source{ \url{https://github.com/pharmaverse/pharmaversesdtm/blob/main/data/pc.rda} diff --git a/man/pp.Rd b/man/pp.Rd index 06bc06e..981578a 100644 --- a/man/pp.Rd +++ b/man/pp.Rd @@ -5,7 +5,7 @@ \alias{pp} \title{Pharmacokinetic Parameters Dataset} \format{ -An object of class \code{data.frame} with 2352 rows and 14 columns. +An object of class \code{data.frame} with 2688 rows and 14 columns. } \source{ \url{https://github.com/pharmaverse/pharmaversesdtm/blob/main/data/pp.rda}