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

Enhancement request: Allow exclusion based on adjusted r^2 #317

Open
Andy00000000000 opened this issue Oct 9, 2024 · 3 comments
Open

Enhancement request: Allow exclusion based on adjusted r^2 #317

Andy00000000000 opened this issue Oct 9, 2024 · 3 comments

Comments

@Andy00000000000
Copy link

Hi,

Really great package that makes NCA quite easy, thank you for that contribution!

I was wondering if there is an option for implementing lambda z/half-life exclusion from summary statistic tables using adjusted r2 (i.e., $min.hl.r.squared but for adj.r.squared)?

Thanks,

Andy

@billdenney billdenney changed the title Question/Enhancement request Enhancement request: Allow exclusion based on adjusted r^2 Oct 9, 2024
@billdenney
Copy link
Owner

Currently, the exclusion is only setup based on r-squared and not adjusted. It's a good suggestion to add, so I will do so.

@Andy00000000000
Copy link
Author

Great, looking forward to it, thanks!

As a short-term workaround (which appears to be working as intended after manually checking) I copied the exclude_nca_min.hl.r.squared function and modified to pull adj.r.squared while still utilizing the min.hl.r.squared option; then passed the modified function into the exclude() call.

exclude_nca_min.hl.adj.r.squared <- function (min.hl.r.squared){
  affected_parameters <- get.parameter.deps("half.life")
  missing_min.hl.r.squared <- missing(min.hl.r.squared)
  function(x, ...) {
    if (missing_min.hl.r.squared) {
      min.hl.r.squared <- PKNCA.options("min.hl.r.squared")
    }
    ret <- rep(NA_character_, nrow(x))
    if (!is.na(min.hl.r.squared)) {
      idx_r.squared <- which(x$PPTESTCD %in% "adj.r.squared")
      if (length(idx_r.squared) == 0) {
      }
      else if (length(idx_r.squared) == 1) {
        current_r.squared <- x$PPORRES[idx_r.squared]
        drop_r.squared <- !is.na(current_r.squared) &
          current_r.squared < min.hl.r.squared
        if (drop_r.squared) {
          ret[x$PPTESTCD %in% affected_parameters] <- sprintf("Half-life adj.r-squared < %g",
                                                              min.hl.r.squared)
        }
      }
      else if (length(idx_r.squared) > 1) {
        stop("Should not see more than one r.squared (please report this as a bug)")
      }
    }
    ret
  }
}

o_result1 <- exclude(o_result1,FUN = exclude_nca_min.hl.adj.r.squared())

@billdenney
Copy link
Owner

Yep, that's a perfect work-around. The final solution within the package will look very similar to that (with more documentation, tests, etc.).

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

When branches are created from issues, their pull requests are automatically linked.

2 participants