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

Update Survival Plots #208

Merged
merged 20 commits into from
Sep 20, 2023
Merged

Update Survival Plots #208

merged 20 commits into from
Sep 20, 2023

Conversation

gowerc
Copy link
Collaborator

@gowerc gowerc commented Aug 25, 2023

Closes #200

@danielinteractive - Still a work in progress but just wanted to share my current state to get any initial feedback. Currently I've delegated the process of generating the data to a dedicated predict function so that users can return the underlying data if they want it e.g:

survival_samples <- survival(stan_samples)

pts <- sample(dat_os$pt, 4)
predict(
    survival_samples,
    patients = pts
)

    time       median        lower        upper    group type
1      0 1.000000e+00 1.000000e+00 1.000000e+00 pt_00099 surv
2     10 9.734132e-01 9.692208e-01 9.769738e-01 pt_00099 surv
3     20 9.475333e-01 9.393889e-01 9.544777e-01 pt_00099 surv
4     30 9.223415e-01 9.104752e-01 9.324998e-01 pt_00099 surv
5     40 8.978197e-01 8.824514e-01 9.110277e-01 pt_00099 surv
6     50 8.739497e-01 8.552899e-01 8.900500e-01 pt_00099 surv
7     60 8.507142e-01 8.289654e-01 8.695555e-01 pt_00099 surv
8     70 8.280962e-01 8.034502e-01 8.495328e-01 pt_00099 surv
9     80 8.060794e-01 7.787204e-01 8.299712e-01 pt_00099 surv
...

## Also supports groupings
pts <- list(
    "g1" = sample(dat_os$pt, 3),
    "g2" = sample(dat_os$pt, 5),
    "g3" = sample(dat_os$pt, 10)
)

predict(
    survival_samples,
    patients = pts,
    type = "haz",
    time_grid = c(0, 100, 200)
)

  time      median       lower       upper group type
1    0 0.003011690 0.002616886 0.003464048    g1  haz
2  100 0.003011690 0.002616886 0.003464048    g1  haz
3  200 0.003011690 0.002616886 0.003464048    g1  haz
4    0 0.006655227 0.005623280 0.007806013    g2  haz
5  100 0.006655227 0.005623280 0.007806013    g2  haz
6  200 0.006655227 0.005623280 0.007806013    g2  haz
7    0 0.004403979 0.003879670 0.004916867    g3  haz
8  100 0.004403979 0.003879670 0.004916867    g3  haz
9  200 0.004403979 0.003879670 0.004916867    g3  haz

The autoplot function is now essentially just a thin wrapper around this e.g.

pts <- list(
    "g1" = sample(dat_os$pt, 4),
    "g2" = sample(dat_os$pt, 4)
)

autoplot(
    survival_samples,
    pts,
    type = "cumhaz",
    add_wrap = FALSE
)

image

I still need to re-implement the KM option and need to update all the unit tests accordingly.

Copy link
Collaborator

@danielinteractive danielinteractive left a comment

Choose a reason for hiding this comment

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

Thanks @gowerc yeah sounds good!

@gowerc
Copy link
Collaborator Author

gowerc commented Aug 25, 2023

@danielinteractive - Hmm only thing is it looks like the ggplot2.utils only supports survival estimates for the KM curves.

Options are:

  1. Restrict this feature for type="surv" only
  2. Code something up by hand so that we can support type="cumhaz" as well (not too difficult)

Though for "haz" and "loghaz" I'm not so sure how to proceed. Apparently you can get empirical estimates using muhaz::muhaz (link) though it would not be accurate to call these "km" so would perhaps need to rename the argument add_reference or something like that ?

@danielinteractive
Copy link
Collaborator

We could also add these features to ggplot2.utils (because it is our package). But I would say for now we can restrict to km and put the rest on backlog

@gowerc
Copy link
Collaborator Author

gowerc commented Aug 25, 2023

Makes sense. I've put a backlog item for us here and a enhancement ticket for ggplot2.utils here

@gowerc
Copy link
Collaborator Author

gowerc commented Aug 25, 2023

Ok I think this PR is now feature complete. I just need to do the documentation and unit tests...

pts <- list(
    "g1" = sample(dat_os$pt, 100),
    "g2" = sample(dat_os$pt, 100)
)

autoplot(
    survival_samples,
    pts,
    add_km = TRUE
)

@gowerc gowerc marked this pull request as ready for review September 8, 2023 15:33
@gowerc
Copy link
Collaborator Author

gowerc commented Sep 8, 2023

Hey @danielinteractive , This is now ready for review. Apologies for the delay the documentation and testing ended up being more involved that I was expecting. That being said it should be all ready now (pending any bugs found by the cicd testing)

@gowerc gowerc changed the title DRAFT: Update Survival Plots Update Survival Plots Sep 8, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2023

badge

Code Coverage Summary

Filename                       Stmts    Miss  Cover    Missing
---------------------------  -------  ------  -------  ----------------------
R/DataJoint.R                     27       0  100.00%
R/DataLongitudinal.R              71       0  100.00%
R/DataSurvival.R                  46       0  100.00%
R/defaults.R                      11       6  45.45%   27, 57-84, 111
R/generics.R                      11       1  90.91%   173
R/JointModel.R                    46       5  89.13%   85-99
R/JointModelSamples.R             54       0  100.00%
R/Link.R                           6       0  100.00%
R/LinkGSF.R                       63      12  80.95%   109-120
R/LinkNone.R                       3       1  66.67%   36
R/LinkRandomSlope.R               10       0  100.00%
R/LongitudinalGSF.R               23       0  100.00%
R/LongitudinalModel.R             10       0  100.00%
R/LongitudinalRandomSlope.R       17       1  94.12%   43
R/LongitudinalSamples.R           15       0  100.00%
R/Parameter.R                     12       0  100.00%
R/ParameterList.R                 28       0  100.00%
R/Prior.R                         58       9  84.48%   127-135
R/simulations_gsf.R               43       0  100.00%
R/simulations_os.R                11       5  54.55%   35-39
R/simulations_rs.R                21       0  100.00%
R/simulations.R                   99       1  98.99%   122
R/StanModel.R                      7       0  100.00%
R/StanModule.R                   145       5  96.55%   185-186, 202, 235, 246
R/SurvivalExponential.R            9       0  100.00%
R/SurvivalLoglogistic.R           10      10  0.00%    31-40
R/SurvivalModel.R                 12       0  100.00%
R/SurvivalSamples.R              124       0  100.00%
R/SurvivalWeibullPH.R             10       0  100.00%
R/utilities.R                    146       1  99.32%   13
R/zzz.R                           11      11  0.00%    4-29
TOTAL                           1159      68  94.13%

Diff against main

Filename                 Stmts    Miss  Cover
---------------------  -------  ------  --------
R/DataJoint.R              +19       0  +100.00%
R/generics.R                -1       0  -0.76%
R/JointModel.R              -5      -3  +4.82%
R/JointModelSamples.R      -37       0  +100.00%
R/SurvivalSamples.R        +81       0  +100.00%
R/utilities.R              +30       0  +0.18%
R/zzz.R                     +1      +1  +100.00%
TOTAL                      +88      -2  +0.67%

Results for commit: 642e073

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2023

Unit Tests Summary

    1 files    25 suites   7m 13s ⏱️
  57 tests   56 ✔️ 1 💤 0
228 runs  227 ✔️ 1 💤 0

Results for commit 6c42723.

♻️ This comment has been updated with latest results.

@gowerc gowerc mentioned this pull request Sep 8, 2023
@danielinteractive danielinteractive self-assigned this Sep 18, 2023
Copy link
Collaborator

@danielinteractive danielinteractive left a comment

Choose a reason for hiding this comment

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

thx Craig, just a few minor things below

R/generics.R Outdated Show resolved Hide resolved
R/utilities.R Outdated Show resolved Hide resolved
R/utilities.R Outdated Show resolved Hide resolved
@gowerc
Copy link
Collaborator Author

gowerc commented Sep 19, 2023

Hey @danielinteractive , Think I addressed all your comments. I also changed the documentation for the SurvivalSamples to be a single page with the constructor (not sure why I hadn't done this). Appears to be an package version issue with the lintr which I've raised a query about with the IDR guys.

@gowerc gowerc merged commit 7d06fe0 into main Sep 20, 2023
@gowerc gowerc deleted the feature/survival_plot branch September 20, 2023 15:37
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.

Create a unified survival plot
2 participants