AUC bug with interval

Hello,

It appears that auc calculations, when an interval is specified, will do the lamdaz calculation, even when it shouldn’t. This results in missing auc, when the lamdaz calculation fails, even though the data is present to calculate the auc on the specified interval.

Hi @donaldlee3, a reproducer would be helpful. I’ve made certain assumptions and tried to reproduce what you are asking for, and here is what I see. Please note the following points:

  1. default NCA.auc computes 0-inf.
  2. when you specify an interval calculation using the kwarg interval = (tstart, tstop), if you are tstop is missing concentration, than the interval calculation will be missing as expected as there is no way of learning what that data point is without having a lambdaz to begin with.

Here is reproducer you can go through and let us know if you still think this is an issue.

julia> using NCA

julia> using PharmaDatasets

julia> df1 = DataFrame(;
                  id = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],
                  time = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4],
                  amt = [10, 0, 0, 0, 0, 10, 0, 0, 0, 0],
                  conc = [missing, 8, 6, 4, 2, missing, 8, 6, missing, missing],
                  route = ["iv", "iv", "iv", "iv", "iv", "iv", "iv", "iv", "iv", "iv"],
              )
10×5 DataFrame
 Row │ id     time   amt    conc     route
     │ Int64  Int64  Int64  Int64?   String
─────┼──────────────────────────────────────
   1 │     1      0     10  missing  iv
   2 │     1      1      0        8  iv
   3 │     1      2      0        6  iv
   4 │     1      3      0        4  iv
   5 │     1      4      0        2  iv
   6 │     2      0     10  missing  iv
   7 │     2      1      0        8  iv
   8 │     2      2      0        6  iv
   9 │     2      3      0  missing  iv
  10 │     2      4      0  missing  iv

julia> ncapop = read_nca(df1)
NCAPopulation (2 subjects):
  Number of missing observations: 4
  Number of blq observations: 0

julia> NCA.lambdaz(ncapop)
[ Info: ID 2 errored: lambdaz calculation needs at least three data points between Cmax and the last positive concentration
2×2 DataFrame
 Row │ id      lambdaz
     │ String  Float64?
─────┼────────────────────────
   1 │ 1             0.549306
   2 │ 2       missing

julia> NCA.auc(ncapop)
[ Info: ID 2 errored: lambdaz calculation needs at least three data points between Cmax and the last positive concentration
2×2 DataFrame
 Row │ id      auc
     │ String  Float64?
─────┼──────────────────────
   1 │ 1            27.9743
   2 │ 2       missing

julia> NCA.auc(ncapop, interval = (0, 2))
2×2 DataFrame
 Row │ id      auc0_2
     │ String  Float64
─────┼─────────────────
   1 │ 1       16.3333
   2 │ 2       16.3333

julia> NCA.auc(ncapop, interval = (0, 3))
[ Info: ID 2 errored: lambdaz calculation needs at least three data points between Cmax and the last positive concentration
2×2 DataFrame
 Row │ id      auc0_3
     │ String  Float64?
─────┼──────────────────────
   1 │ 1            21.3333
   2 │ 2       missing

Hi @vijay,

I’ve identified the source of the problem. I have multiple dose data and group by occasion, as opposed to using ii. I still give the read_NCA time = :time as opposed to time = :tad. It appears that the auc function with a time interval is calculating tad itself for all the occasions, which is resulting in numerical/decimal issues. For example, my last tad should be 27.9999, but if I manually create my own tad column, and give time = :tad to read_NCA, I will get missing from the auc calculation on a time interval, due to the last time being 27.999899999999997.

I have fixed this issue by correcting the numerical issues:
df.tad .= ifelse.(df.tad .> 27, 27.9999, df1.tad)

It would be great if there were a way for the user to not have to deal with these numerical issues.