|
a |
|
b/Nomogram.R |
|
|
1 |
## Here are the simple examples for plotting nomogram, ROC curves, Calibration curves, and Decision curves |
|
|
2 |
## in training and test dataset by using R language. |
|
|
3 |
|
|
|
4 |
# Library and data |
|
|
5 |
library(rms) |
|
|
6 |
library(pROC) |
|
|
7 |
library(rmda) |
|
|
8 |
train <-read.csv("E:/Experiments/YinjunDong/nomogram/EGFR-nomogram.csv") |
|
|
9 |
test <-read.csv("E:/Experiments/YinjunDong/nomogram/EGFR-nomogram-test.csv") |
|
|
10 |
|
|
|
11 |
# Nomogram |
|
|
12 |
dd=datadist(train) |
|
|
13 |
options(datadist="dd") |
|
|
14 |
f1 <- lrm(EGFR~ Rad |
|
|
15 |
+Smoking |
|
|
16 |
+Type |
|
|
17 |
,data = train,x = TRUE,y = TRUE) |
|
|
18 |
|
|
|
19 |
nom <- nomogram(f1, fun=plogis,fun.at=c(.001, .01, seq(.1,.9, by=.4)), lp=F, funlabel="Risk") |
|
|
20 |
plot(nom) |
|
|
21 |
|
|
|
22 |
# ROC train |
|
|
23 |
f2 <- glm(EGFR~ Rad |
|
|
24 |
+Smoking |
|
|
25 |
+Type |
|
|
26 |
,data = train,family = "binomial") |
|
|
27 |
|
|
|
28 |
pre <- predict(f2, type='response') |
|
|
29 |
plot.roc(train$EGFR, pre, |
|
|
30 |
main="ROC Curve", percent=TRUE, |
|
|
31 |
print.auc=TRUE, |
|
|
32 |
ci=TRUE, ci.type="bars", |
|
|
33 |
of="thresholds", |
|
|
34 |
thresholds="best", |
|
|
35 |
print.thres="best", |
|
|
36 |
col="blue" |
|
|
37 |
#,identity=TRUE |
|
|
38 |
,legacy.axes=TRUE, |
|
|
39 |
print.auc.x=ifelse(50,50), |
|
|
40 |
print.auc.y=ifelse(50,50) |
|
|
41 |
) |
|
|
42 |
|
|
|
43 |
# ROC test |
|
|
44 |
pre1 <- predict(f2,newdata = test) |
|
|
45 |
plot.roc(test$EGFR, pre1, |
|
|
46 |
main="ROC Curve", percent=TRUE, |
|
|
47 |
print.auc=TRUE, |
|
|
48 |
ci=TRUE, ci.type="bars", |
|
|
49 |
of="thresholds", |
|
|
50 |
thresholds="best", |
|
|
51 |
print.thres="best", |
|
|
52 |
col="blue",legacy.axes=TRUE, |
|
|
53 |
print.auc.x=ifelse(50,50), |
|
|
54 |
print.auc.y=ifelse(50,50) |
|
|
55 |
) |
|
|
56 |
|
|
|
57 |
# Calibration Curve train |
|
|
58 |
rocplot1 <- roc(train$EGFR, pre) |
|
|
59 |
ci.auc(rocplot1) |
|
|
60 |
cal <- calibrate(f1, method = "boot", B = 1000) |
|
|
61 |
plot(cal, xlab = "Nomogram Predicted Survival", ylab = "Actual Survival",main = "Calibration Curve") |
|
|
62 |
|
|
|
63 |
# Calibration Curve test |
|
|
64 |
rocplot2 <- roc(test$EGFR,pre1) |
|
|
65 |
ci.auc(rocplot2) |
|
|
66 |
f3 <- lrm(test$EGFR ~ pre1,x = TRUE,y = TRUE) |
|
|
67 |
cal2 <- calibrate(f3, method = "boot", B = 1000) |
|
|
68 |
plot(cal2, xlab = "Nomogram Predicted Survival", ylab = "Actual Survival",main = "Calibration Curve") |
|
|
69 |
|
|
|
70 |
# Decision Curve train |
|
|
71 |
Rad<- decision_curve(EGFR~ |
|
|
72 |
Rad, data = train, family = binomial(link ='logit'), |
|
|
73 |
thresholds= seq(0,1, by = 0.01), |
|
|
74 |
confidence.intervals =0.95,study.design = 'case-control', |
|
|
75 |
population.prevalence = 0.3) |
|
|
76 |
|
|
|
77 |
Clinical<- decision_curve(EGFR~ |
|
|
78 |
Smoking+Type, data = train, family = binomial(link ='logit'), |
|
|
79 |
thresholds= seq(0,1, by = 0.01), |
|
|
80 |
confidence.intervals =0.95,study.design = 'case-control', |
|
|
81 |
population.prevalence = 0.3) |
|
|
82 |
|
|
|
83 |
clinical_Rad<- decision_curve(EGFR~ Rad |
|
|
84 |
+Smoking+Type, data = train, |
|
|
85 |
family = binomial(link ='logit'), thresholds = seq(0,1, by = 0.01), |
|
|
86 |
confidence.intervals= 0.95,study.design = 'case-control', |
|
|
87 |
population.prevalence= 0.3) |
|
|
88 |
|
|
|
89 |
List<- list(Clinical,Rad,clinical_Rad) |
|
|
90 |
plot_decision_curve(List,curve.names= c('Clinical','Rad-Score','Nomogram'), |
|
|
91 |
cost.benefit.axis =FALSE,col = c('green','red','blue'), |
|
|
92 |
confidence.intervals =FALSE,standardize = FALSE, |
|
|
93 |
#legend.position = "none" |
|
|
94 |
legend.position = "bottomleft" |
|
|
95 |
) |
|
|
96 |
|
|
|
97 |
# Decision Curve test |
|
|
98 |
Rad1<- decision_curve(EGFR~ |
|
|
99 |
Rad, data = test, family = binomial(link ='logit'), |
|
|
100 |
thresholds= seq(0,1, by = 0.01), |
|
|
101 |
confidence.intervals =0.95,study.design = 'case-control', |
|
|
102 |
population.prevalence = 0.3) |
|
|
103 |
|
|
|
104 |
Clinical1<- decision_curve(EGFR~ |
|
|
105 |
Smoking+Type, data = test, family = binomial(link ='logit'), |
|
|
106 |
thresholds= seq(0,1, by = 0.01), |
|
|
107 |
confidence.intervals =0.95,study.design = 'case-control', |
|
|
108 |
population.prevalence = 0.3) |
|
|
109 |
|
|
|
110 |
clinical_Rad1<- decision_curve(EGFR~ Rad |
|
|
111 |
+Smoking+Type, data = test, |
|
|
112 |
family = binomial(link ='logit'), thresholds = seq(0,1, by = 0.01), |
|
|
113 |
confidence.intervals= 0.95,study.design = 'case-control', |
|
|
114 |
population.prevalence= 0.3) |
|
|
115 |
|
|
|
116 |
List1<- list(Clinical1, Rad1, clinical_Rad1) |
|
|
117 |
plot_decision_curve(List1,curve.names= c('Clinical','Rad-Score','Nomogram'), |
|
|
118 |
cost.benefit.axis =FALSE,col = c('green','red','blue'), |
|
|
119 |
confidence.intervals =FALSE,standardize = FALSE, |
|
|
120 |
legend.position = "bottomleft") |