billdenney / pknca

An R package is designed to perform all noncompartmental analysis (NCA) calculations for pharmacokinetic (PK) data.
http://billdenney.github.io/pknca/
GNU Affero General Public License v3.0
67 stars 24 forks source link

Half life with NC values in output #316

Closed danieleboaretti closed 2 weeks ago

danieleboaretti commented 2 weeks ago

Hello,

I would like to report that when there is a subject with an half life that cannot be computed, i.e. it gives as output NC when computed by itself, this information is not reported in the output when the half life is computed in a group with such subject with pk.nca. I think it would be ideal to show a warning in the output and reporting the IDs that have a NC as half life.

Reproducible example for a single ID which gives a NC as half life:

data_conc <- as.data.frame(datasets::Theoph)[datasets::Theoph$Subject == 1, ]

# Manually change the values to get a NC
data_conc[c(5,8,9, 11), "conc"] <- 12
# Keep all points
conc_obj <-
  PKNCAconc(
    data_conc,
    conc~Time|Subject
  )

# Only calculate half-life and parameters required for half-life
current_intervals <- data.frame(start=0, end=Inf, half.life=TRUE)
data_obj <- PKNCAdata(conc_obj, intervals=current_intervals)
result_obj <- pk.nca(data_obj)

# Extract the results for subject 1 
as.data.frame(summary(result_obj))

Output:

  start end N half.life
1     0 Inf 1        NC

Example with a group:

data_conc <- as.data.frame(datasets::Theoph)
# Manually change the values to get a NC only for ID=1
data_conc[datasets::Theoph$Subject == 1,][c(5,8,9, 11), "conc"] <- 12
# Keep all points
conc_obj <-
  PKNCAconc(
    data_conc,
    conc~Time|Subject
  )

# Only calculate half-life and parameters required for half-life
current_intervals <- data.frame(start=0, end=Inf, half.life=TRUE)
data_obj <- PKNCAdata(conc_obj, intervals=current_intervals)
result_obj <- pk.nca(data_obj)

# Extract the results for subject 1 
as.data.frame(summary(result_obj))

Output:

  start end  N    half.life
1     0 Inf 12 7.62 [0.911]

and 7.62 is the arithmetic mean of all half life values except for ID=1. Indeed, without manually setting those values to 12, the half life for the whole group is 8.18 while the half life for ID=1 is 14.3, hence

(8.18*12-14.3)/11=7.62

Moreover, I also highlight that this might be a problem when having other output values like AUC, CMax, and TMax because those values could report N=12 (they are not directly affected by the computation of the AUC), while for half life it should be reported N=11 in the case I showed above.

I hope it is clear.

Thank you for your time

Daniele

billdenney commented 2 weeks ago

Thank you for the report. I think that what you're asking for was implemented in PKNCA version 0.11.0 (see the first bullet of the news here: https://github.com/billdenney/pknca/blob/main/NEWS.md#pknca-0110).

With that, you will see "n = 11" when a summary statistic does not include all 12, as in your example.

Can you please confirm that you're running version 0.11.0 (or the development version) and let me know if that is what you're looking for?

danieleboaretti commented 2 weeks ago

Thank you for your reply, indeed it was version 0.10.2. With the latest version I get the output you mentioned. Still, I think it would be useful also to know which IDs might be not included for further user inspection. It looks to me this information is not reported, right?

billdenney commented 2 weeks ago

The way to find the IDs that are excluded is to look at the "exclude" column and filter for NA values in the PPORRES column when you run as.data.frame(result_obj).

I keep this separate because the purpose of the summary is to provide that summary without going into the details of which may be missing or be excluded. That list can get very long in some cases, so it would overwhelm the summary table.