kassambara / survminer

Survival Analysis and Visualization
https://rpkgs.datanovia.com/survminer/
495 stars 160 forks source link

Wrong p-value if subset is specified in the model #71

Closed jseoane closed 7 years ago

jseoane commented 7 years ago

The surv.diff p-value is not the same that the one reported in the plot when a subset is selected in the fitted survival model (i.e. surv.fit(Surv(time,event)~feature,data=data1,subset=feature2==TRUE) )

This is caused because you are getting the information for calculate p-value from the original data object in the function .get_pvalue, without checking if a subset was selected.

kassambara commented 7 years ago

Hi @jseoane ,

Thank you for pointing this out! The issue is now fixed.

Please install the latest version on Github and let me know if it's ok for you, so that we can close the issue.

if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/survminer", build_vignettes = FALSE)
library("survival")
library("survminer")
fit <- survfit(Surv(time, status)~sex, subset = ph.ecog==1, data = lung)
ggsurvplot(fit, risk.table = TRUE, pval = TRUE)

Best, /A