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

Multiple dose AUC with actual times #140

Closed
fisherjm opened this issue Mar 16, 2021 · 2 comments
Closed

Multiple dose AUC with actual times #140

fisherjm opened this issue Mar 16, 2021 · 2 comments

Comments

@fisherjm
Copy link

Is it possible to individualize start and/or stop times with manual interval specifications. For example, if I have the following data and time is TAFD, how could I specify that for subject 1, arm 1 the first dose was administered at time=264.2 so I want AUC with start=264.2 and end =288.2. While for subject 2, arm 1 the interval I want is for 264-288? If I specify a manual interval with start=264 and end=288, I don't get an AUC for subject 1.

With the same example, you'll notice the concentration for subject 2 at time=288 is missing. If I wanted another AUC interval from 288-312 for all subjects, the AUC is not calculated for this subject. Do I have to insert records at every time specified in my manual_interval in order to get AUC?

I hope that was clear.

e.dat <- data.frame(conc=c(0.5,2,5,9.2,12,2,1.85,1.08,0.5,0.3,2.4,4.5,10.2,15,2.6,1.65,1.1,
                           0.5,2,5,9.2,12,2,1.85,1.08,NA,0.3,2.4,4.5,10.2,15,2.6,1.65,1.1),
                    time=c(seq(264.2,312.2,3),seq(264,312,3)),
                    ARM=rep(c(rep(1,8),rep(2,9)),2),
                    SUBJ=c(rep(1,17),rep(2,17)),
                    Dose=c(rep(5,17)),rep(5,17))
 
## Generate the dosing data
d_dose <- e.dat %>% distinct(SUBJ,Dose,ARM) %>% mutate(time=rep(c(264,288),2))
# d_dose$Time <- 0

conc_obj <-
  PKNCAconc(
    e.dat,
    conc~time|SUBJ + ARM
  )
dose_obj <-
  PKNCAdose(
    d_dose,
    Dose~time|SUBJ + ARM
  )  
## Calculate the NCA parameters
intervals_manual <- data.frame(start = c(264,  288),
                               end =   c(288, 312),
                               auclast=c(TRUE,TRUE),
                               aucall=c(TRUE,TRUE),
                               tlast=c(TRUE,TRUE))

data_obj <- PKNCAdata(conc_obj, dose_obj, intervals=intervals_manual)

results_obj <- pk.nca(data_obj)
as.data.frame(results_obj, out.format = "wide")
              
@billdenney
Copy link
Owner

I have converted your code into a reprex and added the option to show all warnings to help clarify my responses below:

library(PKNCA)
library(tidyverse, quietly=TRUE)
#> Warning: package 'tibble' was built under R version 4.0.4
options(warn=1)

e.dat <-
  data.frame(
    conc=c(0.5,2,5,9.2,12,2,1.85,1.08,0.5,0.3,2.4,4.5,10.2,15,2.6,1.65,1.1,
           0.5,2,5,9.2,12,2,1.85,1.08,NA,0.3,2.4,4.5,10.2,15,2.6,1.65,1.1),
    time=c(seq(264.2,312.2,3),seq(264,312,3)),
    ARM=rep(c(rep(1,8),rep(2,9)),2),
    SUBJ=c(rep(1,17),rep(2,17)),
    Dose=c(rep(5,17)),rep(5,17)
  )

## Generate the dosing data
d_dose <- e.dat %>% distinct(SUBJ,Dose,ARM) %>% mutate(time=rep(c(264,288),2))
# d_dose$Time <- 0

conc_obj <-
  PKNCAconc(
    e.dat,
    conc~time|SUBJ + ARM
  )
dose_obj <-
  PKNCAdose(
    d_dose,
    Dose~time|SUBJ + ARM
  )  
## Calculate the NCA parameters
intervals_manual <- data.frame(start = c(264,  288),
                               end =   c(288, 312),
                               auclast=c(TRUE,TRUE),
                               aucall=c(TRUE,TRUE),
                               tlast=c(TRUE,TRUE))

data_obj <- PKNCAdata(conc_obj, dose_obj, intervals=intervals_manual)

results_obj <- pk.nca(data_obj)
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (0.2) is not
#> allowed
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (0.2) is not
#> allowed
#> Warning in FUN(X[[i]], ...): Error with interval SUBJ=1, ARM=1, start=288,
#> end=312: No data for interval
#> Warning in FUN(X[[i]], ...): Error with interval SUBJ=1, ARM=2, start=264,
#> end=288: No data for interval
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (0.2) is not
#> allowed

#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (0.2) is not
#> allowed
#> Warning in FUN(X[[i]], ...): Error with interval SUBJ=2, ARM=1, start=288,
#> end=312: No data for interval
#> Warning in check.conc.time(conc, time): All concentration data is missing

#> Warning in check.conc.time(conc, time): All concentration data is missing

#> Warning in check.conc.time(conc, time): All concentration data is missing
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (3) is not
#> allowed

#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (3) is not
#> allowed
as.data.frame(results_obj, out.format = "wide")
#>   start end SUBJ ARM exclude   aucall  auclast tlast
#> 1   264 288    1   1    <NA>       NA       NA  21.2
#> 2   264 288    2   1    <NA> 94.15728 94.15728  21.0
#> 3   264 288    2   2    <NA>       NA       NA    NA
#> 4   288 312    1   2    <NA>       NA       NA  21.2
#> 5   288 312    2   2    <NA>       NA       NA  24.0

Created on 2021-03-17 by the reprex package (v1.0.0)

@billdenney
Copy link
Owner

PKNCA does not impute before the beginning of the interval. That is (currently) a required data management step before putting your data into PKNCAconc() and PKNCAdose().

One challenge with the way your data are setup is that the ARM column appears to change at 288 hours and you appear to want to have different summaries for ARM == 1 and ARM == 2. Since the grouping variables switch at 288 hours (with the 288 hr time point uniquely in ARM == 2), the ARM == 1 group will not see the 288 hour time point. I assume that is not your goal (but, let me know if I'm wrong in that assumption).

With that assumption, I would setup your grouping to only have the SUBJ column and not ARM and then do subsequent summaries based on time points.

The next question is about how to individualize the intervals. You can add any group to an interval specification, and the interval will only apply to that group. So, in the code below, I have made the start and end times subject-specific by adding a SUBJ column to the intervals. (It doesn't matter how you create the data.frame, and while testing this, there appears to be some error when the intervals are a tibble instead of a data.frame. For the time being, please cast any tibbles to data.frames. I will work on that in #141.)

In the example below, the only missing result is due to the missing value at time 288 for SUBJ == 2. To fix that, you will need to manually impute the concentration at time 288 for that subject before sending the dataset in for analysis (i.e. update e.dat where time == 288 & SUBJ == 2).

library(PKNCA)
library(tidyverse, quietly=TRUE)
#> Warning: package 'tibble' was built under R version 4.0.4
options(warn=1)

e.dat <-
  data.frame(
    conc=c(0.5,2,5,9.2,12,2,1.85,1.08,0.5,0.3,2.4,4.5,10.2,15,2.6,1.65,1.1,
           0.5,2,5,9.2,12,2,1.85,1.08,NA,0.3,2.4,4.5,10.2,15,2.6,1.65,1.1),
    time=c(seq(264.2,312.2,3),seq(264,312,3)),
    ARM=rep(c(rep(1,8),rep(2,9)),2),
    SUBJ=c(rep(1,17),rep(2,17)),
    Dose=c(rep(5,17)),rep(5,17)
  )

## Generate the dosing data
d_dose <- e.dat %>% distinct(SUBJ,Dose,ARM) %>% mutate(time=rep(c(264,288),2))
# d_dose$Time <- 0

conc_obj <-
  PKNCAconc(
    e.dat,
    conc~time|SUBJ
  )
dose_obj <-
  PKNCAdose(
    d_dose,
    Dose~time|SUBJ
  )  
## Calculate the NCA parameters
intervals_manual_first <-
  e.dat %>%
  group_by(SUBJ) %>%
  summarize(
    start=time[between(time, 264, 265)],
    end=time[between(time, 288, 289)]
  )
intervals_manual_second <-
  e.dat %>%
  group_by(SUBJ) %>%
  summarize(
    start=time[between(time, 288, 289)],
    end=time[between(time, 312, 313)]
  )
intervals_manual <-
  bind_rows(intervals_manual_first, intervals_manual_second) %>%
  mutate(
    auclast=TRUE,
    aucall=TRUE,
    tlast=TRUE
  )
as.data.frame(intervals_manual)
#>   SUBJ start   end auclast aucall tlast
#> 1    1 264.2 288.2    TRUE   TRUE  TRUE
#> 2    2 264.0 288.0    TRUE   TRUE  TRUE
#> 3    1 288.2 312.2    TRUE   TRUE  TRUE
#> 4    2 288.0 312.0    TRUE   TRUE  TRUE

# There is some other issue here where intervals are having an issue being a tibble
data_obj <- PKNCAdata(conc_obj, dose_obj, intervals=as.data.frame(intervals_manual))

results_obj <- pk.nca(data_obj)
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (3) is not
#> allowed
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (3) is not
#> allowed
as.data.frame(results_obj, out.format = "wide")
#>   start   end SUBJ exclude    aucall   auclast tlast
#> 1 264.0 288.0    2    <NA>  94.15728  94.15728    21
#> 2 264.2 288.2    1    <NA>  96.41671  96.41671    24
#> 3 288.0 312.0    2    <NA>        NA        NA    24
#> 4 288.2 312.2    1    <NA> 106.98769 106.98769    24

Created on 2021-03-17 by the reprex package (v1.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants