Sunteți pe pagina 1din 1

Creating Survival Plots Diagnostics of Cox Model Summary of Cox Model

Informative and Elegant The function cox.zph() from survival package may be used to test the
proportional hazards assumption for a Cox regression model fit. The
The function ggforest() from the survminer package creates a forest plot
for a Cox regression model fit. Hazard ratio estimates along with confiden-

with survminer graphical verification of this assumption may be performed with the
function ggcoxzph() from the survminer package. For each covariate it
ce intervals and p-values are plotter for each variable.
library("survival")
produces plots with scaled Schoenfeld residuals against the time. library("survminer")
lung$age <- ifelse(lung$age > 70, ">70","<= 70")

w
www
ww
library("survival")
Survival Curves fit <- coxph(Surv(time,
ftest <- cox.zph(fit)
status) ~ sex + age, data = lung)
fit <- coxph( Surv(time, status) ~ sex + ph.ecog + age, data = lung)
fit
ftest . ## Call:
The ggsurvplot() function creates ggplot2 plots from survfit objects. ## rho chisq p ## coxph(formula = Surv(time, status) ~ sex+ph.ecog+age, data=lung)
## sex 0.1236 2.452 0.117 ##
Strata + sex=1 + sex=2 ## age -0.0275 0.129 0.719

w
www
library("survival")

ww
## coef exp(coef) se(coef) z p
fit <- survfit(Surv(time,status) ## GLOBAL NA 2.651 0.266 ## sex -0.567 0.567 0.168 -3.37 0.00075
~ sex, data = lung) 1.00 library("survminer") ## ph.ecog 0.470 1.600 0.113 4.16 3.1e-05
++ ggcoxzph(ftest) ## age>70 0.307 1.359 0.187 1.64 0.10175

w
ww
++
class(fit) ++++ ##
Survival probability

0.75 + Global Schoenfeld Test p: 0.2656 Forest plot for coxph model
## [1] "survfit" + ++++ + ## Likelihood ratio test=31.6 on
++ ++ Schoenfeld Individual Test p: 0.1174 Schoenfeld Individual Test p: 0.7192 ## n= 227, number of events= 164
+
+++ ++
library("survminer")

w
www
w
+++ ++
0.50 + 0.3
3 0.57 (p.value 0.00075***)
sex
ggsurvplot(fit, data = lung) +

+ ggforest(fit)





+++++


0.2






+++

0.25



w
ww

0.1

Beta(t) for age


Beta(t) for sex




1.6 (p.value 0.000031***)


+++ +

ph.ecog

++


0.0


0.00


0 250 500 750 1000



0.1



Time


1.4 (p.value 0.1)



0.2

age>70




Use the fun argument to set the transformation of the survival curve.

0.3





E.g. "event" for cumulative events, "cumhaz" for the cumulative 55 130 180 270 340 430 560 730 55 130 180 270 340 430 560 730 100.4 100.2 100 100.2
Time Time
hazard function or "pct" for survival probability in percentage. Hazard ratio

ggsurvplot(fit, data = lung, fun = "event") The function ggcoxadjustedcurves() from the survminer package plots
ggsurvplot(fit, data = lung, fun = "cumhaz")
The function ggcoxdiagnostics() plots dierent types of residuals as a
Adjusted Survival Curves for Cox Proportional Hazards Model. Adjusted

w
wwww
function of time, linear predictor or observation id. The type of residual is
Survival Curves show how a selected factor influences survival estimated
+ + Strata + sex=1 + sex=2 selected with type argument. Possible values are "martingale",. "devian-
Strata sex=1 sex=2
from a Cox model.
ce", "score", "schoenfeld", "dfbeta"', "dfbetas", and "scaledsch".
1.00
++ ++ Note that these curves dier from Kaplan Meier estimates since they
+++ + The ox.scale argument defines what shall be plotted on the OX axis.
+ 3 + present expected ssurvival based on given Cox model.
+ + Possible values are "linear.predictions", "observation.id", "time".
0.75
+++ + + library("survival")
Cumulative hazard

Logical arguments hline and sline may be used to add horizontal line or variable Male Female
Cumulative event

+++++ +
library("survminer")
+ + 2 smooth line to the plot.
+++ 1.00
0.50 ++ ++ residuals
lung$sex <- ifelse(lung$sex == 1,
++ ++ + library("survival")
++ ++ +++ "Male", "Female")

+ ++++ + +++ library("survminer") 2


+++
1 0.75
+
0.25 ++++ +++ fit <- coxph(Surv(time, status) ~ fit <- coxph(Surv(time, status) ~
++ +++ ++++

Survival rate
++
++++++++++++ sex + age, data = lung)

sex + ph.ecog + age,

Residuals (type = deviance)


++ + 1
++ +
0.50

data = lung)

0.00 0

Group Cases

0 250 500 750 1000 0 250 500 750 1000


ggcoxdiagnostics(fit, ggcoxadjustedcurves(fit, data=lung,
Time Time 0 0.25
type = "deviance",

variable=lung$sex)
ox.scale = "linear.predictions")

With lots of graphical parame-


100

++ 1
0.00
ters you have full control over

++ 0 250 500 750 1000



Survival probability (%)

look and feel of the survival ++++ ggcoxdiagnostics(fit, time


75 +
+ ++++ + type = "schoenfeld", 2
Note that it is not necessary to include the grouping factor in the Cox

plots; position and content of ++ ++ ox.scale = "time") 2 1 0 1 2 3


+
+++ ++ Linear Predictions
model. Survival curves are estimated from Cox model for each group
the legend; additional annota- 50 +++ ++
+
tions like p-value, title, subtitle. + +
+++++ age ecog.ps rx defined by the factor independently. variable (35,55] (55,65] (65,85]
1.0
+++
ggsurvplot(fit, data = lung, 25 + 20
lung$age3 <- cut(lung$age, 1.00
1
conf.int = TRUE, + 0.5 c(35,55,65,85))
+++ +

pval = TRUE,

p = 0.0013 ++

Residuals (type = schoenfeld)

0 10
fun = "pct", ggcoxadjustedcurves(fit, data=lung, 0.75

risk.table = TRUE, 0 250 500 750 1000 0.0


variable=lung$age3)



Survival rate

Time 0
size = 1,



0.50

0
linetype = "strata",

+ + 0.5

Sex Male Female

palette = c("#E7B800",



"#2E9FDF"), Number at risk


0.25
10 1 1.0
legend = "bottom",
Male 138 62 20 7 2
legend.title = "Sex",
Sex

Female 90 53 21 3 0
legend.labs = c("Male",

1.5 0.00
0 250 500 750 1000
"Female")) 200 400 600 200 400 600 200 400 600 0 250 500 750 1000
Time Time time

This onepager presents the survminer package [Alboukadel Kassambara, Marcin Kosinski 2017] in version 0.3. CC BY Przemysaw Biecek http://github.com/pbiecek
See https://github.com/kassambara/survminer/ for more details. https://creativecommons.org/licenses/by/4.0/

S-ar putea să vă placă și