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

Bug: AUC start 0 (which also needs Feature: C0 imputation) #138

Merged
merged 91 commits into from
Jan 17, 2025

Conversation

Gero1999
Copy link
Collaborator

@Gero1999 Gero1999 commented Nov 27, 2024

Issue

Closes #2 #60

Description

After running NCA, AUC calculations always consider the discrete start (start at where first concentration sample was collected). This can indeed alter slightly the real values of the AUC. This is a consequence of 2 problems:

  1. Doses times are being considered at the first measure, instead of at the real dose time
  2. No imputed measure at dose time is consdiered

Change description.

Definition of Done

C0 imputation option for the user specified in Setup > Data Selection

How to test

  • At "NCA">"NCA Results", when C0 is imputed it is expected that start=AFRLT-ARRLT (being AFRLT-ARRLT= 0 in DOSNO=1)
  • At "NCA">"NCA Results", when C0 is not imputed it is expected that start={time of 1st observation}
  • AUC values (auclast, aucinf...) from start=AFRLT-ARRLT are calculated when C0 is imputed
  • All variables that should only be based on observed data (cmax, tmax...) are not considering C0 imputations
  • Test that PKNCA also deals well with predoses as duplicates for the NCA
  • Check slope selector plots and NCA results remain well after running NCA
  • Check if in general C0 imputation logic works well (NCA experts):
    if C0 exists ~ C0=C0
    if DOSNO=1 & IV bolus (ADOSEDUR=0, ROUTE=intravascular) ~ C0=0
    if DOSNO>1 & not IV bolus ~ C0=predose
    if IV bolus and monoexponential data ~ logslope
    if IV bolus and not monoexponential data ~ C0=C1

Contributor checklist

  • Code passes lintr checks
  • Code passes all unit tests
  • New logic covered by unit tests
  • New logic is documented

Notes to reviewer

Anything that the reviewer should know before tacking the pull request?

@Gero1999 Gero1999 marked this pull request as draft November 28, 2024 09:37
Merge remote-tracking branch 'origin/main' into bug/auc-start-0

# Conflicts:
#	inst/shiny/tabs/nca.R
#	inst/shiny/tabs/outputs.R
@Gero1999
Copy link
Collaborator Author

Thanks for your reviews and feedback, I hope that now all looks fine! @js3110 @m-kolomanski

Copy link
Collaborator

@m-kolomanski m-kolomanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, looks much better, thank you for all the hard work! I still do have some feedback, most of it regards style and consistency rather thank quality of the code, but also there seems like some of my comments from the previous review were not addressed?

R/PKNCA_impute_method_additions.R Outdated Show resolved Hide resolved
R/PKNCA_impute_method_additions.R Outdated Show resolved Hide resolved
R/PKNCA_impute_method_additions.R Outdated Show resolved Hide resolved
R/create_start_impute.R Show resolved Hide resolved
R/create_start_impute.R Outdated Show resolved Hide resolved
inst/shiny/tabs/nca.R Outdated Show resolved Hide resolved
inst/shiny/tabs/nca.R Outdated Show resolved Hide resolved
inst/shiny/ui.R Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: For all the test files, please utilize describe and it when writing tests, you can check test-general_lineplot.R, test-utils-slope_selector.R or test-utils.R for good examples. Also this blogpost might be useful to better explain the idea behind it.

Comment on lines 74 to 93
mutate(
impute = case_when(
!!sym(time_column) == start & !is.na(!!sym(conc_column)) ~ NA,
DOSNO == 1 &
(tolower(!!sym(route_column)) == "extravascular" |
!!sym(duration_column) > 0 |
!!sym(analyte_column) != !!sym(drug_column)) ~ "start_conc0",
DOSNO > 1 &
(tolower(!!sym(route_column)) == "extravascular" |
!!sym(duration_column) > 0 |
!!sym(analyte_column) != !!sym(drug_column)) ~ "start_predose",
tolower(!!sym(route_column)) == "intravascular" &
!!sym(duration_column) == 0 &
!!sym(analyte_column) == !!sym(drug_column) &
is.possible.c0.logslope ~ "start_logslope",
tolower(!!sym(route_column)) == "intravascular" &
!!sym(duration_column) == 0 &
!!sym(analyte_column) == !!sym(drug_column) ~ "start_c1"
)
) %>%
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this comment seems to not have been resolved at all? It is still quite hard to decipher what exactly we are checking here.

@js3110
Copy link
Collaborator

js3110 commented Jan 15, 2025

@Gero1999 it looks good and thank you for all the hard work on this! Unfortunately I have noticed a couple of things:

  1. In the data selection, after you select analyte and dose number, the table shown does not represent the selections, as I can still see all the dose numbers. We want this table for the user to see exactly the data that will be used for NCA, so either we need to filter the dose number here, or move the dose number selectInput. I will let you decide.
  2. For the dummy data, Doseno >3 does not work and the app crashes. I get the following error: Error in if: argument is of length zero. I double checked and I do not get this issue in main, so it is related to something in this branch. Also, for DOSNO = 2, USUBJID 11102 has empty cells for lambda z calculation, but no explanation why and because of this the slope selection crashes. This could be created as a separate bug issue to fix later or you can see if its something to fix now.

Let me know if you have any questions or want any support :)

@Gero1999 Gero1999 requested a review from m-kolomanski January 16, 2025 16:48
Copy link
Collaborator

@m-kolomanski m-kolomanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my side, looks good! Thank you for all the hard work, this is a lengthy change, sure it was not easy!

I am approving, but before merge, please remove the inst/WORDLIST.txt file, as it is redundant - the spelllcheck only uses WORDLIST file.

Comment on lines +28 to +29
all_concs <- conc[time >= start & time <= end]
all_times <- time[time >= start & time <= end]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, style:

Suggested change
all_concs <- conc[time >= start & time <= end]
all_times <- time[time >= start & time <= end]
all_concs <- conc[time >= start & time <= end]
all_times <- time[time >= start & time <= end]

Comment on lines +79 to +93
impute = case_when(
# Start concentration already present: No imputation (NA)
!!sym(time_column) == start & !is.na(!!sym(conc_column)) ~ NA,

# 1st dose with not IV bolus or analyte =! drug : Start concentration is 0
is.first.dose & (!is.ivbolus | !is.analyte.drug) ~ "start_conc0",

# Posterior doses not IV bolus or analyte =! drug : Start concentration shifts to predose
!is.first.dose & (!is.ivbolus | !is.analyte.drug) ~ "start_predose",

# IV bolus with analyte = drug : Start concentration is log-backextrapolated (if possible)
is.ivbolus & is.analyte.drug & is.possible.c0.logslope ~ "start_logslope",

# IV bolus with analyte = drug and not possible logslope: Start concentration is 1st conc
is.ivbolus & is.analyte.drug ~ "start_c1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks clean, thank you for additional comments with explanations!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue(non-blocking): Please remove this file, it is redundant.

Copy link
Collaborator

@js3110 js3110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !!

@Gero1999 Gero1999 merged commit 64dc3dc into main Jan 17, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants