Calculate the time since and amount of the last dose. Additional (ADDL
)
dosing records are expanded and included in the calculation.
knitr::opts_chunk$set(comment = '.', message=FALSE, warning = FALSE, fig.path="man/figures/readme-")
remotes::install_github("metrumresearchgroup/lastdose")
library(lastdose) library(tidyverse) theme_set(theme_bw())
We'll use this PK profile as an example
file <- system.file("csv/data1.csv", package = "lastdose") df <- read.csv(file) head(df)
The dosing runs over 12 weeks and there are 3 epochs, with 3 different doses,
most of which are scheduled into the future via ADDL
.
df %>% filter(EVID==1) %>% count(TIME,AMT,ADDL) ggplot(df, aes(TIME,DV)) + geom_line() + theme_bw()
Use the lastdose()
function
df <- lastdose(df) head(df)
Now we have TAD
, TAFD
, and LDOS
in our data set.
ggplot(df, aes(TIME,LDOS)) + geom_line()
ggplot(df, aes(TIME,TAD)) + geom_line()
Observations before doses at the same time by default
ggplot(df, aes(TIME,TAD)) + geom_line() + scale_x_continuous(breaks = seq(0,72,4), limits=c(0,72)) + scale_y_continuous(breaks = seq(0,24,4), limits=c(0,24))
You can also make doses "happen" first
dd <- lastdose(df, addl_ties = "dose_first") ggplot(dd, aes(TIME,TAD)) + geom_line() + scale_x_continuous(breaks = seq(0,72,4), limits=c(0,72)) + scale_y_continuous(breaks = seq(0,24,4), limits=c(0,24))
df2 <- mrgsolve::realize_addl(df) %>% lastdose() ggplot(df2, aes(TIME,TAD)) + geom_line() + scale_x_continuous(breaks = seq(0,72,4), limits = c(0,72)) + scale_y_continuous(breaks = seq(0,24,4))
Same setup as the previous profile, but more individuals.
We have 500K rows and 1000 individuals
file <- system.file("csv/data_big.RDS", package = "lastdose") big <- readRDS(file) dim(big) length(unique(big$ID))
Timing result
system.time(x2 <- lastdose(big))
system.time(x1 <- lastdose(df)) x3 <- filter(x2, big[["ID"]]==1) %>% as.data.frame() all.equal(x1,x3)
When non-dose records happen prior to the first dose, lastdose calculates the time before the first dose (a negative value) for these records.
file <- system.file("csv/data2.csv", package = "lastdose") df <- read_csv(file) lastdose(df) %>% head()
The user can alternatively control what happens for these records
lastdose(df, fill = NA_real_, back_calc=FALSE) %>% head()
See inst/doc/about.md for more details.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.