Professional Documents
Culture Documents
Survminer PDF
Survminer PDF
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
● ● ●
●● ● ● ● ●
●
●
●● ● ● ●
● ● ● ● ● ●
● ● ●● ● ●
+++
● ● ● ● ● ●
2
● ● ●
● ● ●
+
● ● ● ●●
0.25
●●
● ● ●
● ●
●● ● ● ● ● ●
w
ww
●
0.1
● ● ● ● ● ● ●
● ●
+
● ● ●
1
● ● ●
● ●
+++ +
● ● ● ● ●
●● ● ● ● ●
ph.ecog
● ● ● ●
++
● ● ● ●
● ● ●
0.0
● ●
●
● ● ● ● ●
0.00
● ● ●
● ● ●● ● ● ●● ●●
● ●
0
● ● ● ● ●
● ● ● ●
●
−0.1
● ● ●
● ●● ● ● ●
●
● ● ●
Time
●
● ● ● ● ●
● ● ● ●
−1
● ●
●
−0.2
● ●
age>70
● ●
●● ●
● ● ●
●●● ● ●
●
Use the fun argument to set the transformation of the survival curve.
● ●●●● ● ●
●● ● ●
−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 10−0.4 10−0.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 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)
● ●
data = lung)
● ●
●
0.00 0
Group Cases
●
● ●
variable=lung$sex)
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.3. 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/