-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurvminer_model.R
84 lines (59 loc) · 2.36 KB
/
survminer_model.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
######################################
#
# 生存模型在退市股,ST股领域的应用
#
#######################################
library(patchwork)
library(survival)
library(tidyquant)
library(janitor)
library(tidyverse)
library(survminer)
BiocManager::install("RTCGA.clinical") # data for examples
library(survminer)
library(RTCGA.clinical)
survivalTCGA(BRCA.clinical, OV.clinical,
extract.cols = "admin.disease_code") -> BRCAOV.survInfo
library(survival)
fit <- survfit(Surv(times, patient.vital_status) ~ admin.disease_code,
data = BRCAOV.survInfo)
# Visualize with survminer
ggsurvplot(fit, data = BRCAOV.survInfo, risk.table = TRUE)
ggsurvplot(
fit, # survfit object with calculated statistics.
data = BRCAOV.survInfo, # data used to fit survival curves.
risk.table = TRUE, # show risk table.
pval = TRUE, # show p-value of log-rank test.
conf.int = TRUE, # show confidence intervals for
# point estimaes of survival curves.
xlim = c(0,2000), # present narrower X axis, but not affect
# survival estimates.
break.time.by = 500, # break X axis in time intervals by 500.
ggtheme = theme_minimal(), # customize plot and risk table with a theme.
risk.table.y.text.col = T, # colour risk table text annotations.
risk.table.y.text = FALSE # show bars instead of names in text annotations
# in legend of risk table
)
head(lung)
library("survival")
data("lung")
fit <- survfit(Surv(time, status) ~ sex, data = lung)
###Log-rank (survdiff)
ggsurvplot(fit, data = lung, pval = TRUE, pval.method = TRUE)
###log-rank(comp)
ggsurvplot(fit, data = lung, pval = TRUE, pval.method = TRUE,
log.rank.weights = "1")
###Gehan-Breslow (generalized Wilcoxon)
ggsurvplot(fit, data = lung, pval = TRUE, pval.method = TRUE,
log.rank.weights = "n", pval.method.coord = c(5, 0.1),
pval.method.size = 3)
########Compute a Cox model interaction
res.cox <- coxph(Surv(time, status) ~ ph.karno * age, data=lung)
summary(res.cox, conf.int = FALSE)
#######Visualization of the hazard ratios using the function ggforest().
ggforest(res.cox, data = lung)
head(lung)
lung$ph.karno_age <- lung$ph.karno * lung$age
res.cox2 <- coxph(Surv(time, status) ~ ph.karno + age + ph.karno_age, data = lung)
summary(res.cox2 , conf.int = FALSE)
ggforest(res.cox2, data=lung)