imbs-hl / survivalsvm

Survival Support Vector Analysis
16 stars 8 forks source link

prediction should warn if/which rows are removed #7

Open fdeloscogna opened 2 years ago

fdeloscogna commented 2 years ago

see: https://github.com/imbs-hl/survivalsvm/blob/d0eec0d49f99de6cea8fe8fd8c9de6ba7c153bff/R/predictions.R#L133

library(survival)
library(survivalsvm)

set.seed(123)
n <- nrow(veteran)

train.index <- sample(seq_len(n), 0.7*n, replace = FALSE)
test.index <- setdiff(seq_len(n), train.index)

train <- veteran[train.index, , drop = FALSE]
test <- veteran[test.index, , drop = FALSE]

test[1, "karno"] <- NA_real_

survsvm.reg <- survivalsvm(
  Surv(diagtime, status) ~ .,
  data = train,
  type = "regression",
  gamma.mu = 1,
  opt.meth = "quadprog",
  kernel = "add_kernel"
)

pred.survsvm.reg <- predict(
  object = survsvm.reg,
  newdata = test
)

conindex(
  pred.survsvm.reg,
  Surv(test$diagtime, test$status)
)
#> Error in conindex(pred.survsvm.reg, Surv(test$diagtime, test$status)): Error: lengths do not macht.

complete_rows <- complete.cases(test)
conindex(
  pred.survsvm.reg,
  Surv(
    test$diagtime[complete_rows],
    test$status[complete_rows]
  )
)
#>   C Index 
#> 0.7109905

Created on 2022-04-27 by the reprex package (v2.0.1)

Session info ``` r sessioninfo::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 4.1.2 (2021-11-01) #> os Windows 10 x64 (build 19044) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate Italian_Italy.1252 #> ctype Italian_Italy.1252 #> tz Europe/Berlin #> date 2022-04-27 #> pandoc 2.14.0.3 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown) #> #> - Packages ------------------------------------------------------------------- #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.2) #> backports 1.4.1 2021-12-13 [1] CRAN (R 4.1.2) #> base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.1.1) #> checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.1.2) #> cli 3.1.1 2022-01-20 [1] CRAN (R 4.1.2) #> cluster 2.1.2 2021-04-17 [2] CRAN (R 4.1.2) #> colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.2) #> crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.2) #> data.table 1.14.2 2021-09-27 [1] CRAN (R 4.1.2) #> DBI 1.1.2 2021-12-20 [1] CRAN (R 4.1.2) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.2) #> dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.1.2) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.2) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.2) #> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.1.2) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.2) #> foreign 0.8-81 2020-12-22 [2] CRAN (R 4.1.2) #> Formula 1.2-4 2020-10-16 [1] CRAN (R 4.1.1) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.2) #> generics 0.1.2 2022-01-31 [1] CRAN (R 4.1.2) #> ggplot2 3.3.5 2021-06-25 [1] CRAN (R 4.1.2) #> glue 1.6.1 2022-01-22 [1] CRAN (R 4.1.2) #> gridExtra 2.3 2017-09-09 [1] CRAN (R 4.1.2) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.2) #> highr 0.9 2021-04-16 [1] CRAN (R 4.1.2) #> Hmisc 4.6-0 2021-10-07 [1] CRAN (R 4.1.2) #> htmlTable 2.4.0 2022-01-04 [1] CRAN (R 4.1.2) #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.2) #> htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.1.2) #> jpeg 0.1-9 2021-07-24 [1] CRAN (R 4.1.1) #> knitr 1.37 2021-12-16 [1] CRAN (R 4.1.2) #> lattice 0.20-45 2021-09-22 [2] CRAN (R 4.1.2) #> latticeExtra 0.6-29 2019-12-19 [1] CRAN (R 4.1.2) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.2) #> magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.1.2) #> Matrix 1.3-4 2021-06-01 [2] CRAN (R 4.1.2) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.2) #> nnet 7.3-16 2021-05-03 [2] CRAN (R 4.1.2) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.1.2) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.2) #> png 0.1-7 2013-12-03 [1] CRAN (R 4.1.1) #> pracma 2.3.6 2021-12-07 [1] CRAN (R 4.1.2) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.2) #> quadprog 1.5-8 2019-11-20 [1] CRAN (R 4.1.1) #> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.1.3) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.1.3) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.2) #> RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.1.1) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.3) #> rlang 1.0.1 2022-02-03 [1] CRAN (R 4.1.2) #> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.2) #> rpart 4.1-15 2019-04-12 [2] CRAN (R 4.1.2) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.2) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.2) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.2) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.2) #> styler 1.7.0 2022-03-13 [1] CRAN (R 4.1.3) #> survival * 3.2-13 2021-08-24 [2] CRAN (R 4.1.2) #> survivalsvm * 0.0.5 2018-02-05 [1] CRAN (R 4.1.2) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.2) #> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.2) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.2) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.2) #> withr 2.4.3 2021-11-30 [1] CRAN (R 4.1.2) #> xfun 0.29 2021-12-14 [1] CRAN (R 4.1.2) #> yaml 2.2.2 2022-01-25 [1] CRAN (R 4.1.2) #> #> [1] C:/Users/FedericoScognamiglio/OneDrive - Unit of Biostatistics Epidemiology and Public Health/Documenti/R/win-library/4.1 #> [2] C:/Program Files/R/R-4.1.2/library #> #> ------------------------------------------------------------------------------ ```