billdenney/pknca

AUClast is not estimated

suramanitha opened this issue · 4 comments

I am testing a data set in PKNCA for NCA parameters, however I am unable to get AUClast. I am not sure what is missing, my conc vs time plots look good as well

Below is the code I used:
myconc <- PKNCAconc(data=myrawconcdata,
formula=Concentration~Time|Subject)
mydata <- PKNCAdata(myconc,
intervals=data.frame(start=c(0,0), end=c(29, Inf),
tmax=TRUE,
cmax=TRUE,
tlast=TRUE,
auclast =c(TRUE,TRUE)
))

knitr::kable(PKNCA.options("single.dose.aucs"))
myresults <- pk.nca(mydata)
kable(as.data.frame(myresults))

summary(myresults)

start end N auclast cmax tmax tlast
0 29 4 NC 15400 18.5 [11.0, 29.0] 29.0 [29.0, 29.0]
0 Inf 4 NC 15400 18.5 [11.0, 29.0] 75.0 [60.0, 90.0]

I'm not certain how you generated myrawconcdata from the source data. I think that the underlying issue is that you likely ran as.numeric() on the concentration data without handling the "Not Detected" values (or equivalently filtered out the "Not Detected" rows). Setting those to zero and converting to numeric appears to fix the issue.

Can you confirm that this is what you were expecting?

library(rio)
library(PKNCA)
myrawconcdata <- import("https://github.com/billdenney/pknca/files/6689350/NCA_df.xls")
myconc <- PKNCAconc(data=myrawconcdata,
                    formula=Concentration~Time|Subject)
mydata <- PKNCAdata(myconc,
                    intervals=data.frame(start=c(0,0), end=c(29, Inf),
                                         tmax=TRUE,
                                         cmax=TRUE,
                                         tlast=TRUE,
                                         auclast =c(TRUE,TRUE)
                    ))

# Issue, concentrations are not numeric
myresults <- pk.nca(mydata)
#> No dose information provided, calculations requiring dose will return NA.
#> Error in check.conc.time(conc, time): Error with interval Subject=31002, start=0, end=29: Concentration data must be numeric and not a factor

# Make concentrations numeric (replicate what I think was the previous issue,
# note the warning, "NAs introduced by coercion")
numeric_conc_with_na <- myrawconcdata
numeric_conc_with_na$Concentration <- as.numeric(numeric_conc_with_na$Concentration)
#> Warning: NAs introduced by coercion
myconc <- PKNCAconc(data=numeric_conc_with_na,
                    formula=Concentration~Time|Subject)
mydata <- PKNCAdata(myconc,
                    intervals=data.frame(start=c(0,0), end=c(29, Inf),
                                         tmax=TRUE,
                                         cmax=TRUE,
                                         tlast=TRUE,
                                         auclast =c(TRUE,TRUE)
                    ))
# warnings indicating the issue is that the AUC will not be calculated when the
# starting time is before the first measurement time
myresults <- pk.nca(mydata)
#> No dose information provided, calculations requiring dose will return NA.
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (8) is not
#> allowed
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (8) is not
#> allowed

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

#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (8) is not
#> allowed
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (4) is not
#> allowed

#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (4) is not
#> allowed
#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (8) is not
#> allowed

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

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

#> Warning in pk.calc.auxc(conc = conc, time = time, ..., options = options, :
#> Requesting an AUC range starting (0) before the first measurement (8) is not
#> allowed
as.data.frame(myresults)
#>    start end Subject PPTESTCD   PPORRES exclude
#> 1      0  29   31002  auclast        NA    <NA>
#> 2      0  29   31002     cmax 513291.60    <NA>
#> 3      0  29   31002     tmax     22.00    <NA>
#> 4      0  29   31002    tlast     29.00    <NA>
#> 5      0 Inf   31002  auclast        NA    <NA>
#> 6      0 Inf   31002     cmax 513291.60    <NA>
#> 7      0 Inf   31002     tmax     22.00    <NA>
#> 8      0 Inf   31002    tlast     90.00    <NA>
#> 9      0  29   31003  auclast        NA    <NA>
#> 10     0  29   31003     cmax 145025.68    <NA>
#> 11     0  29   31003     tmax     29.00    <NA>
#> 12     0  29   31003    tlast     29.00    <NA>
#> 13     0 Inf   31003  auclast        NA    <NA>
#> 14     0 Inf   31003     cmax 145025.68    <NA>
#> 15     0 Inf   31003     tmax     29.00    <NA>
#> 16     0 Inf   31003    tlast     29.00    <NA>
#> 17     0  29   91001  auclast        NA    <NA>
#> 18     0  29   91001     cmax   2688.58    <NA>
#> 19     0  29   91001     tmax     29.00    <NA>
#> 20     0  29   91001    tlast     29.00    <NA>
#> 21     0 Inf   91001  auclast        NA    <NA>
#> 22     0 Inf   91001     cmax   2688.58    <NA>
#> 23     0 Inf   91001     tmax     29.00    <NA>
#> 24     0 Inf   91001    tlast     60.00    <NA>
#> 25     0  29   91002  auclast        NA    <NA>
#> 26     0  29   91002     cmax   4065.34    <NA>
#> 27     0  29   91002     tmax     15.00    <NA>
#> 28     0  29   91002    tlast     29.00    <NA>
#> 29     0 Inf   91002  auclast        NA    <NA>
#> 30     0 Inf   91002     cmax   4065.34    <NA>
#> 31     0 Inf   91002     tmax     15.00    <NA>
#> 32     0 Inf   91002    tlast     90.00    <NA>
#> 33     0  29  111001  auclast        NA    <NA>
#> 34     0  29  111001     cmax  10033.27    <NA>
#> 35     0  29  111001     tmax     11.00    <NA>
#> 36     0  29  111001    tlast     29.00    <NA>
#> 37     0 Inf  111001  auclast        NA    <NA>
#> 38     0 Inf  111001     cmax  10033.27    <NA>
#> 39     0 Inf  111001     tmax     11.00    <NA>
#> 40     0 Inf  111001    tlast     60.00    <NA>
summary(myresults)
#>  start end N auclast         cmax              tmax             tlast
#>      0  29 5      NC 24100 [1430] 22.0 [11.0, 29.0] 29.0 [29.0, 29.0]
#>      0 Inf 5      NC 24100 [1430] 22.0 [11.0, 29.0] 60.0 [29.0, 90.0]
#> 
#> Caption: auclast, cmax: geometric mean and geometric coefficient of variation; tmax, tlast: median and range

# Make concentrations numeric (replicate what I think was the previous issue,
# note the warning, "NAs introduced by coercion")
numeric_conc_without_na <- myrawconcdata
numeric_conc_without_na$Concentration[numeric_conc_without_na$Concentration == "Not Detected"] <- 0
# It is still a character vector
numeric_conc_without_na$Concentration
#>  [1] "0"                  "0"                  "0"                 
#>  [4] "8152.5900000000001" "131055.08"          "485765.44"         
#>  [7] "513291.59999999998" "510105.15000000002" "411936.07000000001"
#> [10] "351694.02000000002" "215456.22"          "0"                 
#> [13] "0"                  "0"                  "252.22"            
#> [16] "244.31999999999999" "312.63"             "27438.02"          
#> [19] "145025.67999999999" "0"                  "0"                 
#> [22] "233.28"             "1354.6099999999999" "1991.0599999999999"
#> [25] "1927.4000000000001" "2056.96"            "2688.5799999999999"
#> [28] "1974.8"             "439.37"             "0"                 
#> [31] "0"                  "1078.6700000000001" "3066.52"           
#> [34] "4065.3400000000001" "2310.21"            "963.85000000000002"
#> [37] "157.50999999999999" "61.549999999999997" "71.909999999999997"
#> [40] "0"                  "0"                  "0"                 
#> [43] "2862.2399999999998" "10033.27"           "435.98000000000002"
#> [46] "256.27999999999997" "275.48000000000002" "0"
# Make it numeric (note that there are no warnings this time)
numeric_conc_without_na$Concentration <- as.numeric(numeric_conc_without_na$Concentration)
numeric_conc_without_na$Concentration
#>  [1]      0.00      0.00      0.00   8152.59 131055.08 485765.44 513291.60
#>  [8] 510105.15 411936.07 351694.02 215456.22      0.00      0.00      0.00
#> [15]    252.22    244.32    312.63  27438.02 145025.68      0.00      0.00
#> [22]    233.28   1354.61   1991.06   1927.40   2056.96   2688.58   1974.80
#> [29]    439.37      0.00      0.00   1078.67   3066.52   4065.34   2310.21
#> [36]    963.85    157.51     61.55     71.91      0.00      0.00      0.00
#> [43]   2862.24  10033.27    435.98    256.28    275.48      0.00
myconc <- PKNCAconc(data=numeric_conc_without_na,
                    formula=Concentration~Time|Subject)
mydata <- PKNCAdata(myconc,
                    intervals=data.frame(start=c(0,0), end=c(29, Inf),
                                         tmax=TRUE,
                                         cmax=TRUE,
                                         tlast=TRUE,
                                         auclast =c(TRUE,TRUE)
                    ))
# No warnings given about AUC calculations
myresults <- pk.nca(mydata)
#> No dose information provided, calculations requiring dose will return NA.
as.data.frame(myresults)
#>    start end Subject PPTESTCD     PPORRES exclude
#> 1      0  29   31002  auclast  8537334.42    <NA>
#> 2      0  29   31002     cmax   513291.60    <NA>
#> 3      0  29   31002     tmax       22.00    <NA>
#> 4      0  29   31002    tlast       29.00    <NA>
#> 5      0 Inf   31002  auclast 29550799.00    <NA>
#> 6      0 Inf   31002     cmax   513291.60    <NA>
#> 7      0 Inf   31002     tmax       22.00    <NA>
#> 8      0 Inf   31002    tlast       90.00    <NA>
#> 9      0  29   31003  auclast   703113.31    <NA>
#> 10     0  29   31003     cmax   145025.68    <NA>
#> 11     0  29   31003     tmax       29.00    <NA>
#> 12     0  29   31003    tlast       29.00    <NA>
#> 13     0 Inf   31003  auclast   703113.31    <NA>
#> 14     0 Inf   31003     cmax   145025.68    <NA>
#> 15     0 Inf   31003     tmax       29.00    <NA>
#> 16     0 Inf   31003    tlast       29.00    <NA>
#> 17     0  29   91001  auclast    46935.09    <NA>
#> 18     0  29   91001     cmax     2688.58    <NA>
#> 19     0  29   91001     tmax       29.00    <NA>
#> 20     0  29   91001    tlast       29.00    <NA>
#> 21     0 Inf   91001  auclast    92815.28    <NA>
#> 22     0 Inf   91001     cmax     2688.58    <NA>
#> 23     0 Inf   91001     tmax       29.00    <NA>
#> 24     0 Inf   91001    tlast       60.00    <NA>
#> 25     0  29   91002  auclast    55158.96    <NA>
#> 26     0  29   91002     cmax     4065.34    <NA>
#> 27     0  29   91002     tmax       15.00    <NA>
#> 28     0  29   91002    tlast       29.00    <NA>
#> 29     0 Inf   91002  auclast    64099.84    <NA>
#> 30     0 Inf   91002     cmax     4065.34    <NA>
#> 31     0 Inf   91002     tmax       15.00    <NA>
#> 32     0 Inf   91002    tlast       90.00    <NA>
#> 33     0  29  111001  auclast    61098.48    <NA>
#> 34     0  29  111001     cmax    10033.27    <NA>
#> 35     0  29  111001     tmax       11.00    <NA>
#> 36     0  29  111001    tlast       29.00    <NA>
#> 37     0 Inf  111001  auclast    69340.76    <NA>
#> 38     0 Inf  111001     cmax    10033.27    <NA>
#> 39     0 Inf  111001     tmax       11.00    <NA>
#> 40     0 Inf  111001    tlast       60.00    <NA>
summary(myresults)
#>  start end N       auclast         cmax              tmax             tlast
#>      0  29 5 249000 [1310] 24100 [1430] 22.0 [11.0, 29.0] 29.0 [29.0, 29.0]
#>      0 Inf 5 386000 [3060] 24100 [1430] 22.0 [11.0, 29.0] 60.0 [29.0, 90.0]
#> 
#> Caption: auclast, cmax: geometric mean and geometric coefficient of variation; tmax, tlast: median and range

Created on 2021-06-21 by the reprex package (v2.0.0)

Thank you for looking at this. Now i can see the issue. I had converted the "Not detected" as missing in my testing and this resulted in not outputting the AUClast. Then i converted the "Not detected" at Time =0 to 0 , then i was able to see the AUClast. Now the problem is solved.

Great!