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

Merging survival curves on a KM fit model #282

Closed
qalid7 opened this issue Jan 17, 2018 · 2 comments
Closed

Merging survival curves on a KM fit model #282

qalid7 opened this issue Jan 17, 2018 · 2 comments

Comments

@qalid7
Copy link

qalid7 commented Jan 17, 2018

First of all, many thanks for this absolutely wonderful package! I use it pretty much on a daily basis!

I've seen the two related issues (#97, #226), and have also tried the useful pairwise_survdiff.R function.

However, my suggestion/request is simpler. How can I merge survival curves within the same fit?

For example, merge the three groups (red, purple and green) in the below fit (into one group/curve) and see how the separation would look like against the cyan group - does that make sense?

Basically, how to produce the survival curves presented as shown in (#97)?

Working on TCGA Lung, I can tell this would be a formidable tool especially when we combine 2+ variables on a KM fit.

PS. I realize sex shouldn't be used in surv_cutpoint, this is just a quick reproducible example.

data(lung)
cut <- surv_cutpoint(lung, time = "time", event = "status", minprop = 0.2,
                             variables = c("ph.ecog", "ph.karno", "pat.karno", "sex"))
cat <- surv_categorize(cut)
fit <- survfit(Surv(time, status) ~ ph.ecog+sex, data = cat)
ggsurvplot(fit, data = cat, risk.table = TRUE, pval=TRUE)

image

Thanks a lot!

@kassambara
Copy link
Owner

Hi,

The easiest way to go is to create a new grouping variable into the cat data frame.

For example:

library(dplyr)

data(lung)
cut <- surv_cutpoint(lung, time = "time", event = "status", minprop = 0.2,
                     variables = c("ph.ecog", "ph.karno", "pat.karno", "sex"))

cat <- surv_categorize(cut)
cat <- cat %>%
  mutate(custom.grps = ifelse(ph.ecog == "low" & sex == "high", 1, 0))

fit <- survfit(Surv(time, status) ~ custom.grps, data = cat)
ggsurvplot(fit, data = cat, risk.table = TRUE, pval=TRUE)

rplot

@qalid7
Copy link
Author

qalid7 commented Jan 22, 2018

Wonderful! Thanks.

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

No branches or pull requests

2 participants