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

Allow for survfit(..., conf.type = "none") #335

Merged
merged 2 commits into from
Aug 23, 2018

Conversation

HeidiSeibold
Copy link

This works now and did result in an error before:

library("survminer")
#> Loading required package: ggplot2
#> Loading required package: ggpubr
#> Loading required package: magrittr
library("survival")
data("GBSG2", package = "TH.data")


## Cox model
cxmod <- coxph(Surv(time, cens) ~ horTh + tsize, data = GBSG2)

# retrieve survival curve from model
newdat <- expand.grid(horTh = levels(GBSG2$horTh), tsize = quantile(GBSG2$tsize, 
  probs = c(0.25, 0.5, 0.75)))
rownames(newdat) <- letters[1:6]
newdat
#>   horTh tsize
#> a    no    20
#> b   yes    20
#> c    no    25
#> d   yes    25
#> e    no    35
#> f   yes    35


cxsf <- survfit(cxmod, data = GBSG2, newdata = newdat, conf.type = "none")
str(cxsf)
#> List of 10
#>  $ n       : int 686
#>  $ time    : num [1:574] 8 15 16 17 18 29 42 46 57 63 ...
#>  $ n.risk  : num [1:574] 686 685 684 683 681 680 679 678 677 676 ...
#>  $ n.event : num [1:574] 0 0 0 0 0 0 0 0 0 0 ...
#>  $ n.censor: num [1:574] 1 1 1 2 1 1 1 1 1 1 ...
#>  $ surv    : num [1:574, 1:6] 1 1 1 1 1 1 1 1 1 1 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : NULL
#>   .. ..$ : chr [1:6] "a" "b" "c" "d" ...
#>  $ type    : chr "right"
#>  $ cumhaz  : num [1:574, 1:6] 0 0 0 0 0 0 0 0 0 0 ...
#>  $ std.err : num [1:574, 1:6] 0 0 0 0 0 0 0 0 0 0 ...
#>  $ call    : language survfit(formula = cxmod, newdata = newdat, conf.type = "none", data = GBSG2)
#>  - attr(*, "class")= chr [1:2] "survfit.cox" "survfit"

surv_cxmod0 <- surv_summary(cxsf)
str(surv_cxmod0)
#> 'data.frame':    3444 obs. of  9 variables:
#>  $ time    : num  8 15 16 17 18 29 42 46 57 63 ...
#>  $ n.risk  : num  686 685 684 683 681 680 679 678 677 676 ...
#>  $ n.event : num  0 0 0 0 0 0 0 0 0 0 ...
#>  $ n.censor: num  1 1 1 2 1 1 1 1 1 1 ...
#>  $ surv    : num  1 1 1 1 1 1 1 1 1 1 ...
#>  $ std.err : num  0 0 0 0 0 0 0 0 0 0 ...
#>  $ upper   : logi  NA NA NA NA NA NA ...
#>  $ lower   : logi  NA NA NA NA NA NA ...
#>  $ strata  : Factor w/ 6 levels "a","b","c","d",..: 1 1 1 1 1 1 1 1 1 1 ...
#>  - attr(*, "table")='data.frame':    6 obs. of  7 variables:
#>   ..$ records   : num  686 686 686 686 686 686
#>   ..$ n.max     : num  686 686 686 686 686 686
#>   ..$ n.start   : num  686 686 686 686 686 686
#>   ..$ events    : num  299 299 299 299 299 299
#>   ..$ *rmean    : num  1671 1910 1617 1865 1507 ...
#>   ..$ *se(rmean): num  41.4 51.4 39.2 49.4 34.9 ...
#>   ..$ median    : num  1814 2456 1684 2372 1388 ...

@kassambara
Copy link
Owner

Thank you @HeidiSeibold for your contribution

@kassambara kassambara merged commit 831dfb4 into kassambara:master Aug 23, 2018
@HeidiSeibold
Copy link
Author

I am not sure how you do testing, but adding the above code to the tests might be a good idea. Thanks for the merge @kassambara :octocat:

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.

2 participants