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

Robustly check if lower bound function is equivalent to fixed gs_b() #413

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

jdblischak
Copy link
Collaborator

@jdblischak jdblischak commented Jun 10, 2024

Closes #411
Follow-up to #408

Here's my attempt at robustly comparing the input lower bound function to gs_b(). Unfortunately there is no test case where fixed_futility_bound evaluates to TRUE. Here is a quick demonstration of how it works:

devtools::load_all(".")

# Function that is equivalent to current gsDesign2::gs_b()
gs_b_yihui <- function(par = NULL, k = NULL, ...) {
  if (is.null(k)) par else par[k]
}

x <- list()
x$input$lower <- gs_b_yihui

gs_b_observed <- try(x$input$lower(par = 4:2, k = 2), silent = TRUE)
gs_b_expected <- gs_b(par = 4:2, k = 2)
fixed_futility_bound <- identical(gs_b_observed, gs_b_expected)
fixed_futility_bound
## [1] TRUE

# Function that is not equivalent to gsDesign2::gs_b()
x$input$lower <- gs_spending_bound

gs_b_observed <- try(x$input$lower(par = 4:2, k = 2), silent = TRUE)
gs_b_observed
## [1] "Error in par$timing : $ operator is invalid for atomic vectors\n"
## attr(,"class")
## [1] "try-error"
## attr(,"condition")
## <simpleError in par$timing: $ operator is invalid for atomic vectors>
gs_b_expected <- gs_b(par = 4:2, k = 2)
fixed_futility_bound <- identical(gs_b_observed, gs_b_expected)
fixed_futility_bound
## [1] FALSE

cc @yihui

@jdblischak jdblischak self-assigned this Jun 10, 2024
Copy link
Contributor

@yihui yihui left a comment

Choose a reason for hiding this comment

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

That sounds like a better approach to me.

Copy link
Collaborator

@LittleBeannie LittleBeannie left a comment

Choose a reason for hiding this comment

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

Thanks, @jdblischak, I like this solution!

I also tried lower = gs_spending_bound, then I have gs_b_observed is an error, leading to a FALSE value of fixed_futility_bound.

@LittleBeannie LittleBeannie merged commit 40f85ad into Merck:main Jun 11, 2024
7 checks passed
@jdblischak jdblischak deleted the compare-2-funcs branch June 11, 2024 16:26
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

Successfully merging this pull request may close these issues.

Robust way to compare 2 functions
4 participants