Skip to content

Add possibility for left-truncation to ppc_km_overlay() and ppc_km_overlay_grouped() #347

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

Merged
merged 14 commits into from
May 9, 2025

Conversation

Sakuski
Copy link
Contributor

@Sakuski Sakuski commented Apr 29, 2025

Fixes #290

Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

Thank you for the pull request! I made one comment on the code about adding documentation for the new argument. In addition to that I'm noticing a few issues with new warnings and errors in the tests for ppc_km_overlay and ppc_km_overlay_grouped. In the file tests/testthat/test-ppc-censoring.R all of the examples tested now have a warning:

Warning message:
In survival::Surv(time = data$left_trunc, time2 = data$value, event = data$group) :
  Stop time must be > start time, NA created

Also, all of the "visual tests" that test that the plot doesn't look different are failing, indicating that the functions produce different plots now even when left_truncation_y is NULL.

Any idea what's going on?

Thanks again for the PR, it's great to have new contributors!

@Sakuski Sakuski requested a review from jgabry May 6, 2025 12:53
@jgabry
Copy link
Member

jgabry commented May 7, 2025

Thanks! Sorry for the delay in getting back to you, I've been traveling. I'll be able to take a look again hopefully tomorrow (or possibly later this week).

Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

Sorry again for the delay in looking at this again. This looks great. Thanks for adding the tests. I made a few small commits:

  • the random number generation in the test code was affecting some of the data for other tests unrelated to this, which wasn't your fault
  • I added a test for left_truncation_y error message
  • I also took this opportunity to add tests for the status_y error messages, which I noticed we didn't have before

I think this is basically ready to be merged now, except there's just one thing I just noticed that may or may not be an issue. I get a warning when I run the example you added to the documentation:

> # With left-truncation (delayed entry) times:
> left_truncation_y <- runif(length(y), min = 0, max = 0.6) * y
> 
> ppc_km_overlay(y, yrep[1:25, ], status_y = status_y,
+                left_truncation_y = left_truncation_y)
Warning message:
In survival::Surv(time = left_truncation_y[data$y_id], time2 = data$value,  :
  Stop time must be > start time, NA created

Is that to be expected?

Comment on lines 61 to 66
#' # With left-truncation (delayed entry) times:
#' left_truncation_y <- runif(length(y), min = 0, max = 0.6) * y
#' \donttest{
#' ppc_km_overlay(y, yrep[1:25, ], status_y = status_y,
#' left_truncation_y = left_truncation_y)
#' }
Copy link
Member

Choose a reason for hiding this comment

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

I get a warning when I try this example:

Warning message:
In survival::Surv(time = left_truncation_y[data$y_id], time2 = data$value,  :
  Stop time must be > start time, NA created

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The warning was to be expected in case of that example, but I made a cleaner example that does not produce warnings. In addition, I think the new example visualizes the effect of left-truncation a bit better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In real life, the warning is an indication of an impossible observation or posterior predictive draw, so the warning itself is good. When creating examples, we just have to make sure that each value in left_truncation_y is lower than the corresponding value in y or corresponding values in yrep so we don't get the warning.

Copy link
Member

Choose a reason for hiding this comment

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

Ok great, thanks, that makes sense.

@codecov-commenter
Copy link

codecov-commenter commented May 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.60%. Comparing base (0d891a2) to head (0044845).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #347   +/-   ##
=======================================
  Coverage   98.60%   98.60%           
=======================================
  Files          35       35           
  Lines        5533     5539    +6     
=======================================
+ Hits         5456     5462    +6     
  Misses         77       77           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

I think this is ready to merge. I’ll let the tests finish running and if everything passes I’ll go ahead and merge it later tonight or tomorrow. Thanks again for the PR

@Sakuski
Copy link
Contributor Author

Sakuski commented May 9, 2025

@jgabry Before you merge, I think you should generate a new .Rd file for PPC-censoring, since I changed the example in my last commit. I didn't think of that yesterday.

@jgabry
Copy link
Member

jgabry commented May 9, 2025

@jgabry Before you merge, I think you should generate a new .Rd file for PPC-censoring, since I changed the example in my last commit. I didn't think of that yesterday.

Will do. And actually I just noticed one more issue. The object min_vals in the example code is never defined anywhere so it errors.

Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

The last thing before we merge is to define the min_vals object in the example

@Sakuski Sakuski requested a review from jgabry May 9, 2025 17:44
Copy link
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

Thanks, looks good now. I just regenerated the Rd file and triggered the unit tests to run again. Assuming everything passes (I assume it will) we can merge this!

@jgabry
Copy link
Member

jgabry commented May 9, 2025

Merging now, thanks again!

@jgabry jgabry merged commit 23e00b5 into stan-dev:master May 9, 2025
6 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
Development

Successfully merging this pull request may close these issues.

ppc_km_overlay(): add argument for left-truncation?
3 participants