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

Added support of survfitms #177

Merged
merged 6 commits into from Dec 23, 2017
Merged

Added support of survfitms #177

merged 6 commits into from Dec 23, 2017

Conversation

yoursdearboy
Copy link
Contributor

Greetings.

This PR adds support of survfitms - multistate survival models built using Surv(..., type = 'mstate').

Here is an overview of changes to fortify:

  • To preserve original variable name depending on model class (surv or pstate) it is added to the end of the output data.frame;
  • Where necessary checks for variable name are made;
  • If surv.connect = T new rows are repeated according to number of states;
  • In the end columns are sorted to be in usual order.

To autoplot:

  • Added facet_grid support - argument grid. It's more convenient for 2-dim set plots;
  • Added support to swap order of faceting (if facets) or column with rows (if grid). By default event first, then strata. Argument strip_swap;
  • An argument conf.int.group = NULL was added to plot_confint. It's required to split CI ribbons by both - event and strata, because it can't be done with fill only;
  • such artificial column group is assembled in autoplot.

Feedback or questions are welcome.

@lintr-bot
Copy link

R/fortify_surv.R:72:61: style: Commas should always have a space after.

base <- base[rep(seq_len(nrow(base)), length(strata)),]
                                                            ^

R/fortify_surv.R:79:61: style: Commas should always have a space after.

base <- base[rep(seq_len(nrow(base)), length(events)),]
                                                            ^

R/fortify_surv.R:83:32: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                               ^

R/fortify_surv.R:83:43: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                                          ^

R/fortify_surv.R:83:51: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                                                  ^

R/fortify_surv.R:107:11: style: Commas should always have a space after.

d <- d[,intersect(c(
          ^

R/fortify_surv.R:205:18: style: Commas should always have a space after.

plot.data[,'group'] <- plot.data[,group]
                 ^

R/fortify_surv.R:205:41: style: Commas should always have a space after.

plot.data[,'group'] <- plot.data[,group]
                                        ^

R/fortify_surv.R:207:41: style: Commas should always have a space after.

group.levels <- lapply(plot.data[,group], levels)
                                        ^

R/fortify_surv.R:209:45: style: Commas should always have a space after.

group.data <- factor(apply(plot.data[,group], 1, function(x) paste(x, collapse = ' ')), levels = group.levels)
                                            ^

R/fortify_surv.R:210:18: style: Commas should always have a space after.

plot.data[,'group'] <- group.data
                 ^

R/fortify_surv.R:214:60: style: Place a space before left parenthesis, except in a function call.

if ('event' %in% colnames(plot.data)) 'event' else if(grid) '.',
                                                           ^

R/fortify_surv.R:215:62: style: Place a space before left parenthesis, except in a function call.

if ('strata' %in% colnames(plot.data)) 'strata' else if(grid) '.')
                                                             ^

tests/testthat/test-surv.R:170:73: style: Commas should never have a space before.

event = c(1, 1, 1, 1, 2, 2, 2, 2, 'any', 'any' , 'any', 'any'))
                                                                       ~^

tests/testthat/test-surv.R:194:86: style: Commas should never have a space before.

event = c(1, 2, 'any', 1, 1, 1, 1, 2, 2, 2, 2, 'any', 'any' , 'any', 'any'))
                                                                                    ~^

@lintr-bot
Copy link

R/fortify_surv.R:72:61: style: Commas should always have a space after.

base <- base[rep(seq_len(nrow(base)), length(strata)),]
                                                            ^

R/fortify_surv.R:79:61: style: Commas should always have a space after.

base <- base[rep(seq_len(nrow(base)), length(events)),]
                                                            ^

R/fortify_surv.R:83:32: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                               ^

R/fortify_surv.R:83:43: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                                          ^

R/fortify_surv.R:83:51: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                                                  ^

R/fortify_surv.R:107:11: style: Commas should always have a space after.

d <- d[,intersect(c(
          ^

R/fortify_surv.R:205:18: style: Commas should always have a space after.

plot.data[,'group'] <- plot.data[,group]
                 ^

R/fortify_surv.R:205:41: style: Commas should always have a space after.

plot.data[,'group'] <- plot.data[,group]
                                        ^

R/fortify_surv.R:207:41: style: Commas should always have a space after.

group.levels <- lapply(plot.data[,group], levels)
                                        ^

R/fortify_surv.R:209:45: style: Commas should always have a space after.

group.data <- factor(apply(plot.data[,group], 1, function(x) paste(x, collapse = ' ')), levels = group.levels)
                                            ^

R/fortify_surv.R:210:18: style: Commas should always have a space after.

plot.data[,'group'] <- group.data
                 ^

R/fortify_surv.R:214:60: style: Place a space before left parenthesis, except in a function call.

if ('event' %in% colnames(plot.data)) 'event' else if(grid) '.',
                                                           ^

R/fortify_surv.R:215:62: style: Place a space before left parenthesis, except in a function call.

if ('strata' %in% colnames(plot.data)) 'strata' else if(grid) '.')
                                                             ^

tests/testthat/test-surv.R:170:73: style: Commas should never have a space before.

event = c(1, 1, 1, 1, 2, 2, 2, 2, 'any', 'any' , 'any', 'any'))
                                                                       ~^

tests/testthat/test-surv.R:194:86: style: Commas should never have a space before.

event = c(1, 2, 'any', 1, 1, 1, 1, 2, 2, 2, 2, 'any', 'any' , 'any', 'any'))
                                                                                    ~^

1 similar comment
@lintr-bot
Copy link

R/fortify_surv.R:72:61: style: Commas should always have a space after.

base <- base[rep(seq_len(nrow(base)), length(strata)),]
                                                            ^

R/fortify_surv.R:79:61: style: Commas should always have a space after.

base <- base[rep(seq_len(nrow(base)), length(events)),]
                                                            ^

R/fortify_surv.R:83:32: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                               ^

R/fortify_surv.R:83:43: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                                          ^

R/fortify_surv.R:83:51: style: Commas should always have a space after.

base[base$event == 'any',c('pstate','upper','lower')] <- 1.0
                                                  ^

R/fortify_surv.R:107:11: style: Commas should always have a space after.

d <- d[,intersect(c(
          ^

R/fortify_surv.R:205:18: style: Commas should always have a space after.

plot.data[,'group'] <- plot.data[,group]
                 ^

R/fortify_surv.R:205:41: style: Commas should always have a space after.

plot.data[,'group'] <- plot.data[,group]
                                        ^

R/fortify_surv.R:207:41: style: Commas should always have a space after.

group.levels <- lapply(plot.data[,group], levels)
                                        ^

R/fortify_surv.R:209:45: style: Commas should always have a space after.

group.data <- factor(apply(plot.data[,group], 1, function(x) paste(x, collapse = ' ')), levels = group.levels)
                                            ^

R/fortify_surv.R:210:18: style: Commas should always have a space after.

plot.data[,'group'] <- group.data
                 ^

R/fortify_surv.R:214:60: style: Place a space before left parenthesis, except in a function call.

if ('event' %in% colnames(plot.data)) 'event' else if(grid) '.',
                                                           ^

R/fortify_surv.R:215:62: style: Place a space before left parenthesis, except in a function call.

if ('strata' %in% colnames(plot.data)) 'strata' else if(grid) '.')
                                                             ^

tests/testthat/test-surv.R:170:73: style: Commas should never have a space before.

event = c(1, 1, 1, 1, 2, 2, 2, 2, 'any', 'any' , 'any', 'any'))
                                                                       ~^

tests/testthat/test-surv.R:194:86: style: Commas should never have a space before.

event = c(1, 2, 'any', 1, 1, 1, 1, 2, 2, 2, 2, 'any', 'any' , 'any', 'any'))
                                                                                    ~^

@sinhrks
Copy link
Owner

sinhrks commented Nov 14, 2017

Thanks for the PR. Could you fix the Travis failure?

@yoursdearboy
Copy link
Contributor Author

@sinhrks Everything should be ok now. I don't understand why Travis build failed, there's 0 warnings and errors.

@sinhrks
Copy link
Owner

sinhrks commented Dec 2, 2017

Thx! A warning is raised because of a doc issue.

@@ -114,7 +159,9 @@ autoplot.survfit <- function(object, fun = NULL,
conf.int.fill = '#000000', conf.int.alpha = 0.3,
censor = TRUE, censor.colour = NULL, censor.size = 3,
censor.alpha = NULL, censor.shape = '+',
facets = FALSE, nrow = NULL, ncol = 1, scales = 'free_y',
facets = FALSE, nrow = NULL, ncol = 1,
grid = FALSE, strip_swap = FALSE,
Copy link
Owner

Choose a reason for hiding this comment

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

can u add docs for grid and strip_swap?

@sinhrks sinhrks merged commit f2f68ae into sinhrks:master Dec 23, 2017
@sinhrks
Copy link
Owner

sinhrks commented Dec 23, 2017

Thanks! I'll fix the doc issue.

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.

None yet

3 participants