Skip to content

Comments

Fix bug in ard_survival_survfit() when "=" is in strata variable labels#253

Merged
ddsjoberg merged 6 commits intomainfrom
252_survfit_delim@main
Jan 9, 2025
Merged

Fix bug in ard_survival_survfit() when "=" is in strata variable labels#253
ddsjoberg merged 6 commits intomainfrom
252_survfit_delim@main

Conversation

@edelarua
Copy link
Contributor

@edelarua edelarua commented Jan 7, 2025

What changes are proposed in this pull request?

Closes #252


Pre-review Checklist (if item does not apply, mark is as complete)

  • All GitHub Action workflows pass with a ✅
  • PR branch has pulled the most recent updates from master branch: usethis::pr_merge_main()
  • If a bug was fixed, a unit test was added.
  • If a new ard_*() function was added, it passes the ARD structural checks from cards::check_ard_structure().
  • If a new ard_*() function was added, set_cli_abort_call() has been set.
  • If a new ard_*() function was added and it depends on another package (such as, broom), is_pkg_installed("broom") has been set in the function call and the following added to the roxygen comments: @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom""))
  • Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): devtools::test_coverage()

Reviewer Checklist (if item does not apply, mark is as complete)

  • If a bug was fixed, a unit test was added.
  • Code coverage is suitable for any new functions/features: devtools::test_coverage()

When the branch is ready to be merged:

  • Update NEWS.md with the changes from this pull request under the heading "# cardx (development version)". If there is an issue associated with the pull request, reference it in parentheses at the end update (see NEWS.md for examples).
  • All GitHub Action workflows pass with a ✅
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge" or "Rebase and merge".

@edelarua edelarua added the sme label Jan 7, 2025
@edelarua edelarua changed the title Fix bug in ard_survival_survfit when "=" is in strata variable labels Fix bug in ard_survival_survfit() when "=" is in strata variable labels Jan 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2025

Unit Tests Summary

  1 files  162 suites   1m 11s ⏱️
160 tests 160 ✅ 0 💤 0 ❌
673 runs  673 ✅ 0 💤 0 ❌

Results for commit 1d377c9.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2025

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
ard_attributes.survey.design 💔 $0.02$ $+1.58$ $0$ $-1$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
ard_aod_wald_test 💚 $1.64$ $-1.36$ ard_aod_wald_test_works
ard_attributes.survey.design 💔 $0.02$ $+1.58$ ard_attributes.survey.design_works
ard_continuous.survey.design 💚 $21.80$ $-6.37$ unstratified_ard_continuous.survey.design_works
ard_survival_survfit 👶 $+0.00$ ard_survival_survfit_works_with_in_strata_variable_level_labels
ard_survival_survfit 💔 $1.65$ $+1.11$ ard_survival_survfit_works_with_times_provided
construction_helpers 💔 $0.63$ $+1.71$ construct_model_works
proportion_ci 💔 $0.15$ $+1.53$ check_the_proportion_ci__functions_work

Results for commit 816377c

♻️ This comment has been updated with latest results.

@edelarua edelarua requested a review from ddsjoberg January 7, 2025 21:37
if ("strata" %in% names(ret)) {
ret <- ret %>%
tidyr::separate_wider_delim("strata", "=", names = c("group1", "group1_level"))
tidyr::separate_wider_delim("strata", "=", names = c("group1", "group1_level"), too_many = "merge")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems this code is only run when there is a single stratifying variable, right? Do we know the variable name at this point? Would it be more robust to split this using the variable name, so it's straightforward to split correctly no matter what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point in the function the untidied model is no longer carried over to extract the strata variable name from, and the broom::tidy() results that we have don't include the variable name separately, so I think this is the easiest way to split. Alternatively, we could extract the strata variable name and add it as another argument to the formatting function.

What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I am a little confused. The internals have a function called extract_multi_strata() that processes the stratifying variable names. But there is a condition, that it only parses when there is strictly greater than one stratifying variable. The consequence of this is that when our model has two variables, there was no issue with parsing a level that included an "=" sign. But this section of code is skipped when there is one variable. Can we just change that condition if (length(x_terms) > 0L) ?

extract_multi_strata <- function(x, df_stat) {
  x_terms <- attr(stats::terms(stats::as.formula(x$call$formula)), "term.labels")
  x_terms <- gsub(".*\\(", "", gsub("\\)", "", x_terms))
  if (length(x_terms) > 1) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I am missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, you're correct. I was getting confused by the order that the functions were applied, but I have updated the code to process all strata in the same place now.

@edelarua edelarua requested a review from ddsjoberg January 9, 2025 21:04
Copy link
Collaborator

@ddsjoberg ddsjoberg left a comment

Choose a reason for hiding this comment

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

Beautiful! Thank you for the update!!!

@ddsjoberg ddsjoberg merged commit 41bdebf into main Jan 9, 2025
33 checks passed
@ddsjoberg ddsjoberg deleted the 252_survfit_delim@main branch January 9, 2025 23:05
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ard_survival_survfit fails when stratification variable level includes a "="

2 participants