Professional Documents
Culture Documents
Creating Survival Plots
Creating Survival Plots
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
## [1] "survfit"
0.75 +
+ ++++
Global Schoenfeld Test p: 0.2656 ## Likelihood ratio test=31.6 on
+
++ ++ Schoenfeld Individual Test p: 0.1174 Schoenfeld Individual Test p: 0.7192 ## n= 227, number of events= 164
+
+++ ++ sex 0.57 <0.001 ***
library("survminer")
(N=228) (0.41 − 0.79)
w
www
w
+++ ++
0.50 + 0.3
3
ggsurvplot(fit, data = lung) +
● ●
+ ggforest(fit)
● ● ●
● ●
●● ● ● ●
●● ● ●
+++++
● ● ● ●●
● ● ●
● ● ● ●
0.2
● ● ●
●● ● ● ● ●
●
●
●● ● ● ●
● ● ● ● ● ●
● ● ●● ● ●
+++
● ● ● ● ● ●
2
● ● ●
● ● ●
+
● ● ● ●●
0.25
●●
● ● ●
● ●
●● ● ● ● ● ●
w
ww
●
0.1
● ● ● ● ● ● ●
● ●
+
● ● ●
●
1
● ● ●
● ●
ph.ecog 1.60 <0.001 ***
+++ +
● ● ● ● ●
●● ● ● ●
(N=228) (1.28 − 2.00)
● ●
● ● ●
++
● ● ● ●
● ●
0.0
● ●
●
● ● ● ● ●
0.00
● ● ●
● ● ●● ● ● ●● ●●
● ●
0
● ● ● ● ●
● ● ● ●
●
−0.1
● ● ●
● ●● ● ● ●
●
● ● ●
Time
●
● ● ● ● ●
● ● ● ●
−1
● ●
●
●
●● ●
−0.2
● ● ● ●
●● ●
Use the fun argument to set the transformation of the survival curve.
● ●●●● ● ●
●● ● ●
(N=228) (0.94 − 1.96)
−2
● ● ●● ● ● ● ● ●
● ● ●● ●●● ● ● ●● ● ● ●
● ●
● ●● ●● ●● ●
● ● ●● ●● ● ● ● ●●●
● ● ●
● ●● ● ● ● ● ● ● ● ● ● ●●●● ● ●
● ●
−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
n.events: 164, p.value.log: 6.4e−07 0.4 0.6 0.8 1 1.21.41.61.82
Time Time
hazard function or "pct" for survival probability in percentage. AIC: 1463.37, concordance: 0.64 Hazard ratio
ggsurvplot(fit, data = lung, fun = "event") The function ggadjustedcurves() from the survminer package plots
ggsurvplot(fit, data = lung, fun = "cumhaz")
The function ggcoxdiagnostics() plots different 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 differ 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")
●
Survival rate
++
++++++++++++ sex + age, data = lung)
● ●
strata(sex),
● ●
●
0.00 0
Group Cases
●
data = lung)
● ●
ggcoxadjustedcurves(fit, data=lung)
ox.scale = "linear.predictions")
● ●● ●
●
100 ●
++ −1 ●
0.00
ters you have full control over
●
pval = TRUE,
●
p = 0.0013 ++
●
Residuals (type = schoenfeld)
0 10
fun = "pct", ggcoxadjustedcurves(fit, data=lung, 0.75
● ●
●
Survival rate
● ●
Time 0
size = 1,
● ●
●
● ●
●
0.50
●
0
linetype = "strata",
●
● ●
+ + −0.5
●
palette = c("#E7B800",
● ● ●
●
● ●
●
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.4.0.999 CC BY Przemysław Biecek http://github.com/pbiecek
See https://github.com/kassambara/survminer/ for more details. https://creativecommons.org/licenses/by/4.0/